private void OnSelectedHex(PalePacket palePacket, int start) { if (form == null || form.IsDisposed) return; form.UpdateValues(buffer, start); }
private void OnSelected(PalePacket palePacket) { if (palePacket != null) buffer = palePacket.Packet.GetBuffer(); else buffer = null; form.UpdateValues(buffer, 0); }
/// <summary> /// Loads log file and adds packets to list. /// </summary> /// <param name="path"></param> private void LoadFile(string path) { var newPackets = new List<PalePacket>(); using (var sr = new StreamReader(path)) { string line; for (int ln = 1; (line = sr.ReadLine()) != null; ++ln) { try { line = line.Trim(); var recv = false; if (string.IsNullOrWhiteSpace(line) || (!line.StartsWith("Send ") && !(recv = line.StartsWith("Recv ")))) continue; var tabIndex = line.IndexOf('\t'); var split = line.Substring(0, tabIndex).Split(' '); PacketType type; DateTime date; string name; int length = -1; if (split.Length == 3) { type = (split[0] == "Send" ? PacketType.ClientServer : PacketType.ServerClient); date = DateTime.Parse(split[1]); name = split[2]; } else if (split.Length == 4) { type = (split[0] == "Send" ? PacketType.ClientServer : PacketType.ServerClient); date = DateTime.Parse(split[1]); name = split[2]; length = Convert.ToInt32(split[3]); } else continue; var packetStr = line.Substring(tabIndex + 1, line.Length - tabIndex - 1); var packetArr = HexTool.ToByteArray(packetStr); var packet = new Packet(packetArr, type); var palePacket = new PalePacket(name, length, packet, date, recv); newPackets.Insert(0, palePacket); } catch (Exception ex) { MessageBox.Show("Error on line " + ln + ": " + ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } LstPackets.BeginUpdate(); foreach (var palePacket in newPackets) AddPacketToFormList(palePacket, false); LstPackets.EndUpdate(); UpdateCount(); foreach (var palePacket in newPackets) { if (palePacket.Received) pluginManager.OnRecv(palePacket); else pluginManager.OnSend(palePacket); } }
/// <summary> /// Adds packet to list, scrolls down if scroll is true. /// </summary> /// <param name="palePacket"></param> /// <param name="scroll"></param> private void AddPacketToFormList(PalePacket palePacket, bool scroll) { var name = palePacket.OpName; var lvi = new ListViewItem((palePacket.Received ? "<" : ">") + palePacket.Op.ToString("X8")); lvi.UseItemStyleForSubItems = false; lvi.BackColor = palePacket.Received ? Color.FromArgb(0x0033bbff) : Color.FromArgb(0x00ff5522); lvi.ForeColor = Color.White; lvi.Tag = palePacket; lvi.SubItems.Add(name); lvi.SubItems.Add(palePacket.Time > DateTime.MinValue ? palePacket.Time.ToString("hh:mm:ss.fff") : ""); LstPackets.InvokeIfRequired((MethodInvoker)delegate { LstPackets.Items.Add(lvi); if (scroll) LstPackets.Items[LstPackets.Items.Count - 1].EnsureVisible(); }); }
/// <summary> /// Window message handler, handles incoming data from provider. /// </summary> /// <param name="m"></param> protected override void WndProc(ref Message m) { if (m.Msg == WinApi.WM_COPYDATA) { var cds = (WinApi.COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam, typeof(WinApi.COPYDATASTRUCT)); // The op will *always* be there, who knows about the // other things. if (cds.cbData < 2) return; var recv = (int)cds.dwData == Sign.Recv; var data = new byte[cds.cbData]; Marshal.Copy(cds.lpData, data, 0, cds.cbData); var type = (!recv ? PacketType.ClientServer : PacketType.ServerClient); var packet = new Packet(data, type); var name = Shared.Op.GetName(packet.Op); var length = Shared.Op.GetSize(packet.Op); var palePacket = new PalePacket(name, length, packet, DateTime.Now, recv); lock (packetQueue) packetQueue.Enqueue(palePacket); } base.WndProc(ref m); }
/// <summary> /// Fires Send event. /// </summary> /// <param name="palePacket"></param> internal void OnSend(PalePacket palePacket) { var ev = Send; if (ev == null) return; try { var evs = ev.GetInvocationList().Cast<Action<PalePacket>>(); foreach (var e in evs) { e(palePacket); palePacket.Packet.Rewind(); } } catch (Exception ex) { Trace.TraceError(ex.ToString()); } }