From 25dac71b83ff6542abef63fd0a30c7ef91e88ce2 Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Mon, 3 Jun 2024 06:21:16 -0400 Subject: [PATCH] GP-4628: Fixed an issue with the provided .exports files not getting properly used in some scenarios --- .../opinion/AbstractLibrarySupportLoader.java | 33 ++---------- .../opinion/AbstractOrdinalSupportLoader.java | 50 +++++++------------ .../app/util/opinion/LibraryLookupTable.java | 1 + 3 files changed, 24 insertions(+), 60 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractLibrarySupportLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractLibrarySupportLoader.java index 6e08264c11..f9db579c90 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractLibrarySupportLoader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractLibrarySupportLoader.java @@ -405,24 +405,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader return FileSystemService.getInstance().getByteProvider(libFsrl, true, monitor); } - /** - * Checks whether or not the given library should be loaded. - *

- * It may be appropriate to not load a specific library after examining its bytes. - * - * @param libraryName The name of the library - * @param libraryFsrl The library {@link FSRL} - * @param provider The library bytes - * @param desiredLoadSpec The desired {@link LoadSpec} - * @param log The log - * @return True if the given library should be loaded; otherwise, false - * @throws IOException If an IO-related error occurred - */ - protected boolean shouldLoadLibrary(String libraryName, FSRL libraryFsrl, - ByteProvider provider, LoadSpec desiredLoadSpec, MessageLog log) throws IOException { - return true; - } - /** * Performs optional follow-on actions after an the given library has been loaded * @@ -511,7 +493,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader // options turned off (if shouldSearchAllPaths() is overridden to return true). // In this case, we still want to process those libraries, but we // do not want to save them, so they can be released. - boolean found = false; boolean loaded = false; if (!customSearchPaths.isEmpty()) { log.appendMsg("Searching %d custom path%s for library %s...".formatted( @@ -521,7 +502,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader provider, customSearchPaths, libraryDestFolderPath, unprocessed, depth, desiredLoadSpec, options, log, consumer, monitor); if (loadedLibrary != null) { - found = true; loaded = true; loadedPrograms.add(loadedLibrary); } @@ -534,7 +514,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader provider, localSearchPaths, libraryDestFolderPath, unprocessed, depth, desiredLoadSpec, options, log, consumer, monitor); if (loadedLibrary != null) { - found = true; if (loadLocalLibraries) { loaded = true; loadedPrograms.add(loadedLibrary); @@ -552,7 +531,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader provider, systemSearchPaths, libraryDestFolderPath, unprocessed, depth, desiredLoadSpec, options, log, consumer, monitor); if (loadedLibrary != null) { - found = true; if (loadSystemLibraries) { loaded = true; loadedPrograms.add(loadedLibrary); @@ -562,9 +540,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader } } } - if (!found) { - log.appendMsg("Library not found."); - } else { if (loaded) { log.appendMsg("Saving library to: " + @@ -642,6 +617,11 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader try { List candidateLibraryFsrls = findLibrary(getCheckedPath(libraryName), fsSearchPaths, log, monitor); + if (candidateLibraryFsrls.isEmpty()) { + log.appendMsg("Library not found."); + return null; + } + for (FSRL candidateLibraryFsrl : candidateLibraryFsrls) { monitor.checkCancelled(); List newLibraryList = new ArrayList<>(); @@ -832,9 +812,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader try (ByteProvider provider = createLibraryByteProvider(libraryFsrl, desiredLoadSpec, log, monitor)) { - if (!shouldLoadLibrary(libraryName, libraryFsrl, provider, desiredLoadSpec, log)) { - return null; - } LoadSpec libLoadSpec = matchSupportedLoadSpec(desiredLoadSpec, provider); if (libLoadSpec == null) { diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractOrdinalSupportLoader.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractOrdinalSupportLoader.java index 6821e27782..e7534b32c2 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractOrdinalSupportLoader.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/AbstractOrdinalSupportLoader.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.Iterator; import java.util.List; +import generic.jar.ResourceFile; import ghidra.app.util.Option; import ghidra.app.util.OptionUtils; import ghidra.app.util.bin.ByteProvider; @@ -31,7 +32,6 @@ import ghidra.framework.options.Options; import ghidra.program.model.listing.Function; import ghidra.program.model.listing.Program; import ghidra.program.model.symbol.*; -import ghidra.util.Msg; import ghidra.util.exception.*; import ghidra.util.task.TaskMonitor; @@ -75,47 +75,33 @@ public abstract class AbstractOrdinalSupportLoader extends AbstractLibrarySuppor return shouldPerformOrdinalLookup(options); } - @Override - protected boolean shouldLoadLibrary(String libName, FSRL libFsrl, ByteProvider provider, - LoadSpec loadSpec, MessageLog log) throws IOException { - - if (!super.shouldLoadLibrary(libName, libFsrl, provider, loadSpec, log)) { - return false; - } - - int size = loadSpec.getLanguageCompilerSpec().getLanguageDescription().getSize(); - File localLibFile = getLocalFile(libFsrl); - - if (localLibFile == null || - !LibraryLookupTable.hasFileAndPathAndTimeStampMatch(localLibFile, size) && - LibraryLookupTable.libraryLookupTableFileExists(libName, size)) { - log.appendMsg("WARNING! Using existing exports file for " + libName + - " which may not be an exact match"); - } - - return true; - } - @Override protected void processLibrary(Program lib, String libName, FSRL libFsrl, ByteProvider provider, LoadSpec loadSpec, List