Skip to content

Commit

Permalink
Some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Apr 27, 2016
1 parent 39ac7ef commit 063c297
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
17 changes: 17 additions & 0 deletions FontTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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"):
Expand All @@ -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()
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <FILE>.bcfnt```

Build a CIA with xorpads and a custom output file (no need to encrypt NCCH):

```FontTool.py -font <FILE>.bcfnt -xor -custom <OUTPUT>```

Build a CIA and don't cleanup files after:

```FontTool.py -font <FILE>.bcfnt -nocleanup```

## License / Credits
* `FontTool.py` is under the MIT license.
* All other tools (make_cia, ctrtool, and 3dstool) are under their respective licenses
Expand Down

0 comments on commit 063c297

Please sign in to comment.