mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GP-1895, GP-1894 Fix lib name case sensitivity comp during import, FSRL
Change RandomAccessFileByteProvider to auto specify a FSRL (if not given). Fix library name case comparisons to respect the loader's case sensitivity.
This commit is contained in:
parent
fb054910e0
commit
ab9664aa28
2 changed files with 30 additions and 6 deletions
|
@ -18,6 +18,7 @@ package ghidra.app.util.bin;
|
|||
import java.io.*;
|
||||
|
||||
import ghidra.formats.gfilesystem.FSRL;
|
||||
import ghidra.formats.gfilesystem.FileSystemService;
|
||||
import ghidra.util.Msg;
|
||||
|
||||
/**
|
||||
|
@ -68,7 +69,7 @@ public class RandomAccessByteProvider implements ByteProvider {
|
|||
* @throws IOException if the {@link File} does not exist or other error
|
||||
*/
|
||||
public RandomAccessByteProvider(File file, String permissions) throws IOException {
|
||||
this(file, null, permissions);
|
||||
this(file, FileSystemService.getInstance().getLocalFSRL(file), permissions);
|
||||
}
|
||||
|
||||
private RandomAccessByteProvider(File file, FSRL fsrl, String permissions) throws IOException {
|
||||
|
|
|
@ -15,11 +15,12 @@
|
|||
*/
|
||||
package ghidra.app.util.opinion;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import ghidra.app.util.Option;
|
||||
|
@ -185,6 +186,12 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||
return false;
|
||||
}
|
||||
|
||||
protected Comparator<String> getLibNameComparator() {
|
||||
return isCaseInsensitiveLibraryFilenames()
|
||||
? String.CASE_INSENSITIVE_ORDER
|
||||
: (s1, s2) -> s1.compareTo(s2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path the loaded {@link ByteProvider} is located in.
|
||||
* <p>
|
||||
|
@ -340,6 +347,8 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||
Program program = createProgram(provider, programName, imageBaseAddr, getName(), language,
|
||||
compilerSpec, consumer);
|
||||
|
||||
Comparator<String> libNameComparator = getLibNameComparator();
|
||||
|
||||
int transactionID = program.startTransaction("importing");
|
||||
boolean success = false;
|
||||
try {
|
||||
|
@ -351,9 +360,11 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||
if (unprocessedLibraries != null) {
|
||||
ExternalManager extMgr = program.getExternalManager();
|
||||
String[] externalNames = extMgr.getExternalLibraryNames();
|
||||
Arrays.sort(externalNames);
|
||||
Arrays.sort(externalNames, libNameComparator);
|
||||
for (String name : externalNames) {
|
||||
if (name.equals(provider.getName()) || Library.UNKNOWN.equals(name)) {
|
||||
if (libNameComparator.compare(name, provider.getName()) == 0 ||
|
||||
libNameComparator.compare(name, program.getName()) == 0 ||
|
||||
Library.UNKNOWN.equals(name)) {
|
||||
// skip self-references and UNKNOWN library...
|
||||
continue;
|
||||
}
|
||||
|
@ -457,7 +468,8 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||
monitor.checkCanceled();
|
||||
try {
|
||||
String externalFileName = FilenameUtils.getName(externalLibName);
|
||||
DomainObject matchingExtProgram = progsByName.get(externalFileName);
|
||||
DomainObject matchingExtProgram =
|
||||
findLibraryWithCaseCorrectSearch(progsByName, externalFileName);
|
||||
if (matchingExtProgram != null && matchingExtProgram.getDomainFile().exists()) {
|
||||
extManager.setExternalPath(externalLibName,
|
||||
matchingExtProgram.getDomainFile().getPathname(), false);
|
||||
|
@ -484,6 +496,17 @@ public abstract class AbstractLibrarySupportLoader extends AbstractProgramLoader
|
|||
}
|
||||
}
|
||||
|
||||
protected Program findLibraryWithCaseCorrectSearch(Map<String, Program> progsByName,
|
||||
String libName) {
|
||||
Comparator<String> comparator = getLibNameComparator();
|
||||
for (String s : progsByName.keySet()) {
|
||||
if (comparator.compare(libName, s) == 0) {
|
||||
return progsByName.get(s);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the libPathFilename within the specified importFolder. This method will handle
|
||||
* relative path normalization.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue