Ejemplo n.º 1
0
        //converts a memory address to listbox line number
        private int addressToLine(uint address)
        {
            int result = -1;

            for (int i = 0; i < _codeViewList.Items.Count; i++)
            {
                ListLine lst = (ListLine)(_codeViewList.Items[i]);
                if (lst.Address == address)
                {
                    result = i;
                }
                else if (lst.Address > address && result >= 0)
                {
                    break;
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 响应分割矩形
        /// </summary>
        void PartRect_Click(object sender, EventArgs e)
        {
            Rect selectedRect = ListRect.GetSelectedRects()[0];
            ///触发事件的执行
            PartRectEventArgs partRectArgs = new PartRectEventArgs(selectedRect);

            TDPanel.OnPartRect(partRectArgs);

            if (!partRectArgs.Cancel)
            {
                ///生成新的被分割的矩形
                List <Rect>          newRects = ListRect.PartRect(selectedRect, partRectArgs.IsRow, partRectArgs.PartNum);
                List <PartitionLine> newLines = ListLine.PartRect(selectedRect, partRectArgs.IsRow, partRectArgs.PartNum);

                PartRectCommand partrectCommand = new PartRectCommand(TDPanel, partRectArgs.IsRow, newRects, selectedRect, newLines);
                partrectCommand.Execute();
                TDPanel.CommandList.AddCommand(partrectCommand);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 双击事件之响应代码
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            this.Select();///获取焦点
            if (DrawType == EnumDrawType.MouseSelect ||
                DrawType == EnumDrawType.MouseSelectRect)
            {
                List <Rect>          selectedRects    = ListRect.GetSelectedRects();
                List <PartitionLine> selectedLines    = ListLine.GetSelectedLines();
                List <Rect>          curSelectedRects = new List <Rect>();

                FirstRealPoint = BacktrackMouse(e);
                ///遍历整个rectlist
                foreach (Rect rect in this.ListRect.SnipRectList)
                {
                    if ((!rect.IsDeleted) && rect.IsSelectable(FirstRealPoint))
                    {
                        if ((!rect.IsSelected) || selectedRects.Count > 1)
                        //未被选择,或者如果已经被选择,且有其他矩形被选择,则先激发其他更改选择矩形的命令
                        {
                            curSelectedRects.Add(rect);
                            SelectCommand selectRectCommand = new SelectCommand(TDPanel,
                                                                                curSelectedRects,
                                                                                selectedRects,
                                                                                new List <PartitionLine>(),
                                                                                selectedLines);

                            selectRectCommand.Execute();
                            CommandList.AddCommand(selectRectCommand);
                        }
                        ///弹出属性对话框以查看和修改
                        ChangeSnipPerperty((SnipRect)rect);
                        break;
                    }
                }
            }

            base.OnMouseDoubleClick(e);
        }
Ejemplo n.º 4
0
        protected ListLine analyzeLine(ArmAssembly.ObjFromAsmFileInfo pi, int x, ref ArmAssembly.SectionType sect)
        {
            string s = pi.SourceLines[x];

            if (s == null)
            {
                s = "";
            }
            uint     offsetInFile = pi.Offsets[x];
            string   hexcontents  = pi.HexContent[x];
            ListLine result       = null;
            int      i            = 0;

            while (i < s.Length && Char.IsWhiteSpace(s[i]))
            {
                i++;
            }
            if (i >= s.Length || s[i] == '@' || (!Char.IsLetterOrDigit(s[i]) && s[i] != '.'))
            {
                return(makeResult(s, offsetInFile, hexcontents, sect, pi));
            }

            // it's a label, or opcode, or directive
            int start = i;

            while (i < s.Length && (Char.IsLetterOrDigit(s[i]) || s[i] == '.'))
            {
                i++;
            }
            int length = i - start;

            // skip any white space
            while (i < s.Length && Char.IsWhiteSpace(s[i]))
            {
                i++;
            }
            // if it was a label, or not a directive, nothing to do
            if (i < s.Length && s[i] == ':' || s[start] != '.')
            {
                return(makeResult(s, offsetInFile, hexcontents, sect, pi));
            }

            string directive = s.Substring(start, length).ToLower();

            switch (directive)
            {
            case ".text":
            case ".data":
            case ".rodata":
            case ".rodata.str1.4":
            case ".bss":
                sect = handleSect(directive);
                break;

            case ".section":
                while (i < s.Length && Char.IsWhiteSpace(s[i]))
                {
                    i++;
                }
                if (i >= s.Length)
                {
                    return(result);
                }
                start = i;
                while (i < s.Length && (Char.IsLetterOrDigit(s[i]) || s[i] == '.'))
                {
                    i++;
                }
                length = i - start;
                sect   = handleSect(s.Substring(start, length));
                break;

            default:
                break;
            }
            return(makeResult(s, offsetInFile, hexcontents, sect, pi));
        }
Ejemplo n.º 5
0
        private bool createLines()
        {
            if (linesCreated.HasValue)
            {
                return((bool)linesCreated);
            }
            linesCreated = false; // temporary result until work completed

            ArmAssembly.AssembledProgram ap = JM.AssembledProgram;
            if (ap == null)
            {
                return(false);             // added by NH: 10-04-2015
            }
            _codeViewList.SuspendLayout();
            _codeViewList.Items.Clear();
            Errors = false;

            // it is an object code or executable file

            ArmAssembly.ObjFromAsmFileInfo pi = _PI as ArmAssembly.ObjFromAsmFileInfo;
            if (pi != null)
            {
                ArmAssembly.SectionType sect = ArmAssembly.SectionType.Text;
                for (int i = 0; i < pi.SourceLines.Length; i++)
                {
                    ListLine newLine = analyzeLine(pi, i, ref sect);
                    _codeViewList.Items.Add(newLine);
                }
            }
            else
            {
                uint textAddress = (uint)(_PI.SectionAddress[(int)(ArmAssembly.SectionType.Text)]);
                uint dataAddress = (uint)(_PI.SectionAddress[(int)(ArmAssembly.SectionType.Data)]);
                uint bssAddress  = (uint)(_PI.SectionAddress[(int)(ArmAssembly.SectionType.Bss)]);

                // get sorted list of code labels to intersperse in the code listing
                AddressLabelPair[] cl;
                int clLen;
                if (JM.CodeLabels == null)
                {
                    cl    = null;
                    clLen = 0;
                }
                else
                {
                    cl    = JM.CodeLabels.CodeLabelList();
                    clLen = cl.Length;
                }
                ArmAssembly.DisassembleARM.CurrentLabels = cl;
                int clix = 0;
                while (clix < clLen && cl[clix].Address < textAddress)
                {
                    clix++;
                }
                uint addrss     = textAddress;
                uint endAddress = (uint)(textAddress + _PI.SectionSize[(int)(ArmAssembly.SectionType.Text)]);
                while (addrss < endAddress)
                {
                    while (clix < clLen && cl[clix].Address <= addrss)
                    {
                        _codeViewList.Items.Add(
                            new ListLine(_drawParameters, cl[clix].Label + ":", cl[clix].Address, this));
                        clix++;
                    }
                    string contents;
                    uint   opcode;
                    if (ap != null)
                    {
                        opcode   = ap.LoadWord((int)addrss);
                        contents = "    " + ArmAssembly.DisassembleARM.DisassembleARMInstruction(opcode, addrss);
                    }
                    else
                    {
                        opcode   = 0;
                        contents = "     <<disassembly not available>>";
                    }
                    _codeViewList.Items.Add(new ObjectCodeLine(_drawParameters, addrss, opcode, contents, this));
                    addrss += 4;
                }
                while (clix < clLen && cl[clix].Address < dataAddress)
                {
                    clix++;
                }
                addrss     = dataAddress;
                endAddress = (uint)(dataAddress + _PI.SectionSize[(int)(ArmAssembly.SectionType.Data)]);
                // Generate labels for the defined data area.  We display up to 16 bytes per line.
                while (addrss < endAddress)
                {
                    string hex;
                    uint   nextLabel      = clix < clLen ? cl[clix].Address : (uint)ap.BssStart;
                    int    bytesToDisplay = (int)nextLabel - (int)addrss;
                    if ((addrss & 0x3) != 0)
                    {
                        int oddBytes = 4 - (int)(addrss & 0x3);
                        if (oddBytes > bytesToDisplay)
                        {
                            oddBytes = bytesToDisplay;
                        }
                        hex = convertBytes(oddBytes, addrss);
                        _codeViewList.Items.Add(
                            new ObjectCodeLine(_drawParameters, addrss, ".byte", hex, this));
                        bytesToDisplay -= oddBytes;
                        addrss         += (uint)oddBytes;
                    }
                    while (bytesToDisplay >= 16)
                    {
                        hex = String.Format(
                            "0x{0,8:X8}, 0x{1,8:X8}, 0x{2,8:X8}, 0x{3,8:X8}",
                            ap.LoadWord((int)addrss), ap.LoadWord((int)addrss + 4),
                            ap.LoadWord((int)addrss + 8), ap.LoadWord((int)addrss + 12));
                        _codeViewList.Items.Add(
                            new ObjectCodeLine(_drawParameters, addrss, ".word", hex, this));
                        addrss         += 16;
                        bytesToDisplay -= 16;
                    }
                    if (bytesToDisplay > 0)
                    {
                        if (bytesToDisplay >= 4)
                        {
                            hex = "";
                            string sep  = "";
                            uint   addr = addrss;
                            while (bytesToDisplay >= 4)
                            {
                                hex            += String.Format("{0} 0x{1,8:X8}", sep, ap.LoadWord((int)addrss));
                                sep             = ",";
                                addrss         += 4;
                                bytesToDisplay -= 4;
                            }
                            _codeViewList.Items.Add(
                                new ObjectCodeLine(_drawParameters, addr, ".word", hex, this));
                        }
                        if (bytesToDisplay > 0)
                        {
                            hex = convertBytes(bytesToDisplay, addrss);
                            _codeViewList.Items.Add(
                                new ObjectCodeLine(_drawParameters, addrss, ".byte", hex, this));
                            addrss += (uint)bytesToDisplay;
                        }
                    }
                    if (clix < clLen)
                    {
                        _codeViewList.Items.Add(
                            new ListLine(_drawParameters, cl[clix].Label + ":", cl[clix].Address, this));
                        clix++;
                    }
                }
                while (clix < clLen && cl[clix].Address < bssAddress)
                {
                    clix++;
                }
                addrss     = bssAddress;
                endAddress = (uint)(bssAddress + _PI.SectionSize[(int)(ArmAssembly.SectionType.Bss)]);
                // Generate labels in the BSS region
                while (addrss < endAddress)
                {
                    uint nextLabel      = clix < clLen ? cl[clix].Address : (uint)ap.EndAddress;
                    int  bytesToDisplay = (int)nextLabel - (int)addrss;
                    if (bytesToDisplay > 0)
                    {
                        _codeViewList.Items.Add(
                            new ObjectCodeLine(_drawParameters, addrss, ".space", bytesToDisplay.ToString(), this));
                        addrss = nextLabel;
                    }
                    if (clix < clLen)
                    {
                        _codeViewList.Items.Add(
                            new ListLine(_drawParameters, cl[clix].Label + ":", cl[clix].Address, this));
                        clix++;
                    }
                }
            }

            computeMaxWidth();
            _codeViewList.ResumeLayout();
            linesCreated = true;
            return(true);
        }//init