Merge branch 'GP-1397_ryanmkurtz_PR-2732_arandomdev_small-objc' (Closes

#2719, Closes #2732)
This commit is contained in:
Ryan Kurtz 2021-10-25 12:05:53 -04:00
commit 9b7573d856
3 changed files with 67 additions and 27 deletions

View file

@ -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,18 +24,23 @@ 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;
private boolean _isSmall = false;
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 (isSmall) {
imp = _index + reader.readNextInt();
}
else {
if (state.is32bit) {
imp = reader.readNextInt() & Conv.INT_MASK;
}
@ -42,6 +48,12 @@ public class ObjectiveC2_Implementation implements StructConverter {
imp = reader.readNextLong();
}
}
}
public ObjectiveC2_Implementation(ObjectiveC2_State state, BinaryReader reader)
throws IOException {
this(state, reader, false);
}
public long getImplementation() {
return imp;
@ -52,7 +64,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);

View file

@ -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,28 +15,43 @@
*/
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;
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);
isSmall = isSmallList;
if (isSmallList) {
int nameOffset = (int)ObjectiveC1_Utilities.readNextIndex(reader, true);
int namePtr = reader.readInt(_index + nameOffset);
name = reader.readAsciiString(namePtr);
int typesOffset = (int)ObjectiveC1_Utilities.readNextIndex(reader, true);
types = reader.readAsciiString(_index + 4 + typesOffset);
}
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);
}
imp = new ObjectiveC2_Implementation(state, reader);
imp = new ObjectiveC2_Implementation(state, reader, isSmallList);
}
@Override
@ -55,9 +69,18 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {
public DataType toDataType() throws DuplicateNameException, IOException {
Structure struct = new StructureDataType("method_t", 0);
if (isSmall) {
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 {
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;
}

View file

@ -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;
public long getEntsizeAndFlags() {
return entsizeAndFlags;
}
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) {