summaryrefslogtreecommitdiffstats
path: root/tools/ghidra/gsp-fwimage-570.144/scripts/DumpFuncs.java
blob: 69484928d59b2d98255827108f1dc72ea94bceef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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();
    }
}