public override void ReadSignature() { uint data; int dataLength = Convert.ToInt32(NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data)); CallingConvention = (CorCallingConvention)data; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); uint paramCount = 0; if (CallingConvention != CorCallingConvention.IMAGE_CEE_CS_CALLCONV_FIELD) { dataLength = Convert.ToInt32(NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out paramCount)); NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); if ((CallingConvention & CorCallingConvention.IMAGE_CEE_CS_CALLCONV_GENERIC) == CorCallingConvention.IMAGE_CEE_CS_CALLCONV_GENERIC) { dataLength = Convert.ToInt32(NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out paramCount)); NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); } } ReturnType = ReadSignatureItem(ref signatureBlob); if (paramCount > 0) { Parameters = new List<NuGenBaseSignatureItem>(); } int paramIndex = 0; while (paramIndex < paramCount && signatureBlob.ToInt32() < SignatureEnd) { Parameters.Add(ReadSignatureItem(ref signatureBlob)); paramIndex++; } }
public override void ReadSignature() { uint data; uint dataLength = NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data); CallingConvention = (CorCallingConvention)data; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); uint paramCount = 0; if (CallingConvention != CorCallingConvention.IMAGE_CEE_CS_CALLCONV_FIELD) { dataLength = NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out paramCount); NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); if ((CallingConvention & CorCallingConvention.IMAGE_CEE_CS_CALLCONV_GENERIC) == CorCallingConvention.IMAGE_CEE_CS_CALLCONV_GENERIC) { dataLength = NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out paramCount); NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); } } ReturnType = ReadSignatureItem(ref signatureBlob); if (paramCount > 0) { Parameters = new List <NuGenBaseSignatureItem>(); } int paramIndex = 0; while (paramIndex < paramCount) { dataLength = NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data); CorElementType elementType = (CorElementType)data; if (elementType == CorElementType.ELEMENT_TYPE_SENTINEL) { SentinelFound = true; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); } if (SentinelFound) { if (VarargParameters == null) { VarargParameters = new List <NuGenBaseSignatureItem>(); } NuGenBaseSignatureItem signatureItem = ReadSignatureItem(ref signatureBlob); VarargParameters.Add(signatureItem); } else { NuGenBaseSignatureItem signatureItem = ReadSignatureItem(ref signatureBlob); Parameters.Add(signatureItem); } paramIndex++; } }
private void ReadLocalVarSignature(ref IntPtr signatureBlob) { uint count; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out count)); if (count > 0) { Parameters = new List <NuGenBaseSignatureItem>(); } int index = 0; while (index < count) { index++; uint data; uint dataLength = NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data); bool pinned = ((CorElementType)data == CorElementType.ELEMENT_TYPE_PINNED); if (pinned) { NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); dataLength = NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data); } bool byRef = ((CorElementType)data == CorElementType.ELEMENT_TYPE_BYREF); if (byRef) { NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); } NuGenBaseSignatureItem signatureItem = ReadSignatureItem(ref signatureBlob); NuGenTypeSignatureItem typeSignatureItem = null; if (signatureItem is NuGenArraySignatureItem) { typeSignatureItem = ((NuGenArraySignatureItem)signatureItem).Type; } else if (signatureItem is NuGenTypeSignatureItem) { typeSignatureItem = (NuGenTypeSignatureItem)signatureItem; } if (typeSignatureItem != null) { typeSignatureItem.ByRef = byRef; typeSignatureItem.Pinned = pinned; } Parameters.Add(signatureItem); } }
protected NuGenTypeSignatureItem ReadType(ref IntPtr signatureBlob) { NuGenTypeSignatureItem result = new NuGenTypeSignatureItem(); uint data; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data)); result.ElementType = (CorElementType)data; switch (result.ElementType) { case CorElementType.ELEMENT_TYPE_VALUETYPE: case CorElementType.ELEMENT_TYPE_CLASS: NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data)); result.Token = NuGenSignatureCompression.CorSigUncompressToken(data); break; case CorElementType.ELEMENT_TYPE_SZARRAY: case CorElementType.ELEMENT_TYPE_PTR: CorElementType elementType = CorElementType.ELEMENT_TYPE_BYREF; bool addElementType = false; List <NuGenCustomModifier> customModifiers = new List <NuGenCustomModifier>(); do { if (addElementType) { NuGenCustomModifier customModifier = ReadCustomModifier(ref signatureBlob); customModifiers.Add(customModifier); } addElementType = true; NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data); elementType = (CorElementType)data; } while (elementType == CorElementType.ELEMENT_TYPE_CMOD_OPT || elementType == CorElementType.ELEMENT_TYPE_CMOD_REQD); NuGenBaseSignatureItem nextItem = ReadSignatureItem(ref signatureBlob); result.NextItem = nextItem; if (nextItem.GetType() == typeof(NuGenTypeSignatureItem) && customModifiers.Count > 0) { ((NuGenTypeSignatureItem)nextItem).CustomModifiers = customModifiers; } break; } return(result); }
public override void ReadSignature() { uint data; int dataLength = Convert.ToInt32(NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data)); CallingConvention = (CorCallingConvention)data; NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); uint paramCount = 0; if (CallingConvention != CorCallingConvention.IMAGE_CEE_CS_CALLCONV_FIELD) { dataLength = Convert.ToInt32(NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out paramCount)); NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); if ((CallingConvention & CorCallingConvention.IMAGE_CEE_CS_CALLCONV_GENERIC) == CorCallingConvention.IMAGE_CEE_CS_CALLCONV_GENERIC) { dataLength = Convert.ToInt32(NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out paramCount)); NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength); } } ReturnType = ReadSignatureItem(ref signatureBlob); if (paramCount > 0) { Parameters = new List <NuGenBaseSignatureItem>(); } int paramIndex = 0; while (paramIndex < paramCount && signatureBlob.ToInt32() < SignatureEnd) { Parameters.Add(ReadSignatureItem(ref signatureBlob)); paramIndex++; } }
private void ReadFieldSignature(ref IntPtr signatureBlob) { FieldSignatureItem = ReadSignatureItem(ref signatureBlob); }
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); }
public string GetDefinition(string className, string methodName, bool functionPointer) { string methodDescription = string.Empty; string returnTypeText = string.Empty; string callingConvention = NuGenHelperFunctions.GetCallingConventionName(CallingConvention); NuGenHelperFunctions.SetSignatureItemToken(AllTokens, ReturnType); returnTypeText = ReturnType.ToString(); StringBuilder parameterList = new StringBuilder(); if (functionPointer) { parameterList.Append("*"); } parameterList.Append("("); if (Parameters != null) { for (int parametersIndex = 0; parametersIndex < Parameters.Count; parametersIndex++) { NuGenBaseSignatureItem parameter = Parameters[parametersIndex]; NuGenHelperFunctions.SetSignatureItemToken(AllTokens, parameter); if (parametersIndex == Parameters.Count - 1) { parameterList.Append(parameter); } else { parameterList.AppendFormat("{0}, ", parameter); } } } if (SentinelFound) { if (Parameters != null) { parameterList.Append(", "); } parameterList.Append("..."); if (VarargParameters != null) { parameterList.Append(", "); for (int index = 0; index < VarargParameters.Count; index++) { NuGenBaseSignatureItem varargParameter = VarargParameters[index]; NuGenHelperFunctions.SetSignatureItemToken(AllTokens, varargParameter); if (index == VarargParameters.Count - 1) { parameterList.Append(varargParameter); } else { parameterList.AppendFormat("{0}, ", varargParameter); } } } } parameterList.Append(")"); StringBuilder textBuilder = new StringBuilder(); if (callingConvention.Length > 0) { textBuilder.AppendFormat("{0} ", callingConvention); } textBuilder.AppendFormat("{0} ", returnTypeText); textBuilder.AppendFormat("{0}{1}{2}{3}", className, (className == null ? string.Empty : "::"), methodName, parameterList.ToString()); return(textBuilder.ToString()); }