uzbek-plus/tools/elfinfo.py
q 105bef466a Project Aurora: mainline ARM64 Linux on JZ08AU (MSM8916) LTE modem
Sanitized research log, build/reproducibility docs, DTS, kernel configs,
patches, initramfs sources, bootchain migration plans and test logs.
B5 direct boot PASS; B6 modem lifecycle in progress.
No dumps, NV/EFS, vendor firmware or device identifiers included.
2026-09-30 17:23:18 +03:00

23 lines
1.4 KiB
Python

#!/usr/bin/env python3
# ELF32/64 program-header summary + extent + trailing-data check for QC images.
import struct, sys, hashlib, re
for fn in sys.argv[1:]:
d = open(fn, "rb").read()
if d[:4] != b"\x7fELF":
print(f"{fn}: not ELF, head={d[:16].hex()} nonzero={sum(1 for b in d[:4096] if b)}"); continue
c64 = d[4] == 2
if c64:
e_entry, e_phoff = struct.unpack_from("<QQ", d, 24); e_phnum = struct.unpack_from("<H", d, 56)[0]; esz = 56
else:
e_entry, e_phoff = struct.unpack_from("<II", d, 24); e_phnum = struct.unpack_from("<H", d, 44)[0]; esz = 32
end = 0; segs = []
for i in range(e_phnum):
o = e_phoff + i*esz
if c64: ty, fl, off, va, pa, fs, ms, al = struct.unpack_from("<IIQQQQQQ", d, o)
else: ty, off, va, pa, fs, ms, fl, al = struct.unpack_from("<IIIIIIII", d, o)
end = max(end, off+fs); segs.append(f"{pa:#x}+{fs:#x}(f{fl:#x})")
tail = d[end:]; tnz = len(tail) - tail.count(0) - tail.count(0xff)
vs = [m.decode() for m in re.findall(rb"QC_IMAGE_VERSION_STRING=[\x20-\x7e]+", d)]
vpos = [m.start() for m in re.finditer(rb"QC_IMAGE_VERSION_STRING=", d)]
print(f"{fn}: ELF{64 if c64 else 32} entry={e_entry:#x} phnum={e_phnum} image_end={end:#x} part={len(d):#x} "
f"img_sha256={hashlib.sha256(d[:end]).hexdigest()[:16]} tail_nonblank={tnz}\n segs={' '.join(segs)}\n ver={list(zip(vs, map(hex, vpos)))}")