/// <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; while ((line = sr.ReadLine()) != null) { line = line.Trim(); var recv = false; if (string.IsNullOrWhiteSpace(line) || (!line.StartsWith("Send") && !(recv = line.StartsWith("Recv")))) { continue; } var spaceIdx = line.IndexOf(' '); var date = DateTime.MinValue; if (line[4] == '@') { date = DateTime.Parse(line.Substring(5, spaceIdx - 5)); } var packetStr = line.Substring(spaceIdx + 1, line.Length - spaceIdx - 1); var packetArr = HexTool.ToByteArray(packetStr); var packet = new Packet(packetArr, 0); var palePacket = new PalePacket(packet, date, recv); newPackets.Insert(0, palePacket); } } 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> /// Clears packet list. /// </summary> private void ClearList() { LstPackets.BeginUpdate(); LstPackets.Items.Clear(); LstPackets.EndUpdate(); TxtPacket.Text = ""; UpdateCount(); }
/// <summary> /// Removes packets at the given indexes from list. /// </summary> /// <param name="idxs"></param> private void RemoveFromList(IList <int> idxs) { LstPackets.BeginUpdate(); for (int i = idxs.Count - 1; i >= 0; --i) { LstPackets.Items.RemoveAt(idxs[i]); } LstPackets.EndUpdate(); UpdateCount(); }
/// <summary> /// Clears packet list. /// </summary> private void ClearList() { LstPackets.BeginUpdate(); LstPackets.Items.Clear(); LstPackets.EndUpdate(); TxtPacketInfo.Text = ""; HexBox.ByteProvider = null; pluginManager.OnClear(); UpdateCount(); }
/// <summary> /// Fired regularly while being connected, handles queued packets. /// </summary> /// <param name="state"></param> private void OnQueueTimer(object state, EventArgs args) { if (!WinApi.IsWindow(alissaHWnd)) { Disconnect(); } var count = packetQueue.Count; if (count == 0) { return; } queueTimer.Enabled = false; var newPackets = new List <PalePacket>(); for (int i = 0; i < count; ++i) { PalePacket palePacket; lock (packetQueue) palePacket = packetQueue.Dequeue(); if (palePacket == null) { continue; } newPackets.Add(palePacket); } LstPackets.InvokeIfRequired((MethodInvoker) delegate { LstPackets.BeginUpdate(); foreach (var palePacket in newPackets) { lock (recvFilter) if (Settings.Default.FilterRecvEnabled && recvFilter.Contains(palePacket.Op)) { continue; } lock (sendFilter) if (Settings.Default.FilterSendEnabled && sendFilter.Contains(palePacket.Op)) { continue; } AddPacketToFormList(palePacket, true); if (palePacket.Received) { pluginManager.OnRecv(palePacket); } else { pluginManager.OnSend(palePacket); } } LstPackets.EndUpdate(); }); UpdateCount(); queueTimer.Enabled = true; }
/// <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); } } }