mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-02 04:11:44 +08:00
Merge remote-tracking branch
'origin/GP-5545-5600_ryanmkurtz_autoimporter--SQUASHED' (Closes #8097)
This commit is contained in:
+16
-13
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+11
-10
@@ -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;
|
||||
@@ -381,13 +380,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);
|
||||
}
|
||||
|
||||
+10
-8
@@ -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);
|
||||
|
||||
+12
-19
@@ -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.
|
||||
@@ -30,17 +30,16 @@ import generic.theme.GThemeDefaults.Colors;
|
||||
import generic.theme.GThemeDefaults.Colors.Palette;
|
||||
import ghidra.app.plugin.core.codebrowser.CodeViewerProvider;
|
||||
import ghidra.app.plugin.core.references.*;
|
||||
import ghidra.app.util.importer.*;
|
||||
import ghidra.app.util.importer.ProgramLoader;
|
||||
import ghidra.app.util.opinion.LoadResults;
|
||||
import ghidra.app.util.opinion.LoaderService;
|
||||
import ghidra.framework.main.DataTreeDialog;
|
||||
import ghidra.framework.model.Project;
|
||||
import ghidra.program.model.listing.CodeUnit;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.model.mem.Memory;
|
||||
import ghidra.program.model.mem.MemoryAccessException;
|
||||
import ghidra.util.InvalidNameException;
|
||||
import ghidra.util.exception.*;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.exception.VersionException;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
|
||||
public class ReferencesPluginScreenShots extends GhidraScreenShotGenerator {
|
||||
@@ -301,20 +300,14 @@ public class ReferencesPluginScreenShots extends GhidraScreenShotGenerator {
|
||||
|
||||
}
|
||||
|
||||
private void importFile(File file) throws CancelledException, DuplicateNameException,
|
||||
InvalidNameException, VersionException, IOException {
|
||||
String programNameOverride = null;
|
||||
private void importFile(File file) throws CancelledException, VersionException, IOException {
|
||||
Project project = env.getProject();
|
||||
LoadResults<Program> loadResults = AutoImporter.importFresh(file, project,
|
||||
project.getProjectData().getRootFolder().getPathname(), this, new MessageLog(),
|
||||
TaskMonitor.DUMMY, LoaderService.ACCEPT_ALL, LoadSpecChooser.CHOOSE_THE_FIRST_PREFERRED,
|
||||
programNameOverride, OptionChooser.DEFAULT_OPTIONS);
|
||||
|
||||
try {
|
||||
loadResults.getPrimary().save(project, new MessageLog(), TaskMonitor.DUMMY);
|
||||
}
|
||||
finally {
|
||||
loadResults.release(this);
|
||||
try (LoadResults<Program> loadResults = ProgramLoader.builder()
|
||||
.source(file)
|
||||
.project(project)
|
||||
.projectFolderPath(project.getProjectData().getRootFolder().getPathname())
|
||||
.load()) {
|
||||
loadResults.getPrimary().save(TaskMonitor.DUMMY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user