Beispiel #1
0
        private void DASMTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeView     temp = (TreeView)sender;
            MethodInfo   mtemp;
            ILCodeReader reader;

            if (e.Node.Tag != null)
            {
                mtemp  = AssemblyInfo.m_methods.ElementAt((int)e.Node.Tag);
                reader = new ILCodeReader(AssemblyInfo.modules[1], mtemp.GetMethodBody().GetILAsByteArray());
                this.richTextBox.Text = "";
                string str;
                foreach (ILInstruct item in reader.m_ILInstructs)
                {
                    str = mtemp.Name + "_" + item.Offset + " : " + item.Opcode;
                    if (item.Operand != null)
                    {
                        str += ", operand: " + item.Operand.ToString();
                    }
                    str += "\n";

                    this.richTextBox.Text += str;
                }
            }
            else
            {
                this.richTextBox.Text += "함수 본문을 찾을 수 없음";
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            GlobalStatic.LoadOpcode();

            Assembly asm = Assembly.LoadFile(@"C:\HJM\bitAPI\c#\CSharp\SunCraft\bin\Debug\SunCraft.exe");
            // 메소드 내용 있는거 저장용
            List <MethodInfo> limethod = new List <MethodInfo>();

            Console.WriteLine(asm.Location);
            Module[] Modules = asm.GetModules();
            #region 메소드 불러오기
            foreach (Module item in Modules)
            {
                Console.WriteLine("-" + item.ToString());
                Type[] types = item.GetTypes();
                foreach (Type Class in types)
                {
                    Console.WriteLine("======");
                    Console.WriteLine("--" + Class.ToString());

                    #region 클래스 내부 모든 멤버들
                    //MemberInfo[] members= Class.GetMembers(BindingFlags.NonPublic | BindingFlags.Public);
                    //foreach (MemberInfo member in members)
                    //{
                    //    //Console.WriteLine("---[member]:" + member.Name);
                    //}
                    #endregion

                    MethodInfo[] methods = Class.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                    foreach (MethodInfo method in methods)
                    {
                        limethod.Add(method);

                        Console.Write("---[method]:" + method.Name);
                        #region  라미터
                        //ParameterInfo[] parameters = method.GetParameters();

                        //foreach (ParameterInfo parameter in parameters)
                        //{
                        //    Console.Write(parameter.Name+",");

                        //}
                        //Console.WriteLine("");
                        #endregion
                    }
                    FieldInfo[] fields = Class.GetFields();
                    foreach (FieldInfo field in fields)
                    {
                        //Console.WriteLine("---[field]:" + field.Name);
                    }
                }
            }
            #endregion


            ILCodeReader reader;
            foreach (MethodInfo method in limethod)
            {
                List <OpCode> codes    = new List <OpCode>();
                int           position = 0;

                Console.WriteLine(method.Name + "code");
                //코드 보기
                if (method.GetMethodBody() == null)
                {
                    continue;
                }
                byte[] ilcodes = method.GetMethodBody().GetILAsByteArray();

                reader = new ILCodeReader(Modules[0], ilcodes);

                foreach (ILInstruct ilin in reader.m_ILInstructs)
                {
                    Console.Write(ilin.Opcode.Name);
                    if (ilin.Operand != null)
                    {
                        Console.WriteLine(", operand: " + ilin.Operand.ToString());
                    }
                    else
                    {
                        Console.WriteLine("");
                    }
                }

                /*
                 * int a;
                 * string str;
                 * for (position = 0; position < ilcodes.Length - 1; )
                 * {
                 *  a = 0;
                 *  str = null;
                 *  OpCode opcode = OpCodes.Nop;
                 *  ushort value = ilcodes[position++];
                 *
                 *  if (value != 0xfe)
                 *  {
                 *      opcode = Globals.singleByteOpCodes[(int)value];
                 *  }
                 *  else
                 *  {
                 *      value = ilcodes[position++];
                 *      opcode = Globals.multiByteOpCodes[(int)value];
                 *      value = (ushort)(value | 0xfe00);
                 *  }
                 *  Console.WriteLine("IL_" + position + ":" + value + ":" + opcode.Name);
                 *  codes.Add(opcode);
                 *
                 *  if (opcode.OperandType == OperandType.InlineString)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *      str = Modules[0].ResolveString(a);
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineBrTarget)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineField)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineI)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineI8)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineMethod)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineNone)
                 *  {
                 *      a = 0;
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineR)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineSig)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineSwitch)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineTok)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineType)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *  }
                 *  else if (opcode.OperandType == OperandType.InlineVar)
                 *  {
                 *      a = (ilcodes[position++] | (ilcodes[position++] << 8));
                 *  }
                 *  else if (opcode.OperandType == OperandType.ShortInlineBrTarget)
                 *  {
                 *      a = ilcodes[position++];
                 *  }
                 *  else if (opcode.OperandType == OperandType.ShortInlineI)
                 *  {
                 *      a = ilcodes[position++];
                 *  }
                 *  else if (opcode.OperandType == OperandType.ShortInlineR)
                 *  {
                 *      a = (((ilcodes[position++] | (ilcodes[position++] << 8)) |
                 *      (ilcodes[position++] << 0x10)) | (ilcodes[position++] << 0x18));
                 *  }
                 *  else if (opcode.OperandType == OperandType.ShortInlineVar)
                 *  {
                 *      a = ilcodes[position++];
                 *  }
                 *  Console.WriteLine("operand: " + str);
                 * }
                 * Console.WriteLine("\n");
                 */
            }
        }