/// <param name="packet">Packet to test.</param> /// <param name="opNames">Definitions pairing opcodes with their human-readable name.</param> /// <returns>Whether <paramref name="packet"/> matches against this SearchParametres object.</returns> /// <exception cref="InvalidOperationException">Thrown if this SearchParametres object has its search mode set to 'NoOp'.</exception> public bool IsMatch(PalePacket packet, Dictionary <int, string> opNames) { // Handle obvious mismatches if (this.SearchMode == SearchModes.NoOp) { throw new InvalidOperationException("This object has its search mode set to 'NoOp'. Cannot evaluate packet."); return(false); } if (!this.PacketBounds.HasFlag(packet.Received ? SendOrRecv.Recv : SendOrRecv.Send)) { return(false); } // Begin probing packet if (this.SearchMode == SearchModes.Hexadecimal) { return(HexTool.ToString(packet.Packet.GetBuffer()).IndexOf(this.StringQuery, StringComparison.OrdinalIgnoreCase) >= 0); } else //if (this.SearchMode == SearchModes.String) { StringComparison comp = this.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; if (this.LookAt.HasFlag(LookAtCandidates.Ops)) { if ((opNames.ContainsKey(packet.Op) && opNames[packet.Op].IndexOf(this.StringQuery, comp) >= 0) || // Try op name (packet.Op.ToString("X8").IndexOf(this.StringQuery, StringComparison.OrdinalIgnoreCase) >= 0)) // Try op code { return(true); } } if (this.LookAt.HasFlag(LookAtCandidates.Ids)) { if (packet.Id.ToString("X16").IndexOf(this.StringQuery, StringComparison.OrdinalIgnoreCase) >= 0) { return(true); } } if (this.LookAt.HasFlag(LookAtCandidates.Data_String)) { if (packet.ToString().IndexOf(this.StringQuery, comp) >= 0) { return(true); } } return(false); } }
/// <param name="packet">Packet to test.</param> /// <param name="opNames">Definitions pairing opcodes with their human-readable name.</param> /// <returns>Whether <paramref name="packet"/> matches against this SearchParametres object.</returns> /// <exception cref="InvalidOperationException">Thrown if this SearchParametres object has its search mode set to 'NoOp'.</exception> public bool IsMatch(PalePacket packet, Dictionary <int, string> opNames) { // Handle obvious mismatches if (this.SearchMode == SearchModes.NoOp) { throw new InvalidOperationException("This object has its search mode set to 'NoOp'. Cannot evaluate packet."); return(false); } if (!this.PacketBounds.HasFlag(packet.Received ? SendOrRecv.Recv : SendOrRecv.Send)) { return(false); } // Begin probing packet if (this.SearchMode == SearchModes.Hexadecimal) { return(HexTool.ToString(packet.Packet.GetBuffer()).Contains(this.StringQuery)); } else //if (this.SearchMode == SearchModes.String) { if (this.LookAt.HasFlag(LookAtCandidates.Ops)) { if (opNames.ContainsKey(packet.Op) && opNames[packet.Op].Contains(this.StringQuery)) { return(true); } } if (this.LookAt.HasFlag(LookAtCandidates.Ids)) { if (packet.Id.ToString("X16").Contains(this.StringQuery.ToUpper())) { return(true); } } if (this.LookAt.HasFlag(LookAtCandidates.Data_String)) { if (packet.ToString().Contains(this.StringQuery)) { return(true); } } return(false); } }
/// <summary> /// Called when selecting a packet in the list, /// shows the packet in the textbox. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void LstPackets_SelectedIndexChanged(object sender, EventArgs e) { PalePacket palePacket = null; if (LstPackets.SelectedItems.Count == 0) { TxtPacket.Text = ""; } else { palePacket = (PalePacket)LstPackets.SelectedItems[0].Tag; TxtPacket.Text = palePacket.ToString(); } pluginManager.OnSelected(palePacket); }