예제 #1
0
#pragma warning restore 649

        public MethodContext(DynamicMethod method)
        {
            Method        = null;
            MethodBody    = null;
            _msilBytes    = _ilGeneratorBakeByteArray(method.GetILGenerator());
            TokenResolver = new DynamicMethodTokenResolver(method);
        }
예제 #2
0
파일: ILReader.cs 프로젝트: FenixDan/Jitex
 /// <summary>
 /// Create a new enumerator to read instructions.
 /// </summary>
 /// <param name="il">IL to read.</param>
 /// <param name="resolver">Module to resolver tokens.</param>
 /// <param name="genericTypeArguments">Generic class arguments used in instructions.</param>
 /// <param name="genericMethodArguments">Generic method arguments used in instructions.</param>
 public ILEnumerator(byte[] il, ITokenResolver resolver, Type[] genericTypeArguments, Type[] genericMethodArguments)
 {
     _il                     = il;
     _resolver               = resolver;
     _genericTypeArguments   = genericTypeArguments;
     _genericMethodArguments = genericMethodArguments;
 }
예제 #3
0
 public ILReader(IILProvider ilProvider, ITokenResolver tokenResolver)
 {
     m_resolver   = tokenResolver;
     m_ilProvider = ilProvider ?? throw new ArgumentNullException(nameof(ilProvider));
     m_byteArray  = m_ilProvider.GetByteArray();
     m_position   = 0;
 }
예제 #4
0
 static object AskForDef(string title, ITokenResolver resolver) => MsgBox.Instance.Ask(dnSpy_Resources.GoToToken_Label, null, title, s => {
     string error;
     uint token    = SimpleTypeConverter.ParseUInt32(s, uint.MinValue, uint.MaxValue, out error);
     var memberRef = resolver.ResolveToken(token);
     var member    = ResolveDef(memberRef);
     return(member);
 }, s => {
     string error;
     uint token = SimpleTypeConverter.ParseUInt32(s, uint.MinValue, uint.MaxValue, out error);
     if (!string.IsNullOrEmpty(error))
     {
         return(error);
     }
     var memberRef = resolver.ResolveToken(token);
     var member    = ResolveDef(memberRef);
     if (memberRef == null)
     {
         return(string.Format(dnSpy_Resources.GoToToken_InvalidToken, token));
     }
     else if (member == null)
     {
         return(string.Format(dnSpy_Resources.GoToToken_CouldNotResolve, token));
     }
     return(string.Empty);
 });
예제 #5
0
 public ILReader(
     BinaryReader reader,
     ITokenResolver resolver)
 {
     _reader   = reader;
     _resolver = resolver;
 }
예제 #6
0
 internal Instruction(ITokenResolver resolver, int offsetPosition, OpCode opCode)
 {
     Resolver       = resolver;
     OffsetPosition = offsetPosition;
     OpCode         = opCode;
     FormatProvider = new DefaultFormatProvider();
 }
예제 #7
0
        private void EnsureInitialized()
        {
            if (_initialized)
            {
                return;
            }

            if (_optionFactory != null)
            {
                var op = new TransformOptions();
                _optionFactory.Invoke(op);

                if (op.TokenExtractors.Any())
                {
                    _tokens = new ReadOnlyCollection <ITokenExtractor>(op.TokenExtractors);
                }

                _tokenResolver      = op.TokenResolver;
                _formatter          = op.Formatter;
                _disabledLocalCache = op.DisabledLocalCache;
                _globalParameters   = op.GlobalParameters;
            }

            if (_tokens?.Any() != true)
            {
                _tokens = DefaultTokenExtractors;
            }

            _tokenResolver ??= DefaultTokenResolver;
            _formatter ??= DefaultConvertor;

            _initialized = true;
        }
예제 #8
0
 static IDnlibDef AskForDef(string title, ITokenResolver resolver)
 {
     return(Shared.App.MsgBox.Instance.Ask(dnSpy_Resources.GoToToken_Label, null, title, s => {
         string error;
         uint token = NumberVMUtils.ParseUInt32(s, uint.MinValue, uint.MaxValue, out error);
         var memberRef = resolver.ResolveToken(token);
         var member = ResolveDef(memberRef);
         return member;
     }, s => {
         string error;
         uint token = NumberVMUtils.ParseUInt32(s, uint.MinValue, uint.MaxValue, out error);
         if (!string.IsNullOrEmpty(error))
         {
             return error;
         }
         var memberRef = resolver.ResolveToken(token);
         var member = ResolveDef(memberRef);
         if (memberRef == null)
         {
             return string.Format(dnSpy_Resources.GoToToken_InvalidToken, token);
         }
         else if (member == null)
         {
             return string.Format(dnSpy_Resources.GoToToken_CouldNotResolve, token);
         }
         return string.Empty;
     }));
 }
        MethodBodyReader(MethodBase method)
        {
            this.method   = method;
            this.resolver = method.GetTokenResolver();

            var bytes = method.GetILBytes();

            if (bytes == null)
            {
                throw new ArgumentException("Can not get the body of the method");
            }

            if (!(method is ConstructorInfo))
            {
                method_arguments = GetGenericMethodArguments();
            }

            if (method.DeclaringType != null)
            {
                type_arguments = method.DeclaringType.GetGenericArguments();
            }

            if (!method.IsStatic)
            {
                this.this_parameter = new ThisParameter(method);
            }
            this.parameters   = method.GetParameters();
            this.locals       = GetLocals();
            this.il           = new ByteBuffer(bytes);
            this.instructions = new List <Instruction> ((bytes.Length + 1) / 2);
        }
예제 #10
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="membershipProvider"></param>
 public PasswordService(IRepository repository, ISendMailProvider sendMail, IAuthenticationContentProvider authenticationContentProvider, ITokenResolver tokenResolver)
 {
     _repository    = repository;
     this._sendMail = sendMail;
     _authenticationContentProvider = authenticationContentProvider;
     _tokenResolver = tokenResolver;
     _httpContext   = HttpContext.Current;
 }
예제 #11
0
 public MethodContext(MethodBase method)
 {
     Method     = method;
     MethodBody = method.GetMethodBody();
     Debug.Assert(MethodBody != null, "Method body is null");
     _msilBytes    = MethodBody.GetILAsByteArray();
     TokenResolver = new NormalTokenResolver(method);
 }
예제 #12
0
 public MethodContext(DynamicMethod method)
 {
     Method                 = null;
     MethodBody             = null;
     _msilBytes             = _ilGeneratorBakeByteArray(method.GetILGenerator());
     _dynamicExceptionTable = _ilGeneratorGetExceptionHandlers(method.GetILGenerator());
     TokenResolver          = new DynamicMethodTokenResolver(method);
 }
예제 #13
0
        public ILReader(IILProvider ilProvider, ITokenResolver tokenResolver)
        {
            if (ilProvider == null)
            {
                throw new ArgumentNullException(nameof(ilProvider));
            }

            m_resolver  = tokenResolver;
            m_byteArray = ilProvider.GetByteArray();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ILInstructionReader"/> class.
 /// </summary>
 /// <param name="ilProvider">The il provider.</param>
 /// <param name="tokenResolver">The token resolver.</param>
 /// <exception cref="System.ArgumentNullException">ilProvider</exception>
 internal ILInstructionReader(IILProvider ilProvider, ITokenResolver tokenResolver)
 {
     this._resolver          = tokenResolver;
     this._ilProvider        = ilProvider ?? throw new ArgumentNullException("ilProvider");
     this._byteArray         = this._ilProvider.GetByteArray();
     this._position          = 0;
     this.stackByOffset      = new Dictionary <int, ImmutableStack <ILVariable> >();
     this.unionFind          = new UnionFind <ILVariable>();
     this.stackMismatchPairs = new List <(ILVariable, ILVariable)>();
     this.currentStack       = ImmutableStack <ILVariable> .Empty;
 }
예제 #15
0
 static void AddToken(this IList <short> instrs, ITokenResolver resolver, uint token)
 {
     if (resolver == null || resolver.ResolveToken(token) == null)
     {
         instrs.AddUnknownInt32();
     }
     else
     {
         instrs.AddInt32(unchecked ((int)token));
     }
 }
예제 #16
0
파일: ILReader.cs 프로젝트: dr-BEat/NShim
        public ILReader(IILProvider ilProvider, ITokenResolver tokenResolver)
        {
            if (ilProvider == null)
            {
                throw new ArgumentNullException("ilProvider");
            }

            _resolver  = tokenResolver;
            _byteArray = ilProvider.GetByteArray();
            _position  = 0;
        }
예제 #17
0
파일: ILReader.cs 프로젝트: FenixDan/Jitex
        /// <summary>
        /// Read IL from array byte.
        /// </summary>
        /// <param name="il">IL to read.</param>
        /// <param name="module">Module from IL.</param>
        /// <param name="genericTypeArguments">Generic class arguments used in instructions.</param>
        /// <param name="genericMethodArguments">Generic method arguments used in instructions.</param>
        public ILReader(byte[] il, Module module, Type[] genericTypeArguments = null, Type[] genericMethodArguments = null)
        {
            _il = il;

            _genericTypeArguments   = genericTypeArguments;
            _genericMethodArguments = genericMethodArguments;

            if (module != null)
            {
                _resolver = new ModuleTokenResolver(module);
            }
        }
예제 #18
0
        public ILReaderBase(object target)
        {
            m_target         = target;
            this.m_resolver  = getTokenResolver(target);
            this.m_byteArray = getMethodBodyAsByteArray(target);

            if (this.m_byteArray == null)
            {
                this.m_byteArray = new byte[0];
            }
            this.m_position = 0;
        }
예제 #19
0
 public JoinSgController(IUsersApi usersApi, IGroupMemberRepository groupMemberRepository,IPlatformTokenProvider platformTokenProvider,
     ITokenResolver tokenResolver, IGroupMemberResolver groupMemberResolver, IShopGroupFromInputValidator shopGroupFromInputValidator,
     IShopGroupRepository shopGroupRepository, IGroupIdProvider groupIdProvider)
 {
     _usersApi = usersApi;
     _groupMemberRepository = groupMemberRepository;
     _tokenResolver = tokenResolver;
     _groupMemberResolver = groupMemberResolver;
     _shopGroupFromInputValidator = shopGroupFromInputValidator;
     _platformTokenProvider = platformTokenProvider;
     _shopGroupRepository = shopGroupRepository;
     _groupIdProvider = groupIdProvider;
 }
예제 #20
0
 public HomeController(IShopGroupRepository shopGroupRepository, IPlatformTokenProvider platformTokenProvider,IUsersApi usersApi, ITokenResolver tokenResolver,
      IProductsApi productsApi, IAuthApi authApi, IPlatformSettings platformSettings, IGroupMemberRepository groupMemberRepository, IGroupMemberResolver groupMemberResolver)
 {
     _platformTokenProvider = platformTokenProvider;
     _platformSettings = platformSettings;
     _usersApi = usersApi;
     _shopGroupRepository = shopGroupRepository;
     _groupMemberRepository = groupMemberRepository;
     _productsApi = productsApi;
     _authApi = authApi;
     _tokenResolver = tokenResolver;
     _groupMemberResolver = groupMemberResolver;
 }
예제 #21
0
        public ILReader(MethodBase method)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            Type type = method.GetType();

            if (type != ILReader.s_runtimeMethodInfoType && type != ILReader.s_runtimeConstructorInfoType)
            {
                throw new ArgumentException("method must be RuntimeMethodInfo or RuntimeConstructorInfo for this constructor.");
            }
            this.m_ilProvider = (IILProvider) new MethodBaseILProvider(method);
            this.m_resolver   = (ITokenResolver) new ModuleScopeTokenResolver(method);
            this.m_byteArray  = this.m_ilProvider.GetByteArray();
            this.m_position   = 0;
        }
예제 #22
0
        public ILReader(MethodBase method)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            Type rtType = method.GetType();

            //if (rtType != s_runtimeMethodInfoType && rtType != s_runtimeConstructorInfoType) {
            //    throw new ArgumentException("method must be RuntimeMethodInfo or RuntimeConstructorInfo for this constructor.");
            //}

            m_ilProvider = new MethodBaseILProvider(method);
            m_resolver   = new ModuleScopeTokenResolver(method);
            m_byteArray  = m_ilProvider.GetByteArray();
            m_position   = 0;
        }
예제 #23
0
        public Reader(DynamicMethod dynamicMethod)
        {
            _resolver = new DynamicScopeTokenResolver(dynamicMethod);
            var ilgen = dynamicMethod.GetILGenerator();

            FixupSuccess = false;
            try
            {
                _byteArray   = ilgen.PublicBakeByteArray();
                FixupSuccess = true;
            }
            catch (TargetInvocationException)
            {
                var length = (int)FiLen.GetValue(ilgen);
                _byteArray = new byte[length];
                Array.Copy((byte[])FiStream.GetValue(ilgen), _byteArray, length);
            }
            _position = 0;
        }
예제 #24
0
파일: ILReader.cs 프로젝트: dr-BEat/NShim
        public ILReader(MethodBase method)
        {
            if (method == null)
            {
                throw new ArgumentNullException(nameof(method));
            }

            var rtType = method.GetType();

            if (rtType != RuntimeMethodInfoType && rtType != RuntimeConstructorInfoType)
            {
                throw new ArgumentException(
                          "method must be RuntimeMethodInfo or RuntimeConstructorInfo for this constructor.");
            }

            var ilProvider = new MethodBaseILProvider(method);

            _resolver  = new ModuleScopeTokenResolver(method);
            _byteArray = ilProvider.GetByteArray();
            _position  = 0;
        }
예제 #25
0
파일: ILReader.cs 프로젝트: FenixDan/Jitex
        /// <summary>
        /// Read IL from method.
        /// </summary>
        /// <param name="methodILBase">Method to read IL.</param>
        public ILReader(MethodBase methodILBase)
        {
            if (methodILBase == null)
            {
                throw new ArgumentNullException(nameof(methodILBase));
            }

            _il = methodILBase.GetILBytes();

            _genericTypeArguments   = methodILBase.DeclaringType.GenericTypeArguments;
            _genericMethodArguments = methodILBase.GetGenericArguments();

            if (methodILBase is DynamicMethod dynamicMethod)
            {
                _resolver = new DynamicMethodTokenResolver(dynamicMethod);
            }
            else
            {
                _resolver = new ModuleTokenResolver(methodILBase.Module);
            }
        }
예제 #26
0
 static IDnlibDef AskForDef(string title, ITokenResolver resolver)
 {
     return Shared.App.MsgBox.Instance.Ask(dnSpy_Resources.GoToToken_Label, null, title, s => {
         string error;
         uint token = NumberVMUtils.ParseUInt32(s, uint.MinValue, uint.MaxValue, out error);
         var memberRef = resolver.ResolveToken(token);
         var member = ResolveDef(memberRef);
         return member;
     }, s => {
         string error;
         uint token = NumberVMUtils.ParseUInt32(s, uint.MinValue, uint.MaxValue, out error);
         if (!string.IsNullOrEmpty(error))
             return error;
         var memberRef = resolver.ResolveToken(token);
         var member = ResolveDef(memberRef);
         if (memberRef == null)
             return string.Format(dnSpy_Resources.GoToToken_InvalidToken, token);
         else if (member == null)
             return string.Format(dnSpy_Resources.GoToToken_CouldNotResolve, token);
         return string.Empty;
     });
 }
예제 #27
0
        public MonoILReader(DynamicMethod dynamicMethod)
        {
            this.m_resolver = new MonoDynamicScopeTokenResolver(dynamicMethod);
            ILGenerator ilgen = dynamicMethod.GetILGenerator();

            this.m_fixupSuccess = false;
            try
            {
                s_miLabelFixup.Invoke(ilgen, null);
                this.m_byteArray = (byte[])s_fiStream.GetValue(ilgen);
                if (this.m_byteArray == null)
                {
                    this.m_byteArray = new byte[0];
                }
                m_fixupSuccess = true;
            }
            catch (TargetInvocationException)
            {
                int length = (int)s_fiLen.GetValue(ilgen);
                this.m_byteArray = new byte[length];
                Array.Copy((byte[])s_fiStream.GetValue(ilgen), this.m_byteArray, length);
            }
            this.m_position = 0;
        }
		MethodBodyReader (MethodBase method)
		{
            //wicky.patch.start: check DynamicMethod
            byte[] bytes;
            if (DynamicMethodHelper.IsDynamicOrRTDynamicMethod(method))
            {
                DynamicMethod dynamicMethod = DynamicMethodHelper.GetDynamicMethod(method);
                this.method = dynamicMethod;
                bytes = DynamicMethodHelper.GetILAsByteArray(dynamicMethod);
                if (bytes == null) 
                    bytes = new byte[0];                
                if (dynamicMethod.DeclaringType != null)
                    type_arguments = dynamicMethod.DeclaringType.GetGenericArguments();
                this.parameters = dynamicMethod.GetParameters();                
                this.module = dynamicMethod.Module;
                //this.locals = ??
                this.il = new ByteBuffer(bytes);
                this.tokenResolver = new DynamicScopeTokenResolver(dynamicMethod);
            }
            else
            {
                this.method = method;
                this.body = method.GetMethodBody();
                if (this.body == null)
                    bytes = new byte[0];
                else
                    bytes = body.GetILAsByteArray();
                if (bytes == null)
                    bytes = new byte[0];

                bytes = body.GetILAsByteArray();

                if (!(method is ConstructorInfo))
                    method_arguments = method.GetGenericArguments();

                if (method.DeclaringType != null)
                    type_arguments = method.DeclaringType.GetGenericArguments();

                this.parameters = method.GetParameters();
                this.locals = body.LocalVariables;
                this.module = method.Module;
                this.il = new ByteBuffer(bytes);
                this.tokenResolver = new ModuleScopeTokenResolver(method);
            }

            /*
            this.method = method;

			this.body = method.GetMethodBody ();
			if (this.body == null)
				throw new ArgumentException ("Method has no body");

			var bytes = body.GetILAsByteArray ();
			if (bytes == null)
				throw new ArgumentException ("Can not get the body of the method");

			if (!(method is ConstructorInfo))
				method_arguments = method.GetGenericArguments ();

			if (method.DeclaringType != null)
				type_arguments = method.DeclaringType.GetGenericArguments ();

			this.parameters = method.GetParameters ();
			this.locals = body.LocalVariables;
			this.module = method.Module;
			this.il = new ByteBuffer (bytes);
            */

            //wicky.patch.end
        }
예제 #29
0
 public LocalsSignatureParser(ITokenResolver tokenResolver, ITypeFactory typeFactory)
 {
     _tokenResolver = tokenResolver;
     _typeFactory   = typeFactory;
 }
예제 #30
0
 internal InlineFieldInstruction(ITokenResolver resolver, int offset, OpCode opCode, int token)
     : base(offset, opCode)
 {
     _resolver = resolver;
     Token = token;
 }
예제 #31
0
 public ShortInlineVarInstruction(ITokenResolver resolver, int offsetPosition, OpCode opCode, byte value)
     : base(resolver, offsetPosition, opCode, value)
 {
 }
 public InlineTypeInstruction(ITokenResolver resolver, Int32 offset, OpCode opCode, Int32 token)
     : base(resolver, offset, opCode)
 {
     this.m_token = token;
 }
 public ShortInlineRInstruction(ITokenResolver resolver, Int32 offset, OpCode opCode, Single value)
     : base(resolver, offset, opCode)
 {
     this.m_value = value;
 }
예제 #34
0
		static void AddToken(this IList<short> instrs, ITokenResolver resolver, uint token) {
			if (resolver == null || resolver.ResolveToken(token) == null)
				instrs.AddUnknownInt32();
			else
				instrs.AddInt32(unchecked((int)token));
		}
예제 #35
0
		public static void AddOperand(IList<short> instrs, ITokenResolver resolver, uint offset, OpCode opCode, object operand) {
			Instruction target;
			IVariable variable;
			switch (opCode.OperandType) {
			case OperandType.InlineBrTarget:
				target = operand as Instruction;
				if (target == null)
					instrs.AddUnknownInt32();
				else
					instrs.AddInt32(unchecked((int)target.Offset - (int)(offset + 4)));
				break;

			case OperandType.InlineField:
			case OperandType.InlineMethod:
			case OperandType.InlineTok:
			case OperandType.InlineType:
				var tok = operand as ITokenOperand;
				instrs.AddToken(resolver, tok == null ? 0 : tok.MDToken.Raw);
				break;

			case OperandType.InlineSig:
				var msig = operand as MethodSig;
				instrs.AddToken(resolver, msig == null ? 0 : msig.OriginalToken);
				break;

			case OperandType.InlineString:
				instrs.AddUnknownInt32();
				break;

			case OperandType.InlineI:
				if (operand is int)
					instrs.AddInt32((int)operand);
				else
					instrs.AddUnknownInt32();
				break;

			case OperandType.InlineI8:
				if (operand is long)
					instrs.AddInt64((long)operand);
				else
					instrs.AddUnknownInt64();
				break;

			case OperandType.InlineR:
				if (operand is double)
					instrs.AddDouble((double)operand);
				else
					instrs.AddUnknownInt64();
				break;

			case OperandType.ShortInlineR:
				if (operand is float)
					instrs.AddSingle((float)operand);
				else
					instrs.AddUnknownInt32();
				break;

			case OperandType.InlineSwitch:
				var targets = operand as IList<Instruction>;
				if (targets == null)
					instrs.AddUnknownInt32();
				else {
					uint offsetAfter = offset + 4 + (uint)targets.Count * 4;
					instrs.AddInt32(targets.Count);
					foreach (var instr in targets) {
						if (instr == null)
							instrs.AddUnknownInt32();
						else
							instrs.AddInt32(unchecked((int)instr.Offset - (int)offsetAfter));
					}
				}
				break;

			case OperandType.InlineVar:
				variable = operand as IVariable;
				if (variable == null)
					instrs.AddUnknownInt16();
				else if (ushort.MinValue <= variable.Index && variable.Index <= ushort.MaxValue)
					instrs.AddInt16(unchecked((short)variable.Index));
				else
					instrs.AddUnknownInt16();
				break;

			case OperandType.ShortInlineVar:
				variable = operand as IVariable;
				if (variable == null)
					instrs.AddUnknownByte();
				else if (byte.MinValue <= variable.Index && variable.Index <= byte.MaxValue)
					instrs.Add((byte)variable.Index);
				else
					instrs.AddUnknownByte();
				break;

			case OperandType.ShortInlineBrTarget:
				target = operand as Instruction;
				if (target == null)
					instrs.AddUnknownByte();
				else {
					int displ = unchecked((int)target.Offset - (int)(offset + 1));
					if (sbyte.MinValue <= displ && displ <= sbyte.MaxValue)
						instrs.Add((short)(displ & 0xFF));
					else
						instrs.AddUnknownByte();
				}
				break;

			case OperandType.ShortInlineI:
				if (operand is sbyte)
					instrs.Add((short)((sbyte)operand & 0xFF));
				else if (operand is byte)
					instrs.Add((short)((byte)operand & 0xFF));
				else
					instrs.AddUnknownByte();
				break;

			case OperandType.InlineNone:
			case OperandType.InlinePhi:
				break;

			default:
				throw new InvalidOperationException();
			}
		}
예제 #36
0
 public InstructionReader(ITokenResolver tokens, byte[] bytes)
     : this(tokens, new ByteConverter(bytes, 0))
 {
 }
예제 #37
0
 public InstructionReader(ITokenResolver tokens, ByteConverter stream)
 {
     this.tokens = tokens;
     this.stream = stream;
 }
 internal InlineSigInstruction(Int32 offset, OpCode opCode, Int32 token, ITokenResolver resolver)
     : base(offset, opCode)
 {
     m_resolver = resolver;
     m_token = token;
 }
예제 #39
0
 public LocalsSignatureParser(ITokenResolver tokenResolver, ITypeFactory typeFactory)
 {
     _tokenResolver = tokenResolver;
     _typeFactory = typeFactory;
 }
예제 #40
0
 internal InlineStringInstruction(int offset, OpCode opCode, int token, ITokenResolver resolver)
     : base(offset, opCode)
 {
     _resolver = resolver;
     Token = token;
 }
 public InlineNoneInstruction(ITokenResolver resolver, Int32 offset, OpCode opCode)
     : base(resolver, offset, opCode)
 {
 }
예제 #42
0
		static object AskForDef(string title, ITokenResolver resolver) => MsgBox.Instance.Ask(dnSpy_Resources.GoToToken_Label, null, title, s => {
			string error;
			uint token = SimpleTypeConverter.ParseUInt32(s, uint.MinValue, uint.MaxValue, out error);
			var memberRef = resolver.ResolveToken(token);
			var member = ResolveDef(memberRef);
			return member;
		}, s => {
			string error;
			uint token = SimpleTypeConverter.ParseUInt32(s, uint.MinValue, uint.MaxValue, out error);
			if (!string.IsNullOrEmpty(error))
				return error;
			var memberRef = resolver.ResolveToken(token);
			var member = ResolveDef(memberRef);
			if (memberRef == null)
				return string.Format(dnSpy_Resources.GoToToken_InvalidToken, token);
			else if (member == null)
				return string.Format(dnSpy_Resources.GoToToken_CouldNotResolve, token);
			return string.Empty;
		});
 public InlineSwitchInstruction(ITokenResolver resolver, Int32 offset, OpCode opCode, Int32[] deltas)
     : base(resolver, offset, opCode)
 {
     this.m_deltas = deltas;
 }
 public InlineBrTargetInstruction(ITokenResolver resolver, Int32 offset, OpCode opCode, Int32 delta)
     : base(resolver, offset, opCode)
 {
     this.m_delta = delta;
 }
 public ShortInlineIInstruction(ITokenResolver resolver, Int32 offset, OpCode opCode, Byte value)
     : base(resolver, offset, opCode)
 {
     this.m_int8 = value;
 }
예제 #46
0
 internal InlineTypeInstruction(Int32 offset, OpCode opCode, Int32 token, ITokenResolver resolver)
     : base(offset, opCode)
 {
     this.m_resolver = resolver;
     this.m_token = token;
 }
 public ShortInlineVarInstruction(ITokenResolver resolver, Int32 offset, OpCode opCode, Byte ordinal)
     : base(resolver, offset, opCode)
 {
     this.m_ordinal = ordinal;
 }
예제 #48
0
 internal InlineMethodInstruction(int offset, OpCode opCode, int token, ITokenResolver resolver)
     : base(offset, opCode)
 {
     this.m_resolver = resolver;
       this.m_token = token;
 }
예제 #49
0
            public ILReader(MethodBase method)
            {
                if (method == null)
                {
                    throw new ArgumentNullException("method");
                }

                Type rtType = method.GetType();
                if (rtType != s_runtimeMethodInfoType && rtType != s_runtimeConstructorInfoType)
                {
                    throw new ArgumentException("method must be RuntimeMethodInfo or RuntimeConstructorInfo for this constructor.");
                }

                m_ilProvider = new MethodBaseILProvider(method);
                m_resolver = new ModuleScopeTokenResolver(method);
                InstructionBytes = m_ilProvider.GetByteArray();
                m_position = 0;
            }
예제 #50
0
            public ILReader(IILProvider ilProvider, ITokenResolver tokenResolver)
            {
                if (ilProvider == null)
                {
                    throw new ArgumentNullException("ilProvider");
                }

                m_resolver = tokenResolver;
                m_ilProvider = ilProvider;
                InstructionBytes = m_ilProvider.GetByteArray();
                m_position = 0;
            }
예제 #51
0
 internal Instruction(ITokenResolver resolver, int offsetPosition, OpCode opCode, T value)
     : this(resolver, offsetPosition, opCode)
 {
     InternalValue = value;
 }
 internal InlineFieldInstruction(ITokenResolver resolver, Int32 offset, OpCode opCode, Int32 token)
     : base(offset, opCode)
 {
     m_resolver = resolver;
     m_token = token;
 }
예제 #53
0
 public InlineIInstruction(ITokenResolver resolver, int offsetPosition, OpCode opCode, int value)
     : base(resolver, offsetPosition, opCode, value)
 {
 }
 public InlineI8Instruction(ITokenResolver resolver, Int32 offset, OpCode opCode, Int64 value)
     : base(resolver, offset, opCode)
 {
     this.m_int64 = value;
 }
예제 #55
0
        public static void AddOperand(IList <short> instrs, ITokenResolver resolver, uint offset, OpCode opCode, object operand)
        {
            Instruction target;
            IVariable   variable;

            switch (opCode.OperandType)
            {
            case OperandType.InlineBrTarget:
                target = operand as Instruction;
                if (target == null)
                {
                    instrs.AddUnknownInt32();
                }
                else
                {
                    instrs.AddInt32(unchecked ((int)target.Offset - (int)(offset + 4)));
                }
                break;

            case OperandType.InlineField:
            case OperandType.InlineMethod:
            case OperandType.InlineTok:
            case OperandType.InlineType:
                var tok = operand as ITokenOperand;
                instrs.AddToken(resolver, tok == null ? 0 : tok.MDToken.Raw);
                break;

            case OperandType.InlineSig:
                var msig = operand as MethodSig;
                instrs.AddToken(resolver, msig == null ? 0 : msig.OriginalToken);
                break;

            case OperandType.InlineString:
                instrs.AddUnknownInt32();
                break;

            case OperandType.InlineI:
                if (operand is int)
                {
                    instrs.AddInt32((int)operand);
                }
                else
                {
                    instrs.AddUnknownInt32();
                }
                break;

            case OperandType.InlineI8:
                if (operand is long)
                {
                    instrs.AddInt64((long)operand);
                }
                else
                {
                    instrs.AddUnknownInt64();
                }
                break;

            case OperandType.InlineR:
                if (operand is double)
                {
                    instrs.AddDouble((double)operand);
                }
                else
                {
                    instrs.AddUnknownInt64();
                }
                break;

            case OperandType.ShortInlineR:
                if (operand is float)
                {
                    instrs.AddSingle((float)operand);
                }
                else
                {
                    instrs.AddUnknownInt32();
                }
                break;

            case OperandType.InlineSwitch:
                var targets = operand as IList <Instruction>;
                if (targets == null)
                {
                    instrs.AddUnknownInt32();
                }
                else
                {
                    uint offsetAfter = offset + 4 + (uint)targets.Count * 4;
                    instrs.AddInt32(targets.Count);
                    foreach (var instr in targets)
                    {
                        if (instr == null)
                        {
                            instrs.AddUnknownInt32();
                        }
                        else
                        {
                            instrs.AddInt32(unchecked ((int)instr.Offset - (int)offsetAfter));
                        }
                    }
                }
                break;

            case OperandType.InlineVar:
                variable = operand as IVariable;
                if (variable == null)
                {
                    instrs.AddUnknownInt16();
                }
                else if (ushort.MinValue <= variable.Index && variable.Index <= ushort.MaxValue)
                {
                    instrs.AddInt16(unchecked ((short)variable.Index));
                }
                else
                {
                    instrs.AddUnknownInt16();
                }
                break;

            case OperandType.ShortInlineVar:
                variable = operand as IVariable;
                if (variable == null)
                {
                    instrs.AddUnknownByte();
                }
                else if (byte.MinValue <= variable.Index && variable.Index <= byte.MaxValue)
                {
                    instrs.Add((byte)variable.Index);
                }
                else
                {
                    instrs.AddUnknownByte();
                }
                break;

            case OperandType.ShortInlineBrTarget:
                target = operand as Instruction;
                if (target == null)
                {
                    instrs.AddUnknownByte();
                }
                else
                {
                    int displ = unchecked ((int)target.Offset - (int)(offset + 1));
                    if (sbyte.MinValue <= displ && displ <= sbyte.MaxValue)
                    {
                        instrs.Add((short)(displ & 0xFF));
                    }
                    else
                    {
                        instrs.AddUnknownByte();
                    }
                }
                break;

            case OperandType.ShortInlineI:
                if (operand is sbyte)
                {
                    instrs.Add((short)((sbyte)operand & 0xFF));
                }
                else if (operand is byte)
                {
                    instrs.Add((short)((byte)operand & 0xFF));
                }
                else
                {
                    instrs.AddUnknownByte();
                }
                break;

            case OperandType.InlineNone:
            case OperandType.InlinePhi:
                break;

            default:
                throw new InvalidOperationException();
            }
        }
 internal ILInstruction(ITokenResolver resolver, Int32 offset, OpCode opCode)
 {
     this.m_resolver = resolver;
     this.m_offset = offset;
     this.m_opCode = opCode;
 }
예제 #57
0
 internal InlineSigInstruction(Int32 offset, OpCode opCode, Int32 token, ITokenResolver resolver)
     : base(offset, opCode)
 {
     m_resolver = resolver;
     m_token    = token;
 }
		public ModifiedInstructionBytesReader(MethodDef method) {
			resolver = method.Module;
			instrs = method.Body.Instructions;
		}