40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
|
|
# Headless post-script: force-disassemble all executable blocks and
|
||
|
|
# re-run auto-analysis. Run with:
|
||
|
|
# analyzeHeadless <proj_dir> <proj> -process <prog> -noanalysis \
|
||
|
|
# -scriptPath tools/ghidra_scripts -postScript ForceDisasmPost.py
|
||
|
|
#@category Analysis
|
||
|
|
|
||
|
|
from ghidra.app.cmd.disassemble import DisassembleCommand
|
||
|
|
from ghidra.app.plugin.core.analysis import AutoAnalysisManager
|
||
|
|
from ghidra.program.model.address import AddressSet
|
||
|
|
|
||
|
|
listing = currentProgram.getListing()
|
||
|
|
mem = currentProgram.getMemory()
|
||
|
|
monitor.setMessage('collecting executable blocks')
|
||
|
|
|
||
|
|
total = AddressSet()
|
||
|
|
for b in mem.getBlocks():
|
||
|
|
if b.isExecute() and 'elf' not in b.getName():
|
||
|
|
total.addRange(b.getStart(), b.getEnd())
|
||
|
|
|
||
|
|
before_ins = listing.getNumInstructions()
|
||
|
|
before_fun = currentProgram.getFunctionManager().getFunctionCount()
|
||
|
|
print('ForceDisasm before: %d instructions, %d functions'
|
||
|
|
% (before_ins, before_fun))
|
||
|
|
|
||
|
|
cmd = DisassembleCommand(total, total, False)
|
||
|
|
tx = currentProgram.startTransaction('force disasm')
|
||
|
|
try:
|
||
|
|
ok = cmd.applyTo(currentProgram, monitor)
|
||
|
|
finally:
|
||
|
|
currentProgram.endTransaction(tx, True)
|
||
|
|
print('ForceDisasm disasm apply: %s' % ok)
|
||
|
|
|
||
|
|
mgr = AutoAnalysisManager.getAnalysisManager(currentProgram)
|
||
|
|
mgr.reAnalyzeAll(None)
|
||
|
|
mgr.startAnalysis(monitor)
|
||
|
|
|
||
|
|
print('ForceDisasm after: %d instructions, %d functions'
|
||
|
|
% (listing.getNumInstructions(),
|
||
|
|
currentProgram.getFunctionManager().getFunctionCount()))
|