GP-1397: Fix for small objc methods, and code cleanup

This commit is contained in:
Ryan Kurtz 2021-10-15 11:22:25 -04:00
parent 1c52ddf637
commit d94e27ec30
3 changed files with 39 additions and 38 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,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,10 +31,16 @@ 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 (isSmall) {
imp = _index + reader.readNextInt();
}
else {
if (state.is32bit) {
imp = reader.readNextInt() & Conv.INT_MASK;
}
@ -43,13 +48,11 @@ public class ObjectiveC2_Implementation implements StructConverter {
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() {

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,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;
}
}
}

View file

@ -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() {