Init
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""PyGhidra pass 4: dense disassembly seeding + full-range listing dumps.
|
||||
|
||||
Reuses /tmp/opencode/ghidra-lab/pyproj/LofiPy.
|
||||
Writes /tmp/opencode/ghidra-lab/out/gfull_<name>.txt
|
||||
"""
|
||||
import os
|
||||
|
||||
OUT = "/tmp/opencode/ghidra-lab/out"
|
||||
PROJ_LOC = "/tmp/opencode/ghidra-lab/pyproj/LofiPy"
|
||||
PROJ_NAME = "LofiPy"
|
||||
PROG = "/ais_sect1_addrC7074800.bin"
|
||||
RANGES = {
|
||||
"eloop": ("C708E400", 0x400),
|
||||
"callers2": ("C709E700", 0x500),
|
||||
"orch": ("C7086300", 0x900),
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
import pyghidra
|
||||
|
||||
pyghidra.start()
|
||||
with pyghidra.open_project(PROJ_LOC, PROJ_NAME) as project:
|
||||
with pyghidra.program_context(project, PROG) as program:
|
||||
from ghidra.program.flatapi import FlatProgramAPI
|
||||
|
||||
flat = FlatProgramAPI(program)
|
||||
with pyghidra.transaction(program, "seed"):
|
||||
for name, (t, size) in RANGES.items():
|
||||
base = int(t, 16)
|
||||
n = 0
|
||||
a = base
|
||||
while a < base + size:
|
||||
try:
|
||||
flat.disassemble(flat.toAddr("0x%08X" % a))
|
||||
n += 1
|
||||
except Exception:
|
||||
pass
|
||||
a += 8
|
||||
print("%s seeded %d" % (name, n), flush=True)
|
||||
for name, (t, size) in RANGES.items():
|
||||
try:
|
||||
base = int(t, 16)
|
||||
it = program.getListing().getInstructions(
|
||||
flat.toAddr("0x%08X" % base), True)
|
||||
lines = []
|
||||
while it.hasNext():
|
||||
ins = it.next()
|
||||
off = ins.getAddress().getOffset()
|
||||
if off >= base + size:
|
||||
break
|
||||
lines.append("%08X %s %s" % (
|
||||
off, ins.getMnemonicString(), ins.toString()))
|
||||
if len(lines) > 4000:
|
||||
break
|
||||
open(os.path.join(OUT, "gfull_" + name + ".txt"),
|
||||
"w").write("\n".join(lines) + "\n")
|
||||
print("%s: %d insns" % (name, len(lines)), flush=True)
|
||||
except Exception as e:
|
||||
print(name + " FAILED: " + str(e)[:200], flush=True)
|
||||
print("GFULL_DONE", flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user