mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-02 18:26:53 +08:00
GP-4081 streamline pdb parsing in the ContainerFileSymbolServer
This commit is contained in:
@@ -15,14 +15,14 @@
|
|||||||
*/
|
*/
|
||||||
package pdb.symbolserver;
|
package pdb.symbolserver;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
|
||||||
import ghidra.app.util.bin.ByteProvider;
|
import ghidra.app.util.bin.format.pdb2.pdbreader.*;
|
||||||
import ghidra.formats.gfilesystem.*;
|
import ghidra.formats.gfilesystem.*;
|
||||||
import ghidra.util.exception.CancelledException;
|
import ghidra.util.exception.CancelledException;
|
||||||
import ghidra.util.task.TaskMonitor;
|
import ghidra.util.task.TaskMonitor;
|
||||||
@@ -96,31 +96,19 @@ public class ContainerFileSymbolServer implements SymbolServer {
|
|||||||
TaskMonitor monitor) {
|
TaskMonitor monitor) {
|
||||||
|
|
||||||
try (RefdFile fref = getFile(fileInfo.getName(), monitor)) {
|
try (RefdFile fref = getFile(fileInfo.getName(), monitor)) {
|
||||||
// TODO: need to be able to read info from candidate pdb file using some type of stream
|
|
||||||
if (fref != null) {
|
if (fref != null) {
|
||||||
GFile file = fref.file;
|
GFile file = fref.file;
|
||||||
GFileSystem fs = file.getFilesystem();
|
GFileSystem fs = file.getFilesystem();
|
||||||
try (ByteProvider bp = fs.getByteProvider(file, monitor)) {
|
try (AbstractPdb pdb = PdbParser.parse(fs.getByteProvider(file, monitor),
|
||||||
File tmpPdbFile = fsService.createPlaintextTempFile(bp, "temp_pdb", monitor);
|
new PdbReaderOptions(), monitor)) {
|
||||||
File tmpPdbDir =
|
PdbIdentifiers pdbIdent = pdb.getIdentifiers();
|
||||||
Files.createTempDirectory(tmpPdbFile.getParentFile().toPath(), "temp_pdb")
|
SymbolFileInfo foundInfo =
|
||||||
.toFile();
|
SymbolFileInfo.fromPdbIdentifiers(file.getName(), pdbIdent);
|
||||||
File destPdbFile = new File(tmpPdbDir, file.getName()).getCanonicalFile();
|
return List.of(new SymbolFileLocation(fileInfo.getName(), this, foundInfo));
|
||||||
if (!destPdbFile.getParentFile().equals(tmpPdbDir)) {
|
|
||||||
throw new IOException("Bad filename: " + destPdbFile);
|
|
||||||
}
|
|
||||||
if (!tmpPdbFile.renameTo(destPdbFile)) {
|
|
||||||
throw new IOException(
|
|
||||||
"Unable to move file: " + tmpPdbFile + " to " + destPdbFile);
|
|
||||||
}
|
|
||||||
SymbolFileInfo foundInfo = SymbolFileInfo.fromFile(destPdbFile, monitor);
|
|
||||||
destPdbFile.delete();
|
|
||||||
tmpPdbDir.delete();
|
|
||||||
return List.of(new SymbolFileLocation(file.getName(), this, foundInfo));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException | CancelledException e) {
|
catch (Exception e) {
|
||||||
// fall thru
|
// fall thru
|
||||||
}
|
}
|
||||||
return List.of();
|
return List.of();
|
||||||
|
|||||||
Reference in New Issue
Block a user