GP-5545_5600: ProgramLoader and more flexible loader args

This commit is contained in:
Ryan Kurtz
2025-07-01 08:18:36 -04:00
parent 4aa78ae6d0
commit d3aed2c4b3
47 changed files with 2026 additions and 976 deletions

View File

@@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,8 +20,7 @@ import java.io.File;
import org.junit.*;
import db.Transaction;
import ghidra.app.util.importer.AutoImporter;
import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.importer.ProgramLoader;
import ghidra.app.util.opinion.LoadResults;
import ghidra.base.project.GhidraProject;
import ghidra.framework.Application;
@@ -57,15 +56,19 @@ public class TutorialDebuggerMaintenance extends AbstractGhidraHeadedIntegration
@Test
public void testRecreateTermminesGzf() throws Throwable {
File termmines = Application.getModuleDataFile("TestResources", "termmines").getFile(false);
LoadResults<Program> results = AutoImporter.importByUsingBestGuess(termmines,
env.getProject(), "/", this, new MessageLog(), CONSOLE);
program = results.getPrimaryDomainObject();
try (Transaction tx = program.openTransaction("Analyze")) {
program.setExecutablePath("/tmp/termmines");
GhidraProject.analyze(program);
try (LoadResults<Program> loadResults = ProgramLoader.builder()
.source(termmines)
.project(env.getProject())
.monitor(CONSOLE)
.load()) {
program = loadResults.getPrimaryDomainObject(this);
try (Transaction tx = program.openTransaction("Analyze")) {
program.setExecutablePath("/tmp/termmines");
GhidraProject.analyze(program);
}
File dest = new File(termmines.getParentFile(), "termmines.gzf");
dest.delete();
program.saveToPackedFile(dest, CONSOLE);
}
File dest = new File(termmines.getParentFile(), "termmines.gzf");
dest.delete();
program.saveToPackedFile(dest, CONSOLE);
}
}

View File

@@ -15,7 +15,7 @@
*/
package ghidraclass.debugger.screenshot;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
@@ -74,8 +74,7 @@ import ghidra.app.plugin.core.terminal.TerminalProvider;
import ghidra.app.script.GhidraState;
import ghidra.app.services.*;
import ghidra.app.services.DebuggerEmulationService.EmulationResult;
import ghidra.app.util.importer.AutoImporter;
import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.importer.ProgramLoader;
import ghidra.app.util.opinion.LoadResults;
import ghidra.async.AsyncTestUtils;
import ghidra.debug.api.modules.ModuleMapProposal;
@@ -389,13 +388,15 @@ public class TutorialDebuggerScreenShots extends GhidraScreenShotGenerator
protected Program importModule(TraceModule module) throws Throwable {
Program prog = null;
try {
long snap = flatDbg.getCurrentSnap();
MessageLog log = new MessageLog();
LoadResults<Program> result = AutoImporter.importByUsingBestGuess(
new File(module.getName(snap)), env.getProject(), "/", this, log, monitor);
result.save(env.getProject(), this, log, monitor);
prog = result.getPrimaryDomainObject();
long snap = flatDbg.getCurrentSnap();
try (LoadResults<Program> result = ProgramLoader.builder()
.source(new File(module.getName(snap)))
.project(env.getProject())
.monitor(monitor)
.load()) {
result.save(monitor);
prog = result.getPrimaryDomainObject(this);
GhidraProgramUtilities.markProgramNotToAskToAnalyze(prog);
programManager.openProgram(prog);
}

View File

@@ -15,9 +15,8 @@
*/
package ghidra.app.plugin.core.debug.gui.tracermi.launcher;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assert.*;
import static org.junit.Assume.*;
import java.nio.file.Paths;
import java.util.*;
@@ -31,8 +30,7 @@ import ghidra.app.plugin.core.analysis.AnalysisBackgroundCommand;
import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
import ghidra.app.plugin.core.debug.gui.AbstractGhidraHeadedDebuggerTest;
import ghidra.app.services.TraceRmiLauncherService;
import ghidra.app.util.importer.AutoImporter;
import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.importer.ProgramLoader;
import ghidra.app.util.opinion.LoadResults;
import ghidra.debug.api.ValStr;
import ghidra.debug.api.tracermi.TraceRmiLaunchOffer;
@@ -80,9 +78,13 @@ public class TraceRmiLauncherServicePluginTest extends AbstractGhidraHeadedDebug
@Test
public void testGetClassName() throws Exception {
ResourceFile rf = Application.getModuleDataFile("TestResources", "HelloWorld.class");
LoadResults<Program> results = AutoImporter.importByUsingBestGuess(rf.getFile(false),
env.getProject(), "/", this, new MessageLog(), monitor);
program = results.getPrimaryDomainObject();
try (LoadResults<Program> results = ProgramLoader.builder()
.source(rf.getFile(false))
.project(env.getProject())
.monitor(monitor)
.load()) {
program = results.getPrimaryDomainObject(this);
}
AutoAnalysisManager analyzer = AutoAnalysisManager.getAnalysisManager(program);
analyzer.reAnalyzeAll(null);
Command<Program> cmd = new AnalysisBackgroundCommand(analyzer, false);