GP-3013 Refactor of Relocation API (created V6 DB adapter) to include

status and stored length when original FileBytes are used.
This commit is contained in:
ghidra1 2023-01-17 15:04:22 -05:00
parent f022b9a4d5
commit 5b433f35ca
63 changed files with 2146 additions and 1147 deletions

View file

@ -20,6 +20,8 @@ import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.Memory;
import ghidra.program.model.mem.MemoryAccessException;
import ghidra.program.model.reloc.RelocationResult;
import ghidra.program.model.reloc.Relocation.Status;
import ghidra.util.exception.NotFoundException;
public class SPARC_ElfRelocationHandler extends ElfRelocationHandler {
@ -32,13 +34,14 @@ public class SPARC_ElfRelocationHandler extends ElfRelocationHandler {
}
@Override
public void relocate(ElfRelocationContext elfRelocationContext, ElfRelocation relocation,
public RelocationResult relocate(ElfRelocationContext elfRelocationContext,
ElfRelocation relocation,
Address relocationAddress) throws MemoryAccessException, NotFoundException {
ElfHeader elf = elfRelocationContext.getElfHeader();
if (elf.e_machine() != ElfConstants.EM_SPARC &&
elf.e_machine() != ElfConstants.EM_SPARC32PLUS) {
return;
return RelocationResult.FAILURE;
}
Program program = elfRelocationContext.getProgram();
@ -46,7 +49,7 @@ public class SPARC_ElfRelocationHandler extends ElfRelocationHandler {
int type = relocation.getType();
if (type == SPARC_ElfRelocationConstants.R_SPARC_NONE) {
return;
return RelocationResult.SKIPPED;
}
int symbolIndex = relocation.getSymbolIndex();
@ -63,6 +66,8 @@ public class SPARC_ElfRelocationHandler extends ElfRelocationHandler {
int oldValue = memory.getInt(relocationAddress);
int newValue = 0;
int byteLength = 4; // most relocations affect 4-bytes (change if different)
switch (type) {
case SPARC_ElfRelocationConstants.R_SPARC_DISP32:
newValue = (int) (symbolValue + addend - offset);
@ -102,12 +107,13 @@ public class SPARC_ElfRelocationHandler extends ElfRelocationHandler {
case SPARC_ElfRelocationConstants.R_SPARC_COPY:
markAsWarning(program, relocationAddress, "R_SPARC_COPY", symbolName, symbolIndex,
"Runtime copy not supported", elfRelocationContext.getLog());
break;
return RelocationResult.UNSUPPORTED;
default:
markAsUnhandled(program, relocationAddress, type, symbolIndex, symbolName,
elfRelocationContext.getLog());
break;
return RelocationResult.UNSUPPORTED;
}
return new RelocationResult(Status.APPLIED, byteLength);
}
}