Ghidra is a software reverse engineering (SRE) framework
added support for small objc methods
hao wang1c52ddf63777
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_Implementation.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_Implementation.javaindex ed36ee9928..d16c9ec7f9 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_Implementation.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_Implementation.java@@ -28,6 +28,7 @@ import java.io.IOException;public class ObjectiveC2_Implementation implements StructConverter {private boolean _is32bit;private long _index;+ private boolean _isSmall = false;private long imp;@@ -43,6 +44,14 @@ public class ObjectiveC2_Implementation implements StructConverter {}}+ public ObjectiveC2_Implementation(ObjectiveC2_State state, BinaryReader reader, boolean isSmall) throws IOException {+ this._is32bit = state.is32bit;+ this._index = reader.getPointerIndex();+ this._isSmall = isSmall;++ imp = _index + reader.readNextInt();+ }+public long getImplementation() {return imp;}@@ -52,7 +61,10 @@ public class ObjectiveC2_Implementation implements StructConverter {}public DataType toDataType() throws DuplicateNameException, IOException {- if (_is32bit) {+ if (_isSmall) {+ return new TypedefDataType("ImplementationOffset", DWORD);+ }+ else if (_is32bit) {return new TypedefDataType("Implementation", DWORD);}return new TypedefDataType("Implementation", QWORD);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 d0fef75c0e..d7dabf2406 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@@ -28,16 +28,31 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {private String types;private ObjectiveC2_Implementation imp;- public ObjectiveC2_Method(ObjectiveC2_State state, BinaryReader reader, ObjectiveC_MethodType methodType) throws IOException {+ private boolean isSmall;++ public ObjectiveC2_Method(ObjectiveC2_State state, BinaryReader reader, ObjectiveC_MethodType methodType, boolean isSmallList) throws IOException {super(state, reader, methodType);- long nameIndex = ObjectiveC1_Utilities.readNextIndex(reader, state.is32bit);- name = reader.readAsciiString(nameIndex);+ isSmall = isSmallList;++ if (isSmallList) {+ int nameOffset = (int)ObjectiveC1_Utilities.readNextIndex(reader, true);+ name = reader.readAsciiString(_index + nameOffset);++ int typesOffset = (int)ObjectiveC1_Utilities.readNextIndex(reader, true);+ types = reader.readAsciiString(_index + 4 + typesOffset);++ imp = new ObjectiveC2_Implementation(state, reader, true);+ }+ else {+ long nameIndex = ObjectiveC1_Utilities.readNextIndex(reader, state.is32bit);+ name = reader.readAsciiString(nameIndex);- long typesIndex = ObjectiveC1_Utilities.readNextIndex(reader, state.is32bit);- types = reader.readAsciiString(typesIndex);+ long typesIndex = ObjectiveC1_Utilities.readNextIndex(reader, state.is32bit);+ types = reader.readAsciiString(typesIndex);- imp = new ObjectiveC2_Implementation(state, reader);+ imp = new ObjectiveC2_Implementation(state, reader);+ }}@Override@@ -54,12 +69,22 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {}public DataType toDataType() throws DuplicateNameException, IOException {- Structure struct = new StructureDataType("method_t", 0);- struct.add(new PointerDataType(STRING), _state.pointerSize, "name", null);- struct.add(new PointerDataType(STRING), _state.pointerSize, "types", null);- struct.add(new PointerDataType(VOID), _state.pointerSize, "imp", null);- struct.setCategoryPath(ObjectiveC2_Constants.CATEGORY_PATH);- return struct;+ if (isSmall) {+ Structure struct = new StructureDataType("method_t_small", 0);+ struct.add(new SignedDWordDataType(), 4, "name", null);+ struct.add(new SignedDWordDataType(), 4, "types", null);+ struct.add(new SignedDWordDataType(), 4, "imp", null);+ struct.setCategoryPath(ObjectiveC2_Constants.CATEGORY_PATH);+ return struct;+ }+ else {+ Structure struct = new StructureDataType("method_t", 0);+ struct.add(new PointerDataType(STRING), _state.pointerSize, "name", null);+ struct.add(new PointerDataType(STRING), _state.pointerSize, "types", null);+ struct.add(new PointerDataType(VOID), _state.pointerSize, "imp", null);+ struct.setCategoryPath(ObjectiveC2_Constants.CATEGORY_PATH);+ return struct;+ }}}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_MethodList.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_MethodList.javaindex 9edfb5daee..6682f2d39e 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_MethodList.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/objc2/ObjectiveC2_MethodList.java@@ -26,7 +26,7 @@ import ghidra.util.exception.DuplicateNameException;public class ObjectiveC2_MethodList extends ObjectiveC_MethodList {public final static String NAME = "method_list_t";- private int entsize;+ private int entsizeAndFlags;private int count;public ObjectiveC2_MethodList(ObjectiveC2_State state, BinaryReader reader, ObjectiveC_MethodType methodType) throws IOException {@@ -36,16 +36,18 @@ public class ObjectiveC2_MethodList extends ObjectiveC_MethodList {return;}- entsize = reader.readNextInt();+ entsizeAndFlags = reader.readNextInt();count = reader.readNextInt();+ boolean isSmallList = (entsizeAndFlags & 0x80000000) != 0;+for (int i = 0 ; i < count ; ++i) {- methods.add( new ObjectiveC2_Method(state, reader, methodType) );+ methods.add( new ObjectiveC2_Method(state, reader, methodType, isSmallList) );}}public long getEntsize() {- return entsize;+ return entsizeAndFlags & ~0xffff0003;}public long getCount() {@@ -54,7 +56,7 @@ public class ObjectiveC2_MethodList extends ObjectiveC_MethodList {public static DataType toGenericDataType() throws DuplicateNameException {Structure struct = new StructureDataType(NAME, 0);- struct.add(DWORD, "entsize", null);+ struct.add(DWORD, "entsizeAndFlags", null);struct.add(DWORD, "count", null);struct.setCategoryPath(ObjectiveC2_Constants.CATEGORY_PATH);return struct;@@ -63,7 +65,7 @@ public class ObjectiveC2_MethodList extends ObjectiveC_MethodList {public DataType toDataType() throws DuplicateNameException, IOException {Structure struct = new StructureDataType(NAME+'_'+count+'_', 0);- struct.add(DWORD, "entsize", null);+ struct.add(DWORD, "entsizeAndFlags", null);struct.add(DWORD, "count", null);for (int i = 0 ; i < methods.size() ; ++i) {