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)); } }
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); } }
public static InlineOperand ReadInternal(BinaryReader reader) { InlineOperand u = new InlineOperand(); u.ValueType = ValueType.Position; u.Value = reader.ReadInt32(); return(u); }
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); }
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); }
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); }
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; } }
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"); } }
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); } }
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)); } }
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); } }
protected override void Deserialize(BinaryReader reader) { this.FieldType = InlineOperand.ReadInternal(reader); this.Name = reader.ReadString(); this.Flags = reader.ReadBoolean(); }
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); } }
/// <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)); }
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; } }
/// <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); }
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)); } }
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"); } }
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; } }
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; }
public static InlineOperand ReadInternal(BinaryReader reader) { InlineOperand u = new InlineOperand(); u.ValueType = ValueType.Position; u.Value = reader.ReadInt32(); return u; }