import ghidra.app.script.GhidraScript; import ghidra.app.decompiler.DecompInterface; import ghidra.app.decompiler.DecompileResults; import ghidra.program.model.listing.Function; import ghidra.program.model.listing.FunctionManager; import ghidra.program.model.address.Address; import java.io.PrintWriter; import java.io.FileWriter; public class DumpCandidates extends GhidraScript { @Override public void run() throws Exception { long[] addrs = { 0x180536f70L, 0x180537160L, 0x180536f60L, 0x180536670L, 0x180536660L, 0x180536cc0L, 0x180537720L, 0x180536cb0L, 0x180536b90L, 0x180537930L, 0x180536b80L, 0x180536c60L, 0x1813658a0L, 0x18052c7e0L, 0x18053846cL, 0x1852000000L, 0x18052c7e0L, 0x180538484L, 0x180536b60L, 0x1805379a0L, 0x180536b50L, 0x180536850L }; DecompInterface di = new DecompInterface(); di.openProgram(currentProgram); FunctionManager fm = currentProgram.getFunctionManager(); PrintWriter pw = new PrintWriter(new java.io.BufferedWriter(new FileWriter("/home/m/re-tools/decomp_candidates.txt", false))); for (long a : addrs) { Address addr = currentProgram.getAddressFactory().getDefaultAddressSpace().getAddress(a); Function f = fm.getFunctionAt(addr); if (f == null) { pw.println("=== 0x" + Long.toHexString(a) + " : NOT A FUNCTION ===\n"); continue; } DecompileResults res = di.decompileFunction(f, 60, monitor); pw.println("==================== 0x" + Long.toHexString(a) + " " + f.getName() + " size=" + f.getBody().getNumAddresses() + " refs=" + f.getSymbol().getReferenceCount() + " ===="); if (res != null) pw.println(res.getDecompiledFunction().getC()); pw.println(); } pw.close(); di.dispose(); println("DUMP_DONE"); } }