import ghidra.app.script.GhidraScript; import ghidra.program.model.address.Address; import ghidra.program.model.listing.Function; import ghidra.program.model.listing.FunctionManager; import ghidra.app.decompiler.DecompInterface; import ghidra.app.decompiler.DecompileResults; import ghidra.util.task.TaskMonitor; public class DumpFuncs extends GhidraScript { @Override protected void run() throws Exception { String[] args = getScriptArgs(); FunctionManager fm = currentProgram.getFunctionManager(); DecompInterface decompiler = new DecompInterface(); decompiler.openProgram(currentProgram); for (String arg : args) { String s = arg.trim(); Address addr = toAddr(s); Function func = fm.getFunctionContaining(addr); if (func == null) { func = createFunction(addr, null); } println("### FUNC " + s + " -> " + (func != null ? func.getName() + " @ " + func.getEntryPoint() : "NOT FOUND")); if (func != null) { DecompileResults res = decompiler.decompileFunction(func, 120, monitor); if (res != null && res.decompileCompleted()) { println(res.getDecompiledFunction().getC()); } else { println("// decompile failed: " + (res != null ? res.getErrorMessage() : "null")); } } } decompiler.dispose(); } }