Skip to content

Instantly share code, notes, and snippets.

@ihaveamac
Created May 29, 2019 05:34
Show Gist options
  • Save ihaveamac/57ea1a582b5b4088415c0466897bdb05 to your computer and use it in GitHub Desktop.
Save ihaveamac/57ea1a582b5b4088415c0466897bdb05 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# very lazy script to generate the Title Info Entry for title.db
import argparse
import random
parser = argparse.ArgumentParser(description='Generate Title Info Entry.')
parser.add_argument('-o', help='output filename', type=argparse.FileType('wb'), required=True)
parser.add_argument('-v', help='title version', type=int, required=True)
parser.add_argument('-m', help='has manual', action='store_true')
parser.add_argument('-t', help='tmd content id as hexstring', required=True)
parser.add_argument('-c', help='cmd content id as hexstring', required=True)
parser.add_argument('-s', help='has SD save data', action='store_true')
parser.add_argument('-e', help='extdataid low as hexstring', required=True)
parser.add_argument('-p', help='product code', required=True)
a = parser.parse_args()
data = [
# title size, putting 0 for now
(0).to_bytes(8, 'little'),
# title type, assuming 0x40 as it usually is
0x40.to_bytes(4, 'little'),
# title version
a.v.to_bytes(4, 'little'),
# flags_0, only checking electronic manual
(1 if a.m else 0).to_bytes(4, 'little'),
# tmd content id
bytes.fromhex(a.t.rjust(8, '0'))[::-1],
# cmd content id
bytes.fromhex(a.c.rjust(8, '0'))[::-1],
# flags_1, only checking save data
(1 if a.s else 0).to_bytes(4, 'little'),
# extdataid low
bytes.fromhex(a.e.rjust(8, '0'))[::-1],
# reserved
b'\0' * 4,
# flags_2, only using a common value
0x100000000.to_bytes(8, 'little'),
# product code
a.p.encode('ascii').ljust(0x10, b'\0'),
# reserved
b'\0' * 0x10,
# unknown
random.randint(0, 0xFFFFFFFF).to_bytes(4, 'little'),
# reserved
b'\0' * 0x2c
]
result = b''.join(data)
a.o.write(result)
a.o.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment