예제 #1
0
        private void FindButton_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrEmpty(SearchTextBox.Text) || ByteViewer.ByteProvider == null)
            {
                return;
            }

            if (SearchBytesRadioButton.IsChecked == true && SearchOptionCheckBox.IsChecked == true)
            {
                SignatureSearchResult = 1;
                SignatureScan scan    = new SignatureScan(SearchTextBox.Text, ByteViewer.ByteProvider, SignatureSearchResult);
                long          address = scan.Address();
                if (address >= 0)
                {
                    ByteViewer.SelectionStart  = address;
                    ByteViewer.SelectionLength = scan.PatternSize;
                }
                else
                {
                    MessageBox.Show("The following specified hexadecimal bytes was not found: \n\n" + SearchTextBox.Text, "Binary Engine", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                return;
            }
            else
            {
                try
                {
                    ByteViewer.SelectionStart     = 0;
                    ByteViewFindOptions.MatchCase = (bool)SearchOptionCheckBox.IsChecked;
                    ByteViewFindOptions.Type      = (bool)SearchBytesRadioButton.IsChecked ? FindType.Hex : FindType.Text;

                    if (ByteViewFindOptions.Type == FindType.Hex)
                    {
                        ByteViewFindOptions.Hex = BytesConverter.StringToBytes(SearchTextBox.Text);
                    }
                    else
                    {
                        ByteViewFindOptions.Text = SearchTextBox.Text;
                    }

                    ByteViewFindOptions.IsValid = true;
                }
                catch
                {
                }
            }

            FindNextButton_Click(this, e);
        }
예제 #2
0
        private void FindAllButton_Click(object sender, RoutedEventArgs e)
        {
            FindAllReferencesGroupBox.Visibility = Visibility.Visible;
            ByteViewerHost.Margin = new Thickness(0, 20, 250, 105);

            FindAllListBox.Items.Clear();

            if (String.IsNullOrEmpty(SearchTextBox.Text) || ByteViewer.ByteProvider == null)
            {
                return;
            }

            if (SearchBytesRadioButton.IsChecked == true && SearchOptionCheckBox.IsChecked == true)
            {
                SignatureSearchResult = 1;
                SignatureScan scan = new SignatureScan(SearchTextBox.Text, ByteViewer.ByteProvider, SignatureSearchResult);
                for (long address = scan.Address(); address >= 0; scan.Result++, address = scan.Address())
                {
                    byte[] data = new byte[scan.PatternSize];
                    for (int i = 0; i < scan.PatternSize; ++i)
                    {
                        data[i] = ByteViewer.ByteProvider.ReadByte(address + i);
                    }

                    string content = $"{address.ToString("X8")} ({scan.PatternSize}): {new BytesConverter(data).ToHexadecimalString()} [\"{Encoding.ASCII.GetString(data)}\"]";
                    FindAllListBox.Items.Add(new ListBoxItem()
                    {
                        Content = content,
                        Tag     = new KeyValuePair <long, long>(address, scan.PatternSize),
                        ToolTip = new ToolTip()
                        {
                            Content = content
                        }
                    });
                }

                return;
            }
            else
            {
                try
                {
                    ByteViewer.SelectionStart     = 0;
                    ByteViewFindOptions.MatchCase = (bool)SearchOptionCheckBox.IsChecked;
                    ByteViewFindOptions.Type      = (bool)SearchBytesRadioButton.IsChecked ? FindType.Hex : FindType.Text;

                    if (ByteViewFindOptions.Type == FindType.Hex)
                    {
                        ByteViewFindOptions.Hex = BytesConverter.StringToBytes(SearchTextBox.Text);
                    }
                    else
                    {
                        ByteViewFindOptions.Text = SearchTextBox.Text;
                    }

                    ByteViewFindOptions.IsValid = true;


                    const long NO_MATCH = -1;

                    while (ByteViewer.Find(ByteViewFindOptions) != NO_MATCH)
                    {
                        byte[] data = new byte[ByteViewer.SelectionLength];
                        for (int i = 0; i < ByteViewer.SelectionLength; ++i)
                        {
                            data[i] = ByteViewer.ByteProvider.ReadByte(ByteViewer.SelectionStart + i);
                        }

                        string content = $"{ByteViewer.SelectionStart.ToString("X8")} ({ByteViewer.SelectionLength}): {new BytesConverter(data).ToHexadecimalString()} [\"{Encoding.ASCII.GetString(data)}\"]";
                        FindAllListBox.Items.Add(new ListBoxItem()
                        {
                            Content = content,
                            Tag     = new KeyValuePair <long, long>(ByteViewer.SelectionStart, ByteViewer.SelectionLength),
                            ToolTip = new ToolTip()
                            {
                                Content = content
                            }
                        });
                    }
                }
                catch
                {
                }
            }
        }
예제 #3
0
        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(); }));
            }
        }