def main(self, filename, data, verbose, opts={}): self.outfile = make_outfile(filename, 'txt') self.verbose = verbose if 'showescapes' in opts: self.escapes = True if opts['showescapes'].strip().lower( ) == 'true' else False else: self.escapes = True self.read_header(data) self.strnum = None for i in range(self.sectionnum): magic = data.read(4) data.seek(-4, 1) switch( magic, (data, magic), { b'LBL1': self.readLBL1, b'TXT2': self.readTXT2, b'ATR1': self.readATR1, b'ATO1': self.readATO1, b'NLI1': self.readNLI1, b'TSY1': self.readTSY1, SWITCH_DEFAULT: self.unknown_section, }) dic = [None for i in range(self.strnum)] for names in self.names: '''group = {} for id, name in names: group[name] = self.strings[id + 1] dic.append(group)''' for id, name in names: dic[id] = {name: self.strings[id]} final = {'Strings': dic, 'Number of strings': self.strnum} out = dump(final) write(out, self.outfile)
def extractHeader(self, data, outname): info = OrderedDict() ntr = OrderedDict() twl = OrderedDict() ntr['name'] = self.name ntr['gamecode'] = self.gamecode ntr['makercode'] = self.makercode ntr['unitcode'] = self.unitcode ntr['device-capacity'] = self.devicecapacity ntr['region'] = self.ntr_region ntr['version'] = self.version ntr['encryption-seed-select'] = self.encryptionseed_select arm9 = OrderedDict() arm7 = OrderedDict() arm9['RAM-address'] = self.arm9.ramaddress arm9['entry-address'] = self.arm9.entryaddress arm9['auto-load'] = self.arm9.autoload arm7['RAM-address'] = self.arm7.ramaddress arm7['entry-address'] = self.arm7.entryaddress arm7['auto-load'] = self.arm7.autoload ntr['ARM9'] = arm9 ntr['ARM7'] = arm7 ntr['auto-start'] = self.autostart ntr['ROM-used-size'] = self.ntr_usedsize ntr['normal-control-setting'] = self.normalcontrol_setting ntr['secure-control-setting'] = self.securecontrol_setting ntr['secure-disable'] = self.secure.disable ntr['secure-transfer-timeout'] = self.secure.transfer_timeout info['NTR'] = ntr if 'DSI' in self.unitcode: twl['ARM9i-RAM-address'] = self.arm9i.ramaddress twl['ARM7i-RAM-address'] = self.arm9.ramaddress mbk = OrderedDict() mbk['MBK1'] = self.mbk1setting mbk['MBK2'] = self.mbk2setting mbk['MBK3'] = self.mbk3setting mbk['MBK4'] = self.mbk4setting mbk['MBK5'] = self.mbk5setting arm9 = OrderedDict() arm7 = OrderedDict() arm9['MBK6'] = self.arm9.mbk6setting arm9['MBK7'] = self.arm9.mbk7setting arm9['MBK8'] = self.arm9.mbk8setting arm7['MBK6'] = self.arm7.mbk6setting arm7['MBK7'] = self.arm7.mbk7setting arm7['MBK8'] = self.arm7.mbk8setting mbk['MBK9'] = self.mbk9setting mbk['ARM9'] = arm9 mbk['ARM7'] = arm7 twl['MBK-settings'] = mbk twl['ARM7-SCFG-extmask'] = self.arm7.scfg_extmask twl['access-control'] = self.accesscontrol twl['region'] = self.region(self.regionflags) twl['total-used-size'] = self.total_usedsize twl['titleID'], twl['content-type'] = self.maketitleid(self.titleid) twl['public.sav-size'] = self.publicsav_size twl['private.sav-size'] = self.privatesav_size twl['age-ratings'] = self.makeageratings(self.age_ratings) info['TWL'] = twl write(dump(info), outname)
def main(self, filename, file, verbose, opts={}): self.outfile = make_outfile(filename, 'tflan') self.verbose = verbose self.file = file self.tree = OrderedDict() self.tree['BFLAN'] = OrderedDict() self.root = self.tree['BFLAN'] ptr = self.readheader() self.extract_sections(ptr) write(dump(self.tree), self.outfile)
def extractLTBL(self): bwrite(self.ltbl, self.metapath + 'LTBL.bin') ltbl = self.unpack(ALYT_LTBL_STRUCT, self.ltbl) entries = ltbl[4] final = [] for edat in entries: entry = OrderedDict() entry['BFLYT'] = self.nametable[edat[0]] entry['unknown'] = edat[3] entry['prt1'] = [self.symtable[el[0]] for el in edat[5]] entry['links'] = [self.symtable[el[0]] for el in edat[6]] entry['animations'] = [self.nametable[el[0]] for el in edat[7]] final.append(entry) write(dump({'LTBL': final}), self.metapath + 'LTBL.txt')
def main(self, filename, data, opts={}): self.outfile = make_outfile(filename, 'txt') self.byteorder = '<' self.tree = OrderedDict() self.tree['SCI'] = OrderedDict() self.tree['ACI'] = OrderedDict() self.tree['ACI-limiter'] = OrderedDict() self.split(data) self.extract_sci() self.extract_aci(self.aci, self.tree['ACI']) self.extract_aci(self.limit_aci, self.tree['ACI-limiter']) self.tree['AccessDesc-Signature'] = self.accessdesc_signature self.tree['NCCH-Header-public-key'] = self.public_key final = txtree.dump(self.tree) write(final, self.outfile)
def extract_data(self): tree = OrderedDict() tree['NCCH'] = OrderedDict() root = tree['NCCH'] root['PartitionID'] = self.partition_id, 16 root['TitleID'] = {'High': self.tid_high, 'Low ': self.tid_low} root['Product-code'] = self.product_code root['Version'] = self.version root['Makercode'] = self.maker_code root['Platform'] = self.platform root['Content-types'] = self.content_types root['Has-RomFS'] = self.has_romfs root['Has-Crypto'] = self.has_crypto root['Fixed-Crypto-key'] = self.fixed_cryptokey root['Crypto-Keyslot'] = self.crypto_keyslot root['Uses-new-KeyY-generator'] = self.use_new_keyYgen root['RSA-signature'] = self.rsa_signature root['Hashes'] = OrderedDict() hashes = root['Hashes'] hashes['ExeFS'] = rawutil.hex(self.exefs_hash) hashes['RomFS'] = rawutil.hex(self.romfs_hash) hashes['Logo'] = rawutil.hex(self.logo_hash) hashes['ExtHeader'] = rawutil.hex(self.extheader_hash) hashes['ID'] = rawutil.hex(self.id_hash, 8) root['Structure'] = OrderedDict() struct = root['Structure'] struct['Media-size-unit'] = self.unitsize struct['Comment'] = 'All these sizes and offsets are in bytes' struct['ExtHeader-size'] = self.extheader_size struct['Plain-offset'] = self.plain_offset struct['Plain-size'] = self.plain_size struct['Logo-offset'] = self.logo_offset struct['Logo-size'] = self.logo_size struct['ExeFS-offset'] = self.exefs_offset struct['ExeFS-size'] = self.exefs_size struct['ExeFS-HashRegion-size'] = self.exefs_hashregion_size struct['RomFS-offset'] = self.romfs_offset struct['RomFS-size'] = self.romfs_size struct['RomFS-HashRegion-size'] = self.romfs_hashregion_size final = txtree.dump(tree) write(final, self.outdir + 'header.txt')
def extractIcon(self, data, outdir): info = OrderedDict() info['animated'] = False version, ptr = self.uint16(data, 0) crc, ptr = self.uint16(data, ptr) if self.crc16(data[0x0020:0x0840]) != crc: error('Invalid NDS ROM: Invalid icon CRC', 305) if version < 0x0103: bitmap, palette = self.unpack_from('512s16[H]', data, 0x20) img = self.extractIconBitmap(bitmap, palette) img.save(outdir + 'icon.png', 'PNG') else: frames = [] pals = [] bitmap, pal = self.unpack_from('512s16[H]', data, 0x20) noanim = self.extractIconBitmap(bitmap, pal) ptr = 0x1240 palptr = 0x2240 for i in range(0, 8): bmp, ptr = self.unpack_from('512s', data, ptr, getptr=True) pal, palptr = self.unpack_from('16[H]', data, palptr, getptr=True) frames.append(bmp[0]) pals.append(pal[0]) tokens = self.unpack_from('64H', data, 0x2340) if tokens[0] == 0x0000: noanim.save(outdir + 'icon.png', 'PNG') else: info['animated'] = True anim = [] durations = [] for tk in tokens: vertflip = tk & 0b1000000000000000 horiflip = tk & 0b0100000000000000 palindex = tk & 0b0011100000000000 bmpindex = tk & 0b0000011100000000 duration = tk & 0b0000000011111111 palindex >>= 11 bmpindex >>= 8 frame = self.extractIconBitmap(frames[bmpindex], pals[palindex]) if vertflip: ImageOps.flip(frame) if horiflip: ImageOps.mirror(frame) anim.append(frame) durations.append(duration / 60) writeGif(outdir + 'icon.gif', anim, durations) jp = self.utf16string(data, 0x240)[0] en = self.utf16string(data, 0x340)[0] fr = self.utf16string(data, 0x440)[0] de = self.utf16string(data, 0x540)[0] it = self.utf16string(data, 0x640)[0] es = self.utf16string(data, 0x740)[0] info['title'] = OrderedDict() info['title']['JP'] = jp info['title']['EN'] = en info['title']['FR'] = fr info['title']['DE'] = de info['title']['IT'] = it info['title']['ES'] = es if version >= 0x0002: cn = self.utf16string(data, 0x840)[0] info['title']['CN'] = cn if version >= 0x0003: kr = self.utf16string(data, 0x940)[0] info['title']['KR'] = kr write(dump(info), outdir + 'icon.txt')
def list(self): print(dump(self.tree))
def main(self, filename, data, opts={}): outfile = make_outfile(filename, 'tflyt') self.bflyt = data self.readheader() write(dump(self.parsedata()), outfile)