GP-1575_emteere code review

This commit is contained in:
emteere
2021-12-03 23:06:45 +00:00
parent 89f3b78128
commit d3a3809925
2 changed files with 19 additions and 5 deletions

View File

@@ -17,7 +17,6 @@ package ghidra.app.plugin.exceptionhandlers.gcc;
import ghidra.app.plugin.exceptionhandlers.gcc.datatype.SignedLeb128DataType;
import ghidra.app.plugin.exceptionhandlers.gcc.datatype.UnsignedLeb128DataType;
import ghidra.app.util.opinion.ElfLoader;
import ghidra.program.model.address.*;
import ghidra.program.model.data.*;
import ghidra.program.model.listing.Program;
@@ -334,10 +333,13 @@ abstract class AbstractDwarfEHDecoder implements DwarfEHDecoder {
switch (appMode) {
case DW_EH_PE_absptr:
// if the program has been rebased, need to add in the image base difference.
Long oib = ElfLoader.getElfOriginalImageBase(prog);
long programBaseAddressFixup = prog.getImageBase().getOffset() - oib.longValue();
val = val + programBaseAddressFixup;
// if the program has been re-based, need to add in the image base difference.
// but only if there are no relocations at this location
if (prog.getRelocationTable().getRelocation(addr) == null) {
long programBaseAddressFixup = context.getOriginalImageBaseOffset();
val = val + programBaseAddressFixup;
}
break;
case DW_EH_PE_aligned:

View File

@@ -15,6 +15,7 @@
*/
package ghidra.app.plugin.exceptionhandlers.gcc;
import ghidra.app.util.opinion.ElfLoader;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Function;
import ghidra.program.model.listing.Program;
@@ -34,6 +35,7 @@ public class DwarfDecodeContext {
private Object decodedValue;
private int encodedLength;
private MemBuffer buffer;
private long originalImageBaseOffset; // offset from image base used in original dwarf, and the actual load image base
/**
* Constructs a Dwarf decode context.
@@ -96,6 +98,8 @@ public class DwarfDecodeContext {
this.ehBlock = ehBlock;
this.functionEntryPoint = entryPoint;
Long oib = ElfLoader.getElfOriginalImageBase(program);
this.originalImageBaseOffset = program.getImageBase().getOffset() - oib.longValue();
}
/**
@@ -180,4 +184,12 @@ public class DwarfDecodeContext {
public Address getFunctionEntryPoint() {
return functionEntryPoint;
}
/**
* Gets the offset from the programs image base and the dwarf original image base
* @return offset that if added to the current image base would be the original dwarf image base
*/
public long getOriginalImageBaseOffset() {
return originalImageBaseOffset;
}
}