コード例 #1
0
        ITokenOperand ResolveToken_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);

            if (operand.IsToken)
            {
                throw new NotSupportedException("Currently unable to resolve a token via MDToken");
            }
            else
            {
                if (operand.Data.Type == InlineOperandType.Field)
                {
                    return(this.ResolveField_NoLock(position));
                }
                if (operand.Data.Type == InlineOperandType.Method)
                {
                    return(this.ResolveMethod_NoLock(position));
                }
                if (operand.Data.Type == InlineOperandType.Type)
                {
                    return(this.ResolveType_NoLock(position));
                }

                throw new InvalidOperationException(String.Format(
                                                        "Expected inline operand type of token to be either Type, Field or Method; instead got {0}",
                                                        operand.Data.Type));
            }
        }
コード例 #2
0
        IField ResolveField_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);

            if (operand.IsToken)
            {
                MDToken token = new MDToken(operand.Token);
                return(this.Module.ResolveField(token.Rid));
            }
            else
            {
                FieldData     data          = operand.Data as FieldData;
                ITypeDefOrRef declaringType = this.ResolveType_NoLock(data.FieldType.Position);
                if (declaringType == null)
                {
                    throw new Exception("[ResolveField_NoLock] Unable to resolve type as TypeDef or TypeRef");
                }

                NameResolver nameResolver = new NameResolver(this.Module);
                IField       field        = nameResolver.ResolveField(declaringType, data.Name);
                if (field == null)
                {
                    throw new Exception(String.Format(
                                            "[ResolveField_NoLock] Unable to resolve field: DeclaringType={0}, Field={1}",
                                            declaringType.ReflectionFullName, data.Name));
                }

                return(field);
            }
        }
コード例 #3
0
            public static InlineOperand ReadInternal(BinaryReader reader)
            {
                InlineOperand u = new InlineOperand();

                u.ValueType = ValueType.Position;
                u.Value     = reader.ReadInt32();
                return(u);
            }
コード例 #4
0
 protected override void Deserialize(BinaryReader reader)
 {
     this.SomeIndex       = reader.ReadInt32();
     this.SomeIndex2      = reader.ReadInt32();
     this.Unknown3        = reader.ReadBoolean();
     this.Name            = reader.ReadString();
     this.HasGenericTypes = reader.ReadBoolean();
     this.GenericTypes    = InlineOperand.ReadArrayInternal(reader);
 }
コード例 #5
0
 protected override void Deserialize(BinaryReader reader)
 {
     this.DeclaringType = InlineOperand.ReadInternal(reader);
     //this.Unknown2 = reader.ReadBoolean();
     this.Flags            = reader.ReadBoolean();
     this.Name             = reader.ReadString();
     this.ReturnType       = InlineOperand.ReadInternal(reader);
     this.Parameters       = InlineOperand.ReadArrayInternal(reader);
     this.GenericArguments = InlineOperand.ReadArrayInternal(reader);
 }
コード例 #6
0
            public static InlineOperand[] ReadArrayInternal(BinaryReader reader)
            {
                Int32 count = reader.ReadInt16();

                InlineOperand[] arr = new InlineOperand[count];

                for (Int32 i = 0; i < arr.Length; i++)
                {
                    arr[i] = InlineOperand.ReadInternal(reader);
                }

                return(arr);
            }
コード例 #7
0
ファイル: Resolver.cs プロジェクト: misharcrack/eazdevirt
		String ResolveString_NoLock(Int32 position)
		{
			this.Stream.Position = position;

			InlineOperand operand = new InlineOperand(this.Reader);
			if (operand.IsToken)
			{
				return this.Module.ReadUserString((UInt32)operand.Token);
			}
			else
			{
				StringData data = operand.Data as StringData;
				return data.Value;
			}
		}
コード例 #8
0
        IMethod ResolveMethod_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);

            if (operand.IsToken)
            {
                MDToken token = new MDToken(operand.Token);
                if (token.Table == Table.Method)
                {
                    return(this.Module.ResolveMethod(token.Rid));
                }
                else if (token.Table == Table.MemberRef)
                {
                    return(this.Module.ResolveMemberRef(token.Rid));
                }
                else if (token.Table == Table.MethodSpec)
                {
                    return(this.Module.ResolveMethodSpec(token.Rid));
                }

                throw new Exception("[ResolveMethod_NoLock] Bad MDToken table");
            }
            else
            {
                MethodData    data      = operand.Data as MethodData;
                ITypeDefOrRef declaring = this.ResolveType_NoLock(data.DeclaringType.Position);

                if (declaring is TypeDef)
                {
                    TypeDef declaringDef = declaring as TypeDef;
                    return(this.ResolveMethod_NoLock(declaringDef, data));
                }
                else if (declaring is TypeRef)
                {
                    TypeRef declaringRef = declaring as TypeRef;
                    return(this.ResolveMethod_NoLock(declaringRef, data));
                }
                else if (declaring is TypeSpec)
                {
                    TypeSpec declaringSpec = declaring as TypeSpec;
                    return(this.ResolveMethod_NoLock(declaringSpec, data));
                }

                throw new Exception("[ResolveMethod_NoLock] Expected declaring type to be a TypeDef, TypeRef or TypeSpec");
            }
        }
コード例 #9
0
        String ResolveString_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);

            if (operand.IsToken)
            {
                return(this.Module.ReadUserString((UInt32)operand.Token));
            }
            else
            {
                StringData data = operand.Data as StringData;
                return(data.Value);
            }
        }
コード例 #10
0
        IMethod ResolveEazCall_NoLock(Int32 value)
        {
            // Currently unsure what these two flags do
            Boolean flag1    = (value & 0x80000000) != 0;    // Probably indicates the method has no generic vars
            Boolean flag2    = (value & 0x40000000) != 0;
            Int32   position = value & 0x3FFFFFFF;           // Always a stream position

            if (flag1)
            {
                //throw new Exception(String.Format(
                //	"Unsure what to do if EazCall operand flag1 is set (operand = 0x{0:X8})",
                //	value
                //));

                // void DoSomething(Int32, Type[], Type[], Boolean):
                // -> DoSomething(position, null, null, flag2);

                return(ResolveEazCall_Helper(position, null, null, flag1));
            }
            else
            {
                this.Stream.Position = position;

                InlineOperand operand = new InlineOperand(this.Reader);
                UnknownType7  data    = operand.Data as UnknownType7;

                Int32 num = data.Unknown1;
                // This method is used to get generics info?
                IMethod method                = this.ResolveMethod_NoLock(data.Unknown2);
                Type[]  genericTypes          = null;       // Todo
                Type[]  declaringGenericTypes = null;       // Todo

                Boolean subflag1 = (num & 0x40000000) != 0;
                num &= unchecked ((Int32)0xBFFFFFFF);

                // -> DoSomething(num, genericTypes, declaringGenericTypes, subflag1);
                return(ResolveEazCall_Helper(num, genericTypes, declaringGenericTypes, subflag1));
            }
        }
コード例 #11
0
ファイル: Resolver.cs プロジェクト: 3H54N/eazdevirt
        IMethod ResolveEazCall_NoLock(Int32 value)
        {
            // Currently unsure what these two flags do
            Boolean flag1 = (value & 0x80000000) != 0; // Probably indicates the method has no generic vars
            Boolean flag2 = (value & 0x40000000) != 0;
            Int32 position = value & 0x3FFFFFFF; // Always a stream position

            if (flag1)
            {
                //throw new Exception(String.Format(
                //	"Unsure what to do if EazCall operand flag1 is set (operand = 0x{0:X8})",
                //	value
                //));

                // void DoSomething(Int32, Type[], Type[], Boolean):
                // -> DoSomething(position, null, null, flag2);

                return ResolveEazCall_Helper(position, null, null, flag1);
            }
            else
            {
                this.Stream.Position = position;

                InlineOperand operand = new InlineOperand(this.Reader);
                UnknownType7 data = operand.Data as UnknownType7;

                Int32 num = data.Unknown1;
                // This method is used to get generics info?
                IMethod method = this.ResolveMethod_NoLock(data.Unknown2);
                Type[] genericTypes = null; // Todo
                Type[] declaringGenericTypes = null; // Todo

                Boolean subflag1 = (num & 0x40000000) != 0;
                num &= unchecked((Int32)0xBFFFFFFF);

                // -> DoSomething(num, genericTypes, declaringGenericTypes, subflag1);
                return ResolveEazCall_Helper(num, genericTypes, declaringGenericTypes, subflag1);
            }
        }
コード例 #12
0
 protected override void Deserialize(BinaryReader reader)
 {
     this.FieldType = InlineOperand.ReadInternal(reader);
     this.Name      = reader.ReadString();
     this.Flags     = reader.ReadBoolean();
 }
コード例 #13
0
        ITypeDefOrRef ResolveType_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);

            if (operand.IsToken)
            {
                MDToken token = new MDToken(operand.Token);

                if (token.Table == Table.TypeDef)
                {
                    return(this.Module.ResolveTypeDef(token.Rid));
                }
                else if (token.Table == Table.TypeRef)
                {
                    return(this.Module.ResolveTypeRef(token.Rid));
                }
                else if (token.Table == Table.TypeSpec)
                {
                    return(this.Module.ResolveTypeSpec(token.Rid));
                }

                throw new Exception("Unable to resolve type: bad MDToken table");
            }
            else
            {
                TypeData data = operand.Data as TypeData;

                // Resolve via name
                TypeName      typeName     = new TypeName(data.Name);
                NameResolver  nameResolver = new NameResolver(this.Module);
                ITypeDefOrRef typeDefOrRef = nameResolver.ResolveTypeDefOrRef(typeName);

                if (typeDefOrRef == null)
                {
                    throw new Exception(String.Format(
                                            "Unable to resolve ITypeDefOrRef from given name: {0}",
                                            typeName.FullName));
                }

                // Apply generics, if any (resulting in a TypeSpec)
                if (data.GenericTypes.Length > 0)
                {
                    typeDefOrRef = ApplyGenerics(typeDefOrRef, data);
                }

                if (typeDefOrRef == null)
                {
                    throw new Exception(String.Format(
                                            "Unable to apply generic types: {0}", typeName.FullName
                                            ));
                }

                // Apply [], *, &
                typeDefOrRef = SigUtil.FromBaseSig(typeDefOrRef.ToTypeSig(), typeName.Modifiers)
                               .ToTypeDefOrRef();

                return(typeDefOrRef);
            }
        }
コード例 #14
0
        /// <summary>
        /// Resolve a type from a deserialized inline operand, which should
        /// have a direct token (position).
        /// </summary>
        /// <param name="operand">Inline operand</param>
        /// <returns>TypeSig</returns>
        TypeSig ResolveType(InlineOperand operand)
        {
            ITypeDefOrRef type = this.ResolveType_NoLock(operand.Position);

            return(type.ToTypeSig(true));
        }
コード例 #15
0
ファイル: Resolver.cs プロジェクト: 3H54N/eazdevirt
        ITypeDefOrRef ResolveType_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);
            if (operand.IsToken)
            {
                MDToken token = new MDToken(operand.Token);

                if (token.Table == Table.TypeDef)
                    return this.Module.ResolveTypeDef(token.Rid);
                else if (token.Table == Table.TypeRef)
                    return this.Module.ResolveTypeRef(token.Rid);
                else if (token.Table == Table.TypeSpec)
                    return this.Module.ResolveTypeSpec(token.Rid);

                throw new Exception("Unable to resolve type: bad MDToken table");
            }
            else
            {
                TypeData data = operand.Data as TypeData;

                // Resolve via name
                TypeName typeName = new TypeName(data.Name);
                NameResolver nameResolver = new NameResolver(this.Module);
                ITypeDefOrRef typeDefOrRef = nameResolver.ResolveTypeDefOrRef(typeName);

                if (typeDefOrRef == null)
                {
                    throw new Exception(String.Format(
                        "Unable to resolve ITypeDefOrRef from given name: {0}",
                        typeName.FullName));
                }

                // Apply generics, if any (resulting in a TypeSpec)
                if (data.GenericTypes.Length > 0)
                    typeDefOrRef = ApplyGenerics(typeDefOrRef, data);

                if (typeDefOrRef == null)
                {
                    throw new Exception(String.Format(
                        "Unable to apply generic types: {0}", typeName.FullName
                        ));
                }

                // Apply [], *, &
                typeDefOrRef = SigUtil.FromBaseSig(typeDefOrRef.ToTypeSig(), typeName.Modifiers)
                    .ToTypeDefOrRef();

                return typeDefOrRef;
            }
        }
コード例 #16
0
ファイル: Resolver.cs プロジェクト: 3H54N/eazdevirt
 /// <summary>
 /// Resolve a type from a deserialized inline operand, which should
 /// have a direct token (position).
 /// </summary>
 /// <param name="operand">Inline operand</param>
 /// <returns>TypeSig</returns>
 TypeSig ResolveType(InlineOperand operand)
 {
     ITypeDefOrRef type = this.ResolveType_NoLock(operand.Position);
     return type.ToTypeSig(true);
 }
コード例 #17
0
ファイル: Resolver.cs プロジェクト: 3H54N/eazdevirt
        ITokenOperand ResolveToken_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);
            if (operand.IsToken)
            {
                throw new NotSupportedException("Currently unable to resolve a token via MDToken");
            }
            else
            {
                if (operand.Data.Type == InlineOperandType.Field)
                    return this.ResolveField_NoLock(position);
                if (operand.Data.Type == InlineOperandType.Method)
                    return this.ResolveMethod_NoLock(position);
                if (operand.Data.Type == InlineOperandType.Type)
                    return this.ResolveType_NoLock(position);

                throw new InvalidOperationException(String.Format(
                    "Expected inline operand type of token to be either Type, Field or Method; instead got {0}",
                    operand.Data.Type));
            }
        }
コード例 #18
0
ファイル: Resolver.cs プロジェクト: 3H54N/eazdevirt
        IMethod ResolveMethod_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);
            if(operand.IsToken)
            {
                MDToken token = new MDToken(operand.Token);
                if (token.Table == Table.Method)
                    return this.Module.ResolveMethod(token.Rid);
                else if (token.Table == Table.MemberRef)
                    return this.Module.ResolveMemberRef(token.Rid);
                else if (token.Table == Table.MethodSpec)
                    return this.Module.ResolveMethodSpec(token.Rid);

                throw new Exception("[ResolveMethod_NoLock] Bad MDToken table");
            }
            else
            {
                MethodData data = operand.Data as MethodData;
                ITypeDefOrRef declaring = this.ResolveType_NoLock(data.DeclaringType.Position);

                if (declaring is TypeDef)
                {
                    TypeDef declaringDef = declaring as TypeDef;
                    return this.ResolveMethod_NoLock(declaringDef, data);
                }
                else if (declaring is TypeRef)
                {
                    TypeRef declaringRef = declaring as TypeRef;
                    return this.ResolveMethod_NoLock(declaringRef, data);
                }
                else if (declaring is TypeSpec)
                {
                    TypeSpec declaringSpec = declaring as TypeSpec;
                    return this.ResolveMethod_NoLock(declaringSpec, data);
                }

                throw new Exception("[ResolveMethod_NoLock] Expected declaring type to be a TypeDef, TypeRef or TypeSpec");
            }
        }
コード例 #19
0
ファイル: Resolver.cs プロジェクト: 3H54N/eazdevirt
        IField ResolveField_NoLock(Int32 position)
        {
            this.Stream.Position = position;

            InlineOperand operand = new InlineOperand(this.Reader);
            if (operand.IsToken)
            {
                MDToken token = new MDToken(operand.Token);
                return this.Module.ResolveField(token.Rid);
            }
            else
            {
                FieldData data = operand.Data as FieldData;
                ITypeDefOrRef declaringType = this.ResolveType_NoLock(data.FieldType.Position);
                if (declaringType == null)
                    throw new Exception("[ResolveField_NoLock] Unable to resolve type as TypeDef or TypeRef");

                NameResolver nameResolver = new NameResolver(this.Module);
                IField field = nameResolver.ResolveField(declaringType, data.Name);
                if (field == null)
                {
                    throw new Exception(String.Format(
                    "[ResolveField_NoLock] Unable to resolve field: DeclaringType={0}, Field={1}",
                    declaringType.ReflectionFullName, data.Name));
                }

                return field;
            }
        }
コード例 #20
0
			public static InlineOperand[] ReadArrayInternal(BinaryReader reader)
			{
				Int32 count = reader.ReadInt16();
				InlineOperand[] arr = new InlineOperand[count];

				for (Int32 i = 0; i < arr.Length; i++)
					arr[i] = InlineOperand.ReadInternal(reader);

				return arr;
			}
コード例 #21
0
			public static InlineOperand ReadInternal(BinaryReader reader)
			{
				InlineOperand u = new InlineOperand();
				u.ValueType = ValueType.Position;
				u.Value = reader.ReadInt32();
				return u;
			}