Ghidra is a software reverse engineering (SRE) framework
GP-3194: The MachoLoader now correctly handles DYLD_CHAINED_PTR_64_OFFSET fixups
Ryan Kurtzfdafa401cd7a
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldChainedPtr.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldChainedPtr.javaindex 0b757a2251..595dd44d47 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldChainedPtr.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/macho/dyld/DyldChainedPtr.java@@ -22,7 +22,7 @@ import ghidra.program.model.reloc.Relocation.Status;import ghidra.program.model.reloc.RelocationResult;/**- * @see <a href="https://opensource.apple.com/source/dyld/dyld-852.2/include/mach-o/fixup-chains.h.auto.html">mach-o/fixup-chains.h</a>+ * @see <a href="https://github.com/apple-oss-distributions/dyld/blob/main/include/mach-o/fixup-chains.h">mach-o/fixup-chains.h</a>*/public class DyldChainedPtr {@@ -168,6 +168,18 @@ public class DyldChainedPtr {}}+ public static boolean isRelative(DyldChainType ptrFormat) {+ switch (ptrFormat) {+ case DYLD_CHAINED_PTR_64_OFFSET:+ case DYLD_CHAINED_PTR_ARM64E_KERNEL:+ case DYLD_CHAINED_PTR_ARM64E_USERLAND:+ case DYLD_CHAINED_PTR_ARM64E_USERLAND24:+ return true;+ default:+ return false;+ }+ }+public static boolean isBound(DyldChainType ptrFormat, long chainValue) {switch (ptrFormat) {diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.javaindex 24dac9bc6e..b2c8e33c72 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/opinion/MachoProgramBuilder.java@@ -480,6 +480,8 @@ public class MachoProgramBuilder {}protected boolean processExports(MachHeader header) throws Exception {+ monitor.setMessage("Processing exports...");+List<ExportEntry> exports = new ArrayList<>();// Old way - export tree in DyldInfoCommand@@ -1794,7 +1796,9 @@ public class MachoProgramBuilder {}else {newChainValue = DyldChainedPtr.getTarget(pointerFormat, chainValue);- newChainValue += imageBaseOffset;+ if (DyldChainedPtr.isRelative(pointerFormat)) {+ newChainValue += imageBaseOffset;+ }}if (!start || !program.getRelocationTable().hasRelocation(chainLoc)) {