Last active
July 24, 2018 03:37
-
-
Save SocraticBliss/e910c37a1f26ff66c21d0b3ffab5f7ae to your computer and use it in GitHub Desktop.
A badly written way to patch your FS!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from shutil import copyfile | |
from os import path | |
from subprocess import call | |
import hashlib | |
import sys | |
PATCHES = { | |
'FS-1.0.0-normal.vcdiff':'F01DAD47CC0561440246820AF7A60A0E49F91A64FB3528CEF5C3D0B8A9579C87', | |
'FS-1.0.0-exfat.vcdiff':'D723935EF9D4DFE4E145E8AA2CF0238A497B2978FDBF0BD01CABF695A285CE84', | |
'FS-2.0.0-normal.vcdiff':'002EB1C935A4E928054B1FB555C3DA2D40461A106061F506D1EB61F86B774244', | |
'FS-2.0.0-exfat.vcdiff':'10B3BE1FE407A02962FA703DD0B3B225743E944ACA6386570B7929C7328C4065', | |
'FS-2.1.0-normal.vcdiff':'2659407A406475B4D8B765F0784717F16654383837B57D69DF480D6192CED299', | |
'FS-2.1.0-exfat.vcdiff':'28EAD4171B3945DDFCBCE3664B37DC65C48BDFF05D7CAC4A63A400110F618940', | |
'FS-3.0.0-normal.vcdiff':'1E87AE33DCD6B34DCC0DA43B97E4F05AD1ED8667CD2DD63064F3C2D11BD18E62', | |
'FS-3.0.0-exfat.vcdiff':'6E39DB6B50BE028F90585112FB013A742082F45E1DA2C2D8E4E58F8CF56A4E4A', | |
'FS-3.0.1-normal.vcdiff':'FA1318DBEF75400C102174064EEA71B6A6C4CD82E41170D6B0E75405FD144584', | |
'FS-3.0.1-exfat.vcdiff':'3F1298D44642DD242D225B1895FF2F46FE9083A4119E7AFC364FD138B8DFAE5B', | |
'FS-4.0.1-normal.vcdiff':'E1B92409A6D912C6E8C5E7945420082AEEEBD6C6326B551B6455046463A5D9E2', | |
'FS-4.0.1-exfat.vcdiff':'DBCFFB6817C3E6BF04FC2BD4E97F790A5AADE7B7FEB90AFF094646A4A6BEC72B', | |
'FS-4.1.0-normal.vcdiff':'3F9A64748DE8CB294F305229ABE999DFD9DF0082AD1B296A02E069E78E65ABAE', | |
'FS-4.1.0-exfat.vcdiff':'CDA7BE099159815E5C6BE16120A909001DE1FA56A1E7817419C337B26C3827A5', | |
'FS-5.0.0-normal.vcdiff':'7C32E78E598373DA38CB625514BC629EC8079E3721F38E789B4137B7C5759DDA', | |
'FS-5.0.0-exfat.vcdiff':'13E9A75641BE8F0A2CEBB711DDF937E3507008D489E4B98E197415BC483B9B39', | |
'FS-5.1.0-normal.vcdiff':'E712577B7B472B25F4AF1F0360FFC5BEDF281F40C70294C21347ECF14666E158', | |
'FS-5.1.0-exfat.vcdiff':'6D14F2D93FEDDB61EB3F778FA0D5B289DC090234FB574CD853A5D39BE2D5214D' | |
} | |
def error(message): | |
print('\nError: ' + message) | |
sys.exit(1) | |
def check_files(files): | |
existing = [file for file in files if path.isfile(file)] | |
missing = list(set(existing) ^ set(files)) | |
return missing | |
def main(argc, argv): | |
if argc != 1: | |
print('') | |
print('FSPatch.py: a badly written way to patch your FS by SocraticBliss!') | |
print('Thanks to rajkosto for biskeydump, HacDiskMount and hashes/improvements') | |
print('') | |
print('Usage: %s FSPatch.py' % argv[0]) | |
sys.exit(1) | |
print('') | |
print('rajkosto\'s instructions located at https://pastebin.com/hXs4VCgs') | |
print('') | |
print('Place the following dependency files in your Current Directory:') | |
print('1. hactool.exe (https://github.com/SciresM/hactool/releases/download/1.1.0/hactool-1.1.0.win.zip)') | |
print('2. BCPKG2-1-Normal-Main.bin') | |
print('3. FS-X.X.X-type.vcdiff patch') | |
print('4. kip1decomp.exe') | |
print('5. xdelta3.exe (https://sourceforge.net/projects/xdelta3-gui/files/latest/download)') | |
print('') | |
print('Checking for dependency binaries/executables...') | |
BINARIES = ['hactool.exe','BCPKG2-1-Normal-Main.bin','kip1decomp.exe','xdelta3.exe'] | |
missing = check_files(BINARIES) | |
while len(missing) > 0: | |
print('Missing Dependency: %s' % missing) | |
try: | |
input = raw_input('Press Enter if you want to check again...') | |
except NameError: pass | |
missing = check_files(missing) | |
print('Found All Binary Dependencies!\n') | |
try: | |
input = raw_input('Press Enter to patch your FS') | |
except NameError: pass | |
print('Opening BCPKG2-1-Normal-Main.bin...') | |
with open('BCPKG2-1-Normal-Main.bin', 'rb') as BCPKG21: | |
BCPKG21_data = BCPKG21.read() | |
print('Extracting package2.bin from BCPKG2-1-Normal-Main.bin...') | |
with open('package2.bin', 'wb+') as PKG21: | |
PKG21_data = BCPKG21_data[0x4000 : len(BCPKG21_data)] | |
PKG21.write(PKG21_data) | |
print('Extracting INI1 from package2.bin...') | |
try: | |
if path.isfile('keys.txt'): | |
call('hactool.exe --keyset=keys.txt -tpk21 --package2dir=package2 --ini1dir=ini1 package2.bin') | |
else: | |
call('hactool.exe -tpk21 --package2dir=package2 --ini1dir=ini1 package2.bin') | |
except: | |
error('Failed to unpack package2.bin! (Did you forget your keys.txt?)') | |
print('Copying FS.kip1 to Current Directory...') | |
copyfile('ini1/FS.kip1', 'FS.orig.kip1') | |
print('Decompressing FS.orig.kip1...') | |
call('kip1decomp.exe d FS.orig.kip1 FS.decomp.kip1') | |
print('Determining FS.decomp.kip1 patch...') | |
with open('FS.decomp.kip1', 'rb') as DECOMPRESSED: | |
patch_hash = hashlib.sha256(DECOMPRESSED.read()).hexdigest().upper() | |
for key in sorted(PATCHES.keys()): | |
if PATCHES[key] == patch_hash: | |
patch = key | |
if not path.isfile(patch): | |
error('Your FS.decomp.kip1 requires patch %s!\n\n(Download at https://files.sshnuke.net/%s)' % (patch, patch)) | |
try: | |
print('Patching FS.decomp.kip1 with %s...' % (patch)) | |
call('xdelta3.exe -d -f -s FS.decomp.kip1 %s FS.patched.kip1' % patch) | |
except: | |
error('Your FS.decomp.kip1 requires a patch that isn\'t available yet, Sorry!!!') | |
print('Creating new FS.kip1...') | |
call('kip1decomp.exe c FS.patched.kip1 FS.kip1') | |
print('') | |
print('FS.kip1 Created Successfully!') | |
print('') | |
print('1. Place the FS.kip1 into the root of your Switch\'s microSD') | |
print('2. Add the following line to your hekate_ipl.ini launch configuration:') | |
print(' kip1=FS.kip1') | |
print('') | |
print('Thanks to rajkosto for biskeydump, HacDiskMount and hashes/improvements') | |
print('~SocraticBliss') | |
sys.exit(0) | |
if __name__=='__main__': | |
main(len(sys.argv), sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment