Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3112 - PDB Universal Reader/Analyzer - 122 commits

ghizard1a6cf81d919a
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/plugin/core/analysis/PdbUniversalAnalyzer.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/plugin/core/analysis/PdbUniversalAnalyzer.java
index 5be73c3868..1d104d0cd2 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/plugin/core/analysis/PdbUniversalAnalyzer.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/plugin/core/analysis/PdbUniversalAnalyzer.java
@@ -134,17 +134,11 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
//==============================================================================================
// PdbApplicator options
//==============================================================================================
- // Apply Data Types Only.
- private static final String OPTION_NAME_APPLY_DATA_TYPES_ONLY = "Apply Data Types Only";
- private static final String OPTION_DESCRIPTION_APPLY_DATA_TYPES_ONLY =
- "If checked, only applies data types to program.";
- private boolean applyDataTypesOnly;
-
- // Apply Public Symbols Only.
- private static final String OPTION_NAME_PUBLIC_SYMBOLS_ONLY = "Apply Public Symbols Only";
- private static final String OPTION_DESCRIPTION_PUBLIC_SYMBOLS_ONLY =
- "If checked, only applies public symbols to program. Does not apply data types.";
- private boolean applyPublicSymbolsOnly;
+ // Applicator Restrictions.
+ private static final String OPTION_NAME_PROCESSING_RESTRICTIONS = "Processing Restrictions";
+ private static final String OPTION_DESCRIPTION_PROCESSING_RESTRICTIONS =
+ "Restrictions on applicator processing.";
+ private static PdbApplicatorRestrictions restrictions;
// Apply Code Block Comments.
private static final String OPTION_NAME_APPLY_CODE_SCOPE_BLOCK_COMMENTS =
@@ -206,10 +200,8 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
//==============================================================================================
// Additional instance data
//==============================================================================================
- private AbstractPdb myPdb = null;
private PdbReaderOptions pdbReaderOptions;
private PdbApplicatorOptions pdbApplicatorOptions;
- private MessageLog messageLog = null;
//==============================================================================================
//==============================================================================================
@@ -245,7 +237,6 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
public boolean added(Program program, AddressSetView set, TaskMonitor monitor, MessageLog log)
throws CancelledException {
- messageLog = log;
// TODO:
// Work on use cases...
// Code for checking if the PDB is already loaded (... assumes it was analyzed as well).
@@ -268,6 +259,8 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
return true;
}
+ setPdbLogging(log);
+
String pdbFilename;
if (doForceLoad) {
pdbFilename = forceLoadFile.getAbsolutePath();
@@ -292,10 +285,9 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
PdbLog.message("PDB Filename: " + pdbFilename + "\n");
try (AbstractPdb pdb = PdbParser.parse(pdbFilename, pdbReaderOptions, monitor)) {
- myPdb = pdb;
monitor.setMessage("PDB: Parsing " + pdbFilename + "...");
pdb.deserialize(monitor);
- PdbApplicator applicator = new PdbApplicator(pdbFilename, myPdb);
+ PdbApplicator applicator = new PdbApplicator(pdbFilename, pdb);
applicator.applyTo(program, program.getDataTypeManager(), program.getImageBase(),
pdbApplicatorOptions, monitor, log);
}
@@ -348,17 +340,6 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
@Override
public void registerOptions(Options options, Program program) {
- // TODO: keeping around while still developing, but eventually delete these.
-// options.removeOption(OPTION_NAME_DO_FORCELOAD);
-// options.removeOption(OPTION_NAME_FORCELOAD_FILE);
-// options.removeOption(OPTION_NAME_INCLUDE_PE_PDB_PATH);
-// options.removeOption(OPTION_NAME_PDB_READER_ANALYZER_LOGGING);
-// options.removeOption(OPTION_NAME_APPLY_INSTRUCTION_LABELS);
-// options.removeOption(OPTION_NAME_SYMBOLPATH);
-// options.removeOption(OPTION_NAME_ONE_BYTE_CHARSET_NAME);
-// options.removeOption(OPTION_NAME_WCHAR_CHARSET_NAME);
-// options.removeOption("Analyzers.PDB Universal Reader/Analyzer.Symbol Repository Path");
-
// PDB file location information
options.registerOption(OPTION_NAME_DO_FORCELOAD, doForceLoad, null,
OPTION_DESCRIPTION_DO_FORCELOAD);
@@ -373,31 +354,40 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
getPdbReaderOptions();
options.registerOption(OPTION_NAME_PDB_READER_ANALYZER_LOGGING, pdbLogging, null,
OPTION_DESCRIPTION_PDB_READER_ANALYZER_LOGGING);
- options.registerOption(OPTION_NAME_ONE_BYTE_CHARSET_NAME, oneByteCharsetName, null,
- OPTION_DESCRIPTION_ONE_BYTE_CHARSET_NAME);
- options.registerOption(OPTION_NAME_WCHAR_CHARSET_NAME, wideCharCharsetName, null,
- OPTION_DESCRIPTION_WCHAR_CHARSET_NAME);
+ if (developerMode) {
+ options.registerOption(OPTION_NAME_ONE_BYTE_CHARSET_NAME, oneByteCharsetName, null,
+ OPTION_DESCRIPTION_ONE_BYTE_CHARSET_NAME);
+ options.registerOption(OPTION_NAME_WCHAR_CHARSET_NAME, wideCharCharsetName, null,
+ OPTION_DESCRIPTION_WCHAR_CHARSET_NAME);
+ }
// PdbApplicatorOptions
getPdbApplicatorOptions();
- options.registerOption(OPTION_NAME_APPLY_DATA_TYPES_ONLY, applyDataTypesOnly, null,
- OPTION_DESCRIPTION_APPLY_DATA_TYPES_ONLY);
- options.registerOption(OPTION_NAME_PUBLIC_SYMBOLS_ONLY, applyPublicSymbolsOnly, null,
- OPTION_DESCRIPTION_PUBLIC_SYMBOLS_ONLY);
+ options.registerOption(OPTION_NAME_PROCESSING_RESTRICTIONS, restrictions, null,
+ OPTION_DESCRIPTION_PROCESSING_RESTRICTIONS);
options.registerOption(OPTION_NAME_APPLY_CODE_SCOPE_BLOCK_COMMENTS,
applyCodeScopeBlockComments, null, OPTION_DESCRIPTION_APPLY_CODE_SCOPE_BLOCK_COMMENTS);
if (developerMode) {
// Mechanism to apply instruction labels is not yet implemented-> does nothing
options.registerOption(OPTION_NAME_APPLY_INSTRUCTION_LABELS, applyInstructionLabels,
null, OPTION_DESCRIPTION_APPLY_INSTRUCTION_LABELS);
+ // The remap capability is not completely implemented... do not turn on.
options.registerOption(OPTION_NAME_ADDRESS_REMAP,
remapAddressUsingExistingPublicMangledSymbols, null,
OPTION_DESCRIPTION_ADDRESS_REMAP);
options.registerOption(OPTION_NAME_ALLOW_DEMOTE_MANGLED_PRIMARY,
allowDemotePrimaryMangledSymbol, null,
OPTION_DESCRIPTION_ALLOW_DEMOTE_MANGLED_PRIMARY);
+ // Function params and local implementation is not complete... do not turn on.
options.registerOption(OPTION_NAME_APPLY_FUNCTION_VARIABLES, applyFunctionVariables,
null, OPTION_DESCRIPTION_APPLY_FUNCTION_VARIABLES);
+ // Object-oriented composite layout is fairly far along, but its use will likely not
+ // be forward compatible with future Ghidra work in this area; i.e., it might leave
+ // the data type manager in a bad state for future revisions. While the current
+ // layout mechanism might work, I will likely change it to, instead, create a
+ // syntactic intermediate representation before creating the final layout. This will
+ // aid portability between tool chains and versions and yield a standard way of
+ // data-basing and presenting the information to a user.
options.registerOption(OPTION_NAME_COMPOSITE_LAYOUT, compositeLayout, null,
OPTION_DESCRIPTION_COMPOSITE_LAYOUT);
}
@@ -438,21 +428,18 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
includePeSpecifiedPdbPath =
options.getBoolean(OPTION_NAME_INCLUDE_PE_PDB_PATH, includePeSpecifiedPdbPath);
- pdbLogging = options.getBoolean(OPTION_NAME_PDB_READER_ANALYZER_LOGGING, pdbLogging);
- setPdbLogging();
-
// PdbReaderOptions
- oneByteCharsetName =
- options.getString(OPTION_NAME_ONE_BYTE_CHARSET_NAME, oneByteCharsetName);
- wideCharCharsetName =
- options.getString(OPTION_NAME_WCHAR_CHARSET_NAME, wideCharCharsetName);
+ pdbLogging = options.getBoolean(OPTION_NAME_PDB_READER_ANALYZER_LOGGING, pdbLogging);
+ if (developerMode) {
+ oneByteCharsetName =
+ options.getString(OPTION_NAME_ONE_BYTE_CHARSET_NAME, oneByteCharsetName);
+ wideCharCharsetName =
+ options.getString(OPTION_NAME_WCHAR_CHARSET_NAME, wideCharCharsetName);
+ }
setPdbReaderOptions();
// PdbApplicatorOptions
- applyDataTypesOnly =
- options.getBoolean(OPTION_NAME_APPLY_DATA_TYPES_ONLY, applyDataTypesOnly);
- applyPublicSymbolsOnly =
- options.getBoolean(OPTION_NAME_PUBLIC_SYMBOLS_ONLY, applyPublicSymbolsOnly);
+ restrictions = options.getEnum(OPTION_NAME_PROCESSING_RESTRICTIONS, restrictions);
applyCodeScopeBlockComments = options.getBoolean(
OPTION_NAME_APPLY_CODE_SCOPE_BLOCK_COMMENTS, applyCodeScopeBlockComments);
if (developerMode) {
@@ -535,16 +522,16 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
return true;
}
- private void setPdbLogging() {
+ private void setPdbLogging(MessageLog log) {
try {
PdbLog.setEnabled(pdbLogging);
}
catch (IOException e) {
// Probably could not open the file.
- if (messageLog != null) {
- messageLog.appendMsg(getClass().getSimpleName(),
+ if (log != null) {
+ log.appendMsg(getClass().getSimpleName(),
"IOException when trying to open PdbLog file: ");
- messageLog.appendException(e);
+ log.appendException(e);
}
}
}
@@ -561,8 +548,7 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
private void getPdbApplicatorOptions() {
applyCodeScopeBlockComments = PdbApplicatorOptions.DEFAULT_APPLY_CODE_SCOPE_BLOCK_COMMENTS;
- applyDataTypesOnly = PdbApplicatorOptions.DEFAULT_APPLY_DATA_TYPES_ONLY;
- applyPublicSymbolsOnly = PdbApplicatorOptions.DEFAULT_APPLY_PUBLIC_SYMBOLS_ONLY;
+ restrictions = PdbApplicatorOptions.DEFAULT_RESTRICTIONS;
applyInstructionLabels = PdbApplicatorOptions.DEFAULT_APPLY_INSTRUCTION_LABELS;
remapAddressUsingExistingPublicMangledSymbols =
@@ -574,8 +560,7 @@ public class PdbUniversalAnalyzer extends AbstractAnalyzer {
}
private void setPdbApplicatorOptions() {
- pdbApplicatorOptions.setApplyDataTypesOnly(applyDataTypesOnly);
- pdbApplicatorOptions.setApplyPublicSymbolsOnly(applyPublicSymbolsOnly);
+ pdbApplicatorOptions.setRestrictions(restrictions);
pdbApplicatorOptions.setApplyCodeScopeBlockComments(applyCodeScopeBlockComments);
pdbApplicatorOptions.setApplyInstructionLabels(applyInstructionLabels);
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DataSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DataSymbolApplier.java
index ed9d544652..e2563c6137 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DataSymbolApplier.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/DataSymbolApplier.java
@@ -39,7 +39,6 @@ public class DataSymbolApplier extends MsSymbolApplier {
* Constructor
* @param applicator the {@link PdbApplicator} for which we are working.
* @param iter the Iterator containing the symbol sequence being processed
- * @throws CancelledException upon user cancellation
*/
public DataSymbolApplier(PdbApplicator applicator, AbstractMsSymbolIterator iter) {
super(applicator, iter);
@@ -55,9 +54,6 @@ public class DataSymbolApplier extends MsSymbolApplier {
void applyTo(MsSymbolApplier applyToApplier) throws PdbException, CancelledException {
if (applyToApplier instanceof FunctionSymbolApplier) {
FunctionSymbolApplier functionSymbolApplier = (FunctionSymbolApplier) applyToApplier;
- if (symbol.getSegment() == 0 && symbol.getOffset() == 0L) {
- return; // silently return.
- }
MsTypeApplier applier = getTypeApplier();
DataType dataType = applier.getDataType();
if (dataType == null) { // TODO: check that we can have null here.
@@ -65,21 +61,22 @@ public class DataSymbolApplier extends MsSymbolApplier {
}
String name = symbol.getName();
Address address = applicator.getAddress(symbol);
-
+ if (applicator.isInvalidAddress(address, symbol.getName())) {
+ return;
+ }
functionSymbolApplier.setLocalVariable(address, name, dataType);
}
}
@Override
void apply() throws CancelledException, PdbException {
- // skip if both zero (i.e,. process if either is not zero)
- if (symbol.getSegment() != 0 || symbol.getOffset() != 0L) {
- Address symbolAddress = applicator.getAddress(symbol);
- Address remapAddress = applicator.getRemapAddressByAddress(symbolAddress);
- RecordNumber typeRecordNumber = symbol.getTypeRecordNumber();
- applicator.createSymbol(symbolAddress, symbol.getName(), true);
- createData(remapAddress, typeRecordNumber);
+ Address symbolAddress = applicator.getAddress(symbol);
+ if (applicator.isInvalidAddress(symbolAddress, symbol.getName())) {
+ return;
}
+ RecordNumber typeRecordNumber = symbol.getTypeRecordNumber();
+ applicator.createSymbol(symbolAddress, symbol.getName(), true);
+ createData(symbolAddress, typeRecordNumber);
}
MsTypeApplier getTypeApplier() {
@@ -102,6 +99,10 @@ public class DataSymbolApplier extends MsSymbolApplier {
}
return;
}
+ if (applicator.getImageBase().equals(address) &&
+ !"_IMAGE_DOS_HEADER".equals(dataType.getName())) {
+ return; // Squash some noise
+ }
if (!(dataType instanceof FunctionDefinition)) {
//TODO: might want to do an ApplyDatatypeCmd here!!!
DumbMemBufferImpl memBuffer =
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/FunctionSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/FunctionSymbolApplier.java
index 95d79a87ac..36c6038f33 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/FunctionSymbolApplier.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/FunctionSymbolApplier.java
@@ -41,10 +41,9 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
private static final String BLOCK_INDENT = " ";
- private AbstractProcedureMsSymbol procedureSymbol;
- private AbstractThunkMsSymbol thunkSymbol;
+ private AddressMsSymbol symbol;
private Address specifiedAddress;
- private Address remapAddress;
+ private Address address;
private Function function = null;
private long specifiedFrameSize = 0;
private long currentFrameSize = 0;
@@ -75,19 +74,16 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
comments = new BlockCommentsManager();
currentBlockAddress = null;
- if (abstractSymbol instanceof AbstractProcedureMsSymbol) {
- procedureSymbol = (AbstractProcedureMsSymbol) abstractSymbol;
- specifiedAddress = applicator.getAddress(procedureSymbol);
- }
- else if (abstractSymbol instanceof AbstractThunkMsSymbol) {
- thunkSymbol = (AbstractThunkMsSymbol) abstractSymbol;
- specifiedAddress = applicator.getAddress(thunkSymbol);
+ if (abstractSymbol instanceof AbstractProcedureMsSymbol ||
+ abstractSymbol instanceof AbstractThunkMsSymbol) {
+ symbol = (AddressMsSymbol) abstractSymbol;
+ specifiedAddress = applicator.getRawAddress(symbol);
+ address = applicator.getAddress(symbol);
}
else {
throw new AssertException(
"Invalid symbol type: " + abstractSymbol.getClass().getSimpleName());
}
- remapAddress = applicator.getRemapAddressByAddress(specifiedAddress);
manageBlockNesting(this);
while (notDone()) {
@@ -102,16 +98,17 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
void manageBlockNesting(MsSymbolApplier applierParam) {
if (applierParam instanceof FunctionSymbolApplier) {
FunctionSymbolApplier functionSymbolApplier = (FunctionSymbolApplier) applierParam;
- if (procedureSymbol != null) {
- long start = procedureSymbol.getDebugStartOffset();
- long end = procedureSymbol.getDebugEndOffset();
- Address blockAddress = remapAddress.add(start);
+ if (symbol instanceof AbstractProcedureMsSymbol) {
+ AbstractProcedureMsSymbol sym = (AbstractProcedureMsSymbol) symbol;
+ long start = sym.getDebugStartOffset();
+ long end = sym.getDebugEndOffset();
+ Address blockAddress = address.add(start);
long length = end - start;
- functionSymbolApplier.beginBlock(blockAddress, procedureSymbol.getName(), length);
+ functionSymbolApplier.beginBlock(blockAddress, sym.getName(), length);
}
- else if (thunkSymbol != null) {
- functionSymbolApplier.beginBlock(remapAddress, thunkSymbol.getName(),
- thunkSymbol.getLength());
+ else {
+ AbstractThunkMsSymbol sym = (AbstractThunkMsSymbol) symbol;
+ functionSymbolApplier.beginBlock(address, sym.getName(), sym.getLength());
}
}
}
@@ -154,11 +151,8 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
* @return the function name
*/
String getName() {
- if (procedureSymbol != null) {
- return procedureSymbol.getName();
- }
- else if (thunkSymbol != null) {
- return thunkSymbol.getName();
+ if (symbol != null) {
+ return ((NameMsSymbol) symbol).getName();
}
return "";
}
@@ -178,13 +172,15 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
}
boolean applyTo(TaskMonitor monitor) throws PdbException, CancelledException {
- return applyTo(applicator.getProgram(), remapAddress, monitor);
- }
-
- boolean applyTo(Program program, Address address, TaskMonitor monitor)
- throws PdbException, CancelledException {
+ if (applicator.isInvalidAddress(specifiedAddress, getName())) {
+ return false;
+ }
+ if (!(symbol instanceof AbstractProcedureMsSymbol)) {
+ return false;
+ }
+ AbstractProcedureMsSymbol procedureSymbol = (AbstractProcedureMsSymbol) symbol;
- boolean functionSuccess = applyFunction(program, address, monitor);
+ boolean functionSuccess = applyFunction(monitor);
if (functionSuccess == false) {
return false;
}
@@ -198,7 +194,7 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
// comments
long addressDelta = address.subtract(specifiedAddress);
- comments.applyTo(program, addressDelta);
+ comments.applyTo(applicator.getProgram(), addressDelta);
// line numbers
// TODO: not done yet
@@ -232,20 +228,20 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
comments.addPreComment(currentBlockAddress, comment);
}
- private boolean applyFunction(Program program, Address address, TaskMonitor monitor) {
- Listing listing = program.getListing();
+ private boolean applyFunction(TaskMonitor monitor) {
+ Listing listing = applicator.getProgram().getListing();
applicator.createSymbol(address, getName(), true);
function = listing.getFunctionAt(address);
if (function == null) {
- function = createFunction(program, address, monitor);
+ function = createFunction(monitor);
}
if (function != null && !function.isThunk() &&
(function.getSignatureSource() == SourceType.DEFAULT ||
function.getSignatureSource() == SourceType.ANALYSIS)) {
// Set the function definition
- setFunctionDefinition(program, address, monitor);
+ setFunctionDefinition(monitor);
}
if (function == null) {
@@ -256,10 +252,10 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
return true;
}
- private Function createFunction(Program program, Address address, TaskMonitor monitor) {
+ private Function createFunction(TaskMonitor monitor) {
// Does function already exist?
- Function myFunction = program.getListing().getFunctionAt(address);
+ Function myFunction = applicator.getProgram().getListing().getFunctionAt(address);
if (myFunction != null) {
// Actually not sure if we should set to 0 or calculate from the function here.
// Need to investigate more, so at least keeping it as a separate 'else' for now.
@@ -267,25 +263,25 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
}
// Disassemble
- Instruction instr = program.getListing().getInstructionAt(address);
+ Instruction instr = applicator.getProgram().getListing().getInstructionAt(address);
if (instr == null) {
DisassembleCommand cmd = new DisassembleCommand(address, null, true);
- cmd.applyTo(program, monitor);
+ cmd.applyTo(applicator.getProgram(), monitor);
}
- myFunction = createFunctionCommand(program, address, monitor);
+ myFunction = createFunctionCommand(monitor);
return myFunction;
}
- private boolean setFunctionDefinition(Program program, Address address, TaskMonitor monitor) {
- if (procedureSymbol == null) {
+ private boolean setFunctionDefinition(TaskMonitor monitor) {
+ if (!(symbol instanceof AbstractProcedureMsSymbol)) {
// TODO: is there anything we can do with thunkSymbol?
// long x = thunkSymbol.getParentPointer();
return true;
}
// Rest presumes procedureSymbol.
- RecordNumber typeRecordNumber = procedureSymbol.getTypeRecordNumber();
+ RecordNumber typeRecordNumber = ((AbstractProcedureMsSymbol) symbol).getTypeRecordNumber();
MsTypeApplier applier = applicator.getTypeApplier(typeRecordNumber);
if (applier == null) {
applicator.appendLogMsg("Error: Failed to resolve datatype RecordNumber " +
@@ -308,7 +304,7 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
FunctionDefinition def = (FunctionDefinition) dataType;
ApplyFunctionSignatureCmd sigCmd =
new ApplyFunctionSignatureCmd(address, def, SourceType.IMPORTED);
- if (!sigCmd.applyTo(program, monitor)) {
+ if (!sigCmd.applyTo(applicator.getProgram(), monitor)) {
applicator.appendLogMsg(
"failed to apply signature to function at address " + address.toString());
return false;
@@ -317,13 +313,12 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
return true;
}
- private Function createFunctionCommand(Program program, Address entryPoint,
- TaskMonitor monitor) {
- CreateFunctionCmd funCmd = new CreateFunctionCmd(entryPoint);
- if (!funCmd.applyTo(program, monitor)) {
- applicator.appendLogMsg("Failed to apply function at address " + entryPoint.toString() +
+ private Function createFunctionCommand(TaskMonitor monitor) {
+ CreateFunctionCmd funCmd = new CreateFunctionCmd(address);
+ if (!funCmd.applyTo(applicator.getProgram(), monitor)) {
+ applicator.appendLogMsg("Failed to apply function at address " + address.toString() +
"; attempting to use possible existing function");
- return program.getListing().getFunctionAt(entryPoint);
+ return applicator.getProgram().getListing().getFunctionAt(address);
}
return funCmd.getFunction();
}
@@ -335,7 +330,7 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
int endBlock() {
if (--symbolBlockNestingLevel < 0) {
applicator.appendLogMsg(
- "Block Nesting went negative for " + getName() + " at " + remapAddress);
+ "Block Nesting went negative for " + getName() + " at " + address);
}
if (symbolBlockNestingLevel == 0) {
//currentFunctionSymbolApplier = null;
@@ -349,6 +344,9 @@ public class FunctionSymbolApplier extends MsSymbolApplier {
if (!applicator.getPdbApplicatorOptions().applyCodeScopeBlockComments()) {
return;
}
+ if (applicator.isInvalidAddress(startAddress, name)) {
+ return;
+ }
String indent = getIndent(nestingLevel);
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java
index b6884d88ba..53018e150b 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/LabelSymbolApplier.java
@@ -58,6 +58,9 @@ public class LabelSymbolApplier extends MsSymbolApplier {
// Place compiler generated symbols (e.g., $LN9) within containing function when possible
String name = symbol.getName();
Address symbolAddress = applicator.getAddress(symbol);
+ if (applicator.isInvalidAddress(symbolAddress, name)) {
+ return;
+ }
FunctionManager functionManager = applicator.getProgram().getFunctionManager();
// TODO: What do we do with labels such as this?... "__catch$?test_eh1@@YAHXZ$7"
if (name.startsWith("$") && !name.contains(Namespace.DELIMITER)) {
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbAddressManager.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbAddressManager.java
index 6c87c6c84d..c4da076a6f 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbAddressManager.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbAddressManager.java
@@ -20,6 +20,7 @@ import java.util.*;
import ghidra.app.util.bin.format.pdb2.pdbreader.*;
import ghidra.app.util.bin.format.pdb2.pdbreader.symbol.*;
import ghidra.program.model.address.Address;
+import ghidra.program.model.address.AddressSpace;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.Memory;
import ghidra.program.model.mem.MemoryBlock;
@@ -33,7 +34,11 @@ import ghidra.util.exception.CancelledException;
*/
public class PdbAddressManager {
- private static final Address BAD_ADDRESS = Address.NO_ADDRESS; // using NO_ADDRESS as a marker
+ // This could be a valid address for the program, but we are using it as a flag. We return
+ // it to designate that an address is an external address, and we use it outside of this class
+ // to test for it being an external address.
+ static final Address EXTERNAL_ADDRESS = AddressSpace.EXTERNAL_SPACE.getAddress(0);
+ static final Address BAD_ADDRESS = Address.NO_ADDRESS; // using NO_ADDRESS as a marker
//==============================================================================================
private Map<Integer, Long> realAddressesBySection;
@@ -79,46 +84,90 @@ public class PdbAddressManager {
allSegmentsInfo = new ArrayList<>();
addressByPreExistingSymbolName = new HashMap<>();
primarySymbolByAddress = new HashMap<>();
- remapAddressByAddress = new HashMap<>();
determineMemoryBlocks();
mapPreExistingSymbols();
+ createAddressRemap();
}
/**
- * Returns the Address for the given section and offset.
+ * Returns the Address for the given symbol. If the {@link PdbApplicatorOptions}
+ * Address Remap option is turned on is turned on, it will attempt to map the address to a
+ * new address in the current program.
* @param symbol The {@link AddressMsSymbol}
- * @return The Address
+ * @return The Address, which can be {@code Address.NO_ADDRESS} if invalid or
+ * {@code Address.EXTERNAL_ADDRESS} if the address is external to the program.
*/
- // Returns an address using the section and offset.
Address getAddress(AddressMsSymbol symbol) {
return getAddress(symbol.getSegment(), symbol.getOffset());
}
+ /**
+ * Returns the Address for the given section and offset. If the {@link PdbApplicatorOptions}
+ * Address Remap option is turned on is turned on, it will attempt to map the address to a
+ * new address in the current program.
+ * @param segment The segment
+ * @param offset The offset
+ * @return The Address, which can be {@code Address.NO_ADDRESS} if invalid or
+ * {@code Address.EXTERNAL_ADDRESS} if the address is external to the program.
+ */
+ Address getAddress(int segment, long offset) {
+ Address address = getRawAddress(segment, offset);
+ if (applicator.getPdbApplicatorOptions().remapAddressUsingExistingPublicSymbols()) {
+ return getRemapAddressByAddress(address);
+ }
+ return address;
+ }
+
+ /**
+ * Returns the Address for the given section and offset. If the {@link PdbApplicatorOptions}
+ * Address Remap option is turned on is turned on, it will attempt to map the address to a
+ * new address in the current program.
+ * @param symbol The {@link AddressMsSymbol}
+ * @return The Address, which can be {@code Address.NO_ADDRESS} if invalid or
+ * {@code Address.EXTERNAL_ADDRESS} if the address is external to the program.
+ */
+ Address getRawAddress(AddressMsSymbol symbol) {
+ return getRawAddress(symbol.getSegment(), symbol.getOffset());
+ }
+
/**
* Returns the Address for the given section and offset. Will attempt to map the address
* to a new address if the {@link PdbApplicatorOptions}
* @param segment The segment
* @param offset The offset
- * @return The Address, which can be {@code Address.NO_ADDRESS} if it was the original address.
+ * @return The Address, which can be {@code Address.NO_ADDRESS} if invalid or
+ * {@code Address.EXTERNAL_ADDRESS} if the address is external to the program.
*/
- // Returns an address using the section and offset.
- Address getAddress(int segment, long offset) {
+ Address getRawAddress(int segment, long offset) {
if (segment < 0 || segment > allSegmentsInfo.size()) {
- return Address.NO_ADDRESS;
+ return BAD_ADDRESS;
}
else if (segment == allSegmentsInfo.size()) {
- // Was getting issues of _IMAGE_DOSHEADER showing up with a segemnt index one
- // beyond the end.
- segment = 0; // The anomaly of last segment meaning the first.
+ // External address.
+ // Was getting issues of _IMAGE_DOSHEADER showing up with a segment index one
+ // beyond the end.
+ return EXTERNAL_ADDRESS;
}
SegmentInfo segmentInfo = allSegmentsInfo.get(segment);
if (offset >= segmentInfo.getLength()) {
- return Address.NO_ADDRESS;
+ return BAD_ADDRESS;
}
return segmentInfo.getStartAddress().add(offset);
}
+ /**
+ * Returns the Address of an existing symbol for the query address, where the mapping is
+ * derived by using a the address of a PDB symbol as the key and finding the address of
+ * a symbol in the program of the same "unique" name. This is accomplished using public
+ * mangled symbols. If the program symbol came from the PDB, then it maps to itself.
+ * @param address the query address
+ * @return the remapAddress
+ */
+ Address getRemapAddressByAddress(Address address) {
+ return remapAddressByAddress.getOrDefault(address, address);
+ }
+
/**
* Returns the primary symbol for the address, as determined at the start of PDB processing
* before apply any PDB symbols.
@@ -145,22 +194,6 @@ public class PdbAddressManager {
return existingAddress;
}
- /**
- * Returns the Address of an existing symbol for the query address, where the mapping is
- * derived by using a the address of a PDB symbol as the key and finding the address of
- * a symbol in the program of the same "unique" name. This is accomplished using public
- * mangled symbols. If the program symbol came from the PDB, then it maps to itself.
- * @param address the query address
- * @return the remapAddress
- */
- Address getRemapAddressByAddress(Address address) {
- if (!Address.NO_ADDRESS.equals(address) &&
- applicator.getPdbApplicatorOptions().remapAddressUsingExistingPublicSymbols()) {
- return remapAddressByAddress.getOrDefault(address, address);
- }
- return address;
- }
-
/**
* Method for callee to set the real address for the section.
* @param sectionNum the section number
@@ -217,7 +250,7 @@ public class PdbAddressManager {
private void determineMemoryBlocks() {
// Set section/segment 0 to image base. (should be what is header), but what is its size?
- // TODO... made up size for now... is there something else? We could
+ // TODO... made up size for now... is there something else? We could
long segmentZeroLength = 0x7fffffff;
allSegmentsInfo.add(new SegmentInfo(imageBase, segmentZeroLength));
AbstractDatabaseInterface dbi = applicator.getPdb().getDatabaseInterface();
@@ -227,13 +260,14 @@ public class PdbAddressManager {
for (ImageSectionHeader imageSectionHeader : imageSectionHeaders) {
long virtualAddress = imageSectionHeader.getVirtualAddress();
// TODO: not sure when unionPAVS is physical address vs. virtual size. Perhaps
- // it keys off whether virtualAddress is not some special value such as
- // 0x00000000 or 0xffffffff.
+ // it keys off whether virtualAddress is not some special value such as
+ // 0x00000000 or 0xffffffff.
long size = imageSectionHeader.getUnionPAVS();
allSegmentsInfo.add(new SegmentInfo(imageBase.add(virtualAddress), size));
}
}
// else instance of DatabaseInterface; TODO: what can we do here?
+ // Maybe get information from the program itself.
// TODO: what should we do with these? Not doing anything at the moment
AbstractPdb pdb = applicator.getPdb();
@@ -251,6 +285,11 @@ public class PdbAddressManager {
* @throws PdbException If Program is null;
*/
private void mapPreExistingSymbols() throws PdbException {
+ // Cannot do this commented-out code here... as we are relying on the primary symbol
+ // map, regardless of the remap... so might need to separate the two. TODO: later thoughts
+// if (!applicator.getPdbApplicatorOptions().remapAddressUsingExistingPublicSymbols()) {
+// return;
+// }
Program program = applicator.getProgram();
if (program == null) {
throw new PdbException("Program may not be null");
@@ -258,7 +297,7 @@ public class PdbAddressManager {
SymbolIterator iter = program.getSymbolTable().getAllSymbols(false);
while (iter.hasNext()) {
Symbol symbol = iter.next();
- String name = symbol.getName();
+ String name = symbol.getPath().toString();
Address address = symbol.getAddress();
Address existingAddress = addressByPreExistingSymbolName.get(name);
if (existingAddress == null) {
@@ -283,9 +322,9 @@ public class PdbAddressManager {
private Address getAddressByPreExistingSymbolName(String name) {
Address address = addressByPreExistingSymbolName.get(name);
// Thin the list of map values we no longer need. This method should only be
- // used after the list has been completely populated, and the NO_ADDRESS marker
- // was only being used during the method that populated the list to indicate that a
- // name was not unique for our needs.
+ // used after the list has been completely populated, and the NO_ADDRESS marker
+ // was only being used during the method that populated the list to indicate that a
+ // name was not unique for our needs.
if (address != null && address.equals(Address.NO_ADDRESS)) {
addressByPreExistingSymbolName.remove(name);
return null;
@@ -293,6 +332,15 @@ public class PdbAddressManager {
return address;
}
+ private void createAddressRemap() {
+ remapAddressByAddress = new HashMap<>();
+
+ // Put in two basic entries so we do not have to do conditional tests before looking
+ // up values in the table.
+ remapAddressByAddress.put(BAD_ADDRESS, BAD_ADDRESS);
+ remapAddressByAddress.put(EXTERNAL_ADDRESS, EXTERNAL_ADDRESS);
+ }
+
/**
* Write the mapped address for a query address, where where the mapping is
* derived by using a the address of a PDB symbol as the key and finding the address of
@@ -321,8 +369,8 @@ public class PdbAddressManager {
*/
private void logMemorySectionRefinement() throws CancelledException {
// Offer memory refinement (could have done it as symbols came in; we just collected
- // them and are dealing with them now... ultimately not sure if we will want to use
- // this refinement.
+ // them and are dealing with them now... ultimately not sure if we will want to use
+ // this refinement.
// Look at SectionFlags.java for characteristics information.
// TODO: should we perform refinement of program memory blocks?
PdbLog.message("\nMemorySectionRefinement");
@@ -347,14 +395,14 @@ public class PdbAddressManager {
*/
private void logMemoryGroupRefinement() throws CancelledException {
// Note that I've seen example where PE header has two .data sections (one for initialized
- // and the other for uninitialized, 0x2800 and 0x250 in size, respectively), but the PDB
- // information shows two sections totally 0x2a50 size, but sizes of 0x2750 and 0x0300,
- // the latter of which is marked as ".bss" in name. This suggests that the PE header is
- // more focused on what needs initialized, which includes 0x2750 of .data and 0xa0 of
- // .bss, the remaining 0x250 of .bss is not initialized. These .bss portion that needs
- // initialized is lumped with the .data section in the PE header... only my opinion...
- // however, this leaves us with question of what we do here. Do believe the PDB over
- // the PE? (See vcamp110.arm.pdb and (arm) vcamp110.dll).
+ // and the other for uninitialized, 0x2800 and 0x250 in size, respectively), but the PDB
+ // information shows two sections totally 0x2a50 size, but sizes of 0x2750 and 0x0300,
+ // the latter of which is marked as ".bss" in name. This suggests that the PE header is
+ // more focused on what needs initialized, which includes 0x2750 of .data and 0xa0 of
+ // .bss, the remaining 0x250 of .bss is not initialized. These .bss portion that needs
+ // initialized is lumped with the .data section in the PE header... only my opinion...
+ // however, this leaves us with question of what we do here. Do believe the PDB over
+ // the PE? (See vcamp110.arm.pdb and (arm) vcamp110.dll).
// TODO: should we perform refinement of program memory blocks?
PdbLog.message("\nMemoryGroupRefinement");
for (PeCoffGroupMsSymbol sym : memoryGroupRefinement) {
@@ -373,7 +421,7 @@ public class PdbAddressManager {
//==============================================================================================
//==============================================================================================
// TODO: This is not complete... It was a research thought, which might get looked at in the
- // future.
+ // future.
/**
* Tries to align section/segment information of the PDB in {@link SegmentMapDescription} from
* the {@link AbstractDatabaseInterface} header substream with the memory blocks of the
@@ -412,7 +460,7 @@ public class PdbAddressManager {
List<SegmentInfo> myAllSegmentsInfo = new ArrayList<>(); // Contender set of segment info (vs what is in class)
- allSegmentsInfo.add(new SegmentInfo(blocks[0].getStart(), blocks[0].getSize()));
+ myAllSegmentsInfo.add(new SegmentInfo(blocks[0].getStart(), blocks[0].getSize()));
// Try to match memory in order, grouping as needed.
long blockAccum = 0;
while (progIndex < progIndexLimit && pdbIndex < pdbIndexLimit) {
@@ -454,7 +502,7 @@ public class PdbAddressManager {
//==============================================================================================
// TODO: This is not complete... It was a research thought, which might get looked at in the
- // future.
+ // future.
@SuppressWarnings("unused") // for method not being called.
private boolean garnerSectionSegmentInformation() throws PdbException {
AbstractPdb pdb = applicator.getPdb();
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicator.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicator.java
index a00fffc254..6b6657b263 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicator.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicator.java
@@ -183,17 +183,19 @@ public class PdbApplicator {
initializeApplyTo(programParam, dataTypeManagerParam, imageBaseParam,
applicatorOptionsParam, monitorParam, logParam);
- if (!applicatorOptions.applyPublicSymbolsOnly()) {
- processTypes();
- }
-
- if (program != null && !applicatorOptions.applyDataTypesOnly()) {
- if (applicatorOptions.applyPublicSymbolsOnly()) {
+ switch (applicatorOptions.getRestrictions()) {
+ case DATA_TYPES_ONLY:
+ processTypes();
+ break;
+ case PUBLIC_SYMBOLS_ONLY:
processPublicSymbols();
- }
- else {
+ break;
+ case NONE:
+ processTypes();
processSymbols();
- }
+ break;
+ default:
+ throw new PdbException("Invalid Restriction");
}
pdbAddressManager.logReport();
@@ -328,6 +330,8 @@ public class PdbApplicator {
DataTypeManager dataTypeManagerParam, Address imageBaseParam,
PdbApplicatorOptions applicatorOptionsParam, TaskMonitor monitorParam,
MessageLog logParam) throws PdbException {
+ applicatorOptions =
+ (applicatorOptionsParam != null) ? applicatorOptionsParam : new PdbApplicatorOptions();
if (programParam == null) {
if (dataTypeManagerParam == null) {
throw new PdbException(
@@ -336,11 +340,11 @@ public class PdbApplicator {
if (imageBaseParam == null) {
throw new PdbException("programParam and imageBaseParam may not both be null.");
}
- }
- applicatorOptions =
- (applicatorOptionsParam != null) ? applicatorOptionsParam : new PdbApplicatorOptions();
- if (applicatorOptions.applyDataTypesOnly() && applicatorOptions.applyPublicSymbolsOnly()) {
- throw new PdbException("Cannot have both: applyDataTypesOnly, applyPublicSymbolOnly.");
+ if (applicatorOptions.getRestrictions() != PdbApplicatorRestrictions.DATA_TYPES_ONLY) {
+ throw new PdbException(
+ "programParam may not be null for the chosen PdbApplicatorRestrictions: " +
+ applicatorOptions.getRestrictions());
+ }
}
monitor = (monitorParam != null) ? monitorParam : TaskMonitor.DUMMY;
log = (logParam != null) ? logParam : new MessageLog();
@@ -773,10 +777,39 @@ public class PdbApplicator {
//==============================================================================================
// Address-related methods.
//==============================================================================================
+ /**
+ * Returns true if the {@link Address} is an invalid address for continuing application of
+ * information to the program. Will report Error or message for an invalid address and will
+ * report a "External address" message for the name when the address is external.
+ * @param address the address to test
+ * @param name name associated with the address used for reporting error/info situations.
+ * @return {@code true} if the address should be processed.
+ */
+ boolean isInvalidAddress(Address address, String name) {
+ if (address == PdbAddressManager.BAD_ADDRESS) {
+ appendLogMsg("Invalid address encountered for: " + name);
+ return true;
+ }
+ if (address == PdbAddressManager.EXTERNAL_ADDRESS) {
+ appendLogMsg("External address not known for: " + name);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns the image base Address being used by the applicator.
+ * @return The Address
+ */
+ Address getImageBase() {
+ return imageBase;
+ }
+
/**
* Returns the Address for the given section and offset.
* @param symbol The {@link AddressMsSymbol}
- * @return The Address
+ * @return The Address, which can be {@code Address.NO_ADDRESS} if invalid or
+ * {@code Address.EXTERNAL_ADDRESS} if the address is external to the program.
*/
Address getAddress(AddressMsSymbol symbol) {
return pdbAddressManager.getAddress(symbol);
@@ -789,7 +822,17 @@ public class PdbApplicator {
* @return The Address
*/
Address getAddress(int segment, long offset) {
- return pdbAddressManager.getAddress(segment, offset);
+ return pdbAddressManager.getRawAddress(segment, offset);
+ }
+
+ /**
+ * Returns the Address for the given section and offset.
+ * @param symbol The {@link AddressMsSymbol}
+ * @return The Address, which can be {@code Address.NO_ADDRESS} if invalid or
+ * {@code Address.EXTERNAL_ADDRESS} if the address is external to the program.
+ */
+ Address getRawAddress(AddressMsSymbol symbol) {
+ return pdbAddressManager.getRawAddress(symbol);
}
/**
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorMetrics.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorMetrics.java
index 8e0f6942c6..460568ddd3 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorMetrics.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorMetrics.java
@@ -213,8 +213,9 @@ public class PdbApplicatorMetrics {
private String reportNonappliableTypes() {
StringBuilder builder = new StringBuilder();
for (Class<? extends AbstractMsType> clazz : cannotApplyTypes) {
- builder.append("Could not apply one or more instances of PDB data type: " +
- clazz.getSimpleName() + "\n");
+ builder.append(
+ "Could not apply one or more instances of an unsupported PDB data type: " +
+ clazz.getSimpleName() + "\n");
}
return builder.toString();
}
@@ -246,8 +247,9 @@ public class PdbApplicatorMetrics {
private String reportNonappliableSymbols() {
StringBuilder builder = new StringBuilder();
for (Class<? extends AbstractMsSymbol> clazz : cannotApplySymbols) {
- builder.append("Could not apply one or more instances of PDB symbol type: " +
- clazz.getSimpleName() + "\n");
+ builder.append(
+ "Could not apply one or more instances of an unsupported PDB symbol type: " +
+ clazz.getSimpleName() + "\n");
}
return builder.toString();
}
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorOptions.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorOptions.java
index 61b951e514..a4d1ea9de1 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorOptions.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorOptions.java
@@ -26,8 +26,8 @@ public class PdbApplicatorOptions {
public static final boolean DEFAULT_APPLY_CODE_SCOPE_BLOCK_COMMENTS = false;
public static final boolean DEFAULT_APPLY_INSTRUCTION_LABELS = false;
- public static final boolean DEFAULT_APPLY_DATA_TYPES_ONLY = false;
- public static final boolean DEFAULT_APPLY_PUBLIC_SYMBOLS_ONLY = false;
+ public static final PdbApplicatorRestrictions DEFAULT_RESTRICTIONS =
+ PdbApplicatorRestrictions.NONE;
public static final boolean DEFAULT_REMAP_ADDRESSES_USING_EXISTING_SYMBOLS = false;
public static final boolean DEFAULT_ALLOW_DEMOTE_PRIMARY_MANGLED_SYMBOLS = true;
@@ -46,8 +46,7 @@ public class PdbApplicatorOptions {
//==============================================================================================
private boolean applyCodeScopeBlockComments;
private boolean applyInstructionLabels;
- private boolean applyDataTypesOnly;
- private boolean applyPublicSymbolsOnly;
+ private PdbApplicatorRestrictions restrictions;
private boolean remapAddressesUsingExistingPublicSymbols;
private boolean allowDemotePrimaryMangledSymbols;
@@ -68,8 +67,7 @@ public class PdbApplicatorOptions {
public void restoreDefaults() {
applyCodeScopeBlockComments = DEFAULT_APPLY_CODE_SCOPE_BLOCK_COMMENTS;
applyInstructionLabels = DEFAULT_APPLY_INSTRUCTION_LABELS;
- applyDataTypesOnly = DEFAULT_APPLY_DATA_TYPES_ONLY;
- applyPublicSymbolsOnly = DEFAULT_APPLY_PUBLIC_SYMBOLS_ONLY;
+ restrictions = DEFAULT_RESTRICTIONS;
remapAddressesUsingExistingPublicSymbols = DEFAULT_REMAP_ADDRESSES_USING_EXISTING_SYMBOLS;
allowDemotePrimaryMangledSymbols = DEFAULT_ALLOW_DEMOTE_PRIMARY_MANGLED_SYMBOLS;
applyFunctionVariables = DEFAULT_APPLY_FUNCTION_VARIABLES;
@@ -109,36 +107,19 @@ public class PdbApplicatorOptions {
}
/**
- * Enable/disable the option to only apply data types (skipping symbol information).
- * In other words, the default is to apply symbols.
- * @param applyDataTypesOnly {@code true} to turn applyDataTypesOnly on
+ * Set processing restrictions for PdbApplicator
+ * @param restrictions the restrictions
*/
- public void setApplyDataTypesOnly(boolean applyDataTypesOnly) {
- this.applyDataTypesOnly = applyDataTypesOnly;
+ public void setRestrictions(PdbApplicatorRestrictions restrictions) {
+ this.restrictions = restrictions;
}
/**
- * Returns {@code true} if applyDataTypesOnly is "on."
- * @return {@code true} if applyDataTypesOnly is "on."
+ * Returns the current restrictions on PdbApplicator processing
+ * @return the restrictions
*/
- public boolean applyDataTypesOnly() {
- return applyDataTypesOnly;
- }
-
- /**
- * Enable/disable the option to only apply public symbols.
- * @param applyPublicSymbolsOnly {@code true} to turn applyPublicSymbolsOnly on
- */
- public void setApplyPublicSymbolsOnly(boolean applyPublicSymbolsOnly) {
- this.applyPublicSymbolsOnly = applyPublicSymbolsOnly;
- }
-
- /**
- * Returns {@code true} if applyPublicSymbolsOnly is "on."
- * @return {@code true} if applyPublicSymbolsOnly is "on."
- */
- public boolean applyPublicSymbolsOnly() {
- return applyPublicSymbolsOnly;
+ public PdbApplicatorRestrictions getRestrictions() {
+ return restrictions;
}
/**
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorRestrictions.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorRestrictions.java
new file mode 100644
index 0000000000..893c91862e
--- /dev/null
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbApplicatorRestrictions.java
@@ -0,0 +1,35 @@
+/* ###
+ * IP: GHIDRA
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ghidra.app.util.pdb.pdbapplicator;
+
+/**
+ * PDB Applicator restrictions of actions performed. Used by {@link PdbApplicatorOptions}
+ */
+public enum PdbApplicatorRestrictions {
+ NONE("None"), DATA_TYPES_ONLY("Data Types Only"), PUBLIC_SYMBOLS_ONLY("Public Symbols Only");
+
+ private final String label;
+
+ @Override
+ public String toString() {
+ return label;
+ }
+
+ private PdbApplicatorRestrictions(String label) {
+ this.label = label;
+ }
+
+}
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbResearch.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbResearch.java
index e42eb782eb..381bd85d22 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbResearch.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbResearch.java
@@ -689,8 +689,11 @@ public class PdbResearch {
!((AbstractPublic32MsSymbol) symbol).isFunction()) {
return;
}
- Address address = applicator.getAddress((AbstractPublicMsSymbol) symbol);
String name = ((AbstractPublicMsSymbol) symbol).getName();
+ Address address = applicator.getAddress((AbstractPublicMsSymbol) symbol);
+ if (applicator.isInvalidAddress(address, name)) {
+ return;
+ }
String demangledName = getDemangledQualifiedName(name);
if (demangledName != null) {
stuff = new Stuff(symbol, demangledName, What.PUBLIC_QUAL_FROM_MANGLED);
@@ -704,8 +707,11 @@ public class PdbResearch {
private static void processProcedureSymbol(PdbApplicator applicator,
Map<Address, List<Stuff>> map, AbstractMsSymbol symbol) {
if (symbol instanceof AbstractProcedureMsSymbol) {
- Address address = applicator.getAddress((AbstractProcedureMsSymbol) symbol);
String name = ((AbstractProcedureMsSymbol) symbol).getName();
+ Address address = applicator.getAddress((AbstractProcedureMsSymbol) symbol);
+ if (applicator.isInvalidAddress(address, name)) {
+ return;
+ }
Stuff stuff = new Stuff(symbol, name, What.GLOBAL);
addStuff(map, address, stuff);
}
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbVbtManager.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbVbtManager.java
index 9b15d2d24b..6049d8341a 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbVbtManager.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PdbVbtManager.java
@@ -75,7 +75,9 @@ public class PdbVbtManager extends VbtManager {
String name = pubSymbol.getName();
if (name.startsWith("??_8")) {
Address address = applicator.getAddress(pubSymbol);
- myAddressByMangledName.put(name, address);
+ if (!applicator.isInvalidAddress(address, name)) {
+ myAddressByMangledName.put(name, address);
+ }
}
}
monitor.incrementProgress(1);
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PeCoffGroupSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PeCoffGroupSymbolApplier.java
index 1400e889bf..4e0f0bc21b 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PeCoffGroupSymbolApplier.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PeCoffGroupSymbolApplier.java
@@ -49,12 +49,10 @@ public class PeCoffGroupSymbolApplier extends MsSymbolApplier {
void apply() throws PdbException, CancelledException {
applicator.addMemoryGroupRefinement(symbol);
Address symbolAddress = applicator.getAddress(symbol);
- if (!Address.NO_ADDRESS.equals(symbolAddress)) {
- applicator.createSymbol(symbolAddress, symbol.getName(), false);
- }
- else {
-// monitor.setMessage("Skipping NO_ADDRESS symbol " + symb.getName() + "...");
+ if (applicator.isInvalidAddress(symbolAddress, symbol.getName())) {
+ return;
}
+ applicator.createSymbol(symbolAddress, symbol.getName(), false);
}
@Override
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PublicSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PublicSymbolApplier.java
index e53764c595..1822bc2671 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PublicSymbolApplier.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/PublicSymbolApplier.java
@@ -56,20 +56,18 @@ public class PublicSymbolApplier extends MsSymbolApplier {
void apply() throws CancelledException, PdbException {
symbolAddress = applicator.getAddress(symbol);
- if (!Address.NO_ADDRESS.equals(symbolAddress)) {
- existingSymbolAddress = applicator.witnessSymbolNameAtAddress(getName(), symbolAddress);
- // TODO: Consider... could add restriction of not putting down symbol if it is mangled,
- // as this would violate the uniqueness of the symbol... but we would also want to
- // know that this situation was being presented.
- if (!symbolAddress.equals(existingSymbolAddress)) {
- // Note: there might be issues of thunk functions getting the same mangled name
- // as thunked functions, which violates the thesis of their being unique.
- // TODO: investigate this.
- applicator.createSymbol(symbolAddress, symbol.getName(), true);
- }
+ if (applicator.isInvalidAddress(symbolAddress, symbol.getName())) {
+ return;
}
- else {
- pdbLogAndInfoMessage(this, "Could not apply symbol at NO_ADDRESS: " + symbol.getName());
+ existingSymbolAddress = applicator.witnessSymbolNameAtAddress(getName(), symbolAddress);
+ // TODO: Consider... could add restriction of not putting down symbol if it is mangled,
+ // as this would violate the uniqueness of the symbol... but we would also want to
+ // know that this situation was being presented.
+ if (!symbolAddress.equals(existingSymbolAddress)) {
+ // Note: there might be issues of thunk functions getting the same mangled name
+ // as thunked functions, which violates the thesis of their being unique.
+ // TODO: investigate this.
+ applicator.createSymbol(symbolAddress, symbol.getName(), true);
}
}
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/SeparatedCodeSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/SeparatedCodeSymbolApplier.java
index e5296b3f92..be3772718d 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/SeparatedCodeSymbolApplier.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/SeparatedCodeSymbolApplier.java
@@ -101,6 +101,9 @@ public class SeparatedCodeSymbolApplier extends MsSymbolApplier {
@Override
void apply() throws PdbException, CancelledException {
+ if (applicator.isInvalidAddress(currentBlockAddress, craftedName)) {
+ return;
+ }
// DO NOTHING FOR NOW. TODO: should we have a configuration option?
// Note: these comments can be noise in the decompiler an code browser
setComments(false);
diff --git a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/TrampolineSymbolApplier.java b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/TrampolineSymbolApplier.java
index 071aa38239..a5871b6c9d 100644
--- a/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/TrampolineSymbolApplier.java
+++ b/Ghidra/Features/PDB/src/main/java/ghidra/app/util/pdb/pdbapplicator/TrampolineSymbolApplier.java
@@ -61,8 +61,14 @@ public class TrampolineSymbolApplier extends MsSymbolApplier {
Address targetAddress =
applicator.getAddress(symbol.getSegmentTarget(), symbol.getOffsetTarget());
- Function target = createNewFunction(targetAddress, 1);
- Function thunk = createNewFunction(symbolAddress, symbol.getSizeOfThunk());
+ Function target = null;
+ Function thunk = null;
+ if (!applicator.isInvalidAddress(targetAddress, "thunk target")) {
+ target = createNewFunction(targetAddress, 1);
+ }
+ if (!applicator.isInvalidAddress(symbolAddress, "thunk symbol")) {
+ thunk = createNewFunction(symbolAddress, symbol.getSizeOfThunk());
+ }
if (target != null && thunk != null) {
thunk.setThunkedFunction(target);
}