mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-02 08:52:26 +08:00
GP-0: Formatting/Certify. Also removing untested code.
This commit is contained in:
+9
-37
@@ -16,17 +16,10 @@
|
|||||||
package ghidra.app.util.bin.format.coff.relocation;
|
package ghidra.app.util.bin.format.coff.relocation;
|
||||||
|
|
||||||
import ghidra.app.util.bin.format.RelocationException;
|
import ghidra.app.util.bin.format.RelocationException;
|
||||||
import ghidra.app.util.bin.format.coff.CoffFileHeader;
|
import ghidra.app.util.bin.format.coff.*;
|
||||||
import ghidra.app.util.bin.format.coff.CoffMachineType;
|
|
||||||
import ghidra.app.util.bin.format.coff.CoffRelocation;
|
|
||||||
import ghidra.program.model.address.Address;
|
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.mem.MemoryAccessException;
|
||||||
import ghidra.program.model.reloc.Relocation;
|
|
||||||
import ghidra.program.model.reloc.RelocationResult;
|
import ghidra.program.model.reloc.RelocationResult;
|
||||||
import org.apache.logging.log4j.Level;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
|
|
||||||
public class PowerPC_CoffRelocationHandler implements CoffRelocationHandler {
|
public class PowerPC_CoffRelocationHandler implements CoffRelocationHandler {
|
||||||
|
|
||||||
@@ -40,31 +33,8 @@ public class PowerPC_CoffRelocationHandler implements CoffRelocationHandler {
|
|||||||
CoffRelocationContext relocationContext)
|
CoffRelocationContext relocationContext)
|
||||||
throws MemoryAccessException, RelocationException {
|
throws MemoryAccessException, RelocationException {
|
||||||
|
|
||||||
Program program = relocationContext.getProgram();
|
|
||||||
Memory mem = program.getMemory();
|
|
||||||
|
|
||||||
int addend = mem.getInt(address);
|
|
||||||
|
|
||||||
int byteLength = 4; // most relocations affect 4-bytes (change if different)
|
|
||||||
|
|
||||||
switch (relocation.getType()) {
|
switch (relocation.getType()) {
|
||||||
|
|
||||||
// We are implementing these types:
|
|
||||||
case IMAGE_REL_PPC_ADDR32: {
|
|
||||||
int value = (int) relocationContext.getSymbolAddress(relocation)
|
|
||||||
.add(addend)
|
|
||||||
.getOffset();
|
|
||||||
program.getMemory().setInt(address, value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case IMAGE_REL_PPC_ADDR32NB: {
|
|
||||||
int value = (int) relocationContext.getSymbolAddress(relocation)
|
|
||||||
.add(addend)
|
|
||||||
.subtract(program.getImageBase());
|
|
||||||
mem.setInt(address, value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We are choosing to ignore these types:
|
// We are choosing to ignore these types:
|
||||||
case IMAGE_REL_PPC_ABSOLUTE:
|
case IMAGE_REL_PPC_ABSOLUTE:
|
||||||
case IMAGE_REL_PPC_SECTION:
|
case IMAGE_REL_PPC_SECTION:
|
||||||
@@ -74,6 +44,8 @@ public class PowerPC_CoffRelocationHandler implements CoffRelocationHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We haven't implemented these types yet:
|
// We haven't implemented these types yet:
|
||||||
|
case IMAGE_REL_PPC_ADDR32:
|
||||||
|
case IMAGE_REL_PPC_ADDR32NB:
|
||||||
case IMAGE_REL_PPC_ADDR64:
|
case IMAGE_REL_PPC_ADDR64:
|
||||||
case IMAGE_REL_PPC_ADDR24:
|
case IMAGE_REL_PPC_ADDR24:
|
||||||
case IMAGE_REL_PPC_ADDR16:
|
case IMAGE_REL_PPC_ADDR16:
|
||||||
@@ -90,7 +62,6 @@ public class PowerPC_CoffRelocationHandler implements CoffRelocationHandler {
|
|||||||
return RelocationResult.UNSUPPORTED;
|
return RelocationResult.UNSUPPORTED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new RelocationResult(Relocation.Status.APPLIED, byteLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +81,8 @@ public class PowerPC_CoffRelocationHandler implements CoffRelocationHandler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The low 24 bits of the VA of the target.
|
* The low 24 bits of the VA of the target.
|
||||||
* This is valid only when the target symbol is absolute and can be sign-extended to its original value.
|
* This is valid only when the target symbol is absolute and can be sign-extended to its
|
||||||
|
* original value.
|
||||||
*/
|
*/
|
||||||
public final static short IMAGE_REL_PPC_ADDR24 = 0x0003;
|
public final static short IMAGE_REL_PPC_ADDR24 = 0x0003;
|
||||||
|
|
||||||
@@ -159,10 +131,10 @@ public class PowerPC_CoffRelocationHandler implements CoffRelocationHandler {
|
|||||||
public final static short IMAGE_REL_PPC_SECREL16 = 0x000F;
|
public final static short IMAGE_REL_PPC_SECREL16 = 0x000F;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The high 16 bits of the target's 32-bit VA.
|
* The high 16 bits of the target's 32-bit VA. This is used for the first instruction in a
|
||||||
* This is used for the first instruction in a two-instruction sequence that loads a full address.
|
* two-instruction sequence that loads a full address. This relocation must be immediately
|
||||||
* This relocation must be immediately followed by a PAIR relocation whose SymbolTableIndex contains a signed
|
* followed by a PAIR relocation whose SymbolTableIndex contains a signed 16-bit displacement
|
||||||
* 16-bit displacement that is added to the upper 16 bits that was taken from the location that is being relocated.
|
* that is added to the upper 16 bits that was taken from the location that is being relocated.
|
||||||
*/
|
*/
|
||||||
public final static short IMAGE_REL_PPC_REFHI = 0x0010;
|
public final static short IMAGE_REL_PPC_REFHI = 0x0010;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user