WIP
This commit is contained in:
71
scripts/DumpCurrentFunctionRecursive.java
Normal file
71
scripts/DumpCurrentFunctionRecursive.java
Normal file
@@ -0,0 +1,71 @@
|
||||
// Decompile selected function recursively
|
||||
// @category _Reman3
|
||||
// @menupath Reman3.Dump Current Function (recursive)
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.program.model.listing.Function;
|
||||
import re3lib.FunctionDumper;
|
||||
import re3lib.GlobalDumper;
|
||||
import re3lib.PCallTracer;
|
||||
import re3lib.RecompileConfig;
|
||||
|
||||
public class DumpCurrentFunctionRecursive extends GhidraScript {
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
RecompileConfig.INSTANCE = new RecompileConfig(this);
|
||||
RecompileConfig.INSTANCE.createDirectories();
|
||||
|
||||
GlobalDumper globalDumper = new GlobalDumper(this);
|
||||
globalDumper.loadGlobalManifest();
|
||||
|
||||
PCallTracer tracer = new PCallTracer();
|
||||
tracer.traceCalls(getFunctionContaining(currentAddress));
|
||||
|
||||
List<Function> functionsToDump = new ArrayList<>();
|
||||
List<Function> functionsToDumpNew = new ArrayList<>();
|
||||
for (Function func : tracer.out) {
|
||||
if (FunctionDumper.isDumpedFix(func))
|
||||
continue;
|
||||
|
||||
println("Dump: " + func.getName());
|
||||
functionsToDump.add(func);
|
||||
|
||||
if (!FunctionDumper.isDumpedAuto(func))
|
||||
functionsToDumpNew.add(func);
|
||||
}
|
||||
|
||||
if (!functionsToDump.isEmpty()) {
|
||||
String newOpt = "Only new (" + functionsToDumpNew.size() + ")";
|
||||
String okOpt = "Yes (" + functionsToDump.size() + ")";
|
||||
String choice = askChoice("Confirmation", "About to generate " + functionsToDump.size() + " functions ("
|
||||
+ functionsToDumpNew.size() + " new), continue?",
|
||||
new ArrayList<String>() {
|
||||
{
|
||||
add(okOpt);
|
||||
add(newOpt);
|
||||
add("No");
|
||||
}
|
||||
}, okOpt);
|
||||
if (choice == okOpt) {
|
||||
} else if (choice == newOpt) {
|
||||
functionsToDump = functionsToDumpNew;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
FunctionDumper functionDumper = new FunctionDumper(this, globalDumper);
|
||||
for (Function func : functionsToDump) {
|
||||
functionDumper.dump(func);
|
||||
}
|
||||
|
||||
if (functionDumper.createdFile)
|
||||
RecompileConfig.INSTANCE.touchCMakeTimestamp();
|
||||
|
||||
globalDumper.dumpGlobals();
|
||||
globalDumper.saveGlobalManifest();
|
||||
}
|
||||
}
|
||||
}
|
@@ -128,6 +128,9 @@ public class GlobalDumper {
|
||||
String escapeCString(String str) {
|
||||
str = str.replace("\\", "\\\\");
|
||||
str = str.replace("\"", "\\\"");
|
||||
str = str.replace("\n", "\\n");
|
||||
str = str.replace("\r", "\\r");
|
||||
str = str.replace("\t", "\\t");
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@@ -52,7 +52,6 @@ public class PCallTracer {
|
||||
Address callAddr = target.getAddress();
|
||||
Function calledFunction = script.getFunctionAt(callAddr);
|
||||
if (calledFunction == null) {
|
||||
|
||||
script.println("PCallTracer, called function not found: " + op.toString() + " - "
|
||||
+ highFunction.getFunction().getName());
|
||||
continue;
|
||||
@@ -69,7 +68,7 @@ public class PCallTracer {
|
||||
if (!visited.contains(function.getEntryPoint())) {
|
||||
visited.add(function.getEntryPoint());
|
||||
if (trace) {
|
||||
// script.println("PCallTracer, visiting " + function.getName() + " (depth:" + depth + ")");
|
||||
script.println("PCallTracer, visiting " + function.getName() + " (depth:" + depth + ")");
|
||||
}
|
||||
DecompileResults decompRes = decomp.getOrInsert(function);
|
||||
visit(decompRes.getHighFunction(), depth);
|
||||
|
Reference in New Issue
Block a user