tools/sbl_dis: range disassembler (struct phdrs, no elftools on zern)

This commit is contained in:
SashegDev
2026-09-14 11:11:02 +00:00
parent 9793076d11
commit cec6a8b3e6
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env python3
import struct
import sys
import capstone
path, va = sys.argv[1], int(sys.argv[2], 0)
n = int(sys.argv[3], 0) if len(sys.argv) > 3 else 96
d = open(path, 'rb').read()
phoff, phnum = struct.unpack('<I', d[28:32])[0], struct.unpack('<H', d[44:46])[0]
for k in range(phnum):
p = d[phoff+k*32:phoff+(k+1)*32]
typ, off, v, _, fsz, msz, _, _ = struct.unpack('<8I', p)
if typ == 1 and v <= va < v + msz:
cs = capstone.Cs(capstone.CS_ARCH_ARM, capstone.CS_MODE_THUMB)
for i in cs.disasm(d[off+(va-v):off+(va-v)+n], va):
print(' 0x%x:\t%s\t%s' % (i.address, i.mnemonic, i.op_str))
break