Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-1575_emteere code review

emteered3a380992541
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/AbstractDwarfEHDecoder.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/AbstractDwarfEHDecoder.java
index 30e0cdb0a1..1d0298a2e5 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/AbstractDwarfEHDecoder.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/AbstractDwarfEHDecoder.java
@@ -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:
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/DwarfDecodeContext.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/DwarfDecodeContext.java
index e4177210af..6357323392 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/DwarfDecodeContext.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/exceptionhandlers/gcc/DwarfDecodeContext.java
@@ -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;
+ }
}