Ghidra is a software reverse engineering (SRE) framework
GP-1397: Fix for small objc methods, and code cleanup
Ryan Kurtzd94e27ec3000
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 d16c9ec7f9..5f487d9005 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@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,6 +15,8 @@*/package ghidra.app.util.bin.format.objc2;+import java.io.IOException;+import ghidra.app.util.bin.BinaryReader;import ghidra.app.util.bin.StructConverter;import ghidra.program.model.data.DataType;@@ -23,8 +24,6 @@ import ghidra.program.model.data.TypedefDataType;import ghidra.util.Conv;import ghidra.util.exception.DuplicateNameException;-import java.io.IOException;-public class ObjectiveC2_Implementation implements StructConverter {private boolean _is32bit;private long _index;@@ -32,24 +31,28 @@ public class ObjectiveC2_Implementation implements StructConverter {private long imp;- public ObjectiveC2_Implementation(ObjectiveC2_State state, BinaryReader reader) throws IOException {+ public ObjectiveC2_Implementation(ObjectiveC2_State state, BinaryReader reader, boolean isSmall)+ throws IOException {this._is32bit = state.is32bit;this._index = reader.getPointerIndex();+ this._isSmall = isSmall;- if (state.is32bit) {- imp = reader.readNextInt() & Conv.INT_MASK;+ if (isSmall) {+ imp = _index + reader.readNextInt();}else {- imp = reader.readNextLong();+ if (state.is32bit) {+ imp = reader.readNextInt() & Conv.INT_MASK;+ }+ else {+ imp = reader.readNextLong();+ }}}- 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 ObjectiveC2_Implementation(ObjectiveC2_State state, BinaryReader reader)+ throws IOException {+ this(state, reader, false);}public long getImplementation() {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 d7dabf2406..b074821c91 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@@ -1,6 +1,5 @@/* ###* IP: GHIDRA- * REVIEWED: YES** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.@@ -16,13 +15,13 @@*/package ghidra.app.util.bin.format.objc2;+import java.io.IOException;+import ghidra.app.util.bin.BinaryReader;import ghidra.app.util.bin.format.objectiveC.*;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;-import java.io.IOException;-public class ObjectiveC2_Method extends ObjectiveC_Method {private String name;private String types;@@ -30,19 +29,19 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {private boolean isSmall;- public ObjectiveC2_Method(ObjectiveC2_State state, BinaryReader reader, ObjectiveC_MethodType methodType, boolean isSmallList) throws IOException {+ public ObjectiveC2_Method(ObjectiveC2_State state, BinaryReader reader,+ ObjectiveC_MethodType methodType, boolean isSmallList) throws IOException {super(state, reader, methodType);isSmall = isSmallList;if (isSmallList) {int nameOffset = (int)ObjectiveC1_Utilities.readNextIndex(reader, true);- name = reader.readAsciiString(_index + nameOffset);+ int namePtr = reader.readInt(_index + nameOffset);+ name = reader.readAsciiString(namePtr);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);@@ -50,9 +49,9 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {long typesIndex = ObjectiveC1_Utilities.readNextIndex(reader, state.is32bit);types = reader.readAsciiString(typesIndex);-- imp = new ObjectiveC2_Implementation(state, reader);}++ imp = new ObjectiveC2_Implementation(state, reader, isSmallList);}@Override@@ -69,22 +68,21 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {}public DataType toDataType() throws DuplicateNameException, IOException {+ Structure struct = new StructureDataType("method_t", 0);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;+ DataType sdw = SignedDWordDataType.dataType;+ String comment = "offset from this address";+ struct.add(sdw, sdw.getLength(), "name", comment);+ struct.add(sdw, sdw.getLength(), "types", comment);+ struct.add(sdw, sdw.getLength(), "imp", comment);}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;}+ 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 6682f2d39e..32be0cdd4b 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@@ -46,8 +46,8 @@ public class ObjectiveC2_MethodList extends ObjectiveC_MethodList {}}- public long getEntsize() {- return entsizeAndFlags & ~0xffff0003;+ public long getEntsizeAndFlags() {+ return entsizeAndFlags;}public long getCount() {