mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
bring pddbdbg up to v2
This commit is contained in:
parent
b3c89e5f09
commit
2d0af08266
1 changed files with 22 additions and 21 deletions
|
|
@ -15,6 +15,15 @@ VPAGE_SIZE = 4064
|
||||||
MBBB_PAGES = 10
|
MBBB_PAGES = 10
|
||||||
DO_CI_TESTS = True
|
DO_CI_TESTS = True
|
||||||
|
|
||||||
|
# PDDB version number is encoded here
|
||||||
|
def basis_aad(name, version=0x02_01, dna=0):
|
||||||
|
name_bytes = bytearray(name, 'utf-8')
|
||||||
|
# name_bytes += bytearray(([0] * (Basis.MAX_NAME_LEN - len(name))))
|
||||||
|
name_bytes += version.to_bytes(4, 'little')
|
||||||
|
name_bytes += dna.to_bytes(8, 'little')
|
||||||
|
|
||||||
|
return name_bytes
|
||||||
|
|
||||||
# build a table mapping all non-printable characters to None
|
# build a table mapping all non-printable characters to None
|
||||||
NOPRINT_TRANS_TABLE = {
|
NOPRINT_TRANS_TABLE = {
|
||||||
i: None for i in range(0, sys.maxunicode + 1) if not chr(i).isprintable()
|
i: None for i in range(0, sys.maxunicode + 1) if not chr(i).isprintable()
|
||||||
|
|
@ -172,7 +181,7 @@ def main():
|
||||||
raw_key = key_f.read()
|
raw_key = key_f.read()
|
||||||
num_keys = int.from_bytes(raw_key[:4], 'little')
|
num_keys = int.from_bytes(raw_key[:4], 'little')
|
||||||
for i in range(num_keys):
|
for i in range(num_keys):
|
||||||
name_all = raw_key[4 + i*96 : 4 + i*96 + 64]
|
name_all = raw_key[4 + i*128 : 4 + i*128 + 64]
|
||||||
name_bytes = bytearray(b'')
|
name_bytes = bytearray(b'')
|
||||||
for b in name_all:
|
for b in name_all:
|
||||||
if b != 0:
|
if b != 0:
|
||||||
|
|
@ -180,10 +189,11 @@ def main():
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
name = name_bytes.decode('utf8', errors='ignore')
|
name = name_bytes.decode('utf8', errors='ignore')
|
||||||
key = raw_key[4 + i*96 + 64 : 4 + i*96 + 96]
|
key_data = raw_key[4 + i*128 + 64 : 4 + i*128 + 96]
|
||||||
keys[name] = key
|
key_pt = raw_key[4 + i*128 + 96 : 4 + i*128 + 128]
|
||||||
|
keys[name] = [key_pt, key_data]
|
||||||
|
|
||||||
logging.info("Found basis keys:")
|
logging.info("Found basis keys (pt, data):")
|
||||||
logging.info(str(keys))
|
logging.info(str(keys))
|
||||||
|
|
||||||
# tunable parameters for a filesystem
|
# tunable parameters for a filesystem
|
||||||
|
|
@ -229,7 +239,7 @@ def main():
|
||||||
|
|
||||||
for name, key in keys.items():
|
for name, key in keys.items():
|
||||||
if name in tables:
|
if name in tables:
|
||||||
logging.info("Basis {}, key: {}".format(name, key.hex()))
|
logging.info("Basis {}, key_pt: {}, key_data: {}".format(name, key[0].hex(), key[1].hex()))
|
||||||
v2p_table = tables[name][0]
|
v2p_table = tables[name][0]
|
||||||
p2v_table = tables[name][1]
|
p2v_table = tables[name][1]
|
||||||
# v2p_table[0xfe0fe0] = 0x1200* 0x100
|
# v2p_table[0xfe0fe0] = 0x1200* 0x100
|
||||||
|
|
@ -239,7 +249,7 @@ def main():
|
||||||
# print("pp_start: {:x}".format(pp_start))
|
# print("pp_start: {:x}".format(pp_start))
|
||||||
pp_data = data[pp_start:pp_start + PAGE_SIZE]
|
pp_data = data[pp_start:pp_start + PAGE_SIZE]
|
||||||
try:
|
try:
|
||||||
pt_data = keycommit_decrypt(key, basis_aad(name), pp_data)
|
pt_data = keycommit_decrypt(key[1], basis_aad(name), pp_data)
|
||||||
basis_data.extend(bytearray(pt_data))
|
basis_data.extend(bytearray(pt_data))
|
||||||
logging.debug("decrypted vpage @ {:x} ppage @ {:x}".format(VPAGE_SIZE, v2p_table[VPAGE_SIZE]))
|
logging.debug("decrypted vpage @ {:x} ppage @ {:x}".format(VPAGE_SIZE, v2p_table[VPAGE_SIZE]))
|
||||||
# print([hex(x) for x in basis_data[:256]])
|
# print([hex(x) for x in basis_data[:256]])
|
||||||
|
|
@ -250,7 +260,7 @@ def main():
|
||||||
dicts_found = 0
|
dicts_found = 0
|
||||||
dict_index = 0
|
dict_index = 0
|
||||||
while dict_index < MAX_DICTS and dicts_found < basis.num_dicts:
|
while dict_index < MAX_DICTS and dicts_found < basis.num_dicts:
|
||||||
bdict = BasisDicts(dict_index, v2p_table, data, key, name)
|
bdict = BasisDicts(dict_index, v2p_table, data, key[1], name)
|
||||||
if bdict.valid:
|
if bdict.valid:
|
||||||
basis_dicts[bdict.name] = bdict
|
basis_dicts[bdict.name] = bdict
|
||||||
dicts_found += 1
|
dicts_found += 1
|
||||||
|
|
@ -587,15 +597,6 @@ class Basis:
|
||||||
#desc += ' DictPtr: {:x}\n'.format(self.dict_ptr)
|
#desc += ' DictPtr: {:x}\n'.format(self.dict_ptr)
|
||||||
return desc
|
return desc
|
||||||
|
|
||||||
def basis_aad(name, version=0x01_01, dna=0):
|
|
||||||
name_bytes = bytearray(name, 'utf-8')
|
|
||||||
# name_bytes += bytearray(([0] * (Basis.MAX_NAME_LEN - len(name))))
|
|
||||||
name_bytes += version.to_bytes(4, 'little')
|
|
||||||
name_bytes += dna.to_bytes(8, 'little')
|
|
||||||
|
|
||||||
return name_bytes
|
|
||||||
|
|
||||||
|
|
||||||
class Pte:
|
class Pte:
|
||||||
PTE_LEN = 16
|
PTE_LEN = 16
|
||||||
def __init__(self, i_bytes):
|
def __init__(self, i_bytes):
|
||||||
|
|
@ -653,8 +654,8 @@ def decode_pagetable(img, entries, keys, mbbb):
|
||||||
key_table = {}
|
key_table = {}
|
||||||
for name, key in keys.items():
|
for name, key in keys.items():
|
||||||
logging.debug("Pages for basis {}".format(name))
|
logging.debug("Pages for basis {}".format(name))
|
||||||
logging.debug("key: {}".format(key.hex()))
|
logging.debug("key: {}".format(key[0].hex()))
|
||||||
cipher = AES.new(key, AES.MODE_ECB)
|
cipher = AES.new(key[0], AES.MODE_ECB)
|
||||||
pages = [img[i:i+PAGE_SIZE] for i in range(0, entries * Pte.PTE_LEN, PAGE_SIZE)]
|
pages = [img[i:i+PAGE_SIZE] for i in range(0, entries * Pte.PTE_LEN, PAGE_SIZE)]
|
||||||
page_num = 0
|
page_num = 0
|
||||||
v2p_table = {}
|
v2p_table = {}
|
||||||
|
|
@ -806,8 +807,8 @@ def decode_fscb(img, keys, FSCB_LEN_PAGES=2):
|
||||||
# print("data: {}".format(fscb_enc.hex()))
|
# print("data: {}".format(fscb_enc.hex()))
|
||||||
try:
|
try:
|
||||||
nonce = fscb_enc[:12]
|
nonce = fscb_enc[:12]
|
||||||
logging.info("key: {}, nonce: {}".format(key.hex(), nonce.hex()))
|
logging.info("key: {}, nonce: {}".format(key[1].hex(), nonce.hex()))
|
||||||
cipher = AES_GCM_SIV(key, nonce)
|
cipher = AES_GCM_SIV(key[1], nonce)
|
||||||
logging.info("aad: {}".format(Fscb.aad().hex()))
|
logging.info("aad: {}".format(Fscb.aad().hex()))
|
||||||
logging.info("mac: {}".format(fscb_enc[-16:].hex()))
|
logging.info("mac: {}".format(fscb_enc[-16:].hex()))
|
||||||
#print("data: {}".format(fscb_enc[12:-16].hex()))
|
#print("data: {}".format(fscb_enc[12:-16].hex()))
|
||||||
|
|
@ -819,7 +820,7 @@ def decode_fscb(img, keys, FSCB_LEN_PAGES=2):
|
||||||
|
|
||||||
if fscb != None:
|
if fscb != None:
|
||||||
logging.debug("key: {}".format(key.hex()))
|
logging.debug("key: {}".format(key.hex()))
|
||||||
cipher = AES.new(key, AES.MODE_ECB)
|
cipher = AES.new(key[0], AES.MODE_ECB)
|
||||||
for update in space_update:
|
for update in space_update:
|
||||||
entries = [update[i:i+SpaceUpdate.SU_LEN] for i in range(0, len(update), SpaceUpdate.SU_LEN)]
|
entries = [update[i:i+SpaceUpdate.SU_LEN] for i in range(0, len(update), SpaceUpdate.SU_LEN)]
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue