Esempio n. 1
0
        public override void ReadSignature()
        {
            uint data;
            int  dataLength = Convert.ToInt32(NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data));

            CorCallingConvention callingConvention = (CorCallingConvention)data;

            NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength);
            Type = ReadSignatureItem(ref signatureBlob);

            if (signatureBlob.ToInt32() < SignatureEnd)
            {
                uint genericParamCount;
                NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out genericParamCount));

                if (genericParamCount > 0)
                {
                    GenericParameters = new List <NuGenBaseSignatureItem>();

                    for (int genericParamIndex = 0; genericParamIndex < genericParamCount; genericParamIndex++)
                    {
                        GenericParameters.Add(ReadSignatureItem(ref signatureBlob));
                    }
                }
            }
        }
Esempio n. 2
0
        public override void ReadSignature()
        {
            uint data;
            int  dataLength = Convert.ToInt32(NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data));

            CallingConvention = (CorCallingConvention)data;
            NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength);
            uint argumentCount = 0;

            dataLength = Convert.ToInt32(NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out argumentCount));
            NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength);

            if (argumentCount > 0)
            {
                Arguments = new List <NuGenBaseSignatureItem>();
            }

            int argumentIndex = 0;

            while (argumentIndex < argumentCount && signatureBlob.ToInt32() < SignatureEnd)
            {
                Arguments.Add(ReadSignatureItem(ref signatureBlob));
                argumentIndex++;
            }
        }
Esempio n. 3
0
        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;

            NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out paramCount));

            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++;
            }
        }
Esempio n. 4
0
        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++;
            }
        }
Esempio n. 5
0
        private void ReadStandAloneMethodSignature(ref IntPtr signatureBlob)
        {
            uint paramCount = 0;

            if (CallingConvention == CorCallingConvention.IMAGE_CEE_CS_CALLCONV_HASTHIS)
            {
                uint data;
                NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data));
                CorCallingConvention explicitThis = (CorCallingConvention)data;

                if (explicitThis == CorCallingConvention.IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS)
                {
                    CallingConvention |= CorCallingConvention.IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS;
                }
                else
                {
                    paramCount = data;
                }
            }
            else
            {
                NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out paramCount));
            }

            ReturnType = ReadSignatureItem(ref signatureBlob);

            if (paramCount > 0)
            {
                Parameters = new List <NuGenBaseSignatureItem>();

                int paramIndex = 0;
                while (paramIndex < paramCount)
                {
                    uint data;
                    NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data);
                    CorElementType elementType = (CorElementType)data;

                    if (elementType == CorElementType.ELEMENT_TYPE_SENTINEL)
                    {
                        throw new NotImplementedException("Sentinel found.");
                    }

                    if (SentinelFound)
                    {
                        if (VarargParameters == null)
                        {
                            VarargParameters = new List <NuGenBaseSignatureItem>();
                        }

                        VarargParameters.Add(ReadSignatureItem(ref signatureBlob));
                    }
                    else
                    {
                        Parameters.Add(ReadSignatureItem(ref signatureBlob));
                    }
                    paramIndex++;
                }
            }
        }
Esempio n. 6
0
        public override void ReadSignature()
        {
            uint           data;
            uint           dataLength  = NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data);
            CorElementType elementType = (CorElementType)data;

            Type = ReadSignatureItem(ref signatureBlob);
        }
        private NuGenMashallingDescriptorItem ReadNativeType()
        {
            NuGenMashallingDescriptorItem result = new NuGenMashallingDescriptorItem();

            uint data;

            NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(SignatureBlob, out data));

            result.NativeType   = (CorNativeType)data;
            result.IsNativeType = true;

            switch (result.NativeType)
            {
            case CorNativeType.NATIVE_TYPE_SAFEARRAY:
                result.NextItem = ReadVariantType();
                break;

            case CorNativeType.NATIVE_TYPE_CUSTOMMARSHALER:
                result.Guid          = ReadString();
                result.UnmanagedType = ReadString();
                result.ManagedType   = ReadString();
                result.Cookie        = ReadString();
                break;

            case CorNativeType.NATIVE_TYPE_ARRAY:
                result.NextItem = ReadNativeType();

                NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(SignatureBlob, out data));
                result.ParamNumber = (int)data;

                if (result.ParamNumber > ParameterCount)
                {
                    result.ParamNumber = -1;
                }

                NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(SignatureBlob, out data));
                result.ElemMultiply = (int)data;

                NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(SignatureBlob, out data));
                result.NumberElem = (int)data;
                break;

            case CorNativeType.NATIVE_TYPE_FIXEDSYSSTRING:
                NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(SignatureBlob, out data));
                result.NumberElem = (int)data;
                break;

            case CorNativeType.NATIVE_TYPE_FIXEDARRAY:
                NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(SignatureBlob, out data));
                result.NumberElem = (int)data;

                result.NextItem = ReadNativeType();
                break;
            }

            return(result);
        }
Esempio n. 8
0
        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);
            }
        }
        private NuGenMashallingDescriptorItem ReadVariantType()
        {
            NuGenMashallingDescriptorItem result = new NuGenMashallingDescriptorItem();

            uint data;

            NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(SignatureBlob, out data));

            result.VariantType  = (VariantType)data;
            result.IsNativeType = false;

            return(result);
        }
Esempio n. 10
0
        protected NuGenCustomModifier ReadCustomModifier(ref IntPtr signatureBlob)
        {
            NuGenCustomModifier result = new NuGenCustomModifier();

            uint data;

            NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data));

            result.Modifier = (CorElementType)data;
            NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data));
            result.TypeToken = NuGenSignatureCompression.CorSigUncompressToken(data);

            return(result);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        public override void ReadSignature()
        {
            uint data;
            int  dataLength = Convert.ToInt32(NuGenSignatureCompression.CorSigUncompressData(signatureBlob, out data));

            CallingConvention = (CorCallingConvention)data;
            NuGenHelperFunctions.StepIntPtr(ref signatureBlob, dataLength);

            if (CallingConvention == CorCallingConvention.IMAGE_CEE_CS_CALLCONV_FIELD)
            {
                ReadFieldSignature(ref signatureBlob);
            }
            else if (CallingConvention == CorCallingConvention.IMAGE_CEE_CS_CALLCONV_LOCAL_SIG)
            {
                ReadLocalVarSignature(ref signatureBlob);
            }
            else
            {
                ReadStandAloneMethodSignature(ref signatureBlob);
            }
        }
        private string ReadString()
        {
            string result = null;

            uint stringLength;

            NuGenHelperFunctions.StepIntPtr(ref signatureBlob, NuGenSignatureCompression.CorSigUncompressData(SignatureBlob, out stringLength));

            if (stringLength > 0)
            {
                byte[] text = new byte[stringLength];

                for (int index = 0; index < stringLength; index++)
                {
                    text[index] = Marshal.ReadByte(signatureBlob, index);
                }

                NuGenHelperFunctions.StepIntPtr(ref signatureBlob, stringLength);
                UTF8Encoding encoding = new UTF8Encoding();
                result = encoding.GetString(text, 0, text.Length);
            }

            return(result);
        }
Esempio n. 14
0
        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);
        }