private void StateLoadLocalVariables(IBinaryAccessor accessor, Module module)
        {
            int count = accessor.Read7BitEncodedInt();

            _localVariables = new List <TypeSignature>(count);

            for (int i = 0; i < count; i++)
            {
                int token = accessor.ReadInt32();
                _localVariables.Add(module.GetSignature <TypeSignature>(token));
            }
        }
        private void StateLoadExceptionHandler(IBinaryAccessor accessor, Module module)
        {
            var handler = new ExceptionHandler();

            handler.Type          = (ExceptionHandlerType)accessor.ReadInt32();
            handler.TryOffset     = accessor.ReadInt32();
            handler.TryLength     = accessor.ReadInt32();
            handler.HandlerOffset = accessor.ReadInt32();
            handler.HandlerLength = accessor.ReadInt32();
            handler.FilterOffset  = accessor.ReadInt32();

            int catchToken = accessor.ReadInt32();

            handler.CatchType = module.GetSignature <TypeSignature>(catchToken);

            _exceptionHandlers.Add(handler);
        }
        private void StateLoadInstructions(IBinaryAccessor accessor, Module module)
        {
            int instructionCount = accessor.Read7BitEncodedInt();

            _instructions = new List <Instruction>(instructionCount);

            for (int i = 0; i < instructionCount; i++)
            {
                OpCode opCode;
                byte   opByte = accessor.ReadByte();
                if (opByte == 0xFE)
                {
                    opByte = accessor.ReadByte();
                    opCode = OpCodes.OpCodeArray[256 + opByte];
                }
                else
                {
                    opCode = OpCodes.OpCodeArray[opByte];
                }

                object value;
                switch (opCode.OperandType)
                {
                case OperandType.InlineBrTarget:
                {
                    value = accessor.ReadInt32();
                }
                break;

                case OperandType.InlineField:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineI:
                {
                    value = accessor.ReadInt32();
                }
                break;

                case OperandType.InlineI8:
                {
                    value = accessor.ReadInt64();
                }
                break;

                case OperandType.InlineMethod:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineR:
                {
                    value = accessor.ReadDouble();
                }
                break;

                case OperandType.InlineSig:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineString:
                {
                    // Token of a userdefined string, whose RID portion is actually an offset in the #US blob stream.
                    value = accessor.ReadLengthPrefixedString(Encoding.Unicode);
                }
                break;

                case OperandType.InlineSwitch:
                {
                    int   count   = accessor.ReadInt32();
                    int[] targets = new int[count];
                    for (int j = 0; j < count; j++)
                    {
                        targets[j] = accessor.ReadInt32();
                    }

                    value = targets;
                }
                break;

                case OperandType.InlineTok:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineType:
                {
                    int token = accessor.ReadInt32();
                    value = module.GetSignature <Signature>(token);
                }
                break;

                case OperandType.InlineVar:
                {
                    value = accessor.ReadInt16();
                }
                break;

                case OperandType.ShortInlineBrTarget:
                {
                    value = accessor.ReadSByte();
                }
                break;

                case OperandType.ShortInlineI:
                {
                    value = accessor.ReadByte();
                }
                break;

                case OperandType.ShortInlineR:
                {
                    value = accessor.ReadSingle();
                }
                break;

                case OperandType.ShortInlineVar:
                {
                    value = accessor.ReadByte();
                }
                break;

                default:
                {
                    value = null;
                }
                break;
                }

                _instructions.Add(new Instruction(opCode, value));
            }
        }