GP-4628: Fixed an issue with the provided .exports files not getting properly used in some scenarios

This commit is contained in:
Ryan Kurtz 2024-06-03 06:21:16 -04:00
parent 2ce5fcc62d
commit 25dac71b83
3 changed files with 24 additions and 60 deletions

View File

@ -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.
* <p>
* 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<FSRL> candidateLibraryFsrls =
findLibrary(getCheckedPath(libraryName), fsSearchPaths, log, monitor);
if (candidateLibraryFsrls.isEmpty()) {
log.appendMsg("Library not found.");
return null;
}
for (FSRL candidateLibraryFsrl : candidateLibraryFsrls) {
monitor.checkCancelled();
List<String> 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) {

View File

@ -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<Option> options, MessageLog log, TaskMonitor monitor)
throws IOException, CancelledException {
int size = loadSpec.getLanguageCompilerSpec().getLanguageDescription().getSize();
File localLibFile = getLocalFile(libFsrl);
ResourceFile existingExportsFile = LibraryLookupTable.getExistingExportsFile(libName, size);
// Create exports file
if (localLibFile == null ||
!LibraryLookupTable.libraryLookupTableFileExists(libName, size) ||
!LibraryLookupTable.hasFileAndPathAndTimeStampMatch(localLibFile, size)) {
log.appendMsg("Examining ordinal info in %s...".formatted(libFsrl));
if (!shouldPerformOrdinalLookup(options)) {
return;
}
// Create exports file if necessary
if (existingExportsFile == null) {
try {
// Need to write correct library exports file (LibrarySymbolTable)
// for use with related imports
LibraryLookupTable.createFile(lib, true, monitor);
ResourceFile newExportsFile = LibraryLookupTable.createFile(lib, true, monitor);
log.appendMsg("Created exports file: " + newExportsFile);
}
catch (IOException e) {
log.appendMsg("Unable to create exports file for " + libFsrl);
Msg.error(this, "Unable to create exports file for " + libFsrl, e);
}
}
else {
log.appendMsg("Using existing exports file: " + existingExportsFile);
File localLibFile = getLocalFile(libFsrl);
if (localLibFile != null &&
!LibraryLookupTable.hasFileAndPathAndTimeStampMatch(localLibFile, size)) {
log.appendMsg("WARNING: Existing exports file may not be an exact match.");
}
}
}

View File

@ -220,6 +220,7 @@ public class LibraryLookupTable {
String cacheKey = LibrarySymbolTable.getCacheKey(dllName, size);
LibrarySymbolTable symTab = cacheMap.get(cacheKey);
if (symTab != null) {
log.appendMsg("Applying cached symbols from " + dllName);
return symTab;
}