mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-30 10:45:37 +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
|
// Undo relocations in the temp file
|
||||||
|
// NOTE: not all relocations are file-backed
|
||||||
String error = null;
|
String error = null;
|
||||||
try (RandomAccessFile fout = new RandomAccessFile(tempFile, "rw")) {
|
try (RandomAccessFile fout = new RandomAccessFile(tempFile, "rw")) {
|
||||||
Iterable<Relocation> relocs = () -> program.getRelocationTable().getRelocations();
|
Iterable<Relocation> relocs = () -> program.getRelocationTable().getRelocations();
|
||||||
for (Relocation reloc : relocs) {
|
for (Relocation reloc : relocs) {
|
||||||
AddressSourceInfo info = memory.getAddressSourceInfo(reloc.getAddress());
|
AddressSourceInfo info = memory.getAddressSourceInfo(reloc.getAddress());
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
error = "Failed to get relocation address source";
|
continue;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if (info.getFileOffset() < 0) {
|
long offset = info.getFileOffset();
|
||||||
error = "Failed to get relocation file offset";
|
byte[] bytes = reloc.getBytes();
|
||||||
break;
|
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