protected virtual void ThreadFunction() { running = true; try { while (running && file.Position < file.Length) { uint packetRecordLength = 0; PACKET_ITEM PItem = new PACKET_ITEM(); switch (FileFormat) { case Format.WINPCAP: PItem.Seconds = Function.Get4BytesFromStream(file, Const.VALUE); PItem.MicroSeconds = Function.Get4BytesFromStream(file, Const.VALUE); PItem.CaptureLength = Function.Get4BytesFromStream(file, Const.VALUE); PItem.PacketLength = Function.Get4BytesFromStream(file, Const.VALUE); break; case Format.XCP001: ulong timestamp = Function.Get4BytesFromStream(file, Const.VALUE); PItem.Seconds = (uint)(timestamp / 1000000000); uint millseconds = (uint)((timestamp / 1000000) % 1000); uint counter = (uint)(timestamp % 1000); PItem.MicroSeconds = millseconds * 1000 + counter; file.Position += 6; PItem.CaptureLength = Function.Get2BytesFromStream(file, Const.VALUE); PItem.PacketLength = PItem.CaptureLength; file.Position += 16; break; case Format.XCP002: ulong temp2 = Function.Get8BytesFromStream(file, Const.VALUE); PItem.Seconds = (uint)(temp2 / 1000000); PItem.MicroSeconds = (uint)(temp2 % 1000000); PItem.CaptureLength = Function.Get2BytesFromStream(file, Const.VALUE); PItem.PacketLength = Function.Get2BytesFromStream(file, Const.VALUE); file.Position += 28; break; case Format.SUNSNOOP: PItem.CaptureLength = Function.Get4BytesFromStream(file, Const.NORMAL); PItem.PacketLength = Function.Get4BytesFromStream(file, Const.NORMAL); packetRecordLength = Function.Get4BytesFromStream(file, Const.NORMAL); uint droppedPackets = Function.Get4BytesFromStream(file, Const.NORMAL); ulong temp3 = Function.Get8BytesFromStream(file, Const.NORMAL); PItem.Seconds = (uint)(temp3 / 1000000); PItem.MicroSeconds = (uint)(temp3 % 1000000); break; } PacketInfo data = new PacketInfo(); data.Data = new byte[PItem.CaptureLength]; data.StartIndex = 14; // skip MAC (6 bytes) x 2 + packet type (2 bytes) file.Read(data.Data, 0, (int)PItem.CaptureLength); data.TimeStamp = BaseTime + new TimeSpan((long)PItem.Seconds * 10000000 + (long)PItem.MicroSeconds * 10); data.Length = PItem.CaptureLength; if (FileFormat == Format.SUNSNOOP) { file.Position += (packetRecordLength - PItem.CaptureLength - 24); } // Increases the progress bar's value based on the size of // the file currently being read. snifferObj.Invoke(snifferObj.IncrementStepInProgressHandler, new object[] { (int)data.Length }); OnDataReceived(data); } //Close the file after reading file file.Close(); } catch (Exception e) { ErrorHandler(e.Message + "\r\n" + e.TargetSite + "\r\n" + e.StackTrace); } finally { bool stopped = tcp.TCPStopAnalyse(); if (stopped) { snifferObj.Invoke(snifferObj.UpdateUIControlsHandler); } } }
protected virtual void ThreadFunction() { running = true; try { while(running && file.Position < file.Length) { uint packetRecordLength = 0; PACKET_ITEM PItem = new PACKET_ITEM(); switch(FileFormat) { case Format.WINPCAP: PItem.Seconds = Function.Get4BytesFromStream( file , Const.VALUE ); PItem.MicroSeconds = Function.Get4BytesFromStream( file , Const.VALUE ); PItem.CaptureLength = Function.Get4BytesFromStream( file , Const.VALUE ); PItem.PacketLength = Function.Get4BytesFromStream( file , Const.VALUE ); break; case Format.XCP001: ulong timestamp = Function.Get4BytesFromStream( file , Const.VALUE ); PItem.Seconds = (uint)(timestamp/1000000000); uint millseconds = (uint)((timestamp/1000000) % 1000); uint counter = (uint)(timestamp % 1000); PItem.MicroSeconds = millseconds * 1000 + counter; file.Position +=6; PItem.CaptureLength = Function.Get2BytesFromStream( file , Const.VALUE ); PItem.PacketLength = PItem.CaptureLength; file.Position +=16; break; case Format.XCP002: ulong temp2 = Function.Get8BytesFromStream( file , Const.VALUE ); PItem.Seconds = (uint)(temp2/1000000); PItem.MicroSeconds = (uint)(temp2 % 1000000); PItem.CaptureLength = Function.Get2BytesFromStream( file , Const.VALUE ); PItem.PacketLength = Function.Get2BytesFromStream( file , Const.VALUE ); file.Position +=28; break; case Format.SUNSNOOP: PItem.CaptureLength = Function.Get4BytesFromStream(file, Const.NORMAL); PItem.PacketLength = Function.Get4BytesFromStream(file, Const.NORMAL); packetRecordLength = Function.Get4BytesFromStream(file, Const.NORMAL); uint droppedPackets = Function.Get4BytesFromStream(file, Const.NORMAL); ulong temp3 = Function.Get8BytesFromStream(file, Const.NORMAL); PItem.Seconds = (uint)(temp3 / 1000000); PItem.MicroSeconds = (uint)(temp3 % 1000000); break; } PacketInfo data = new PacketInfo(); data.Data = new byte[PItem.CaptureLength]; data.StartIndex = 14; // skip MAC (6 bytes) x 2 + packet type (2 bytes) file.Read(data.Data,0,(int)PItem.CaptureLength); data.TimeStamp = BaseTime + new TimeSpan((long)PItem.Seconds * 10000000 + (long)PItem.MicroSeconds * 10); data.Length = PItem.CaptureLength; if (FileFormat == Format.SUNSNOOP) file.Position += (packetRecordLength - PItem.CaptureLength - 24); // Increases the progress bar's value based on the size of // the file currently being read. snifferObj.Invoke(snifferObj.IncrementStepInProgressHandler, new object[] { (int)data.Length }); OnDataReceived(data); } //Close the file after reading file file.Close(); } catch(Exception e) { ErrorHandler( e.Message + "\r\n" + e.TargetSite + "\r\n" + e.StackTrace ); } finally { bool stopped = tcp.TCPStopAnalyse(); if(stopped) { snifferObj.Invoke(snifferObj.UpdateUIControlsHandler); } } }