Created
September 8, 2018 23:47
-
-
Save SocraticBliss/a30475733ba236d76544ae5fb43b1d7b to your computer and use it in GitHub Desktop.
cnmt de-struct-or
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
# cnmt de-struct-or | |
# SocraticBliss (R) | |
from struct import unpack as up | |
from binascii import hexlify as hx | |
''' | |
CNMT HEADER | |
title_id = up('<Q', cnmt[:0x8]) | |
title_version = up('<I', cnmt[0x8:0xC]) | |
title_type = up('<B', cnmt[0xC:0xD]) | |
unk1 = up('<s', cnmt[0xD:0xE]) | |
unk2 = up('<4s', cnmt[0xE:0x12]) | |
entries = up('<H', cnmt[0x12:0x14]) | |
padding = up('<12s', cnmt[0x14:0x20]) | |
CNMT META ENTRIES | |
entry_id_1 = up('<Q', cnmt[0x20:0x28]) | |
entry_version_1 = up('<I', cnmt[0x28:0x2C]) | |
entry_type_1 = up('<B', cnmt[0x2C:0x2D]) | |
unk1 = up('<s', cnmt[0x2D:0x2E]) | |
unk2 = up('<2s', cnmt[0x2E:0x30]) | |
CNMT CONTENT ENTRIES | |
hash_1 = cnmt[0x20:0x40] | |
ncaid_1 = cnmt[0x40:0x50] | |
size_1 = up('<6s', cnmt[0x50:0x56]) | |
type_1 = up('<B', cnmt[0x56:0x57]) | |
padding = up('<s' cnmt[0x57:0x58]) | |
So much fun... but no performance increase | |
titles = {'%016x' % up('<Q', cnmt[0x20+(0x10*i):0x28+(0x10*i)]): '%s' % up('<I', cnmt[0x28+(0x10*i):0x2C+(0x10*i)]) for i in xrange(up('<H', cnmt[0x12:0x14])[0])} | |
''' | |
def parse_meta(cnmt): | |
titles = {} | |
offset = 0x20 | |
entries = up('<H', cnmt[0x12:0x14])[0] | |
for i in xrange(entries): | |
entry_id, entry_version = up('<QI', cnmt[offset:offset+0xC]) | |
offset += 0x10 | |
titles['%016x' % entry_id] = '%s' % entry_version | |
return titles | |
def read(title): | |
try: | |
with open('%s' % title, 'rb') as file: | |
cnmt = file.read() | |
except IOError: | |
raise SystemExit('Error: Failed to read %s!' % title) | |
return cnmt | |
def main(): | |
cnmt = read('SystemUpdate_0100000000000816/SystemUpdate_0100000000000816.cnmt') | |
print('System Update ContentMeta Dictionary: %s' % parse_meta(cnmt)) | |
cnmt = read('SystemData_0100000000000814/SystemData_0100000000000814.cnmt') | |
print('ContentMeta Dictionary: %s' % {'%016x' % up('<Q', cnmt[:0x8]): hx(cnmt[0x40:0x50])}) | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment