Beispiel #1
0
        public static void MarkBlocks(DataGridView dgView)
        {
            if (dgView == null || dgView.ColumnCount == 0 || dgView.RowCount == 0)
            {
                return;
            }

            List <InstructionBlock> list = InstructionBlock.Find(MainForm.CurrentAssembly.Method);

            bool changeColor = false;

            foreach (InstructionBlock ib in list)
            {
                if (changeColor)
                {
                    for (int i = ib.StartIndex; i <= ib.EndIndex; i++)
                    {
                        dgView.Rows[i].DefaultCellStyle.BackColor = DefaultColors.RowBlockColor;
                    }
                }
                changeColor = !changeColor;
            }
        }
        public static List<InstructionBlock> Find(MethodDef method)
        {
            var list = new List<InstructionBlock>();

            if (method == null || !method.HasBody)
                return list;

            IList<Instruction> instructions = method.Body.Instructions;
            if (instructions.Count < 1)
                return list;

            int firstIndex = 0;
            int lastIndex = firstIndex;

            Instruction insLast = instructions[lastIndex];
            while (lastIndex < instructions.Count)
            {
                if (IsBlockDelimiter(insLast) || lastIndex + 1 >= instructions.Count)
                {
                    var instructionBlock = new InstructionBlock(firstIndex, lastIndex);
                    list.Add(instructionBlock);

                    firstIndex = lastIndex + 1;
                    lastIndex = firstIndex;
                }
                else
                {
                    lastIndex++;
                }
                if (lastIndex >= instructions.Count)
                    break;
                insLast = instructions[lastIndex];
            }

            int insCount = 0;
            foreach (InstructionBlock firstBlock in list)
            {
                insCount += firstBlock.EndIndex - firstBlock.StartIndex + 1;

                Instruction insTo = null;
                if (instructions[firstBlock.EndIndex].Operand is Instruction)
                {
                    insTo = instructions[firstBlock.EndIndex].Operand as Instruction;
                }
                if (insTo != null)
                {
                    int to = instructions.IndexOf(insTo);
                    foreach (InstructionBlock nextBlock in list)
                    {
                        if (nextBlock.StartIndex == firstBlock.StartIndex)
                            continue;
                        if (nextBlock.StartIndex <= to && to <= nextBlock.EndIndex)
                        {
                            firstBlock.NextBlock = nextBlock;

                            if (firstBlock.StartIndex < nextBlock.StartIndex)
                                nextBlock.JumpDownRefCount++;
                            else
                                nextBlock.JumpUpRefCount++;
                        }
                    }
                }
            }

            if (insCount != instructions.Count)
            {
                throw new ApplicationException("Internal error in InstructionBlock.Find !");
            }

            return list;
        }
Beispiel #3
0
        public static List <InstructionBlock> Find(MethodDef method)
        {
            var list = new List <InstructionBlock>();

            if (method == null || !method.HasBody)
            {
                return(list);
            }

            IList <Instruction> instructions = method.Body.Instructions;

            if (instructions.Count < 1)
            {
                return(list);
            }

            int firstIndex = 0;
            int lastIndex  = firstIndex;

            Instruction insLast = instructions[lastIndex];

            while (lastIndex < instructions.Count)
            {
                if (IsBlockDelimiter(insLast) || lastIndex + 1 >= instructions.Count)
                {
                    var instructionBlock = new InstructionBlock(firstIndex, lastIndex);
                    list.Add(instructionBlock);

                    firstIndex = lastIndex + 1;
                    lastIndex  = firstIndex;
                }
                else
                {
                    lastIndex++;
                }
                if (lastIndex >= instructions.Count)
                {
                    break;
                }
                insLast = instructions[lastIndex];
            }

            int insCount = 0;

            foreach (InstructionBlock firstBlock in list)
            {
                insCount += firstBlock.EndIndex - firstBlock.StartIndex + 1;

                Instruction insTo = null;
                if (instructions[firstBlock.EndIndex].Operand is Instruction)
                {
                    insTo = instructions[firstBlock.EndIndex].Operand as Instruction;
                }
                if (insTo != null)
                {
                    int to = instructions.IndexOf(insTo);
                    foreach (InstructionBlock nextBlock in list)
                    {
                        if (nextBlock.StartIndex == firstBlock.StartIndex)
                        {
                            continue;
                        }
                        if (nextBlock.StartIndex <= to && to <= nextBlock.EndIndex)
                        {
                            firstBlock.NextBlock = nextBlock;

                            if (firstBlock.StartIndex < nextBlock.StartIndex)
                            {
                                nextBlock.JumpDownRefCount++;
                            }
                            else
                            {
                                nextBlock.JumpUpRefCount++;
                            }
                        }
                    }
                }
            }

            if (insCount != instructions.Count)
            {
                throw new ApplicationException("Internal error in InstructionBlock.Find !");
            }

            return(list);
        }