Example #1
0
        private void BtnFind_Click(object sender, EventArgs e)
        {
            // Verify that the search query is hex if searching by hex.
            if (RadSearchModeHex.Checked)
            {
                // (MabiPale saves packets in uppercase.)
                TxtSearchQuery.Text = TxtSearchQuery.Text.ToUpper();

                Regex hexPattern = new Regex("^[0-9A-F]+$");
                if (!hexPattern.IsMatch(TxtSearchQuery.Text))
                {
                    MessageBox.Show("Invalid hexadecimal string.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }



            DialogResult = DialogResult.OK;
            // Encode search parametres
            // Generate LookAtCandidates, set appropriate bits
            SearchParametres.LookAtCandidates lookAt = 0;
            if (ChkSearchInOps.Checked)
            {
                lookAt |= SearchParametres.LookAtCandidates.Ops;                 // Set bit
            }
            if (ChkSearchInIds.Checked)
            {
                lookAt |= SearchParametres.LookAtCandidates.Ids;                 // Set bit
            }
            if (ChkSearchInData.Checked)
            {
                lookAt |= SearchParametres.LookAtCandidates.Data_String;                 // Set bit
            }
            // Generate PacketBounds, set appropriate bits
            SearchParametres.SendOrRecv packetBounds = 0;
            if (ChkSearchInSends.Checked)
            {
                packetBounds |= SearchParametres.SendOrRecv.Send;                 // Set bit
            }
            if (ChkSearchInRecvs.Checked)
            {
                packetBounds |= SearchParametres.SendOrRecv.Recv;                 // Set bit
            }
            SearchParametres searchParams = new SearchParametres()
            {
                StringQuery = TxtSearchQuery.Text,
                SearchMode  = RadSearchModeStr.Checked
                                        ? SearchParametres.SearchModes.String
                                        : SearchParametres.SearchModes.Hexadecimal,
                SearchDirection = ((Button)sender).Name == BtnFindPrev.Name
                                        ? SearchDirectionHint.Up
                                        : SearchDirectionHint.Down,
                LookAt       = lookAt,
                PacketBounds = packetBounds,
            };

            this.Tag = searchParams;
            this.Close();
        }
Example #2
0
        /*
         * public SearchParametres()
         * {
         *      this.StringQuery = "";
         *      this.SearchMode = SearchModes.NoOp;
         *      this.SearchDirection = SearchDirectionHint.Down;
         *      this.LookAt = 0;
         *      this.PacketBounds = 0;
         * }
         */

        public SearchParametres(SearchParametres spCopy) : this()
        {
            this.StringQuery     = spCopy.StringQuery;
            this.SearchMode      = spCopy.SearchMode;
            this.SearchDirection = spCopy.SearchDirection;
            this.LookAt          = spCopy.LookAt;
            this.PacketBounds    = spCopy.PacketBounds;
        }
Example #3
0
        private void BtnMenuEditFind_Click(object sender, EventArgs e)
        {
            var form   = new FrmFind(searchParams);
            var result = form.ShowDialog();

            if (result == DialogResult.Cancel)
            {
                return;
            }
            else if (result == DialogResult.OK)
            {
                searchParams = (SearchParametres)form.Tag;
                PerformSearch(searchParams);
            }
        }
Example #4
0
        public FrmFind(SearchParametres searchParams)
        {
            InitializeComponent();

            // Load provided searchParams
            TxtSearchQuery.Text = searchParams.StringQuery;
            if (searchParams.SearchMode == SearchParametres.SearchModes.Hexadecimal)
            {
                RadSearchModeHex.Checked = true;
                // (and all LookAtCandidates will be autochecked via CheckedChanged event)
            }
            else
            {
                LblHexNotice.Visible    = false;
                ChkSearchInOps.Checked  = searchParams.LookAt.HasFlag(SearchParametres.LookAtCandidates.Ops);
                ChkSearchInIds.Checked  = searchParams.LookAt.HasFlag(SearchParametres.LookAtCandidates.Ids);
                ChkSearchInData.Checked = searchParams.LookAt.HasFlag(SearchParametres.LookAtCandidates.Data_String);
            }

            ChkSearchInSends.Checked = searchParams.PacketBounds.HasFlag(SearchParametres.SendOrRecv.Send);
            ChkSearchInRecvs.Checked = searchParams.PacketBounds.HasFlag(SearchParametres.SendOrRecv.Recv);
        }
Example #5
0
        private void PerformSearch(SearchParametres searchParams)
        {
            if (LstPackets.Items.Count <= 0)
            {
                MessageBox.Show("Nothing to search.", "No packets loaded", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (searchParams.SearchMode == SearchParametres.SearchModes.NoOp)
            {             // Undefined parametres. Open Find window to define.
                BtnMenuEditFind.PerformClick();
                return;
            }

            // Determine starting (and possibly ending) point of search.
            //TODO Multiple selected packets only picks the max or min as starting point.
            //     Implement ability to only search within range?
            int searchIndex;

            //int searchEndIndex = -1;
            if (LstPackets.SelectedIndices.Count <= 0)
            {
                if (searchParams.SearchDirection == SearchDirectionHint.Down)
                {
                    searchIndex = 0;                     // Start from beginning
                }
                else
                {
                    searchIndex = LstPackets.Items.Count - 1;                     // Start from end
                }
            }
            else if (LstPackets.SelectedIndices.Count == 1)
            {
                searchIndex = LstPackets.SelectedIndices[0]; // Start from currently selected index.
            }
            else                                             //if (LstPackets.SelectedIndices.Count > 1) // Implied only search in range.
            if (searchParams.SearchDirection == SearchDirectionHint.Down)
            {
                searchIndex = Queryable.Min <int>(LstPackets.SelectedIndices.Cast <int>().AsQueryable <int>());
            }
            else
            {
                searchIndex = Queryable.Max <int>(LstPackets.SelectedIndices.Cast <int>().AsQueryable <int>());
            }

            // Define common action: select and scroll list item into view
            Action <ListViewItem> SelectAndScrollTo = (ListViewItem lvi) =>
            {
                LstPackets.SelectedItems.Clear();
                lvi.Selected = true;
                lvi.EnsureVisible();
            };

            // Begin search
            if (searchParams.SearchDirection == SearchDirectionHint.Down)
            {
                ++searchIndex;                 // Skip currently selected packet.
                for (; searchIndex < LstPackets.Items.Count; ++searchIndex)
                {
                    if (searchParams.IsMatch((PalePacket)LstPackets.Items[searchIndex].Tag, opNames))
                    {
                        SelectAndScrollTo(LstPackets.Items[searchIndex]);
                        return;
                    }
                }
                SelectAndScrollTo(LstPackets.Items[LstPackets.Items.Count - 1]);
                MessageBox.Show("Reached bottom of list.", "Packet not found", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                --searchIndex;                 // Skip currently selected packet.
                for (; searchIndex >= 0; --searchIndex)
                {
                    if (searchParams.IsMatch((PalePacket)LstPackets.Items[searchIndex].Tag, opNames))
                    {
                        SelectAndScrollTo(LstPackets.Items[searchIndex]);
                        return;
                    }
                }
                SelectAndScrollTo(LstPackets.Items[0]);
                MessageBox.Show("Reached top of list.", "Packet not found", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }