Skip to content

Commit

Permalink
change around a few messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ihaveamac committed Aug 13, 2016
1 parent ba24790 commit 00a95c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions 3dsconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,6 +55,7 @@
\"<TITLEID>.Main.exheader.xorpad\"
XORpads should be in {} or the directory specified by --xorpads=<dir>
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),
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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 = ""
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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 `<TITLEID>.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 `<TITLEID>.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.

Expand Down

0 comments on commit 00a95c3

Please sign in to comment.