mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-25 19:05:32 +08:00
Merge remote-tracking branch 'origin/GP-1091_ryanmkurtz_exporter-relocs' into patch
This commit is contained in:
+11
-11
@@ -89,25 +89,25 @@ public abstract class AbstractLoaderExporter extends Exporter {
|
||||
}
|
||||
|
||||
// Undo relocations in the temp file
|
||||
// NOTE: not all relocations are file-backed
|
||||
String error = null;
|
||||
try (RandomAccessFile fout = new RandomAccessFile(tempFile, "rw")) {
|
||||
Iterable<Relocation> relocs = () -> program.getRelocationTable().getRelocations();
|
||||
for (Relocation reloc : relocs) {
|
||||
AddressSourceInfo info = memory.getAddressSourceInfo(reloc.getAddress());
|
||||
if (info == null) {
|
||||
error = "Failed to get relocation address source";
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if (info.getFileOffset() < 0) {
|
||||
error = "Failed to get relocation file offset";
|
||||
break;
|
||||
long offset = info.getFileOffset();
|
||||
byte[] bytes = reloc.getBytes();
|
||||
if (offset >= 0) {
|
||||
if (offset + bytes.length > fout.length()) {
|
||||
error = "Relocation at " + reloc.getAddress() + " exceeds file length";
|
||||
break;
|
||||
}
|
||||
fout.seek(offset);
|
||||
fout.write(bytes);
|
||||
}
|
||||
if (info.getFileOffset() >= fout.length()) {
|
||||
error = "Relocation file offset exceeds file length";
|
||||
break;
|
||||
}
|
||||
fout.seek(info.getFileOffset());
|
||||
fout.write(reloc.getBytes());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user