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.GlobalDumper;
import re3lib.RemanConfig;
import re3lib.FunctionDatabase;
public class DumpCurrentFunction extends GhidraScript {
@Override
@ -14,21 +15,23 @@ public class DumpCurrentFunction extends GhidraScript {
RemanConfig.INSTANCE = new RemanConfig(this);
RemanConfig.INSTANCE.createDirectories();
GlobalDumper globalDumper = new GlobalDumper(this);
globalDumper.loadGlobalManifest();
FunctionDumper functionDumper = new FunctionDumper(this, globalDumper);
try (FunctionDatabase functionDatabase = new FunctionDatabase(this)) {
GlobalDumper globalDumper = new GlobalDumper(this, functionDatabase);
globalDumper.loadGlobalManifest();
FunctionDumper functionDumper = new FunctionDumper(this, functionDatabase, globalDumper);
Function currentFunction = getFunctionContaining(currentAddress);
if (currentFunction != null) {
functionDumper.dump(currentFunction);
} else {
println("No function found at the current address.");
Function currentFunction = getFunctionContaining(currentAddress);
if (currentFunction != null) {
functionDumper.dump(currentFunction);
} else {
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);
// Example SQLite usage
FunctionDatabase db = new FunctionDatabase(this);
List<FunctionDatabase.Entry> entries = db.loadAllEntries();
for (FunctionDatabase.Entry entry : entries) {
println("entry.name: " + entry.name + " entry.address: " + entry.address + " entry.type: " + entry.type);
try (FunctionDatabase db = new FunctionDatabase(this)) {
List<FunctionDatabase.Entry> entries = db.loadAllEntries();
for (FunctionDatabase.Entry entry : entries) {
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.listing.Function;
public class FunctionDatabase {
public class FunctionDatabase implements AutoCloseable {
public enum Type {
Auto(0),
Fix(1),
@ -359,8 +359,8 @@ public class FunctionDatabase {
}
public void applyDefaultFilters(boolean rebuildAllGlobals) throws Exception {
GlobalDumper globalDumper = new GlobalDumper(script);
FunctionDumper dumper = new FunctionDumper(script, globalDumper);
GlobalDumper globalDumper = new GlobalDumper(script, this);
FunctionDumper dumper = new FunctionDumper(script, this, globalDumper);
if (rebuildAllGlobals) {
globalDumper.removeGlobalManifest();
@ -484,4 +484,9 @@ public class FunctionDatabase {
typeDumper.run();
}
}
@Override
public void close() throws Exception {
this.disconnect();
}
}