private void openPreparsedDumpToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Readable dumps |*.cap; *.pcap; *.log; *.hex|" + "Libpcap dumpy (*.cap; *.pcap)|*.cap; *.pcap|" + "Mooege dumps (*.log)|*.log|" + "Wireshark hex view (*.hex)|*.hex"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { questTree.Nodes.Clear(); actors.Nodes.Clear(); tree.Nodes.Clear(); BufferNode.Reset(); this.Text = Application.ProductName + " - " + Path.GetFileName(ofd.FileName); if (Path.GetExtension(ofd.FileName).ToLower().Contains("log")) { LoadDump(File.ReadAllText(ofd.FileName)); } if (Path.GetExtension(ofd.FileName).ToLower().Contains("cap")) { LoadPcap(ofd.FileName); } //if (Path.GetExtension(ofd.FileName).ToLower().Contains("hex")) // LoadWiresharkHex(File.ReadAllText(ofd.FileName)); } }
private void LoadWiresharkHex(string text) { if (text.Contains(" ")) { String[] rows = text.Split('\n'); String currentBuffer = ""; text = ""; for (int i = 0; i < rows.Length; i++) { if (i > 0 && (rows[i].StartsWith(" ") ^ rows[i - 1].StartsWith(" "))) { Buffer buffer = new Buffer(String_To_Bytes(currentBuffer)); BufferNode newNode = new BufferNode(buffer, actors, questTree, "1"); newNode.Start = text.Length; newNode.BackColor = rows[i].StartsWith(" ") ? newNode.BackColor = Color.LightCoral : Color.LightBlue; tree.Nodes.Add(newNode); text += currentBuffer; currentBuffer = ""; } currentBuffer += (rows[i].StartsWith(" ") ? rows[i].Substring(14, 3 * 16) : rows[i].Substring(10, 3 * 16)).Trim().Replace(" ", ""); } } else { Buffer buffer = new Buffer(String_To_Bytes(text)); BufferNode newNode = new BufferNode(buffer, actors, questTree, "1"); newNode.Parse(); tree.Nodes.Add(newNode); } input.Text = text; ApplyFilter(); }
private void LoadDump(string text) { String[] rows = text.Split('\n'); string currentDirection = ""; progressBar.Maximum = rows.Length; progressBar.Value = 0; progressBar.Visible = true; allNodes = new List <BufferNode>(); Dictionary <string, TreeNode> actors = new Dictionary <string, TreeNode>(); Dictionary <string, TreeNode> quests = new Dictionary <string, TreeNode>(); Color[][] trafficColors = new Color[][] { new Color[] { Color.LightCoral, Color.LightBlue }, new Color[] { Color.Tomato, Color.Blue }, new Color[] { Color.Red, Color.BlueViolet }, new Color[] { Color.PaleVioletRed, Color.CadetBlue } }; List <string> clients = new List <string>(); Dictionary <string, Color[]> colors = new Dictionary <string, Color[]>(); // to read mooege dumps, some leading info must be removed // the amount of chars is fixed so its calculated once int removeChars = rows[0].IndexOf("Inc:"); if (removeChars < 0) { removeChars = rows[0].IndexOf("Out:"); } string clientHash = ""; int counter = 0; int size = 0; Dictionary <string, BufferNode> lastNodesMissingData = new Dictionary <string, BufferNode>(); for (int i = 0; i < rows.Length; i++) { if (rows[i].Length > removeChars) { // Skip anything til the Inc/Out part (for mooege dumps), note client hash rows[i] = rows[i].Substring(removeChars); clientHash = rows[i].Substring(4, 8); if (clients.Contains(clientHash) == false) { clients.Add(clientHash); lastNodesMissingData.Add(clientHash + "I", null); lastNodesMissingData.Add(clientHash + "O", null); colors[clientHash] = trafficColors[clients.Count - 1]; } progressBar.Value = i; if (rows[i].Length > 3) { // Everytime the direction of data changes, the buffer is parsed and emptied // this is for pcap dumps where the data stream is sent in smaller packets // in mooege, data is dumped in whole if (i > 0 && rows[i].Substring(0, 1) != currentDirection) { byte[] buf = new byte[size / 2]; size = 0; for (int k = i - counter; k < i; k++) { Array.Copy(String_To_Bytes(rows[k]), 0, buf, size / 2, rows[k].Length / 2); size += rows[k].Length; } if (lastNodesMissingData[clientHash + currentDirection] == null) { BufferNode newNode = new BufferNode(actors, quests, clientHash); if (newNode.Append(buf)) { lastNodesMissingData[clientHash + currentDirection] = newNode; } else { lastNodesMissingData[clientHash + currentDirection] = null; } newNode.BackColor = currentDirection == "I" ? colors[clientHash][0] : colors[clientHash][1]; allNodes.Add(newNode); } else { if (false == lastNodesMissingData[clientHash + currentDirection].Append(buf)) { lastNodesMissingData[clientHash + currentDirection] = null; } } counter = 0; size = 0; currentDirection = rows[i].Substring(0, 1); } if (currentDirection == "") { currentDirection = rows[i].Substring(0, 1); } rows[i] = rows[i].Substring(13).Replace("\r", ""); counter++; size += rows[i].Length; } } } if (counter > 0) { byte[] buf = new byte[size / 2]; size = 0; for (int k = rows.Length - counter; k < rows.Length; k++) { Array.Copy(String_To_Bytes(rows[k]), 0, buf, size / 2, rows[k].Length / 2); size += rows[k].Length; } BufferNode newNode = new BufferNode(actors, quests, clientHash); newNode.Append(buf); newNode.BackColor = currentDirection == "I" ? colors[clientHash][0] : colors[clientHash][1]; allNodes.Add(newNode); } foreach (BufferNode bn in allNodes) { bn.ApplyFilter(filterWindow.Filter); } // Create a filter menu entry for every client in the stream. filterPlayersToolStripMenuItem.DropDownItems.Clear(); foreach (string client in clients) { ToolStripMenuItem m = new ToolStripMenuItem(client); m.Tag = client; m.Checked = true; m.Click += new EventHandler(FilterPlayerClick); // find toon name for client hash foreach (BufferNode bn in allNodes) { if (bn.clientHash.Equals(m.Tag.ToString())) { foreach (TreeNode mn in bn.Nodes) { if (mn is MessageNode) { if ((mn as MessageNode).gameMessage is NewPlayerMessage) { m.Text = ((mn as MessageNode).gameMessage as NewPlayerMessage).ToonName; goto hell; } } } } } hell: filterPlayersToolStripMenuItem.DropDownItems.Add(m); } questTree.Nodes.AddRange(quests.Values.ToArray()); this.actors.Nodes.AddRange(actors.Values.ToArray()); tree.Nodes.AddRange(allNodes.ToArray()); progressBar.Visible = false; }
private void LoadDump(string text) { String[] rows = text.Split('\n'); string currentDirection = ""; progressBar.Maximum = rows.Length; progressBar.Value = 0; progressBar.Visible = true; allNodes = new List<BufferNode>(); Dictionary<string, TreeNode> actors = new Dictionary<string, TreeNode>(); Dictionary<string, TreeNode> quests = new Dictionary<string, TreeNode>(); Color[][] trafficColors = new Color[][] { new Color[] { Color.LightCoral , Color.LightBlue }, new Color[] { Color.Tomato, Color.Blue }, new Color[] { Color.Red, Color.BlueViolet }, new Color[] { Color.PaleVioletRed, Color.CadetBlue } }; List<string> clients = new List<string>(); Dictionary<string, Color[]> colors = new Dictionary<string,Color[]>(); // to read mooege dumps, some leading info must be removed // the amount of chars is fixed so its calculated once int removeChars = rows[0].IndexOf("Inc:"); if(removeChars < 0) removeChars = rows[0].IndexOf("Out:"); string clientHash = ""; int lastpacket = 0; int size = 0; Dictionary<string, BufferNode> lastNodesMissingData = new Dictionary<string, BufferNode>(); for (int i = 0; i < rows.Length; i++) { if (rows[i].Length > removeChars) { // Skip anything til the Inc/Out part (for mooege dumps), note client hash rows[i] = rows[i].Substring(removeChars); clientHash = rows[i].Substring(4, 8); if (clients.Contains(clientHash) == false) { clients.Add(clientHash); lastNodesMissingData.Add(clientHash + "I", null); lastNodesMissingData.Add(clientHash + "O", null); colors[clientHash] = trafficColors[clients.Count - 1]; } progressBar.Value = i; if (rows[i].Length > 3) { // Everytime the direction of data changes, the buffer is parsed and emptied // this is for pcap dumps where the data stream is sent in smaller packets // in mooege, data is dumped in whole if (i > 0) if (rows[i].Substring(0, 1) != currentDirection) { byte[] buf = new byte[size / 2]; size = 0; for (int k = lastpacket; k < i; k++) { Array.Copy(String_To_Bytes(rows[k]), 0, buf, size / 2, rows[k].Length / 2); size += rows[k].Length; } if (lastNodesMissingData[clientHash + currentDirection] == null) { BufferNode newNode = new BufferNode(actors, quests, clientHash); if (newNode.Append(buf)) lastNodesMissingData[clientHash + currentDirection] = newNode; else lastNodesMissingData[clientHash + currentDirection] = null; newNode.BackColor = currentDirection == "I" ? colors[clientHash][0] : colors[clientHash][1]; allNodes.Add(newNode); } else { if (false == lastNodesMissingData[clientHash + currentDirection].Append(buf)) lastNodesMissingData[clientHash + currentDirection] = null; } lastpacket = i; size = 0; currentDirection = rows[i].Substring(0, 1); } if (currentDirection == "") currentDirection = rows[i].Substring(0, 1); rows[i] = rows[i].Substring(13).Replace("\r", ""); size += rows[i].Length; } else { //clean invalid lines. rows[i] = ""; } } } if (lastpacket < rows.Length) { byte[] buf = new byte[size / 2]; size = 0; for (int k = lastpacket; k < rows.Length; k++) { Array.Copy(String_To_Bytes(rows[k]), 0, buf, size / 2, rows[k].Length / 2); size += rows[k].Length; } BufferNode newNode = new BufferNode(actors, quests, clientHash); newNode.Append(buf); newNode.BackColor = currentDirection == "I" ? colors[clientHash][0] : colors[clientHash][1]; allNodes.Add(newNode); } foreach(BufferNode bn in allNodes) bn.ApplyFilter(filterWindow.Filter); // Create a filter menu entry for every client in the stream. filterPlayersToolStripMenuItem.DropDownItems.Clear(); foreach (string client in clients) { ToolStripMenuItem m = new ToolStripMenuItem(client); m.Tag = client; m.Checked = true; m.Click += new EventHandler(FilterPlayerClick); // find toon name for client hash foreach(BufferNode bn in allNodes) if(bn.clientHash.Equals(m.Tag.ToString())) foreach(TreeNode mn in bn.Nodes) if(mn is MessageNode) if((mn as MessageNode).gameMessage is NewPlayerMessage) { m.Text = ((mn as MessageNode).gameMessage as NewPlayerMessage).ToonName; goto hell; } hell: filterPlayersToolStripMenuItem.DropDownItems.Add(m); } questTree.Nodes.AddRange(quests.Values.ToArray()); this.actors.Nodes.AddRange(actors.Values.ToArray()); tree.Nodes.AddRange(allNodes.ToArray()); progressBar.Visible = false; }
private void LoadDump(string text) { String[] rows = text.Split('\n'); String currentBuffer = ""; text = ""; string currentDirection = ""; progressBar.Maximum = rows.Length; progressBar.Value = 0; progressBar.Visible = true; allNodes = new List<BufferNode>(); Color[][] trafficColors = new Color[][] { new Color[] { Color.LightCoral , Color.LightBlue }, new Color[] { Color.Tomato, Color.Blue }, new Color[] { Color.Red, Color.BlueViolet }, new Color[] { Color.PaleVioletRed, Color.CadetBlue } }; List<string> clients = new List<string>(); Dictionary<string, Color[]> colors = new Dictionary<string,Color[]>(); // to read mooege dumps, some leading info must be removed // the amount of chars is fixed so its calculated once int removeChars = rows[0].IndexOf("Inc:"); if(removeChars < 0) removeChars = rows[0].IndexOf("Out:"); string clientHash = ""; for (int i = 0; i < rows.Length; i++) { if (rows[i].Length > removeChars) { // Skip anything til the Inc/Out part (for mooege dumps), note client hash rows[i] = rows[i].Substring(removeChars); clientHash = rows[i].Substring(4, 8); if (clients.Contains(clientHash) == false) { clients.Add(clientHash); colors[clientHash] = trafficColors[clients.Count - 1]; } progressBar.Value = i; //causes bugs //Application.DoEvents(); //if (this.Visible == false) // break; if (rows[i].Length > 3) { // Everytime the direction of data changes, the buffer is parsed and emptied // this is for pcap dumps where the data stream is sent in smaller packets // in mooege, data is dumped in whole if (i > 0 && rows[i].Substring(0, 1) != currentDirection) { Buffer buffer = new Buffer(String_To_Bytes(currentBuffer)); BufferNode newNode = new BufferNode(buffer, actors, questTree, clientHash); newNode.Start = text.Length; newNode.BackColor = currentDirection == "I" ? colors[clientHash][0] : colors[clientHash][1]; allNodes.Add(newNode); //tree.Nodes.Add(newNode); newNode.ApplyFilter(filterWindow.Filter); text += currentBuffer; currentBuffer = ""; currentDirection = rows[i].Substring(0, 1); } if (currentDirection == "") currentDirection = rows[i].Substring(0, 1); currentBuffer += (rows[i].Substring(13)).Replace("\r", ""); } } } if (currentBuffer.Length > 10) { Buffer buffer = new Buffer(String_To_Bytes(currentBuffer)); BufferNode newNode = new BufferNode(buffer, actors, questTree, clientHash); newNode.Start = text.Length; newNode.BackColor = currentDirection == "I" ? colors[clientHash][0] : colors[clientHash][1]; allNodes.Add(newNode); newNode.ApplyFilter(filterWindow.Filter); text += currentBuffer; } // Create a filter menu entry for every client in the stream. filterPlayersToolStripMenuItem.DropDownItems.Clear(); foreach (string client in clients) { ToolStripMenuItem m = new ToolStripMenuItem(client); m.Tag = client; m.Checked = true; m.Click += new EventHandler(FilterPlayerClick); // find toon name for client hash foreach(BufferNode bn in allNodes) if(bn.clientHash.Equals(m.Tag.ToString())) foreach(TreeNode mn in bn.Nodes) if(mn is MessageNode) if((mn as MessageNode).gameMessage is NewPlayerMessage) { m.Text = ((mn as MessageNode).gameMessage as NewPlayerMessage).ToonName; goto hell; } hell: filterPlayersToolStripMenuItem.DropDownItems.Add(m); } tree.Nodes.AddRange(allNodes.ToArray()); progressBar.Visible = false; }