Ghidra is a software reverse engineering (SRE) framework
GP-2113: Some fixes to Objective-C support for dyld_shared_cache
Ryan Kurtzd1313cff0528
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_Method.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_Method.javaindex 052b4fdcf5..91a6980a36 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_Method.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_Method.java@@ -18,6 +18,7 @@ package ghidra.app.util.bin.format.objc2;import java.io.IOException;import ghidra.app.util.bin.BinaryReader;+import ghidra.app.util.bin.format.macho.dyld.LibObjcOptimization;import ghidra.app.util.bin.format.objectiveC.*;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;@@ -27,12 +28,14 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {private String types;private ObjectiveC2_Implementation imp;+ private LibObjcOptimization libObjcOptimization;private boolean isSmall;public ObjectiveC2_Method(ObjectiveC2_State state, BinaryReader reader,ObjectiveC_MethodType methodType, boolean isSmallList) throws IOException {super(state, reader, methodType);+ libObjcOptimization = state.libObjcOptimization;isSmall = isSmallList;if (isSmallList) {@@ -42,12 +45,11 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {namePtr = reader.readInt(_index + nameOffset);}else {- if (state.libObjcOptimization != null) {+ if (libObjcOptimization != null) {// We are in a DYLD Cache- if (state.libObjcOptimization.getRelativeSelectorBaseAddressOffset() > 0) {- namePtr = state.libObjcOptimization.getAddr() +- state.libObjcOptimization.getRelativeSelectorBaseAddressOffset() +- nameOffset;+ if (libObjcOptimization.getRelativeSelectorBaseAddressOffset() > 0) {+ namePtr = libObjcOptimization.getAddr() ++ libObjcOptimization.getRelativeSelectorBaseAddressOffset() + nameOffset;}else {namePtr = _index + nameOffset;@@ -93,20 +95,25 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {public DataType toDataType() throws DuplicateNameException, IOException {Structure struct = new StructureDataType("method" + (isSmall ? "_small" : "") + "_t", 0);if (isSmall) {- String comment = "offset from this address";-- PointerTypedef strPtrRefDt = new PointerTypedef(null, new PointerDataType(STRING), 4,- null, PointerType.RELATIVE);-- PointerTypedef strRefDt =- new PointerTypedef(null, STRING, 4, null, PointerType.RELATIVE);-- PointerTypedef voidRefDt =- new PointerTypedef(null, VOID, 4, null, PointerType.RELATIVE);-- struct.add(strPtrRefDt, "name", comment);- struct.add(strRefDt, "types", comment);- struct.add(voidRefDt, "imp", comment);+ String comment = "RelativePointer";+ PointerType REL = PointerType.RELATIVE;+ if (libObjcOptimization != null) {+ if (libObjcOptimization.getRelativeSelectorBaseAddressOffset() > 0) {+ struct.add(DWORD, "name",+ comment + " + " + Long.toHexString(libObjcOptimization.getAddr() ++ libObjcOptimization.getRelativeSelectorBaseAddressOffset()));+ }+ else {+ struct.add(new PointerTypedef(null, new PointerDataType(STRING), 4, null,+ PointerType.RELATIVE), "name", comment);+ }+ }+ else {+ struct.add(new PointerTypedef(null, new PointerDataType(STRING), 4, null, REL),+ "name", comment);+ }+ struct.add(new PointerTypedef(null, STRING, 4, null, REL), "types", comment);+ struct.add(new PointerTypedef(null, VOID, 4, null, REL), "imp", comment);}else {struct.add(new PointerDataType(STRING), _state.pointerSize, "name", null);