mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-03 17:59:46 +02:00
GP-710 Added register symbol processing to ELF PIC30 import processing.
Improved code unit operand format to render memory register name when no reference is present.
This commit is contained in:
parent
7a3945f3bc
commit
c545a6fb5a
2 changed files with 45 additions and 1 deletions
|
@ -493,7 +493,8 @@ public class CodeUnitFormat {
|
||||||
InstructionScalarInfo info = new InstructionScalarInfo(representations, primaryRef);
|
InstructionScalarInfo info = new InstructionScalarInfo(representations, primaryRef);
|
||||||
if (info.hasSingleAddressWithNoScalars()) {
|
if (info.hasSingleAddressWithNoScalars()) {
|
||||||
int addressIndex = info.getAddressIndex();
|
int addressIndex = info.getAddressIndex();
|
||||||
return markupAddressAsScalar(inst, primaryRef, representations, addressIndex);
|
return markupAddressAsRegister(inst, primaryRef, representations, addressIndex) ||
|
||||||
|
markupAddressAsScalar(inst, primaryRef, representations, addressIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.hasNoScalars()) {
|
if (info.hasNoScalars()) {
|
||||||
|
@ -564,6 +565,21 @@ public class CodeUnitFormat {
|
||||||
return primaryRef == null;
|
return primaryRef == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean markupAddressAsRegister(Instruction instr, Reference primaryRef,
|
||||||
|
List<Object> representationList, int addressIndex) {
|
||||||
|
if (primaryRef != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// NOTE: although preferrable, access type/size is not considered
|
||||||
|
Address addr = (Address) representationList.get(addressIndex);
|
||||||
|
Register reg = instr.getProgram().getRegister(addr);
|
||||||
|
if (reg != null) {
|
||||||
|
representationList.set(addressIndex, reg.getName());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean markupAddressAsScalar(Instruction instr, Reference primaryRef,
|
private boolean markupAddressAsScalar(Instruction instr, Reference primaryRef,
|
||||||
List<Object> representationList, int addressIndex) {
|
List<Object> representationList, int addressIndex) {
|
||||||
Address addr = (Address) representationList.get(addressIndex);
|
Address addr = (Address) representationList.get(addressIndex);
|
||||||
|
|
|
@ -22,7 +22,9 @@ import ghidra.app.util.bin.format.elf.*;
|
||||||
import ghidra.program.model.address.Address;
|
import ghidra.program.model.address.Address;
|
||||||
import ghidra.program.model.address.AddressSpace;
|
import ghidra.program.model.address.AddressSpace;
|
||||||
import ghidra.program.model.lang.Language;
|
import ghidra.program.model.lang.Language;
|
||||||
|
import ghidra.program.model.lang.Register;
|
||||||
import ghidra.util.exception.CancelledException;
|
import ghidra.util.exception.CancelledException;
|
||||||
|
import ghidra.util.exception.NoValueException;
|
||||||
import ghidra.util.task.TaskMonitor;
|
import ghidra.util.task.TaskMonitor;
|
||||||
|
|
||||||
public class PIC30_ElfExtension extends ElfExtension {
|
public class PIC30_ElfExtension extends ElfExtension {
|
||||||
|
@ -219,6 +221,32 @@ public class PIC30_ElfExtension extends ElfExtension {
|
||||||
return language.getDefaultDataSpace().equals(start.getAddressSpace().getPhysicalSpace());
|
return language.getDefaultDataSpace().equals(start.getAddressSpace().getPhysicalSpace());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Address calculateSymbolAddress(ElfLoadHelper elfLoadHelper, ElfSymbol elfSymbol)
|
||||||
|
throws NoValueException {
|
||||||
|
|
||||||
|
if (elfSymbol.getValue() != 0 || !elfSymbol.isGlobal() ||
|
||||||
|
elfSymbol.getSectionHeaderIndex() != 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = elfSymbol.getNameAsString();
|
||||||
|
if (name == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name.startsWith("_")) {
|
||||||
|
name = name.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
Register reg = elfLoadHelper.getProgram().getRegister(name);
|
||||||
|
if (reg != null && !reg.getAddress().isRegisterAddress()) {
|
||||||
|
return reg.getAddress(); // only consider memory-based registers
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static class PIC30FilteredDataInputStream extends FilterInputStream {
|
private static class PIC30FilteredDataInputStream extends FilterInputStream {
|
||||||
|
|
||||||
// BYTES: <byte> <pad>
|
// BYTES: <byte> <pad>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue