From 00a95c3a130c0a1f297730862d7758134ab9872f Mon Sep 17 00:00:00 2001 From: ihaveamac Date: Fri, 12 Aug 2016 18:14:19 -0700 Subject: [PATCH] change around a few messages --- 3dsconv.py | 21 ++++++++++----------- README.md | 2 +- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/3dsconv.py b/3dsconv.py index 20963b0..218a2b0 100755 --- a/3dsconv.py +++ b/3dsconv.py @@ -15,13 +15,14 @@ import sys import zlib +# check for PyCrypto, which is used for zerokey support pycrypto_found = False try: from Crypto.Cipher import AES from Crypto.Util import Counter pycrypto_found = True except ImportError: - pass + pass # this is handled later # default directories (relative to current dir unless you use absolute paths) # leave as "" for current working directory @@ -54,6 +55,7 @@ \".Main.exheader.xorpad\" XORpads should be in {} or the directory specified by --xorpads= XORpads are generated by using ncchinfo.bin with Decrypt9 on a 3DS system +- zerokey encryption is supported with PyCrypto - encrypted and decrypted roms can be converted at the same time""".format( version, "current directory" if xorpad_directory == "" else "'{}'".format(xorpad_directory), @@ -64,6 +66,7 @@ # includes certificate chain, ticket (blank titlekey and title id), and tmd signature + blank header (blank title id) # + blank content info records # compressed using zlib then encoded with base64 +# I should find a better way to store this... this is so ugly ciainfo = """eJztlWlQk0kagAmGOE4IIglyn2KMSIhAmKiggCByDTcIBBGJQDgikUMODXI6EUVAOcONJgoEUKIc K6ighCCHYDhEjsWAQLgSBWFUjnEWf03V7pSwNfNj9+l6u7q66u1+q/vp7xMACGwhGhzgPaov9M0k 9QM0CbKpziYW5KLLMim3xJwiJkQWd0U2iYhqDh4cmqSk35107vPNpE2M+gqvaqvdvSkUg16L1WvV @@ -225,8 +228,8 @@ def showprogress(val, maxval): decrypted = int(binascii.hexlify(romf.read(1))) & 0x04 zerokey_enc = int(binascii.hexlify(romf.read(1))) & 0x01 print("- processing: {} ({})".format( - rom[1], "decrypted" if decrypted else ("zerokey" if zerokey_enc else "encrypted")) - ) + rom[1], "decrypted" if decrypted else ("zerokey" if zerokey_enc else "encrypted") + )) if noconvert: print("- not converting {} ({}) because --noconvert was used".format( rom[1], "decrypted" if decrypted else "encrypted" @@ -252,14 +255,13 @@ def showprogress(val, maxval): exh = romf.read(0x400) xor = "" if not decrypted: - print_v("- decrypting ExHeader") if zerokey_enc: - print_v("- using zerokey") + print_v("- decrypting ExHeader, using zerokey") ctr = Counter.new(128, initial_value=long(tid + "0100000000000000", 16)) ctrmode = AES.new(zerokey, AES.MODE_CTR, counter=ctr) exh = ctrmode.decrypt(exh) else: - print_v("- using XORpad") + print_v("- decrypting ExHeader, using XORpad") with open(xorpad, "rb") as xorfile: xor = xorfile.read(0x400) xored = "" @@ -308,22 +310,19 @@ def showprogress(val, maxval): x |= 2 print_v(" shifted: {}".format(hex(x))) exh_list[0xD:0xE] = chr(x) - # there really has to be a better way to do this... - # savesize = str(int(binascii.hexlify(exh[0x1C0:0x1C8][::-1]), 16) / 1024) exh = "".join(exh_list) savesize = exh[0x1C0:0x1C4] new_exh_hash = hashlib.sha256("".join(exh)).digest() if not decrypted: - print_v("- re-encrypting ExHeader") if zerokey_enc: - print_v("- using zerokey") + print_v("- re-encrypting ExHeader, using zerokey") ctr = Counter.new(128, initial_value=long(tid + "0100000000000000", 16)) ctrmode = AES.new(zerokey, AES.MODE_CTR, counter=ctr) exh = ctrmode.encrypt(exh) pass else: - print_v("- using XORpad") + print_v("- re-encrypting ExHeader, using XORpad") xored = "" for byte_f, byte_x in zip(exh_list, xor): xored += chr(ord(byte_f) ^ ord(byte_x)) diff --git a/README.md b/README.md index aa08fd7..7dda797 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # 3dsconv `3dsconv.py` is a Python 2.7 script that converts Nintendo 3DS CTR Cart Image files (CCI, ".cci", ".3ds") to the CTR Importable Archive format (CIA). -3dsconv can detect if a CCI is decrypted or encrypted. Decrypted is preferred and does not require any extra files. Encrypted requires Extended Header (ExHeader) XORpads, with the filename `.Main.exheader.xorpad`. +3dsconv can detect if a CCI is decrypted or encrypted, or zerokey-encrypted. Decrypted is preferred and does not require any extra files. Encrypted requires Extended Header (ExHeader) XORpads, with the filename `.Main.exheader.xorpad`. Zerokey encryption works only if [PyCrypto](https://www.dlitz.net/software/pycrypto/) is installed (can be installed with pip). This does not work with Python 3.