d0k3 / GodMode9

GodMode9 Explorer - A full access file browser for the Nintendo 3DS console :godmode:
GNU General Public License v3.0
2.12k stars 191 forks source link

DSiWare titles will not encrypt in buildcia script or re-encrypt. #478

Closed TurdPooCharger closed 5 years ago

TurdPooCharger commented 5 years ago

This example was done in GodMode9 v1.8.0.

  1. Hold (R)-shoulder and press (A) on [2:] SYSNAND TWLNSearch for titles.
  2. While in the [Z:] LAST SEARCH drive, press (A) on DS Download Play (NTR-HNDA).tmd.
  3. TMD file options...Build CIA (legit).
  4. Go to [0:] SDCARD ( )/gm9/out/
  5. Press (A) on DS Download Play (NTR-HNDA).legit.ciaCIA image options...CIA checker tool.

As expected for an intact TWL system title, the status is:


Continuing...

  1. CIA image options...Decrypt file (0:/gm9/out)
  2. CIA image options...CIA checker tool

The status is now:


No problem. Let's try re-encrypting the .cia.

  1. CIA image options...Encrypt file (0:/gm9/out)
  2. CIA image options...CIA checker tool

However, the status stays as:


When using gm9 script encrypt function on a decrypted DSiWare .cia, the output file stays decrypted.

d0k3 commented 5 years ago

You think the TMD becomes legit again from reencrypting? By doing any crypto stuff there, you change the TMD, thus it is no more legit.

Maybe there's something we can do about it, in that case. Can you do a hex comparison of the two TMDs? The legit one and the illegit one. Or, upload them somewhere for me to have a look at.

TurdPooCharger commented 5 years ago

Late reply. I needed time to reexamine what was observed. From what I gathered, the legit status of the .tmd is a separate issue of whether a .cia file is encrypted or decrypted, yes?

  1. Below are the hex views of several DS Download Play .cia files.
  2. Offset 0x3900 is where the header.bin is located in the .cia.

DSiWare comparison


Encrypted

Method A

Seen on the left, this is produced when using:


Decrypted

Seen on the right, these are the outputs when using:

Method B

On the DS Download Play (NTR-HNDA).legit.cia that was made from Method A,

This is expected.

Method C

Producing standard built .cia.

This is also expected.

Method D

Using this gm9 script code with the "--legit" flag, this does not produce a legit version.

The output is DS Download Play (NTR-HNDA).cia.

I'm not sure if the legit flag was meant to only be used for CTRNAND system titles.

Method E

Using this script code on the .cia file made from Method D,

the SHA-256 hash stays the same for the file.

Method F

Doing this on the same file from Method E,

the SHA-256 hash still stays the same.

d0k3 commented 5 years ago

@TurdPooCharger - I think I found the problem... can you try this test build, please? https://f.secretalgorithm.com/RTSZP/godmode9.firm

TurdPooCharger commented 5 years ago

Sorry, late reply. That build introduces a new bug. When doing Search for titles, it no longer lists the .tmd in [Title ID] [Name] [Product Code] [Region] format. I'll continue with DSiWare (en/de)cryption testing depending if you want to move forward past this.

snap_000212180031

d0k3 commented 5 years ago

Oh well... fix one thing, break two things... Gimme a few minutes with that...

d0k3 commented 5 years ago

@TurdPooCharger - can you try this one? https://f.secretalgorithm.com/8h9Mn/godmode9.firm

TurdPooCharger commented 5 years ago

GodMode9 v1.8.0-46-g2bdcdf8b - Results for DS Download Play.

Method A: :+1: , CIA is built with legit ticket and is encrypted. Method B: :+1: , (A copy of the) CIA from Method A keeps its legit ticket and is decrypted. Method C: :+1: , CIA is built with nonlegit ticket and is decrypted. Method D: :+1: , CIA built through script with -l flag matches hash with the CIA from method A.

Method E: :-1: , (A copy of the) CIA from Method C does not re-encrypt with script's encrypt function. Method F: :-1: , The CIA from Method E does not re-encrypt when using Encrypt file (0:/gm9/out) on it. The hash stays the same.


Other observations.

  1. When editing the file names, the character scroll bar disappears the moment you let off pressing the (UP/DOWN) d-pad.

  2. Pressing the (HOME) button, the Testing... option feels out of place. It should go in-between Payloads... and More... as More... option seems more of natural fit being placed at the end.

d0k3 commented 5 years ago

Okay, I'll look into E&F. Testing stuff is, you may have guessed it, just temporary. Pretty sure you already gave the swkbd a try by now, so I'd be interested in your opinion on it.

I'll also look into the character scroll bar thing.

TurdPooCharger commented 5 years ago
d0k3 commented 5 years ago

Alright, I fixed the character scroll bar, and fill should now work with the -n flag. Permission system will also be fixed. (EDIT: permission system is fixed) Some stuff needs clarification.

Paint9: Well, suggest an actual palette. I may include it. I know the picker tool is not perfect.

Software keyboard: I'm using it on a small N3DS, and it's pixel based (not width based). It takes up the same amount of (relative) screen estate on every console. Using it on the small N3DS it takes a little time to get used to, but I think it works. You should have a lot more room on that big screen of yours.

buildcia -l should always include the legit ticket when building a CIA from a TMD, regardless of from where that CIA is built. Is there any case where you don't get a legit ticket with it?

As for that:

Method E: 👎 , (A copy of the) CIA from Method C does not re-encrypt with script's encrypt function. Method F: 👎 , The CIA from Method E does not re-encrypt when using Encrypt file (0:/gm9/out) on it.

Well... depends on what you want if you encrypt a CIA. We don't do the CIA/titlekey encryption, cause, frankly, no one will likely want that on a already decrypted CIA. We only (NCCH-)encrypt the contents within. The purpose of encryption is not to make it legit again.

Did I forget about something?

TurdPooCharger commented 5 years ago

On that v1.8.0-46-g2bdcdf8b build,

I have mock-up ideas of a full width keyboard and color palette for Paint9, but the screenshot bug prevented getting image templates.