public void ForceResize() { float widthAmount = 0.6f; dataGridView1.Size = new Size((int)(this.Size.Width * widthAmount), this.Size.Height - (this.menuStrip1.Size.Height * 3)); dataGridView1.Location = new Point(this.Size.Width - dataGridView1.Size.Width - this.menuStrip1.Size.Height, this.menuStrip1.Size.Height); if (byteView1 != null) { byteView1.Size = dataGridView1.Size; byteView1.Location = dataGridView1.Location; byteView1.Refresh(); } listView1.Size = new Size((int)(this.Size.Width * (1 - widthAmount)) - (this.menuStrip1.Size.Height * 2), this.Size.Height - (this.menuStrip1.Size.Height * 3)); listView1.Location = new Point(this.menuStrip1.Size.Height / 2, this.menuStrip1.Size.Height); }
public void InitializeByteViewerContextMenu() { Func <byte[]> GetSelectedBytes = () => { byte[] buffer = new byte[ByteViewer.SelectionLength]; for (long i = ByteViewer.SelectionStart, j = 0; i < ByteViewer.SelectionStart + ByteViewer.SelectionLength; i++, j++) { buffer[j] = ByteViewer.ByteProvider.ReadByte(i); } return(buffer); }; Func <string, RoutedEventHandler, MenuItem> NewMenuItem = (menuItemHeader, clickEvent) => { MenuItem menuItem = new MenuItem { Header = menuItemHeader }; menuItem.Click += clickEvent; return(menuItem); }; if (ByteViewerContextMenu == null) { ByteViewerContextMenu = new ContextMenu(); /* COPY SUBMENU BEGIN */ MenuItem copyMenuItem = new MenuItem { Header = "Copy" }; copyMenuItem.Items.Add(NewMenuItem("Decimal Bytes", (sender, e) => { byte[] buffer = GetSelectedBytes(); if (buffer.Length > 0) { Clipboard.SetText(new BytesConverter(buffer).ToDecimalString()); } })); copyMenuItem.Items.Add(new Separator()); copyMenuItem.Items.Add(NewMenuItem("Hexadecimal Bytes", (sender, e) => { //ok byte[] buffer = GetSelectedBytes(); if (buffer.Length > 0) { Clipboard.SetText(new BytesConverter(buffer).ToHexadecimalString(String.Empty)); } })); copyMenuItem.Items.Add(NewMenuItem("Hexadecimal Bytes (\\x00)", (sender, e) => { //ok byte[] buffer = GetSelectedBytes(); if (buffer.Length > 0) { Clipboard.SetText(new BytesConverter(buffer).ToHexadecimalString("\\x")); } })); copyMenuItem.Items.Add(NewMenuItem("Hexadecimal Bytes (0x00)", (sender, e) => { //ok byte[] buffer = GetSelectedBytes(); if (buffer.Length > 0) { Clipboard.SetText(new BytesConverter(buffer).ToHexadecimalString("0x")); } })); copyMenuItem.Items.Add(NewMenuItem("Hexadecimal Bytes (Formatted)", (sender, e) => { ByteViewer.CopyHex(); })); copyMenuItem.Items.Add(new Separator()); copyMenuItem.Items.Add(NewMenuItem("Hexadecimal Words (2 Bytes)", (sender, e) => { byte[] buffer = GetSelectedBytes(); if (buffer.Length > 0 && buffer.Length % 2 == 0) { Clipboard.SetText(new BytesConverter(buffer).ToHexadecimalString(2)); } })); copyMenuItem.Items.Add(NewMenuItem("Hexadecimal Dwords (4 Bytes)", (sender, e) => { //ok byte[] buffer = GetSelectedBytes(); if (buffer.Length > 0 && buffer.Length % 4 == 0) { Clipboard.SetText(new BytesConverter(buffer).ToHexadecimalString(4)); } })); copyMenuItem.Items.Add(NewMenuItem("Hexadecimal Qwords (8 Bytes)", (sender, e) => { //ok byte[] buffer = GetSelectedBytes(); if (buffer.Length > 0 && buffer.Length % 8 == 0) { Clipboard.SetText(new BytesConverter(buffer).ToHexadecimalString(8)); } })); copyMenuItem.Items.Add(new Separator()); copyMenuItem.Items.Add(NewMenuItem("String (Ascii)", (sender, e) => { //ok byte[] buffer = GetSelectedBytes(); if (buffer.Length > 0) { Clipboard.SetText(Encoding.ASCII.GetString(buffer)); } })); copyMenuItem.Items.Add(NewMenuItem("String (Utf-8)", (sender, e) => { //ok byte[] buffer = GetSelectedBytes(); if (buffer.Length > 0) { Clipboard.SetText(Encoding.UTF8.GetString(buffer)); } })); copyMenuItem.Items.Add(new Separator()); copyMenuItem.Items.Add(NewMenuItem("Address", (sender, e) => { string address = ByteViewer.SelectionStart.ToString("X8"); if (ByteViewer.SelectionLength > 1) { address += "-" + (ByteViewer.SelectionStart + ByteViewer.SelectionLength).ToString("X8"); } Clipboard.SetText(address); })); /* COPY SUBMENU END */ ByteViewerContextMenu.Items.Add(copyMenuItem); ByteViewerContextMenu.Items.Add(NewMenuItem("Paste", (sender, e) => { ByteViewer.PasteHex(); })); ByteViewerContextMenu.Items.Add(new Separator()); ByteViewerContextMenu.Items.Add(NewMenuItem("Insert Hexadecimal Bytes...", (sender, e) => { long index = ByteViewer.SelectionStart; if (index >= 0) { string bytes = InputWindow.InputBox("Hexadecimal Bytes: ", "Binary Engine: Insert Hexadecimal Bytes"); if (bytes.Length > 0 && !String.IsNullOrEmpty(bytes)) { ByteViewer.ByteProvider.InsertBytes(index, BytesConverter.StringToBytes(bytes)); ByteViewer.Refresh(); } } })); ByteViewerContextMenu.Items.Add(NewMenuItem("Insert String...", (sender, e) => { long index = ByteViewer.SelectionStart; if (index >= 0) { string data = InputWindow.InputBox("String: ", "Binary Engine: Insert String"); if (data.Length > 0 && !String.IsNullOrEmpty(data)) { ByteViewer.ByteProvider.InsertBytes(index, Encoding.ASCII.GetBytes(data)); ByteViewer.Refresh(); } } })); ByteViewerContextMenu.Items.Add(new Separator()); ByteViewerContextMenu.Items.Add(NewMenuItem("Separator Group Size", (sender, e) => { string m = InputWindow.InputBox("Size: ", "Binary Engine: Separator Group Size", ByteViewer.GroupSize.ToString()); if (int.TryParse(m, out int n)) { if (n % 2 == 0) { ByteViewer.GroupSize = n; } } })); ByteViewerContextMenu.Items.Add(new Separator()); ByteViewerContextMenu.Items.Add(NewMenuItem("Select All", (sender, e) => { ByteViewer.SelectAll(); })); } }