mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-11-22 20:22:44 +00:00
GP-4628: Fixed an issue with the provided .exports files not getting properly used in some scenarios
This commit is contained in:
parent
2ce5fcc62d
commit
25dac71b83
@ -405,24 +405,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||||||
return FileSystemService.getInstance().getByteProvider(libFsrl, true, monitor);
|
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
|
* 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).
|
// options turned off (if shouldSearchAllPaths() is overridden to return true).
|
||||||
// In this case, we still want to process those libraries, but we
|
// In this case, we still want to process those libraries, but we
|
||||||
// do not want to save them, so they can be released.
|
// do not want to save them, so they can be released.
|
||||||
boolean found = false;
|
|
||||||
boolean loaded = false;
|
boolean loaded = false;
|
||||||
if (!customSearchPaths.isEmpty()) {
|
if (!customSearchPaths.isEmpty()) {
|
||||||
log.appendMsg("Searching %d custom path%s for library %s...".formatted(
|
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,
|
provider, customSearchPaths, libraryDestFolderPath, unprocessed, depth,
|
||||||
desiredLoadSpec, options, log, consumer, monitor);
|
desiredLoadSpec, options, log, consumer, monitor);
|
||||||
if (loadedLibrary != null) {
|
if (loadedLibrary != null) {
|
||||||
found = true;
|
|
||||||
loaded = true;
|
loaded = true;
|
||||||
loadedPrograms.add(loadedLibrary);
|
loadedPrograms.add(loadedLibrary);
|
||||||
}
|
}
|
||||||
@ -534,7 +514,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||||||
provider, localSearchPaths, libraryDestFolderPath, unprocessed, depth,
|
provider, localSearchPaths, libraryDestFolderPath, unprocessed, depth,
|
||||||
desiredLoadSpec, options, log, consumer, monitor);
|
desiredLoadSpec, options, log, consumer, monitor);
|
||||||
if (loadedLibrary != null) {
|
if (loadedLibrary != null) {
|
||||||
found = true;
|
|
||||||
if (loadLocalLibraries) {
|
if (loadLocalLibraries) {
|
||||||
loaded = true;
|
loaded = true;
|
||||||
loadedPrograms.add(loadedLibrary);
|
loadedPrograms.add(loadedLibrary);
|
||||||
@ -552,7 +531,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||||||
provider, systemSearchPaths, libraryDestFolderPath, unprocessed, depth,
|
provider, systemSearchPaths, libraryDestFolderPath, unprocessed, depth,
|
||||||
desiredLoadSpec, options, log, consumer, monitor);
|
desiredLoadSpec, options, log, consumer, monitor);
|
||||||
if (loadedLibrary != null) {
|
if (loadedLibrary != null) {
|
||||||
found = true;
|
|
||||||
if (loadSystemLibraries) {
|
if (loadSystemLibraries) {
|
||||||
loaded = true;
|
loaded = true;
|
||||||
loadedPrograms.add(loadedLibrary);
|
loadedPrograms.add(loadedLibrary);
|
||||||
@ -562,9 +540,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found) {
|
|
||||||
log.appendMsg("Library not found.");
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
log.appendMsg("Saving library to: " +
|
log.appendMsg("Saving library to: " +
|
||||||
@ -642,6 +617,11 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||||||
try {
|
try {
|
||||||
List<FSRL> candidateLibraryFsrls =
|
List<FSRL> candidateLibraryFsrls =
|
||||||
findLibrary(getCheckedPath(libraryName), fsSearchPaths, log, monitor);
|
findLibrary(getCheckedPath(libraryName), fsSearchPaths, log, monitor);
|
||||||
|
if (candidateLibraryFsrls.isEmpty()) {
|
||||||
|
log.appendMsg("Library not found.");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
for (FSRL candidateLibraryFsrl : candidateLibraryFsrls) {
|
for (FSRL candidateLibraryFsrl : candidateLibraryFsrls) {
|
||||||
monitor.checkCancelled();
|
monitor.checkCancelled();
|
||||||
List<String> newLibraryList = new ArrayList<>();
|
List<String> newLibraryList = new ArrayList<>();
|
||||||
@ -832,9 +812,6 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||||||
|
|
||||||
try (ByteProvider provider =
|
try (ByteProvider provider =
|
||||||
createLibraryByteProvider(libraryFsrl, desiredLoadSpec, log, monitor)) {
|
createLibraryByteProvider(libraryFsrl, desiredLoadSpec, log, monitor)) {
|
||||||
if (!shouldLoadLibrary(libraryName, libraryFsrl, provider, desiredLoadSpec, log)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
LoadSpec libLoadSpec = matchSupportedLoadSpec(desiredLoadSpec, provider);
|
LoadSpec libLoadSpec = matchSupportedLoadSpec(desiredLoadSpec, provider);
|
||||||
if (libLoadSpec == null) {
|
if (libLoadSpec == null) {
|
||||||
|
@ -20,6 +20,7 @@ import java.io.IOException;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import generic.jar.ResourceFile;
|
||||||
import ghidra.app.util.Option;
|
import ghidra.app.util.Option;
|
||||||
import ghidra.app.util.OptionUtils;
|
import ghidra.app.util.OptionUtils;
|
||||||
import ghidra.app.util.bin.ByteProvider;
|
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.Function;
|
||||||
import ghidra.program.model.listing.Program;
|
import ghidra.program.model.listing.Program;
|
||||||
import ghidra.program.model.symbol.*;
|
import ghidra.program.model.symbol.*;
|
||||||
import ghidra.util.Msg;
|
|
||||||
import ghidra.util.exception.*;
|
import ghidra.util.exception.*;
|
||||||
import ghidra.util.task.TaskMonitor;
|
import ghidra.util.task.TaskMonitor;
|
||||||
|
|
||||||
@ -75,47 +75,33 @@ public abstract class AbstractOrdinalSupportLoader extends AbstractLibrarySuppor
|
|||||||
return shouldPerformOrdinalLookup(options);
|
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
|
@Override
|
||||||
protected void processLibrary(Program lib, String libName, FSRL libFsrl, ByteProvider provider,
|
protected void processLibrary(Program lib, String libName, FSRL libFsrl, ByteProvider provider,
|
||||||
LoadSpec loadSpec, List<Option> options, MessageLog log, TaskMonitor monitor)
|
LoadSpec loadSpec, List<Option> options, MessageLog log, TaskMonitor monitor)
|
||||||
throws IOException, CancelledException {
|
throws IOException, CancelledException {
|
||||||
int size = loadSpec.getLanguageCompilerSpec().getLanguageDescription().getSize();
|
int size = loadSpec.getLanguageCompilerSpec().getLanguageDescription().getSize();
|
||||||
File localLibFile = getLocalFile(libFsrl);
|
ResourceFile existingExportsFile = LibraryLookupTable.getExistingExportsFile(libName, size);
|
||||||
|
|
||||||
// Create exports file
|
if (!shouldPerformOrdinalLookup(options)) {
|
||||||
if (localLibFile == null ||
|
return;
|
||||||
!LibraryLookupTable.libraryLookupTableFileExists(libName, size) ||
|
}
|
||||||
!LibraryLookupTable.hasFileAndPathAndTimeStampMatch(localLibFile, size)) {
|
|
||||||
log.appendMsg("Examining ordinal info in %s...".formatted(libFsrl));
|
// Create exports file if necessary
|
||||||
|
if (existingExportsFile == null) {
|
||||||
try {
|
try {
|
||||||
// Need to write correct library exports file (LibrarySymbolTable)
|
ResourceFile newExportsFile = LibraryLookupTable.createFile(lib, true, monitor);
|
||||||
// for use with related imports
|
log.appendMsg("Created exports file: " + newExportsFile);
|
||||||
LibraryLookupTable.createFile(lib, true, monitor);
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
log.appendMsg("Unable to create exports file for " + libFsrl);
|
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.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,6 +220,7 @@ public class LibraryLookupTable {
|
|||||||
String cacheKey = LibrarySymbolTable.getCacheKey(dllName, size);
|
String cacheKey = LibrarySymbolTable.getCacheKey(dllName, size);
|
||||||
LibrarySymbolTable symTab = cacheMap.get(cacheKey);
|
LibrarySymbolTable symTab = cacheMap.get(cacheKey);
|
||||||
if (symTab != null) {
|
if (symTab != null) {
|
||||||
|
log.appendMsg("Applying cached symbols from " + dllName);
|
||||||
return symTab;
|
return symTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user