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 * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; package ghidra.app.util.bin.format.objc2;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.StructConverter; import ghidra.app.util.bin.StructConverter;
import ghidra.program.model.data.DataType; import ghidra.program.model.data.DataType;
@ -23,8 +24,6 @@ import ghidra.program.model.data.TypedefDataType;
import ghidra.util.Conv; import ghidra.util.Conv;
import ghidra.util.exception.DuplicateNameException; import ghidra.util.exception.DuplicateNameException;
import java.io.IOException;
public class ObjectiveC2_Implementation implements StructConverter { public class ObjectiveC2_Implementation implements StructConverter {
private boolean _is32bit; private boolean _is32bit;
private long _index; private long _index;
@ -32,24 +31,28 @@ public class ObjectiveC2_Implementation implements StructConverter {
private long imp; private long imp;
public ObjectiveC2_Implementation(ObjectiveC2_State state, BinaryReader reader) throws IOException { public ObjectiveC2_Implementation(ObjectiveC2_State state, BinaryReader reader, boolean isSmall)
this._is32bit = state.is32bit; throws IOException {
this._index = reader.getPointerIndex();
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._is32bit = state.is32bit;
this._index = reader.getPointerIndex(); this._index = reader.getPointerIndex();
this._isSmall = isSmall; this._isSmall = isSmall;
imp = _index + reader.readNextInt(); if (isSmall) {
imp = _index + reader.readNextInt();
}
else {
if (state.is32bit) {
imp = reader.readNextInt() & Conv.INT_MASK;
}
else {
imp = reader.readNextLong();
}
}
}
public ObjectiveC2_Implementation(ObjectiveC2_State state, BinaryReader reader)
throws IOException {
this(state, reader, false);
} }
public long getImplementation() { public long getImplementation() {

View file

@ -1,6 +1,5 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; package ghidra.app.util.bin.format.objc2;
import java.io.IOException;
import ghidra.app.util.bin.BinaryReader; import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.format.objectiveC.*; import ghidra.app.util.bin.format.objectiveC.*;
import ghidra.program.model.data.*; import ghidra.program.model.data.*;
import ghidra.util.exception.DuplicateNameException; import ghidra.util.exception.DuplicateNameException;
import java.io.IOException;
public class ObjectiveC2_Method extends ObjectiveC_Method { public class ObjectiveC2_Method extends ObjectiveC_Method {
private String name; private String name;
private String types; private String types;
@ -30,19 +29,19 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {
private boolean isSmall; 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); super(state, reader, methodType);
isSmall = isSmallList; isSmall = isSmallList;
if (isSmallList) { if (isSmallList) {
int nameOffset = (int)ObjectiveC1_Utilities.readNextIndex(reader, true); 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); int typesOffset = (int)ObjectiveC1_Utilities.readNextIndex(reader, true);
types = reader.readAsciiString(_index + 4 + typesOffset); types = reader.readAsciiString(_index + 4 + typesOffset);
imp = new ObjectiveC2_Implementation(state, reader, true);
} }
else { else {
long nameIndex = ObjectiveC1_Utilities.readNextIndex(reader, state.is32bit); 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); long typesIndex = ObjectiveC1_Utilities.readNextIndex(reader, state.is32bit);
types = reader.readAsciiString(typesIndex); types = reader.readAsciiString(typesIndex);
imp = new ObjectiveC2_Implementation(state, reader);
} }
imp = new ObjectiveC2_Implementation(state, reader, isSmallList);
} }
@Override @Override
@ -69,22 +68,21 @@ public class ObjectiveC2_Method extends ObjectiveC_Method {
} }
public DataType toDataType() throws DuplicateNameException, IOException { public DataType toDataType() throws DuplicateNameException, IOException {
Structure struct = new StructureDataType("method_t", 0);
if (isSmall) { if (isSmall) {
Structure struct = new StructureDataType("method_t_small", 0); DataType sdw = SignedDWordDataType.dataType;
struct.add(new SignedDWordDataType(), 4, "name", null); String comment = "offset from this address";
struct.add(new SignedDWordDataType(), 4, "types", null); struct.add(sdw, sdw.getLength(), "name", comment);
struct.add(new SignedDWordDataType(), 4, "imp", null); struct.add(sdw, sdw.getLength(), "types", comment);
struct.setCategoryPath(ObjectiveC2_Constants.CATEGORY_PATH); struct.add(sdw, sdw.getLength(), "imp", comment);
return struct;
} }
else { else {
Structure struct = new StructureDataType("method_t", 0);
struct.add(new PointerDataType(STRING), _state.pointerSize, "name", null); struct.add(new PointerDataType(STRING), _state.pointerSize, "name", null);
struct.add(new PointerDataType(STRING), _state.pointerSize, "types", null); struct.add(new PointerDataType(STRING), _state.pointerSize, "types", null);
struct.add(new PointerDataType(VOID), _state.pointerSize, "imp", 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;
} }
} }

View file

@ -46,8 +46,8 @@ public class ObjectiveC2_MethodList extends ObjectiveC_MethodList {
} }
} }
public long getEntsize() { public long getEntsizeAndFlags() {
return entsizeAndFlags & ~0xffff0003; return entsizeAndFlags;
} }
public long getCount() { public long getCount() {