mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
PDB Refinements - integrated new PDB Universal with Load/Download
actions and corrected PDB age related issue.
This commit is contained in:
parent
5c79ebf6e3
commit
b816f4a939
36 changed files with 800 additions and 535 deletions
|
@ -16,15 +16,20 @@
|
|||
package pdb;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import docking.DockingWindowManager;
|
||||
import docking.widgets.dialogs.MultiLineMessageDialog;
|
||||
import ghidra.app.plugin.core.analysis.*;
|
||||
import ghidra.app.plugin.core.datamgr.archive.DuplicateIdException;
|
||||
import ghidra.app.services.DataTypeManagerService;
|
||||
import ghidra.app.util.bin.format.pdb.PdbException;
|
||||
import ghidra.app.util.bin.format.pdb.PdbParser;
|
||||
import ghidra.app.util.bin.format.pdb2.pdbreader.AbstractPdb;
|
||||
import ghidra.app.util.bin.format.pdb2.pdbreader.PdbReaderOptions;
|
||||
import ghidra.app.util.importer.MessageLog;
|
||||
import ghidra.app.util.pdb.pdbapplicator.*;
|
||||
import ghidra.framework.options.Options;
|
||||
import ghidra.program.model.address.AddressSetView;
|
||||
import ghidra.program.model.listing.Program;
|
||||
|
@ -37,11 +42,16 @@ class LoadPdbTask extends Task {
|
|||
private File pdbFile;
|
||||
private DataTypeManagerService service;
|
||||
private final Program program;
|
||||
private final boolean useMsDiaParser;
|
||||
private final PdbApplicatorRestrictions restrictions; // PDB Universal Parser only
|
||||
|
||||
LoadPdbTask(Program program, File pdbFile, DataTypeManagerService service) {
|
||||
LoadPdbTask(Program program, File pdbFile, boolean useMsDiaParser,
|
||||
PdbApplicatorRestrictions restrictions, DataTypeManagerService service) {
|
||||
super("Loading PDB...", true, false, false);
|
||||
this.program = program;
|
||||
this.pdbFile = pdbFile;
|
||||
this.useMsDiaParser = useMsDiaParser;
|
||||
this.restrictions = restrictions;
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
|
@ -58,33 +68,38 @@ class LoadPdbTask extends Task {
|
|||
|
||||
@Override
|
||||
public boolean analysisWorkerCallback(Program currentProgram, Object workerContext,
|
||||
TaskMonitor currentMonitor) throws Exception, CancelledException, PdbException {
|
||||
TaskMonitor currentMonitor) throws CancelledException {
|
||||
|
||||
PdbParser parser =
|
||||
new PdbParser(pdbFile, program, service, true, currentMonitor);
|
||||
|
||||
parser.parse();
|
||||
parser.openDataTypeArchives();
|
||||
parser.applyTo(log);
|
||||
|
||||
analyzeSymbols(currentMonitor, log);
|
||||
return !monitor.isCancelled();
|
||||
try {
|
||||
if (useMsDiaParser) {
|
||||
if (!parseWithMsDiaParser(log, monitor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!parseWithNewParser(log, monitor)) {
|
||||
return false;
|
||||
}
|
||||
analyzeSymbols(currentMonitor, log);
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.appendMsg("PDB IO Error: " + e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
boolean analyzed =
|
||||
program.getOptions(Program.PROGRAM_INFO).getBoolean(Program.ANALYZED, false);
|
||||
if (analyzed) {
|
||||
Msg.showWarn(this, null, "PDB Warning",
|
||||
"Loading PDB after analysis has been performed will produce" +
|
||||
"\npoor results. PDBs should be loaded prior to analysis or" +
|
||||
"\nautomatically during auto-analysis.");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
AutoAnalysisManager.getAnalysisManager(program)
|
||||
.scheduleWorker(worker, null, true,
|
||||
monitor);
|
||||
if (log.hasMessages()) {
|
||||
MultiLineMessageDialog dialog = new MultiLineMessageDialog("Load PDB File",
|
||||
"There were warnings/errors loading the PDB file.", log.toString(),
|
||||
MultiLineMessageDialog.WARNING_MESSAGE, false);
|
||||
DockingWindowManager.showDialog(null, dialog);
|
||||
}
|
||||
}
|
||||
catch (InterruptedException | CancelledException e1) {
|
||||
// ignore
|
||||
|
@ -105,17 +120,53 @@ class LoadPdbTask extends Task {
|
|||
}
|
||||
}
|
||||
|
||||
message = "Error processing PDB file: " + pdbFile + ".\n" + message;
|
||||
|
||||
Msg.showError(getClass(), null, "Load PDB Failed", message, t);
|
||||
}
|
||||
|
||||
if (log.hasMessages()) {
|
||||
MultiLineMessageDialog dialog = new MultiLineMessageDialog("Load PDB File",
|
||||
"There were warnings/errors loading the PDB file.", log.toString(),
|
||||
MultiLineMessageDialog.WARNING_MESSAGE, false);
|
||||
DockingWindowManager.showDialog(null, dialog);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean parseWithMsDiaParser(MessageLog log, TaskMonitor monitor)
|
||||
throws IOException, CancelledException {
|
||||
PdbParser parser = new PdbParser(pdbFile, program, service, true, monitor);
|
||||
try {
|
||||
parser.parse();
|
||||
parser.openDataTypeArchives();
|
||||
parser.applyTo(log);
|
||||
return true;
|
||||
}
|
||||
catch (PdbException | DuplicateIdException e) {
|
||||
log.appendMsg("PDB Error: " + e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean parseWithNewParser(MessageLog log, TaskMonitor monitor)
|
||||
throws IOException, CancelledException {
|
||||
|
||||
PdbReaderOptions pdbReaderOptions = new PdbReaderOptions(); // use defaults
|
||||
|
||||
PdbApplicatorOptions pdbApplicatorOptions = new PdbApplicatorOptions();
|
||||
|
||||
pdbApplicatorOptions.setRestrictions(restrictions);
|
||||
|
||||
try (AbstractPdb pdb =
|
||||
ghidra.app.util.bin.format.pdb2.pdbreader.PdbParser.parse(pdbFile.getAbsolutePath(),
|
||||
pdbReaderOptions, monitor)) {
|
||||
monitor.setMessage("PDB: Parsing " + pdbFile + "...");
|
||||
pdb.deserialize(monitor);
|
||||
PdbApplicator applicator = new PdbApplicator(pdbFile.getAbsolutePath(), pdb);
|
||||
applicator.applyTo(program, program.getDataTypeManager(), program.getImageBase(),
|
||||
pdbApplicatorOptions, monitor, log);
|
||||
return true;
|
||||
}
|
||||
catch (ghidra.app.util.bin.format.pdb2.pdbreader.PdbException e) {
|
||||
log.appendMsg("PDB Error: " + e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void analyzeSymbols(TaskMonitor monitor, MessageLog log) {
|
||||
|
||||
MicrosoftDemanglerAnalyzer demanglerAnalyzer = new MicrosoftDemanglerAnalyzer();
|
||||
|
@ -135,9 +186,8 @@ class LoadPdbTask extends Task {
|
|||
demanglerAnalyzer.added(program, addrs, monitor, log);
|
||||
}
|
||||
catch (CancelledException e) {
|
||||
// Don't care about CancelledException
|
||||
// ignore cancel
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue