-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExportDecompiled.java
More file actions
41 lines (33 loc) · 1.36 KB
/
ExportDecompiled.java
File metadata and controls
41 lines (33 loc) · 1.36 KB
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
36
37
38
39
40
41
//Exports all decompiled functions to a single text file
// @author Brian Reardon
// @category Decompiler
// @keybinding
// @menupath
// @toolbar
import java.io.*;
import ghidra.app.decompiler.*;
import ghidra.program.model.listing.*;
import ghidra.util.task.ConsoleTaskMonitor;
public class ExportDecompiled extends ghidra.app.script.GhidraScript {
@Override
public void run() throws Exception {
String outputPath = askFile("Choose output file", "Save").getAbsolutePath();
FileWriter writer = new FileWriter(outputPath);
DecompInterface decomp = new DecompInterface();
decomp.openProgram(currentProgram);
FunctionManager fm = currentProgram.getFunctionManager();
int count = 0;
for (Function func : fm.getFunctions(true)) {
monitor.setMessage("Decompiling: " + func.getName());
DecompileResults results = decomp.decompileFunction(func, 30, monitor);
if (results != null && results.decompileCompleted()) {
writer.write("\n// ---------- " + func.getName() + " @ " + func.getEntryPoint() + " ----------\n");
writer.write(results.getDecompiledFunction().getC());
writer.write("\n");
count++;
}
}
writer.close();
println("✅ Exported " + count + " functions to:\n" + outputPath);
}
}