Disassemble() 공개 메소드

public Disassemble ( ) : TUP.AsmResolver.NET.Specialized.MSIL.MSILInstruction[]
리턴 TUP.AsmResolver.NET.Specialized.MSIL.MSILInstruction[]
예제 #1
0
        public MethodBodyDlg(MethodBody body)
        {
            InitializeComponent();
            textBox1.Text = body.IsFat.ToString();
            textBox2.Text = body.HeaderSize.ToString("X8");
            textBox3.Text = body.CodeSize.ToString("X8");
            textBox4.Text = body.MaxStack.ToString("X4");
            textBox5.Text = body.InitLocals.ToString();
            textBox6.Text = body.LocalVarSig.ToString("X8");

            disassembler = new MSILDisassembler(body);
            assembler = new MSILAssembler(body);

            MSILInstruction[] instructions = disassembler.Disassemble();
            foreach (MSILInstruction instruction in instructions)
            {
                listView1.Items.Add(CreateItem(instruction));

            }

            if (body.Variables != null)
            {
                foreach (VariableDefinition variable in body.Variables)
                    listView2.Items.Add(new ListViewItem(new string[] { variable.Index.ToString(), variable.VariableType.ToString() }));
            }
            if (body.HasExtraSections)
            {
                foreach (MethodBodySection section in body.ExtraSections)
                {
                    foreach (ExceptionHandler handler in section.ExceptionHandlers)
                        listView3.Items.Add(new ListViewItem(new string[] { handler.Type.ToString(), handler.TryStart.ToString("X4"), handler.TryEnd.ToString("X4"), handler.HandlerStart.ToString("X4"), handler.HandlerEnd.ToString("X4") , handler.CatchType != null ? handler.CatchType.FullName : ""}));
                }
            }
        }
예제 #2
0
파일: MethodDlg.cs 프로젝트: Rex-Hays/GNIDA
        public MethodDlg(MethodBody body)
        {
            InitializeComponent();
            this.body = body;
            this.propertyGrid1.SelectedObject = body;
            this.disassembler = new MSILDisassembler(body);
            this.Text = "Method Body of " + body.Method.MetaDataToken.ToString("X8");

            try
            {
                this.Text += " (" + body.Method.ToString() + ")";
            }
            catch
            {
                this.Text += " (method.ToString() failed)";
            }

            MSILInstruction[] instructions = disassembler.Disassemble();
            foreach (MSILInstruction instruction in instructions)
            {
                ListViewItem item = new ListViewItem(new string[] {
                    "IL_" + instruction.Offset.ToString("X4"),
                    BytesToString(instruction.OpCode.Bytes) + " " + BytesToString(instruction.OperandBytes),
                    instruction.OpCode.Name,
                    instruction.GetOperandString(),});
                listView1.Items.Add(item);
            }

            if (body.Variables != null && body.Variables.Length > 0)
            {
                foreach (VariableDefinition variable in body.Variables)
                    listView2.Items.Add(new ListViewItem(new string[] {
                    variable.Index.ToString(),
                    variable.VariableType.FullName,
                }));
            }
            if (body.HasExtraSections)
            {
                foreach (MethodBodySection section in body.ExtraSections)
                    if (section.IsExceptionHandler && section.ExceptionHandlers.Length > 0)
                        foreach (ExceptionHandler handler in section.ExceptionHandlers)
                            listView3.Items.Add(new ListViewItem(new string[] {
                                handler.Type == ExceptionHandlerType.Catch ? "Catch -> " + handler.CatchType.FullName : handler.Type.ToString(),
                                handler.TryStart.ToString("X4"),
                                handler.TryEnd.ToString("X4"),
                                handler.HandlerStart.ToString("X4"),
                                handler.HandlerEnd.ToString("X4"),
                                handler.FilterStart.ToString("X4")
                            }));
            }
        }
예제 #3
0
 public MSILInstruction[] Disassemble()
 {
     MSILDisassembler disassembler = new MSILDisassembler(this);
     return disassembler.Disassemble();
 }
        private void SearchAsync()
        {
            List<ListViewItem> items = new List<ListViewItem>();

            NETHeader netHeader = currentAssembly.NETHeader;

            MetaDataTable methodTable = netHeader.TablesHeap.GetTable(MetaDataTableType.Method);

            foreach (MetaDataMember member in methodTable.Members)
            {
                MethodDefinition methodDef = member as MethodDefinition;

                string methodName;
                string fullName;
                try
                {
                    methodName = methodDef.Name;
                }
                catch
                {
                    methodName = string.Empty;
                }
                try
                {
                    fullName = methodDef.FullName;
                }
                catch
                {
                    fullName = string.Empty;
                }

                Invoke(new Action<string, double,double>(ProcessCallBack), "Scanning " + (fullName == string.Empty ? methodDef.MetaDataToken.ToString("X8") : fullName), member.MetaDataToken - ((int)member.TableType << 24), methodTable.Members.Count);
                if (methodDef.HasBody)
                {
                    try
                    {
                        MSILDisassembler disassembler = new MSILDisassembler(methodDef.Body);
                        MSILInstruction[] instructions = disassembler.Disassemble();

                        foreach (MSILInstruction instruction in instructions)
                        {
                            if (instruction.OpCode.Code == MSILCode.Ldstr)
                            {
                                string value = instruction.Operand as string;
                                items.Add(new ListViewItem(new string[] {
                                    value,
                                    "IL_" + instruction.Offset.ToString("X4"),
                                    methodDef.MetaDataToken.ToString("X8"),
                                    methodName,
                                    fullName,
                                }) { Tag = methodDef });
                            }
                        }
                    }
                    catch
                    {
                        // handle
                    }
                }

            }

            Invoke(new Action<List<ListViewItem>>(SearchCallBack), items);
        }