enc_path = content_root_cmd + '/cmd/' + cmd_filename out_path = join(content_root, 'cmd', cmd_filename) print(f'Generating {enc_path}') highest_index = 0 content_ids = {} for record in cia.content_info: highest_index = record.cindex with cia.open_raw_section(record.cindex) as s: s.seek(0x100) cmac_data = s.read(0x100) id_bytes = bytes.fromhex(record.id)[::-1] cmac_data += record.cindex.to_bytes(4, 'little') + id_bytes c = crypto.create_cmac_object(Keyslot.CMACSDNAND) c.update(sha256(cmac_data).digest()) content_ids[record.cindex] = (id_bytes, c.digest()) # add content IDs up to the last one ids_by_index = [CMD_MISSING] * (highest_index + 1) installed_ids = [] cmacs = [] for x in range(len(ids_by_index)): try: info = content_ids[x] except KeyError: cmacs.append(bytes.fromhex('4D495353494E4720434F4E54454E5421')) else: ids_by_index[x] = info[0] cmacs.append(info[1])
highest_index = 0 content_ids = {} for chunk in tmd.chunk_records: try: with open(os.path.join(content_dir, chunk.id + '.app'), 'rb') as f: highest_index = chunk.cindex f.seek(0x100) header = f.read(0x100) id_bytes = bytes.fromhex(chunk.id)[::-1] data = header + chunk.cindex.to_bytes(4, 'little') + id_bytes data_hash = sha256(data) c = crypto.create_cmac_object(keyslot) c.update(data_hash.digest()) content_ids[chunk.cindex] = (id_bytes, c.digest()) except FileNotFoundError: # currently unknown if there's actually a process to generating the cmac for missing contents pass # add content IDs up to the last one ids_by_index = [MISSING] * (highest_index + 1) installed_ids = [] cmacs = [] for x in range(len(ids_by_index)): try: info = content_ids[x] except KeyError: # the 3DS actually puts either random data, or generates it using an unknown process.