protected NuGenBaseSignatureItem ReadSignatureItem(ref IntPtr signatureBlob) { NuGenBaseSignatureItem result = null; uint data; uint dataLength = NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data); CorElementType elementType = (CorElementType)data; switch (elementType) { case CorElementType.ELEMENT_TYPE_CMOD_OPT: case CorElementType.ELEMENT_TYPE_CMOD_REQD: NuGenCustomModifier customModifier = ReadCustomModifier(ref signatureBlob); result = customModifier; customModifier.NextItem = ReadSignatureItem(ref signatureBlob); break; case CorElementType.ELEMENT_TYPE_END: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); result = new NuGenEndSignatureItem(); break; case CorElementType.ELEMENT_TYPE_BYREF: NuGenHelperFunctions.StepIntPtr(ref signatureBlob); result = ReadSignatureItem(ref signatureBlob); NuGenTypeSignatureItem typeItem = null; if (result is NuGenArraySignatureItem) { typeItem = ((NuGenArraySignatureItem)result).Type; typeItem.ByRef = true; } else if (result is NuGenVarSignatureItem) { NuGenVarSignatureItem varItem = ((NuGenVarSignatureItem)result); varItem.ByRef = true; } else { while (result is NuGenCustomModifier) { result = ((NuGenCustomModifier)result).NextItem; } typeItem = (NuGenTypeSignatureItem)result; typeItem.ByRef = true; } break; case CorElementType.ELEMENT_TYPE_TYPEDBYREF: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); NuGenElementSignatureItem elementItem = new NuGenElementSignatureItem(); elementItem.ElementType = elementType; result = elementItem; break; case CorElementType.ELEMENT_TYPE_PINNED: NuGenHelperFunctions.StepIntPtr(ref signatureBlob); result = ReadSignatureItem(ref signatureBlob); ((NuGenTypeSignatureItem)result).Pinned = true; break; case CorElementType.ELEMENT_TYPE_ARRAY: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); uint value; NuGenArraySignatureItem arrayItem = new NuGenArraySignatureItem(); arrayItem.Type = (NuGenTypeSignatureItem)ReadSignatureItem(ref signatureBlob); NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out value)); arrayItem.Rank = value; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out value)); if (value > 0) { arrayItem.Sizes = new List<uint>(Convert.ToInt32(value)); for (int index = 0; index < value; index++) { uint size; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out size)); arrayItem.Sizes.Add(size); } } NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out value)); if (value > 0) { arrayItem.LoBounds = new List<uint>(Convert.ToInt32(value)); for (int index = 0; index < value; index++) { uint loBound; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out loBound)); arrayItem.LoBounds.Add(loBound); } } result = arrayItem; break; case CorElementType.ELEMENT_TYPE_GENERICINST: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); NuGenTypeSignatureItem genericType = (NuGenTypeSignatureItem)ReadType(ref signatureBlob); result = genericType; uint genericParametersCount = 0; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(SignatureBlob, out genericParametersCount)); if (genericParametersCount > 0) { genericType.GenericParameters = new List<NuGenBaseSignatureItem>(); for (uint genericParametersIndex = 0; genericParametersIndex < genericParametersCount; genericParametersIndex++) { genericType.GenericParameters.Add(ReadSignatureItem(ref signatureBlob)); } } break; case CorElementType.ELEMENT_TYPE_FNPTR: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); NuGenMethodRefSignatureReader signatureReader = new NuGenMethodRefSignatureReader(AllTokens, signatureBlob, SignatureLength); signatureReader.ReadSignature(); signatureBlob = signatureReader.SignatureBlob; result = new NuGenFunctionPointerSignatureItem(signatureReader); break; case CorElementType.ELEMENT_TYPE_MVAR: case CorElementType.ELEMENT_TYPE_VAR: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); byte number = Marshal.ReadByte(signatureBlob); NuGenHelperFunctions.StepIntPtr(ref signatureBlob, 1); NuGenVarSignatureItem varSignatureItem = new NuGenVarSignatureItem(number, elementType); result = varSignatureItem; if (!HasGenericMethodParameter && varSignatureItem.MethodParameter) { HasGenericMethodParameter = true; } break; case CorElementType.ELEMENT_TYPE_MAX: case CorElementType.ELEMENT_TYPE_R4_HFA: case CorElementType.ELEMENT_TYPE_R8_HFA: throw new NotImplementedException(string.Format("Unknown signature element ('{0}').", elementType)); default: result = ReadType(ref signatureBlob); break; } return result; }
protected NuGenBaseSignatureItem ReadSignatureItem(ref IntPtr signatureBlob) { NuGenBaseSignatureItem result = null; uint data; uint dataLength = NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data); CorElementType elementType = (CorElementType)data; switch (elementType) { case CorElementType.ELEMENT_TYPE_CMOD_OPT: case CorElementType.ELEMENT_TYPE_CMOD_REQD: NuGenCustomModifier customModifier = ReadCustomModifier(ref signatureBlob); result = customModifier; customModifier.NextItem = ReadSignatureItem(ref signatureBlob); break; case CorElementType.ELEMENT_TYPE_END: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); result = new NuGenEndSignatureItem(); break; case CorElementType.ELEMENT_TYPE_BYREF: NuGenHelperFunctions.StepIntPtr(ref signatureBlob); result = ReadSignatureItem(ref signatureBlob); NuGenTypeSignatureItem typeItem = null; if (result is NuGenArraySignatureItem) { typeItem = ((NuGenArraySignatureItem)result).Type; typeItem.ByRef = true; } else if (result is NuGenVarSignatureItem) { NuGenVarSignatureItem varItem = ((NuGenVarSignatureItem)result); varItem.ByRef = true; } else { while (result is NuGenCustomModifier) { result = ((NuGenCustomModifier)result).NextItem; } typeItem = (NuGenTypeSignatureItem)result; typeItem.ByRef = true; } break; case CorElementType.ELEMENT_TYPE_TYPEDBYREF: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); NuGenElementSignatureItem elementItem = new NuGenElementSignatureItem(); elementItem.ElementType = elementType; result = elementItem; break; case CorElementType.ELEMENT_TYPE_PINNED: NuGenHelperFunctions.StepIntPtr(ref signatureBlob); result = ReadSignatureItem(ref signatureBlob); ((NuGenTypeSignatureItem)result).Pinned = true; break; case CorElementType.ELEMENT_TYPE_ARRAY: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); uint value; NuGenArraySignatureItem arrayItem = new NuGenArraySignatureItem(); arrayItem.Type = (NuGenTypeSignatureItem)ReadSignatureItem(ref signatureBlob); NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out value)); arrayItem.Rank = value; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out value)); if (value > 0) { arrayItem.Sizes = new List <uint>(Convert.ToInt32(value)); for (int index = 0; index < value; index++) { uint size; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out size)); arrayItem.Sizes.Add(size); } } NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out value)); if (value > 0) { arrayItem.LoBounds = new List <uint>(Convert.ToInt32(value)); for (int index = 0; index < value; index++) { uint loBound; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out loBound)); arrayItem.LoBounds.Add(loBound); } } result = arrayItem; break; case CorElementType.ELEMENT_TYPE_GENERICINST: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); NuGenTypeSignatureItem genericType = (NuGenTypeSignatureItem)ReadType(ref signatureBlob); result = genericType; uint genericParametersCount = 0; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(SignatureBlob, out genericParametersCount)); if (genericParametersCount > 0) { genericType.GenericParameters = new List <NuGenBaseSignatureItem>(); for (uint genericParametersIndex = 0; genericParametersIndex < genericParametersCount; genericParametersIndex++) { genericType.GenericParameters.Add(ReadSignatureItem(ref signatureBlob)); } } break; case CorElementType.ELEMENT_TYPE_FNPTR: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); NuGenMethodRefSignatureReader signatureReader = new NuGenMethodRefSignatureReader(AllTokens, signatureBlob, SignatureLength); signatureReader.ReadSignature(); signatureBlob = signatureReader.SignatureBlob; result = new NuGenFunctionPointerSignatureItem(signatureReader); break; case CorElementType.ELEMENT_TYPE_MVAR: case CorElementType.ELEMENT_TYPE_VAR: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); byte number = Marshal.ReadByte(signatureBlob); NuGenHelperFunctions.StepIntPtr(ref signatureBlob, 1); NuGenVarSignatureItem varSignatureItem = new NuGenVarSignatureItem(number, elementType); result = varSignatureItem; if (!HasGenericMethodParameter && varSignatureItem.MethodParameter) { HasGenericMethodParameter = true; } break; case CorElementType.ELEMENT_TYPE_MAX: case CorElementType.ELEMENT_TYPE_R4_HFA: case CorElementType.ELEMENT_TYPE_R8_HFA: throw new NotImplementedException(string.Format("Unknown signature element ('{0}').", elementType)); default: result = ReadType(ref signatureBlob); break; } return(result); }