Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // @author hubertf / Windsurf
- // @category Export
- import ghidra.app.decompiler.*;
- import ghidra.program.model.listing.*;
- import ghidra.util.task.*;
- import java.io.*;
- import ghidra.app.script.GhidraScript;
- import ghidra.util.exception.CancelledException;
- public class hfExportEverythingToSingleFile extends GhidraScript {
- public void run() {
- try {
- // Output file
- File output = askFile("Export decompiled functions", "Save");
- DecompInterface decompiler = new DecompInterface();
- decompiler.openProgram(currentProgram);
- FileWriter writer = new FileWriter(output);
- // Get all functions
- FunctionIterator functions = currentProgram.getFunctionManager().getFunctions(true);
- while (functions.hasNext()) {
- Function func = functions.next();
- if (func.isExternal()) continue;
- // Get decompiled code
- DecompileResults result = decompiler.decompileFunction(func, 30, getMonitor());
- String code = result.getDecompiledFunction().getC();
- // Write to file
- writer.write("=== " + func.getName() + "-" + func.getEntryPoint().toString() + " ===\n\n");
- writer.write(code);
- writer.write("\n\n");
- }
- writer.close();
- decompiler.dispose();
- } catch (Exception e) {
- println("Error: " + e.getMessage());
- }
- }
- }
Advertisement