Ghidra is a software reverse engineering (SRE) framework
GP-496 Fixes that made it to patch but not to master
jmlagor5200de2d4128
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/blobs/CliAbstractSig.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/blobs/CliAbstractSig.javaindex 7264230027..e82c38b122 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/blobs/CliAbstractSig.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/blobs/CliAbstractSig.java@@ -107,12 +107,12 @@ public abstract class CliAbstractSig extends CliBlob implements CliRepresentableELEMENT_TYPE_VALUETYPE(0x11),ELEMENT_TYPE_VAR(0x13), // "Class type variable VAR"(0x16),-+ELEMENT_TYPE_MVAR(0x1e), // Method type variable MVAR-+ELEMENT_TYPE_INTERNAL(0x21), // Internal (generated internally, "will not be persisted in any way")ELEMENT_TYPE_MAX(0x22),-+*/switch (typeCode) {@@ -122,7 +122,7 @@ public abstract class CliAbstractSig extends CliBlob implements CliRepresentablecase ELEMENT_TYPE_BOOLEAN:return BooleanDataType.dataType;case ELEMENT_TYPE_CHAR:- return StringUTF8DataType.dataType;+ return CharDataType.dataType;case ELEMENT_TYPE_I1:return SignedByteDataType.dataType;case ELEMENT_TYPE_U1:@@ -159,14 +159,18 @@ public abstract class CliAbstractSig extends CliBlob implements CliRepresentablecase ELEMENT_TYPE_FNPTR:return PointerDataType.dataType;- case ELEMENT_TYPE_SZARRAY:case ELEMENT_TYPE_STRING:return new PointerDataType(new CharDataType());case ELEMENT_TYPE_ARRAY:+ case ELEMENT_TYPE_SZARRAY:+ case ELEMENT_TYPE_VAR:+ case ELEMENT_TYPE_MVAR:return new PointerDataType(new ByteDataType());case ELEMENT_TYPE_OBJECT: // System.Objectcase ELEMENT_TYPE_CLASS:+ case ELEMENT_TYPE_VALUETYPE:+ case ELEMENT_TYPE_GENERICINST:return PointerDataType.dataType;case ELEMENT_TYPE_SENTINEL:@@ -293,12 +297,53 @@ public abstract class CliAbstractSig extends CliBlob implements CliRepresentable}public class CliTypeArray extends CliSigType {- private CliElementType arrayType;+ private CliSigType arrayType;private CliArrayShape arrayShape;- public CliTypeArray(BinaryReader reader, CliElementType typeCode) throws IOException {+ public CliTypeArray(BinaryReader reader, CliElementType typeCode)+ throws IOException, InvalidInputException {super(typeCode);- arrayType = CliElementType.fromInt(reader.readNextByte());+ CliElementType valueCode = CliElementType.fromInt(reader.readNextByte());++ switch (valueCode) {+ case ELEMENT_TYPE_VALUETYPE:+ arrayType = new CliTypeValueType(reader, typeCode);+ break;++ case ELEMENT_TYPE_CLASS:+ arrayType = new CliTypeClass(reader, typeCode);+ break;++ case ELEMENT_TYPE_FNPTR:+ arrayType = new CliTypeFnPtr(reader, typeCode);+ break;++ case ELEMENT_TYPE_GENERICINST:+ arrayType = new CliTypeGenericInst(reader, typeCode);+ break;++ case ELEMENT_TYPE_MVAR:+ case ELEMENT_TYPE_VAR:+ arrayType = new CliTypeVarOrMvar(reader, typeCode);+ break;++ case ELEMENT_TYPE_PTR:+ arrayType = new CliTypePtr(reader, typeCode);+ break;++ case ELEMENT_TYPE_SZARRAY: // Single dimensional, zero-based array, e.g. a vector+ arrayType = new CliTypeSzArray(reader, typeCode);+ break;++ case ELEMENT_TYPE_ARRAY:+ arrayType = new CliTypeArray(reader, typeCode);+ break;++ default:+ arrayType = new CliTypePrimitive(valueCode);+ break;+ }+arrayShape = new CliArrayShape(reader);}@@ -313,7 +358,12 @@ public abstract class CliAbstractSig extends CliBlob implements CliRepresentableStructureDataType struct = new StructureDataType(new CategoryPath(PATH), "Array", 0);struct.add(CliTypeCodeDataType.dataType, "Array",String.format("Fixed value: 0x%x", CliElementType.ELEMENT_TYPE_ARRAY.id()));- struct.add(CliTypeCodeDataType.dataType, "Type", "Type of array");+ if (arrayType instanceof CliTypePrimitive) {+ struct.add(CliTypeCodeDataType.dataType, "Type", "Type of array");+ }+ else {+ struct.add(arrayType.getDefinitionDataType(), "ValueType", "Class token");+ }struct.add(arrayShape.getDefinitionDataType(), "ArrayShape", null);return struct;}@@ -1000,4 +1050,4 @@ public abstract class CliAbstractSig extends CliBlob implements CliRepresentablereturn "ArrayShapeNotYetRepresented"; // TODO: Give back a pretty representation of ArrayShape}}-}\ No newline at end of file+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/blobs/CliSigMethodRef.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/blobs/CliSigMethodRef.javaindex 366e6674fb..7e423ff732 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/blobs/CliSigMethodRef.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/blobs/CliSigMethodRef.java@@ -28,10 +28,14 @@ public class CliSigMethodRef extends CliAbstractSig {private CliParam params[];private int sizeOfCount;private byte flags;+ private int genericParamCount;+ private int sizeOfGenericCount;+private int sentinelIndex; // SENTINEL is before the parameter index in this fieldprivate final int METHODREFSIG_FLAGS_DEFAULT = 0x00;private final int METHODREFSIG_FLAGS_VARARG = 0x05;+ private final int METHODREFSIG_FLAGS_GENERIC = 0x10;private final int METHODREFSIG_FLAGS_HASTHIS = 0x20;private final int METHODREFSIG_FLAGS_EXPLICITTHIS = 0x40;@@ -43,6 +47,12 @@ public class CliSigMethodRef extends CliAbstractSig {BinaryReader reader = getContentsReader();flags = reader.readNextByte();+ if ((flags & METHODREFSIG_FLAGS_GENERIC) == METHODREFSIG_FLAGS_GENERIC) {+ long origIndex = reader.getPointerIndex();+ genericParamCount = decodeCompressedUnsignedInt(reader);+ sizeOfGenericCount = (int) (reader.getPointerIndex() - origIndex);+ }+long origIndex = reader.getPointerIndex();int paramCount = decodeCompressedUnsignedInt(reader);this.sizeOfCount = (int) (reader.getPointerIndex() - origIndex);@@ -80,7 +90,11 @@ public class CliSigMethodRef extends CliAbstractSig {@Overridepublic DataType getContentsDataType() {StructureDataType struct = new StructureDataType(new CategoryPath(PATH), getName(), 0);- struct.add(BYTE, "flags", "ORed VARARG and HASTHIS/EXPLICITTHIS");+ struct.add(BYTE, "FirstByte", "ORed VARARG and HASTHIS/EXPLICITTHIS");+ if (genericParamCount > 0) {+ struct.add(getDataTypeForBytes(sizeOfGenericCount), "GenParamCount",+ "Number of generic paramameters for the method");+ }struct.add(getDataTypeForBytes(sizeOfCount), "ParamCount","Number of param types to follow RetType");struct.add(retType.getDefinitionDataType(), "RetType", null);diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/streams/CliStreamBlob.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/streams/CliStreamBlob.javaindex 1aa101521d..7432ac7ed7 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/streams/CliStreamBlob.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/streams/CliStreamBlob.java@@ -40,7 +40,7 @@ public class CliStreamBlob extends CliAbstractStream {/*** Gets the name of this stream.- *+ ** @return The name of this stream.*/public static String getName() {@@ -49,9 +49,9 @@ public class CliStreamBlob extends CliAbstractStream {/*** Creates a new Blob stream.- *+ ** @param header The stream header associated with this stream.- * @param offset The reader offset where this stream starts.+ * @param offset The reader offset where this stream starts.* @param rva The relative virtual address where this stream starts.* @param reader A reader that is used to read the stream.* @throws IOException if there is a problem reading the stream.@@ -84,7 +84,7 @@ public class CliStreamBlob extends CliAbstractStream {/*** Gets the blob at the given index.- *+ ** @param index The index of the blob to get.* @return The blob at the given index. Could be null if the index was invalid or* there was a problem reading the blob.@@ -95,7 +95,7 @@ public class CliStreamBlob extends CliAbstractStream {/*** Updates the blob at the given address with the new blob.- *+ ** @param updatedBlob The updated blob.* @param addr The address of the blob to update.* @param program The program that will get the update.@@ -113,18 +113,21 @@ public class CliStreamBlob extends CliAbstractStream {// Make sure there is an old blob at the given addressint structureOffset = (int) addr.subtract(containingData.getAddress());- DataTypeComponent oldBlobDataComponent = containingStructure.getComponentAt(structureOffset);+ DataTypeComponent oldBlobDataComponent =+ containingStructure.getComponentAt(structureOffset);if (oldBlobDataComponent == null) {Msg.error(this, "Existing blob at address " + addr + " was not found.");return false;}-+// Make sure the old blob has the same size as the new blobDataType oldBlobDataType = oldBlobDataComponent.getDataType();DataType newBlobDataType = updatedBlob.toDataType();if (oldBlobDataType.getLength() != newBlobDataType.getLength()) {- Msg.error(this, "Cannot replace existing blob at address " + addr + " with " +- updatedBlob.getName() + " because they have different sizes.");+ Msg.error(this,+ "Cannot replace existing blob at address " + addr + " with " ++ updatedBlob.getName() + " because they have different sizes (Old: " ++ oldBlobDataType.getLength() + ", New: " + newBlobDataType.getLength() + ").");return false;}@@ -148,4 +151,3 @@ public class CliStreamBlob extends CliAbstractStream {return struct;}}-diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/tables/CliTableMethodDef.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/tables/CliTableMethodDef.javaindex bd911db354..4ea7aaf787 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/tables/CliTableMethodDef.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/pe/cli/tables/CliTableMethodDef.java@@ -244,7 +244,7 @@ public class CliTableMethodDef extends CliAbstractTable {}catch (InvalidInputException e) {Msg.warn(this, "Error processing parameter \"" + paramName +- "\" in function \"" + funcName + "\"");+ "\" in function \"" + funcName + "\": " + e.getMessage());}stackOffset += dataType.getLength();