Example #1
0
 //public MyMethodInfo() { }
 public MyMethodInfo(MethodInfo method)
 {
     ILCodes = method.GetMethodBody().GetILAsByteArray();
     ILInstruct ILTemp = new ILInstruct();
 }
Example #2
0
        public void ILBytestoILCode(Module module, Byte[] ILCode)
        {
            int operandvalue = 0;
            int index        = 0;

            m_ILInstructs = new List <ILInstruct>();
            //ilcode 구성 : 첫 바이트는 opcode 종류.
            //              opcode.operandtype에 따라 다음 오퍼랜드 길이가 정해진다.

            ILInstruct ilTemp;

            for (index = 0; index < ILCode.Length - 1;)
            {
                ilTemp       = new ILInstruct();
                operandvalue = 0;

                OpCode opcode = OpCodes.Nop;
                ushort value  = ILCode[index++];

                // ilcode가 일 경우
                if (value != 0xfe)
                {
                    opcode = GlobalStatic.m_SingleOpcodes[(int)value];
                }
                else
                {
                    value  = ILCode[index++];
                    opcode = GlobalStatic.m_MultiOpcodes[(int)value];
                    value  = (ushort)(value | 0xfe00);
                }
                ilTemp.Opcode  = opcode;
                ilTemp.Operand = 0;
                ilTemp.Offset  = index - 1;
                //string 빼고 다 확인 필요
                switch (opcode.OperandType)
                {
                case OperandType.InlineBrTarget:      //점프 주소가 와야할듯 해당 명령어 확인필요
                    operandvalue = BytesTo32Bit(ref index);
                    //ilTemp.Operand = module.ResolveString(operandvalue);
                    break;

                case OperandType.InlineField:
                    operandvalue   = BytesTo32Bit(ref index);
                    ilTemp.Operand = operandvalue;
                    break;

                case OperandType.InlineI:
                    operandvalue   = BytesTo32Bit(ref index);
                    ilTemp.Operand = operandvalue;
                    break;

                case OperandType.InlineI8:
                    ilTemp.Operand = BytesTo64Bit(ref index);
                    break;

                case OperandType.InlineMethod:
                    operandvalue   = BytesTo32Bit(ref index);
                    ilTemp.Operand = module.ResolveMethod(operandvalue);
                    break;

                case OperandType.InlineNone:
                    ilTemp.Operand = null;
                    break;

                //case OperandType.InlinePhi: break;
                case OperandType.InlineR:       //IEEE floating point number - double
                    ilTemp.Operand = BytesToDouble(ref index);
                    break;

                case OperandType.InlineSig:
                    operandvalue   = BytesTo32Bit(ref index);
                    ilTemp.Operand = module.ResolveSignature(operandvalue);
                    break;

                case OperandType.InlineString:
                    operandvalue   = BytesTo32Bit(ref index);
                    ilTemp.Operand = module.ResolveString(operandvalue);
                    break;

                case OperandType.InlineSwitch:
                    ilTemp.Operand = BytesTo32Bit(ref index);
                    break;

                case OperandType.InlineTok:
                    operandvalue   = BytesTo32Bit(ref index);
                    ilTemp.Operand = module.ResolveSignature(operandvalue);
                    break;

                case OperandType.InlineType:
                    operandvalue   = BytesTo32Bit(ref index);
                    ilTemp.Operand = operandvalue;
                    break;

                case OperandType.InlineVar:
                    operandvalue   = BytesTo16Bit(ref index);
                    ilTemp.Operand = operandvalue;
                    break;

                case OperandType.ShortInlineBrTarget:
                    operandvalue   = ByteTo8Bit(ref index);
                    ilTemp.Operand = operandvalue;
                    break;

                case OperandType.ShortInlineI:
                    operandvalue   = ByteTo8Bit(ref index);
                    ilTemp.Operand = operandvalue;
                    break;

                case OperandType.ShortInlineR:
                    operandvalue   = BytesTo32Bit(ref index);
                    ilTemp.Operand = operandvalue;
                    break;

                case OperandType.ShortInlineVar:
                    operandvalue   = ByteTo8Bit(ref index);
                    ilTemp.Operand = operandvalue;
                    break;

                default: break;
                }
                m_ILInstructs.Add(ilTemp);
            }
        }