public void Analyze(CanAnalyseDelegate CanAnalyze) { using (StreamReader SReader = File.OpenText(FilePath)) { string Line = ""; int TempIndex = 0; int TempPosition = 0; byte TempOpcode = 0; string TempOpcodeName; PacketInfo Packet = null; int LineId = 0; int MaxPosition = 0; while (!SReader.EndOfStream) { Line = SReader.ReadLine(); if (Line.Length == 0) { continue; } if (Line[0] == '[') { ++TotalPackets; TempIndex = Line.IndexOf('('); TempOpcodeName = Line.Substring(TempIndex + 7, Line.IndexOf(" ") - (TempIndex + 7)); if (!CanAnalyze(TempOpcodeName)) { if (!SReader.EndOfStream) { Line = SReader.ReadLine(); } if (!SReader.EndOfStream) { Line = SReader.ReadLine(); } if (!SReader.EndOfStream) { Line = SReader.ReadLine(); } while (!SReader.EndOfStream) { Line = SReader.ReadLine(); if (Line[0] == '-') { break; } } continue; } TempOpcode = byte.Parse(Line.Substring(TempIndex + 3, 2), System.Globalization.NumberStyles.HexNumber); Packet = new PacketInfo(this); TempIndex = Line.LastIndexOf('=') + 1; Packet.Size = int.Parse(Line.Substring(TempIndex, Line.Length - TempIndex)); Packet.Opcode = TempOpcode; Packet.OpcodeName = TempOpcodeName; Packet.Data = new byte[Packet.Size]; if (!SReader.EndOfStream) { Line = SReader.ReadLine(); // |------------------------------------------------|----------------| } if (!SReader.EndOfStream) { Line = SReader.ReadLine(); // |00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |0123456789ABCDEF| } if (!SReader.EndOfStream) { Line = SReader.ReadLine(); // |------------------------------------------------|----------------| } Packet.Line = LineId; TempPosition = 0; while (!SReader.EndOfStream) { Line = SReader.ReadLine(); if (Line[0] == '-') { break; } Line = Line.Replace(" ", string.Empty); MaxPosition = Math.Min(33, (Packet.Size - TempPosition) * 2); for (TempIndex = 1; TempIndex < MaxPosition; TempIndex += 2) { Packet.Data[TempPosition] = byte.Parse(Line.Substring(TempIndex, 2), System.Globalization.NumberStyles.HexNumber); ++TempPosition; } } ++LineId; AddPacket(Packet); } } } }
public void Analyze(CanAnalyseDelegate CanAnalyze) { using (StreamReader SReader = File.OpenText(FilePath)) { string Line = ""; int TempIndex = 0; int TempPosition = 0; byte TempOpcode = 0; string TempOpcodeName; PacketInfo Packet = null; int LineId = 0; int MaxPosition = 0; while (!SReader.EndOfStream) { Line = SReader.ReadLine(); if (Line.Length == 0) continue; if (Line[0] == '[') { ++TotalPackets; TempIndex = Line.IndexOf('('); TempOpcodeName = Line.Substring(TempIndex + 7, Line.IndexOf(" ") - (TempIndex + 7)); if (!CanAnalyze(TempOpcodeName)) { if (!SReader.EndOfStream) Line = SReader.ReadLine(); if (!SReader.EndOfStream) Line = SReader.ReadLine(); if (!SReader.EndOfStream) Line = SReader.ReadLine(); while (!SReader.EndOfStream) { Line = SReader.ReadLine(); if (Line[0] == '-') break; } continue; } TempOpcode = byte.Parse(Line.Substring(TempIndex + 3, 2), System.Globalization.NumberStyles.HexNumber); Packet = new PacketInfo(this); TempIndex = Line.LastIndexOf('=') + 1; Packet.Size = int.Parse(Line.Substring(TempIndex, Line.Length - TempIndex)); Packet.Opcode = TempOpcode; Packet.OpcodeName = TempOpcodeName; Packet.Data = new byte[Packet.Size]; if (!SReader.EndOfStream) Line = SReader.ReadLine(); // |------------------------------------------------|----------------| if (!SReader.EndOfStream) Line = SReader.ReadLine(); // |00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |0123456789ABCDEF| if (!SReader.EndOfStream) Line = SReader.ReadLine(); // |------------------------------------------------|----------------| Packet.Line = LineId; TempPosition = 0; while (!SReader.EndOfStream) { Line = SReader.ReadLine(); if (Line[0] == '-') break; Line = Line.Replace(" ", string.Empty); MaxPosition = Math.Min(33, (Packet.Size - TempPosition) * 2); for (TempIndex = 1; TempIndex < MaxPosition; TempIndex += 2) { Packet.Data[TempPosition] = byte.Parse(Line.Substring(TempIndex, 2), System.Globalization.NumberStyles.HexNumber); ++TempPosition; } } ++LineId; AddPacket(Packet); } } } }