Checkpoint EEPROM, firmware analysis and instrument protocol updates
This commit is contained in:
38
python/set_devices/disassembly_scripts/SetguiExportC.java
Normal file
38
python/set_devices/disassembly_scripts/SetguiExportC.java
Normal file
@@ -0,0 +1,38 @@
|
||||
// Local C pseudocode export for a raw, user-selected C28x code range.
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.app.decompiler.DecompInterface;
|
||||
import ghidra.app.decompiler.DecompileResults;
|
||||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.listing.Function;
|
||||
import ghidra.program.model.listing.FunctionIterator;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class SetguiExportC extends GhidraScript {
|
||||
public void run() throws Exception {
|
||||
Address entry = currentProgram.getMinAddress();
|
||||
disassemble(entry);
|
||||
createFunction(entry, null);
|
||||
analyzeAll(currentProgram);
|
||||
DecompInterface decompiler = new DecompInterface();
|
||||
try (PrintWriter out = new PrintWriter(getScriptArgs()[0], StandardCharsets.UTF_8.name())) {
|
||||
out.println("/* Ghidra C pseudocode. Recovered types/names may be incomplete. */");
|
||||
if (!decompiler.openProgram(currentProgram))
|
||||
throw new Exception(decompiler.getLastMessage());
|
||||
FunctionIterator functions = currentProgram.getFunctionManager().getFunctions(true);
|
||||
int count = 0;
|
||||
while (functions.hasNext() && !monitor.isCancelled()) {
|
||||
Function function = functions.next();
|
||||
if (function.isExternal()) continue;
|
||||
DecompileResults result = decompiler.decompileFunction(function, 10, monitor);
|
||||
out.println("/* Address: " + function.getEntryPoint() + " */");
|
||||
if (result.decompileCompleted() && result.getDecompiledFunction() != null) {
|
||||
out.println(result.getDecompiledFunction().getC());
|
||||
count++;
|
||||
} else out.println("/* Decompilation failed: " + result.getErrorMessage() + " */");
|
||||
}
|
||||
if (count == 0) throw new Exception("No functions decompiled. Select a range beginning at a function entry.");
|
||||
out.println("/* SETGUI_DECOMPILE_SUCCESS */");
|
||||
} finally { decompiler.dispose(); }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user