GP-1091: PE and ELF exporters no longer error out when processing

non-file-backed relocations.
This commit is contained in:
Ryan Kurtz 2021-07-01 09:51:16 -04:00
parent 7936f89ab5
commit 1407f36177

View File

@ -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());
}
}