Beispiel #1
0
        public List <IlInstruction> ReadInstructions(MethodBase method)
        {
            ilInstructions     = new List <IlInstruction>();
            this.currentMethod = method;

            var body = method.GetMethodBody();

            parameters = method.GetParameters();
            if (body == null)
            {
                return(ilInstructions);
            }
            locals       = body.LocalVariables;
            instructions = method.GetMethodBody().GetILAsByteArray();
            var str = new ByteStream(instructions, instructions.Length);

            stream = new BinaryReader(str);

            if (!(typeof(ConstructorInfo).IsAssignableFrom(method.GetType())))
            {
                methodArgs = method.GetGenericArguments();
            }

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

            IlInstruction instruction = null;

            while (stream.BaseStream.Position < stream.BaseStream.Length)
            {
                instruction = new IlInstruction();
                bool   isDoubleByte = false;
                OpCode code         = ReadOpCode(ref isDoubleByte);
                instruction.OpCode = code;
                instruction.Offset = stream.BaseStream.Position - 1;
                if (isDoubleByte)
                {
                    instruction.Offset--;
                }
                instruction.Operand = ReadOperand(code, method.Module, ref instruction.LocalVariableIndex);
                ilInstructions.Add(instruction);
            }

            return(ilInstructions);
        }
Beispiel #2
0
        public List<IlInstruction> ReadInstructions(MethodBase method)
        {
            ilInstructions = new List<IlInstruction>();
            this.currentMethod = method;

            var body = method.GetMethodBody();
            parameters = method.GetParameters();
            if (body == null)
                return ilInstructions;
            locals = body.LocalVariables;
            instructions = method.GetMethodBody().GetILAsByteArray();
            var str = new ByteStream(instructions, instructions.Length);
            stream = new BinaryReader(str);

            if (!(typeof(ConstructorInfo).IsAssignableFrom(method.GetType())))
                methodArgs = method.GetGenericArguments();

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

            IlInstruction instruction = null;

            while (stream.BaseStream.Position < stream.BaseStream.Length)
            {
                instruction = new IlInstruction();
                bool isDoubleByte = false;
                OpCode code = ReadOpCode(ref isDoubleByte);
                instruction.OpCode = code;
                instruction.Offset = stream.BaseStream.Position-1;
                if (isDoubleByte)
                {
                    instruction.Offset--;
                }
                instruction.Operand = ReadOperand(code, method.Module,ref instruction.LocalVariableIndex);
                ilInstructions.Add(instruction);
            }

            return ilInstructions;
        }