Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/test/java/kaiju/ghihorn/GhiHornTestEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import ghidra.test.TestEnv;
import ghidra.util.InvalidNameException;
import ghidra.util.Msg;
import ghidra.app.util.importer.ProgramLoader;
import ghidra.app.util.opinion.LoadException;
import ghidra.app.util.opinion.LoadResults;
import ghidra.util.exception.CancelledException;
import ghidra.util.exception.DuplicateNameException;
import ghidra.util.exception.VersionException;
Expand Down Expand Up @@ -293,18 +296,19 @@ public static File asFile(String hex) {

}

public Program importTestProgram(File exe) throws CancelledException, DuplicateNameException, InvalidNameException, VersionException, IOException {

// Import the program
Program p = env.getGhidraProject().importProgram(exe);
env.open(p);

env.getGhidraProject().analyze(p, true);

// And mark it as analyzed? Ok ghidra whatever.
GhidraProgramUtilities.markProgramAnalyzed(p);

return p;
public Program importTestProgram(File exe) throws CancelledException, DuplicateNameException, InvalidNameException, VersionException, IOException, LoadException {

try (LoadResults<Program> results = ProgramLoader.builder()
.source(exe)
.project(env.getGhidraProject().getProject())
.monitor(TaskMonitor.DUMMY)
.load()) {
Program p = results.getPrimaryDomainObject(this);
env.open(p);
env.getGhidraProject().analyze(p, true);
GhidraProgramUtilities.markProgramAnalyzed(p);
return p;
}
}

/**
Expand Down
42 changes: 19 additions & 23 deletions src/test/java/kaiju/ooanalyzer/OOAnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
//import static org.junit.Assert.assertTrue;

import java.nio.file.Path;
import ghidra.app.util.importer.ProgramLoader;
import ghidra.app.util.opinion.LoadResults;
import ghidra.program.model.listing.Program;
import ghidra.program.util.GhidraProgramUtilities;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
import ghidra.util.Msg;
import ghidra.util.task.TaskMonitor;
import kaiju.common.di.GhidraDI;
import kaiju.tools.ooanalyzer.OOAnalyzerGhidraPlugin;

Expand All @@ -55,38 +58,31 @@ public void doTest(Path exe, Path json, Boolean useNs) throws Exception {
env = new TestEnv();
setErrorGUIEnabled(false);

// Import the program
Program p = env.getGhidraProject().importProgram(exe.toFile());
try (LoadResults<Program> results = ProgramLoader.builder()
.source(exe.toFile())
.project(env.getGhidraProject().getProject())
.monitor(TaskMonitor.DUMMY)
.load()) {
Program p = results.getPrimaryDomainObject(this);

// Open in the tool
env.open(p);
env.open(p);
GhidraProgramUtilities.markProgramAnalyzed(p);

// Analyze it
// NOTE: get heap exhaustion errors when doing analysis with Fn2Hash, etc.
// Not necessary to analyze to check JSON importer, but consider
// for future tests.
//env.getGhidraProject ().analyze (p, false);
plugin = env.addPlugin(OOAnalyzerGhidraPlugin.class);

// And mark it as analyzed? Ok ghidra whatever.
GhidraProgramUtilities.markProgramAnalyzed(p);
OOAnalyzerGhidraPlugin.ImportCommand cmd = plugin.configureAndExecute(json.toFile(), useNs);

plugin = env.addPlugin(OOAnalyzerGhidraPlugin.class);
while (!cmd.getCompleted()) {
Msg.debug(this, "Sleeping until completed.");
Thread.sleep(1000);
}

// Import json.
OOAnalyzerGhidraPlugin.ImportCommand cmd = plugin.configureAndExecute(json.toFile(), useNs);
Msg.info(this, "We didn't crash!");

// Use a semaphore or something. Get the tool's TaskMonitor?
while (!cmd.getCompleted ()) {
Msg.debug(this, "Sleeping until completed.");
Thread.sleep(1000);
env.close(p);
}

Msg.info(this, "We didn't crash!");

env.close(p);

env.dispose();

}

}
Loading