mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-20 10:37:27 +08:00
GP-4758 Corrected ELF X86-64 GOT allocation bug. Added a few relocation
types.
This commit is contained in:
+10
-1
@@ -141,6 +141,13 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext<X86_64_ElfRelocat
|
||||
|
||||
private Address allocateGot() {
|
||||
|
||||
if (allocatedGotAddress != null) {
|
||||
if (allocatedGotAddress == Address.NO_ADDRESS) {
|
||||
return null;
|
||||
}
|
||||
return allocatedGotAddress;
|
||||
}
|
||||
|
||||
allocatedGotAddress = Address.NO_ADDRESS;
|
||||
nextAllocatedGotEntryAddress = Address.NO_ADDRESS;
|
||||
|
||||
@@ -193,7 +200,9 @@ class X86_64_ElfRelocationContext extends ElfRelocationContext<X86_64_ElfRelocat
|
||||
*/
|
||||
private Address getNextAllocatedGotEntryAddress() {
|
||||
if (nextAllocatedGotEntryAddress == null) {
|
||||
allocateGot();
|
||||
if (allocateGot() == null) {
|
||||
return Address.NO_ADDRESS; // failed to allocate got
|
||||
}
|
||||
}
|
||||
|
||||
Address addr = nextAllocatedGotEntryAddress;
|
||||
|
||||
+27
-1
@@ -134,7 +134,7 @@ public class X86_64_ElfRelocationHandler extends
|
||||
}
|
||||
catch (NotFoundException e) {
|
||||
markAsError(program, relocationAddress, type, symbolName, symbolIndex,
|
||||
e.getMessage(), elfRelocationContext.getLog());
|
||||
"GOT allocation failure", elfRelocationContext.getLog());
|
||||
return RelocationResult.FAILURE;
|
||||
}
|
||||
break;
|
||||
@@ -257,6 +257,32 @@ public class X86_64_ElfRelocationHandler extends
|
||||
}
|
||||
value = symbolGotAddress.getOffset() + addend - offset;
|
||||
memory.setLong(relocationAddress, value);
|
||||
break;
|
||||
|
||||
case R_X86_64_GOT64: // 64 bit GOT entry offset (UNVERIFIED)
|
||||
symbolGotAddress = elfRelocationContext.getGotEntryAddress(sym);
|
||||
if (symbolGotAddress == null) {
|
||||
markAsError(program, relocationAddress, type, symbolName, symbolIndex,
|
||||
"GOT allocation failure", elfRelocationContext.getLog());
|
||||
return RelocationResult.FAILURE;
|
||||
}
|
||||
value = symbolGotAddress.getOffset() + addend;
|
||||
memory.setLong(relocationAddress, value);
|
||||
break;
|
||||
|
||||
case R_X86_64_PLTOFF64: // 64 bit GOT relative offset to PLT entry (UNVERIFIED)
|
||||
long dotgot;
|
||||
try {
|
||||
dotgot = elfRelocationContext.getGOTValue();
|
||||
}
|
||||
catch (NotFoundException e) {
|
||||
markAsError(program, relocationAddress, type, symbolName, symbolIndex,
|
||||
"GOT allocation failure", elfRelocationContext.getLog());
|
||||
return RelocationResult.FAILURE;
|
||||
}
|
||||
value = symbolValue - dotgot + addend;
|
||||
memory.setLong(relocationAddress, value);
|
||||
break;
|
||||
|
||||
case R_X86_64_RELATIVE:
|
||||
// word64 for LP64 and specifies word32 for ILP32,
|
||||
|
||||
Reference in New Issue
Block a user