tools/sbl_dis: range disassembler (struct phdrs, no elftools on zern)
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user