This commit is contained in:
Guus Waals 2025-05-29 17:36:15 +08:00
parent 2791a66b1f
commit 16e5456079
3 changed files with 30 additions and 21 deletions

View File

@ -7,6 +7,7 @@ import ghidra.program.model.listing.Function;
import re3lib.FunctionDumper; import re3lib.FunctionDumper;
import re3lib.GlobalDumper; import re3lib.GlobalDumper;
import re3lib.RemanConfig; import re3lib.RemanConfig;
import re3lib.FunctionDatabase;
public class DumpCurrentFunction extends GhidraScript { public class DumpCurrentFunction extends GhidraScript {
@Override @Override
@ -14,21 +15,23 @@ public class DumpCurrentFunction extends GhidraScript {
RemanConfig.INSTANCE = new RemanConfig(this); RemanConfig.INSTANCE = new RemanConfig(this);
RemanConfig.INSTANCE.createDirectories(); RemanConfig.INSTANCE.createDirectories();
GlobalDumper globalDumper = new GlobalDumper(this); try (FunctionDatabase functionDatabase = new FunctionDatabase(this)) {
globalDumper.loadGlobalManifest(); GlobalDumper globalDumper = new GlobalDumper(this, functionDatabase);
FunctionDumper functionDumper = new FunctionDumper(this, globalDumper); globalDumper.loadGlobalManifest();
FunctionDumper functionDumper = new FunctionDumper(this, functionDatabase, globalDumper);
Function currentFunction = getFunctionContaining(currentAddress); Function currentFunction = getFunctionContaining(currentAddress);
if (currentFunction != null) { if (currentFunction != null) {
functionDumper.dump(currentFunction); functionDumper.dump(currentFunction);
} else { } else {
println("No function found at the current address."); println("No function found at the current address.");
}
if (functionDumper.createdFile)
RemanConfig.INSTANCE.touchCMakeTimestamp();
globalDumper.dumpGlobals();
globalDumper.saveGlobalManifest();
} }
if (functionDumper.createdFile)
RemanConfig.INSTANCE.touchCMakeTimestamp();
globalDumper.dumpGlobals();
globalDumper.saveGlobalManifest();
} }
} }

View File

@ -14,10 +14,11 @@ public class Test extends GhidraScript {
RemanConfig.INSTANCE = new RemanConfig(this); RemanConfig.INSTANCE = new RemanConfig(this);
// Example SQLite usage // Example SQLite usage
FunctionDatabase db = new FunctionDatabase(this); try (FunctionDatabase db = new FunctionDatabase(this)) {
List<FunctionDatabase.Entry> entries = db.loadAllEntries(); List<FunctionDatabase.Entry> entries = db.loadAllEntries();
for (FunctionDatabase.Entry entry : entries) { for (FunctionDatabase.Entry entry : entries) {
println("entry.name: " + entry.name + " entry.address: " + entry.address + " entry.type: " + entry.type); println("entry.name: " + entry.name + " entry.address: " + entry.address + " entry.type: " + entry.type);
}
} }
} }
} }

View File

@ -19,7 +19,7 @@ import ghidra.app.script.GhidraScript;
import ghidra.program.model.address.Address; import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function; import ghidra.program.model.listing.Function;
public class FunctionDatabase { public class FunctionDatabase implements AutoCloseable {
public enum Type { public enum Type {
Auto(0), Auto(0),
Fix(1), Fix(1),
@ -359,8 +359,8 @@ public class FunctionDatabase {
} }
public void applyDefaultFilters(boolean rebuildAllGlobals) throws Exception { public void applyDefaultFilters(boolean rebuildAllGlobals) throws Exception {
GlobalDumper globalDumper = new GlobalDumper(script); GlobalDumper globalDumper = new GlobalDumper(script, this);
FunctionDumper dumper = new FunctionDumper(script, globalDumper); FunctionDumper dumper = new FunctionDumper(script, this, globalDumper);
if (rebuildAllGlobals) { if (rebuildAllGlobals) {
globalDumper.removeGlobalManifest(); globalDumper.removeGlobalManifest();
@ -484,4 +484,9 @@ public class FunctionDatabase {
typeDumper.run(); typeDumper.run();
} }
} }
@Override
public void close() throws Exception {
this.disconnect();
}
} }