From 063c2976760ca5081936c1ea97848b051856ae7c Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 27 Apr 2016 07:41:31 -0400 Subject: [PATCH] Some cleanup --- FontTool.py | 17 +++++++++++++++++ README.md | 15 +++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/FontTool.py b/FontTool.py index 56b9adf..8bd0e64 100755 --- a/FontTool.py +++ b/FontTool.py @@ -26,6 +26,7 @@ xor = args.xor docleanup = args.nocleanup +#Run a command and print the command running in case there's a failure def runCmd(cmd): process = subprocess.Popen(cmd) process.wait() @@ -34,6 +35,7 @@ def runCmd(cmd): print(cmd) sys.exit(1) +#Clenup if docleanup is true (which it is by default) def clean(): if docleanup: os.remove("romfs/cbf_std.bcfnt.lz") @@ -42,27 +44,38 @@ def clean(): os.remove("romfs-mod.bin") sys.exit(1) +#If output is not specified, use the fontFile's name if output is None: output = os.path.splitext(fontFile)[0] +#Check for the existence of fontFile if not os.path.exists(fontFile): print("Font file does not exist!") sys.exit(1) +#Warning print("Your warranty ends here! Make backups of your NAND before you install this!") +#Try to create romfs folder try: os.makedirs("romfs") except OSError: if not os.path.isdir("romfs"): raise + +#Compress the font file using lz compressiong runCmd(["3dstool", "-zvf", "%s" % fontFile, "--compress-type", "lzex", "--compress-out", "romfs/cbf_std.bcfnt.lz"]) +#Build a modified romfs runCmd(["3dstool", "-cvtf", "romfs", "romfs-mod.bin", "--romfs-dir", "romfs"]) +#Build a cfa file using the modified romfs and ncchheader cmds = ["3dstool", "-cvtf", "cfa", "%s.cfa" % output, "--header", "ncchheader.bin", "--romfs", "romfs-mod.bin"] if xor: print('xor romfs') + #Add xorpad encryption if xor is enabled cmds.extend(["--romfs-xor", "0004009B00014002.Main.romfs.xorpad"]) runCmd(cmds) + +#Make cfa file the proper size with open("%s.cfa" % output, "r+b") as fontcfa: if xor: fontcfa.seek(0x18F) @@ -75,6 +88,8 @@ def clean(): romfssize = binascii.unhexlify(romfssize)[::-1] fontcfa.seek(0x1B4) fontcfa.write(romfssize) + +#Warn user before overwriting file if os.path.exists("%s.cia" % output) and not force: uinput = raw_input("Warning! Output CIA already exists! Continue? (y/n): ") if (uinput == "n"): @@ -86,7 +101,9 @@ def clean(): print("Aborting due to invalid input") clean() +#Make the CIA runCmd(["make_cia", "-v", "-o", "%s.cia" % output, "--content0=%s.cfa" % output, "--index_0=0"]) if not xor: print("Encrypt NCCH using Decrypt9 before installing or it won't work!") +#Clean stuff up clean() diff --git a/README.md b/README.md index 80446a0..db7a546 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,24 @@ Encrypt the NCCH either using xorpad mode or by encrypting it in D9 using the En **Back up your NAND before installing this! If something goes wrong you'll be bricked** -It's also kind of a pain to remove. - It can then be installed using any CIA manager ## Usage See `FontTool.py -h` +## Examples +Build a CIA without xorpads and with the default output file (you'll have to encrypt NCCH): + +```FontTool.py -font .bcfnt``` + +Build a CIA with xorpads and a custom output file (no need to encrypt NCCH): + +```FontTool.py -font .bcfnt -xor -custom ``` + +Build a CIA and don't cleanup files after: + +```FontTool.py -font .bcfnt -nocleanup``` + ## License / Credits * `FontTool.py` is under the MIT license. * All other tools (make_cia, ctrtool, and 3dstool) are under their respective licenses