hubertf

ghidra - hfExportEverythingToSingleFile.java

Feb 7th, 2026
239
0
Never
9
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.62 KB | None | 0 0
  1. // @author hubertf / Windsurf
  2. // @category Export
  3.  
  4. import ghidra.app.decompiler.*;
  5. import ghidra.program.model.listing.*;
  6. import ghidra.util.task.*;
  7. import java.io.*;
  8. import ghidra.app.script.GhidraScript;
  9. import ghidra.util.exception.CancelledException;
  10.  
  11. public class hfExportEverythingToSingleFile extends GhidraScript {
  12.    
  13.     public void run() {
  14.         try {
  15.             // Output file
  16.             File output = askFile("Export decompiled functions", "Save");
  17.            
  18.             DecompInterface decompiler = new DecompInterface();
  19.             decompiler.openProgram(currentProgram);
  20.            
  21.             FileWriter writer = new FileWriter(output);
  22.            
  23.             // Get all functions
  24.             FunctionIterator functions = currentProgram.getFunctionManager().getFunctions(true);
  25.            
  26.             while (functions.hasNext()) {
  27.                 Function func = functions.next();
  28.                 if (func.isExternal()) continue;
  29.                
  30.                 // Get decompiled code
  31.                 DecompileResults result = decompiler.decompileFunction(func, 30, getMonitor());
  32.                 String code = result.getDecompiledFunction().getC();
  33.                
  34.                 // Write to file
  35.                 writer.write("=== " + func.getName() + "-" + func.getEntryPoint().toString() + " ===\n\n");
  36.                 writer.write(code);
  37.                 writer.write("\n\n");
  38.             }
  39.            
  40.             writer.close();
  41.             decompiler.dispose();
  42.            
  43.         } catch (Exception e) {
  44.             println("Error: " + e.getMessage());
  45.         }
  46.     }
  47. }
  48.  
Tags: Java ghidra
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment