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,8 @@ import java.io.File;
import java.io.IOException;
import ghidra.app.script.GhidraScript;
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.framework.model.DomainFolder;
import ghidra.program.model.lang.LanguageCompilerSpecPair;
@ -53,21 +53,20 @@ public class ImportAllProgramsFromADirectoryScript extends GhidraScript {
continue;
}
LoadResults<Program> loadResults = null;
try {
loadResults = AutoImporter.importByLookingForLcs(file, state.getProject(),
folder.getPathname(), language.getLanguage(), language.getCompilerSpec(), this,
log, monitor);
loadResults.getPrimary().save(state.getProject(), log, monitor);
try (LoadResults<Program> loadResults = ProgramLoader.builder()
.source(file)
.project(state.getProject())
.projectFolderPath(folder.getPathname())
.language(language.getLanguage())
.compiler(language.getCompilerSpec())
.log(log)
.monitor(monitor)
.load()) {
loadResults.getPrimary().save(monitor);
}
catch (IOException e) {
println("Unable to import program from file " + file.getName());
}
finally {
if (loadResults != null) {
loadResults.release(this);
}
}
println(log.toString());
log.clear();