#!/usr/bin/env python3 # Parse primary+backup GPT from full image, verify every partition dump against it, # write MANIFEST.md / manifest.tsv, extract GPT blobs. import struct, hashlib, zlib, os, sys W = os.path.expanduser("~/doc/modem/jz08-aurora") full = f"{W}/dumps/full-emmc.bin" f = open(full, "rb"); S = 512 size = os.path.getsize(full); nsec = size // S def rd(lba, n=1): f.seek(lba*S); return f.read(n*S) def hdr(lba): h = rd(lba) sig, rev, hs, crc, _, cur, bak, first, last, guid, elba, n, esz, ecrc = struct.unpack_from("<8sIII4sQQQQ16sQIII", h) hh = bytearray(h[:hs]); hh[16:20] = b"\0"*4 ents = rd(elba, (n*esz+S-1)//S)[:n*esz] return dict(sig=sig, cur=cur, bak=bak, first=first, last=last, elba=elba, n=n, esz=esz, hcrc_ok=zlib.crc32(hh) == crc, ecrc_ok=zlib.crc32(ents) == ecrc, ents=ents) p = hdr(1); b = hdr(p["bak"]) out = [f"full image: {size} bytes, {nsec} sectors, sha256 {hashlib.sha256(open(full,'rb').read()).hexdigest()}"] for nm, h in (("primary", p), ("backup", b)): out.append(f"{nm}: sig={h['sig']} cur={h['cur']} bak={h['bak']} first={h['first']} last={h['last']} entries@{h['elba']} n={h['n']} hdrCRC={'OK' if h['hcrc_ok'] else 'BAD'} entCRC={'OK' if h['ecrc_ok'] else 'BAD'}") out.append(f"primary entries == backup entries: {p['ents'] == b['ents']}; backup hdr at last LBA: {p['bak'] == nsec-1}") open(f"{W}/gpt/gpt-primary-34sectors.bin", "wb").write(rd(0, 34)) open(f"{W}/gpt/gpt-backup-33sectors.bin", "wb").write(rd(nsec-33, 33)) rows = []; ok = True for i in range(p["n"]): e = p["ents"][i*p["esz"]:(i+1)*p["esz"]] if e[:16] == b"\0"*16: continue first, last, attr = struct.unpack_from("