#!/usr/bin/env python import sys, lz4, hashlib from struct import unpack as up, pack as pk def lz4_compress(data): try: import lz4.block as block except ImportError: block = lz4.LZ4_compress return block.compress(data, 'high_compression', store_size=False) def read_file(fn): with open(fn, 'rb') as f: return f.read() def pad(data, size): assert len(data) <= size return (data + '\x00' * size)[:size] def get_overlay(program, i): return program[0x2B000 + 0x14000 * i:0x2B000 + 0x14000 * (i+1)] KIP_NAMES = ['Loader', 'NCM', 'ProcessManager', 'sm', 'boot', 'spl', 'ams_mitm'] def get_kips(): emummc = read_file('../../../../emummc/emummc.kip') loader = read_file('../../../../stratosphere/loader/loader.kip') ncm = read_file('../../../../stratosphere/ncm/ncm.kip') pm = read_file('../../../../stratosphere/pm/pm.kip') sm = read_file('../../../../stratosphere/sm/sm.kip') boot = read_file('../../../../stratosphere/boot/boot.kip') spl = read_file('../../../../stratosphere/spl/spl.kip') ams_mitm = read_file('../../../../stratosphere/ams_mitm/ams_mitm.kip') return (emummc, { 'Loader' : loader, 'NCM' : ncm, 'ProcessManager' : pm, 'sm' : sm, 'boot' : boot, 'spl' : spl, 'ams_mitm' : ams_mitm, }) def write_kip_meta(f, kip, ofs): # Write program id f.write(kip[0x10:0x18]) # Write offset, size f.write(pk('