Merge remote-tracking branch

'origin/GP-5174_dev747368_pdb_altfilenames--SQUASHED' (Closes #7200)
This commit is contained in:
Ryan Kurtz 2024-12-05 13:15:28 -05:00
commit 03eae7abbd
3 changed files with 38 additions and 7 deletions

View file

@ -126,7 +126,10 @@
See <A href="#OneLevel_SymbolDirectory">level 1</A>/<A href="#TwoLevel_SymbolDirectory">level 2</A> or
<A href="#Unorganized_SymbolDirectory">unorganized</A> directory descriptions.</LI>
<LI><B>URL</B> - allows the user to enter a HTTP or HTTPS URL to a web-based symbol server.</LI>
<LI><B>Program's Import Location</B> - automatically references the directory from which the program was imported.</LI>
<LI><B>Program's Import Location</B> - automatically references the directory from
which the program was imported. This option first searches for the 'official'
PDB filename embedded in the program's metadata. If not found, it searches
for other PDB files that match variations of the program's filename.</LI>
<LI><B>Import _NT_SYMBOL_PATH</B> - parses the current value of the <code>_NT_SYMBOL_PATH</code> system environment variable to extract
URLs and symbol directory locations to be added to the Ghidra configuration. If no environment value is present,
the user can paste their own value into the text field.</LI>

View file

@ -34,6 +34,7 @@ import ghidra.app.plugin.PluginCategoryNames;
import ghidra.app.plugin.core.analysis.AutoAnalysisManager;
import ghidra.app.plugin.core.analysis.PdbAnalyzerCommon;
import ghidra.app.services.DataTypeManagerService;
import ghidra.formats.gfilesystem.FSRL;
import ghidra.framework.plugintool.*;
import ghidra.framework.plugintool.util.PluginStatus;
import ghidra.framework.preferences.Preferences;
@ -282,9 +283,11 @@ public class PdbPlugin extends Plugin {
symbolServerInstanceCreatorContext.getSymbolServerInstanceCreatorRegistry()
.newSymbolServer(Preferences.getProperty(SYMBOL_STORAGE_DIR_OPTION, "", true),
symbolServerInstanceCreatorContext);
SymbolStore symbolStore =
(temporarySymbolServer instanceof SymbolStore) ? (SymbolStore) temporarySymbolServer
: new SameDirSymbolStore(symbolServerInstanceCreatorContext.getRootDir());
FSRL programFSRL = symbolServerInstanceCreatorContext.getProgramFSRL();
SymbolStore symbolStore = (temporarySymbolServer instanceof SymbolStore tmpSymbolStore)
? tmpSymbolStore
: new SameDirSymbolStore(symbolServerInstanceCreatorContext.getRootDir(),
programFSRL != null ? programFSRL.getName() : null);
List<SymbolServer> symbolServers =
symbolServerInstanceCreatorContext.getSymbolServerInstanceCreatorRegistry()
.createSymbolServersFromPathList(getSymbolSearchPaths(),

View file

@ -18,6 +18,8 @@ package pdb.symbolserver;
import java.io.*;
import java.util.*;
import org.apache.commons.io.FilenameUtils;
import ghidra.formats.gfilesystem.FSRL;
import ghidra.util.task.TaskMonitor;
import pdb.symbolserver.SymbolServer.StatusRequiresContext;
@ -77,10 +79,12 @@ public class SameDirSymbolStore implements SymbolStore, StatusRequiresContext {
if (programFSRL != null && programFSRL.getNestingDepth() != 1) {
return new ContainerFileSymbolServer(programFSRL);
}
return new SameDirSymbolStore(context.getRootDir());
String programFilename = programFSRL != null ? programFSRL.getName() : null;
return new SameDirSymbolStore(context.getRootDir(), programFilename);
}
private final File rootDir;
private final String programFilename;
/**
* Create a new instance, based on the directory where the program was originally imported from.
@ -90,6 +94,12 @@ public class SameDirSymbolStore implements SymbolStore, StatusRequiresContext {
*/
public SameDirSymbolStore(File rootDir) {
this.rootDir = rootDir;
this.programFilename = null;
}
public SameDirSymbolStore(File rootDir, String programFilename) {
this.rootDir = rootDir;
this.programFilename = programFilename;
}
@Override
@ -147,6 +157,21 @@ public class SameDirSymbolStore implements SymbolStore, StatusRequiresContext {
if (isValid()) {
LocalSymbolStore.searchLevel0(rootDir, this, fileInfo, findOptions, results, monitor);
if (results.isEmpty() && programFilename != null) {
// Search for renamed versions of the pdb file, using the current program's
// name. Note: if this shouldn't be automatic, add FindOption enum to control this
List<String> altPdbfilenames = List.of(programFilename + ".pdb",
FilenameUtils.getBaseName(programFilename) + ".pdb");
for (String altPdbfilename : altPdbfilenames) {
SymbolFileInfo altFileInfo = SymbolFileInfo.fromPdbIdentifiers(altPdbfilename,
fileInfo.getIdentifiers());
LocalSymbolStore.searchLevel0(rootDir, this, altFileInfo, findOptions, results,
monitor);
if (!results.isEmpty()) {
break;
}
}
}
}
return results;