Example #1
0
            /// <summary>
            ///     Read <see cref="string" /> reference from module.
            /// </summary>
            /// <returns><see cref="string" /> referenced.</returns>
            private (string String, int Token) ReadString()
            {
                int token = ReadInt32();

                if (_resolver == null)
                {
                    return(null, token);
                }

                return(_resolver.ResolveString(token), token);
            }
Example #2
0
        void ReadOperand(Instruction instruction)
        {
            switch (instruction.OpCode.OperandType)
            {
            case OperandType.InlineNone:
                break;

            case OperandType.InlineSwitch:
                int   length      = il.ReadInt32();
                int   base_offset = il.position + (4 * length);
                int[] branches    = new int[length];
                for (int i = 0; i < length; i++)
                {
                    branches[i] = il.ReadInt32() + base_offset;
                }

                instruction.Operand = branches;
                break;

            case OperandType.ShortInlineBrTarget:
                instruction.Operand = (sbyte)(((sbyte)il.ReadByte()) + il.position);
                break;

            case OperandType.InlineBrTarget:
                instruction.Operand = il.ReadInt32() + il.position;
                break;

            case OperandType.ShortInlineI:
                if (instruction.OpCode == OpCodes.Ldc_I4_S)
                {
                    instruction.Operand = (sbyte)il.ReadByte();
                }
                else
                {
                    instruction.Operand = il.ReadByte();
                }
                break;

            case OperandType.InlineI:
                instruction.Operand = il.ReadInt32();
                break;

            case OperandType.ShortInlineR:
                instruction.Operand = il.ReadSingle();
                break;

            case OperandType.InlineR:
                instruction.Operand = il.ReadDouble();
                break;

            case OperandType.InlineI8:
                instruction.Operand = il.ReadInt64();
                break;

            case OperandType.InlineSig:
                //wicky.patch.start
                //instruction.Operand = module.ResolveSignature(il.ReadInt32());
                instruction.Operand = tokenResolver.ResolveSignature(il.ReadInt32());
                //wicky.patch.end
                break;

            case OperandType.InlineString:
                //wicky.patch.start
                //instruction.Operand = module.ResolveString(il.ReadInt32());
                instruction.Operand = tokenResolver.ResolveString(il.ReadInt32());
                //wicky.patch.end
                break;

            //wicky.patch.start

            /*
             * case OperandType.InlineTok:
             * case OperandType.InlineType:
             * case OperandType.InlineMethod:
             * case OperandType.InlineField:
             * instruction.Operand = module.ResolveMember(il.ReadInt32(), type_arguments, method_arguments);
             * break;
             */
            case OperandType.InlineTok:
                instruction.Operand = tokenResolver.ResolveMember(il.ReadInt32());
                break;

            case OperandType.InlineType:
                instruction.Operand = tokenResolver.ResolveType(il.ReadInt32());
                break;

            case OperandType.InlineMethod:
                instruction.Operand = tokenResolver.ResolveMethod(il.ReadInt32());
                break;

            case OperandType.InlineField:
                instruction.Operand = tokenResolver.ResolveField(il.ReadInt32());
                break;

            //wicky.patch.end
            case OperandType.ShortInlineVar:
                instruction.Operand = GetVariable(instruction, il.ReadByte());
                break;

            case OperandType.InlineVar:
                instruction.Operand = GetVariable(instruction, il.ReadInt16());
                break;

            default:
                throw new NotSupportedException();
            }
        }