diff --git a/java/ghidra/DumpCurrentFunction.java b/java/ghidra/DumpCurrentFunction.java index c1987d5a..5cc5691a 100644 --- a/java/ghidra/DumpCurrentFunction.java +++ b/java/ghidra/DumpCurrentFunction.java @@ -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(); } } diff --git a/java/ghidra/Test.java b/java/ghidra/Test.java index 9ed63dbc..54618f7e 100644 --- a/java/ghidra/Test.java +++ b/java/ghidra/Test.java @@ -14,10 +14,11 @@ public class Test extends GhidraScript { RemanConfig.INSTANCE = new RemanConfig(this); // Example SQLite usage - FunctionDatabase db = new FunctionDatabase(this); - List 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 entries = db.loadAllEntries(); + for (FunctionDatabase.Entry entry : entries) { + println("entry.name: " + entry.name + " entry.address: " + entry.address + " entry.type: " + entry.type); + } } } } \ No newline at end of file diff --git a/java/ghidra/re3lib/FunctionDatabase.java b/java/ghidra/re3lib/FunctionDatabase.java index be7bd071..cda81f61 100644 --- a/java/ghidra/re3lib/FunctionDatabase.java +++ b/java/ghidra/re3lib/FunctionDatabase.java @@ -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(); + } }