Ejemplo n.º 1
0
        public HexView()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // TODO: Add any initialization after the InitializeComponent call

            backbuff    = new Bitmap(this.Width, this.Height);
            backbuffG   = Graphics.FromImage(backbuff);
            DrawOptions = new HexDrawOptions(HexDrawOptions.DrawModeList.ByteView, this);
        }
Ejemplo n.º 2
0
        int DataViewbpl = 2;      //bytes per line
        private void DrawHexView(Graphics e, HexDrawOptions opt, RectangleF ctrlSz)
        {
            PointF DrawPnt = new PointF(0, 0);

            //hacks
            uint Addr = addr_hvs;
            //end of hacks

            float fntszy = Font.GetHeight(e.DpiY);
            float fntsz  = MeasureDisplayStringWidth(e, "AAAA", this.Font) / 4.0f;

            switch (opt.DrawMode)
            {
            case HexDrawOptions.DrawModeList.ByteView:
            {
                DataViewbpl = 1;
                StringBuilder sb = new StringBuilder("0x");
                sb.Append(Hex(Addr >> 16, 4, '0'));
                sb.Append(' ');
                sb.Append(Hex(Addr & 0xFFFF, 4, '0'));
                sb.Append(" ");

                SizeF szf = new SizeF(MeasureDisplayStringWidth(e, sb.ToString(), this.Font), this.Font.GetHeight(e.DpiY));
                e.DrawLine(Pens.Black, new PointF(szf.Width, 0), new PointF(szf.Width, ctrlSz.Height));

                szf.Width += MeasureDisplayStringWidth(e, " 00", this.Font);
                e.DrawLine(Pens.Black, new PointF(szf.Width, 0), new PointF(szf.Width, ctrlSz.Height));
            }
            break;

            case HexDrawOptions.DrawModeList.DataView:
            {
                StringBuilder sb = new StringBuilder("0x");
                sb.Append(Hex(Addr >> 16, 4, '0'));
                sb.Append(' ');
                sb.Append(Hex(Addr & 0xFFFF, 4, '0'));
                sb.Append(" ");

                SizeF szf = new SizeF(MeasureDisplayStringWidth(e, sb.ToString(), this.Font), this.Font.GetHeight(e.DpiY));
                e.DrawLine(Pens.Black, new PointF(szf.Width, 0), new PointF(szf.Width, ctrlSz.Height));

                float pixrem  = (ctrlSz.Width - 16) - szf.Width;
                int   charrem = (int)(pixrem / fntsz);
                //char count : 4*bytes +1
                if (charrem > 4)
                {
                    DataViewbpl = (charrem - 1) >> 2;
                }
                else
                {
                    DataViewbpl = 1;
                }

                sb = new StringBuilder();
                for (int i = 0; i < DataViewbpl; i++)
                {
                    sb.Append(" 00");
                }
                szf.Width += MeasureDisplayStringWidth(e, sb.ToString(), this.Font);
                e.DrawLine(Pens.Black, new PointF(szf.Width, 0), new PointF(szf.Width, ctrlSz.Height));
            }
            break;

            case HexDrawOptions.DrawModeList.DwordView:
            {
                DataViewbpl = 4;
                StringBuilder sb = new StringBuilder("0x");
                sb.Append(Hex(Addr >> 16, 4, '0'));
                sb.Append(' ');
                sb.Append(Hex(Addr & 0xFFFF, 4, '0'));
                sb.Append(" ");

                SizeF szf = new SizeF(MeasureDisplayStringWidth(e, sb.ToString(), this.Font), this.Font.GetHeight(e.DpiY));
                e.DrawLine(Pens.Black, new PointF(szf.Width, 0), new PointF(szf.Width, ctrlSz.Height));

                szf.Width += MeasureDisplayStringWidth(e, " 00 00 00 00", this.Font);
                e.DrawLine(Pens.Black, new PointF(szf.Width, 0), new PointF(szf.Width, ctrlSz.Height));
            }
            break;

            case HexDrawOptions.DrawModeList.WordView:
            {
                DataViewbpl = 2;
                StringBuilder sb = new StringBuilder("0x");
                sb.Append(Hex(Addr >> 16, 4, '0'));
                sb.Append(' ');
                sb.Append(Hex(Addr & 0xFFFF, 4, '0'));
                sb.Append(" ");

                SizeF szf = new SizeF(MeasureDisplayStringWidth(e, sb.ToString(), this.Font), this.Font.GetHeight(e.DpiY));
                e.DrawLine(Pens.Black, new PointF(szf.Width, 0), new PointF(szf.Width, ctrlSz.Height));

                szf.Width += MeasureDisplayStringWidth(e, " 00 00", this.Font);
                e.DrawLine(Pens.Black, new PointF(szf.Width, 0), new PointF(szf.Width, ctrlSz.Height));
            }
            break;
            }


            //ok , i'ts party time
            while (DrawPnt.Y < ctrlSz.Height)
            {
                //DrawHeader
                DrawString(e, "0x", this.Font, Brushes.Black, ref DrawPnt);

                DrawString(e, Hex(Addr, 8, '0'), this.Font, Brushes.Black, ref DrawPnt);

                DrawString(e, " ", this.Font, Brushes.Black, ref DrawPnt);
                //e.DrawString(sb.ToString(),this.Font,Brushes.Black,DrawPnt);
                //DrawPnt.X+=e.MeasureString(sb.ToString(),this.Font).Width;

                //draw data and string :)
                switch (opt.DrawMode)
                {
                case HexDrawOptions.DrawModeList.ByteView:
                {
                    byte[] tmp = ReadDataArr(Addr, 1);
                    DrawByteDump_Swap(e, tmp, this.Font, Brushes.Black, ref DrawPnt);
                    //	byte tmp=(byte)ReadData(Addr,1);
                    //	DrawString(e," " + Hex(tmp,2,'0') + " " + ((char)tmp),this.Font,Brushes.Black,ref DrawPnt);
                }
                break;

                case HexDrawOptions.DrawModeList.DataView:
                {
                    byte[] tmp = ReadDataArr(Addr, DataViewbpl);
                    DrawByteDump_NoSwap(e, tmp, this.Font, Brushes.Black, ref DrawPnt);
                }
                break;

                case HexDrawOptions.DrawModeList.DwordView:
                {
                    byte[] tmp = ReadDataArr(Addr, 4);
                    DrawByteDump_Swap(e, tmp, this.Font, Brushes.Black, ref DrawPnt);
                }
                break;

                case HexDrawOptions.DrawModeList.WordView:
                {
                    byte[] tmp = ReadDataArr(Addr, 2);
                    DrawByteDump_Swap(e, tmp, this.Font, Brushes.Black, ref DrawPnt);
                }
                break;
                }

                //finish up line  , reset draw pos ect :)
                DrawPnt.Y += fntszy;
                DrawPnt.X  = 0;
                e.DrawLine(Pens.Black, DrawPnt, new PointF(ctrlSz.Width, DrawPnt.Y));
                switch (opt.DrawMode)
                {
                case HexDrawOptions.DrawModeList.ByteView:
                    Addr += 1;
                    break;

                case HexDrawOptions.DrawModeList.DataView:
                    Addr += (uint)DataViewbpl;
                    break;

                case HexDrawOptions.DrawModeList.DwordView:
                    Addr += 4;
                    break;

                case HexDrawOptions.DrawModeList.WordView:
                    Addr += 2;
                    break;
                }
            }
        }