Exemplo n.º 1
0
        protected virtual void OnStreamHeaderRecieved(IStreamHeader header)
        {
            var handler = StreamHeaderReceived;

            if (handler != null)
            {
                handler(this, header);
            }
        }
        static bool IsPcap(IStreamHeader header)
        {
            if (header.Header.Length < 4)
            {
                return(false);
            }
            var h = header.Header;

            // Magic number. See https://wiki.wireshark.org/Development/LibpcapFileFormat.
            return(h[3] == 0xA1 && h[2] == 0xB2 && h[1] == 0xC3 && h[0] == 0xD4);
        }
Exemplo n.º 3
0
 static bool IsZip(PreprocessingStepParams fileInfo, IStreamHeader header)
 {
     if (HasZipExtension(fileInfo.Location) || HasZipExtension(fileInfo.FullPath))
     {
         if (header.Header.Take(4).SequenceEqual(new byte[] { 0x50, 0x4b, 0x03, 0x04 }))
         {
             return(Ionic.Zip.ZipFile.IsZipFile(fileInfo.Location, false));
         }
     }
     return(false);
 }
Exemplo n.º 4
0
 static bool IsGzip(PreprocessingStepParams fileInfo, IStreamHeader header)
 {
     if (HasGzExtension(fileInfo.Location) || HasGzExtension(fileInfo.FullPath))
     {
         if (header.Header.Take(2).SequenceEqual(new byte[] { 0x1f, 0x8b }))
         {
             return(IsGzipFile(fileInfo.Location));
         }
     }
     return(false);
 }
        static bool IsKeys(IStreamHeader header)
        {
            var str = Encoding.ASCII.GetString(header.Header);

            return
                (str.StartsWith("RSA Session-ID:") ||
                 str.StartsWith("CLIENT_HANDSHAKE_TRAFFIC_SECRET ") ||
                 str.StartsWith("SERVER_HANDSHAKE_TRAFFIC_SECRET ") ||
                 str.StartsWith("CLIENT_TRAFFIC_SECRET_0 ") ||
                 str.StartsWith("EXPORTER_SECRET ") ||
                 str.StartsWith("CLIENT_RANDOM "));
        }
        static bool IsHttpArchiveFormat(IStreamHeader header)
        {
            if (header.Header.Length == 0)
            {
                return(false);
            }
            if ((char)header.Header[0] != '{')
            {
                return(false);
            }
            var headerAsStr = new string(header.Header.Select(b => (char)b).ToArray());

            return(headerAsStr.Contains("\"log\"") && headerAsStr.Contains("\"version\"") && headerAsStr.Contains("\"creator\""));
        }
Exemplo n.º 7
0
 private void linker_StreamHeaderReceived(object sender, IStreamHeader e)
 {
     try
     {
         if (_adapter.IsConnected)
         {
             _adapter.Send(e.Serialize());
         }
     }
     catch
     {
         destoryLinker();
     }
 }
Exemplo n.º 8
0
        static bool IsChromeDriverFormat(IStreamHeader header)
        {
            if (header.Header.Length == 0)
            {
                return(false);
            }
            if ((char)header.Header[0] != '[')
            {
                return(false);
            }
            var headerAsStr = new string(header.Header.Select(b => (char)b).ToArray());

            return((new Reader()).TestFormat(headerAsStr));
        }
        bool IsChromeDriverFormat(IStreamHeader header)
        {
            if (header.Header.Length == 0)
            {
                return(false);
            }
            if ((char)header.Header[0] != '[')
            {
                return(false);
            }
            var headerAsStr = new string(header.Header.Select(b => (char)b).ToArray());

            return((new Reader(textLogParser, CancellationToken.None)).TestFormat(headerAsStr));
        }
        static bool IsWebrtcInternalsDump(IStreamHeader header)
        {
            if (header.Header.Length == 0)
            {
                return(false);
            }
            if ((char)header.Header[0] != '{')
            {
                return(false);
            }
            var headerAsStr = new string(header.Header.Select(b => (char)b).ToArray());

            return(headerAsStr.Contains("getUserMedia"));
        }
Exemplo n.º 11
0
        private void streamPipe_StreamHeaderReceived(object sender, IStreamHeader e)
        {
            _headerType = e.DeviceType;
            switch (e.DeviceType)
            {
            case VideoDeviceType.Hikv:
            {
                _headerReceived = true;
                HikM4Header header = new HikM4Header()
                {
                    Type = HikM4Decoder.HeaderType,
                    Data = (e as HikvStreamHeader).Buffer
                };
                HikM4Header = header;
                onHikM4HeaderReceived(new HikM4HeaderEventArgs(header));
                //初始化包头
                if (_decode)
                {
                    _hikm4Decoder.InputData(header.Type, header.Data);
                }
            }
            break;

            case VideoDeviceType.Ffmpeg:
            {
                _headerReceived = true;
                FfmpegStreamHeader tH     = e as FfmpegStreamHeader;
                FfmpegHeader       header = new FfmpegHeader()
                {
                    CodecID = (Constants.AVCodecID)tH.CodecID,
                    Width   = 0,
                    Height  = 0
                };
                FfmpegHeader = header;
                onFfmpegHeaderReceived(new FfmpegHeaderEventArgs(header));
                //初始化包头
                if (_decode)
                {
                    _ffmpegDecoder.Init(header.CodecID, header.Width, header.Height);
                }
            }
            break;

            default:
                break;
            }
        }
Exemplo n.º 12
0
        static bool IsTar(PreprocessingStepParams fileInfo, IStreamHeader header)
        {
            var tarHeader = new ICSharpCode.SharpZipLib.Tar.TarHeader
            {
                Magic = "xxxxx"
            };

            try
            {
                tarHeader.ParseBuffer(header.Header);
            }
            catch (Exception)
            {
                return(false);
            }
            return(tarHeader.IsChecksumValid ||
                   tarHeader.Magic?.Contains(ICSharpCode.SharpZipLib.Tar.TarHeader.TMAGIC) == true);
        }
Exemplo n.º 13
0
        private void _client_ReceiveCompleted(object sender, ReceiveEventArgs args)
        {
            try
            {
                if (args.ByteLenght >= 4)
                {
                    int code = BitConverter.ToInt32(args.ReceivedBytes, 0);
                    switch (code)
                    {
                    case StreamEntityCode.FfmpegHeader:
                    {
                        CurrentHeader = FfmpegStreamHeader.DeserializeTo(args.ReceivedBytes);
                        OnStreamHeaderRecieved(CurrentHeader);
                    }
                    break;

                    case StreamEntityCode.HikvHeader:
                    {
                        CurrentHeader = HikvStreamHeader.DeserializeTo(args.ReceivedBytes);
                        OnStreamHeaderRecieved(CurrentHeader);
                    }
                    break;

                    case StreamEntityCode.StreamData:
                    {
                        OnStreamDataReceived(StreamData.DeserializeTo(args.ReceivedBytes));
                    }
                    break;

                    case StreamEntityCode.RemoteError:
                    {
                        RemoteError re = RemoteError.DeserializeTo(args.ReceivedBytes);
                        OnErrorOccurred(new ErrorEventArgs(re.ErrorMessage, ErrorTypes.Receive));
                    }
                    break;
                    }
                }
            }
            catch (Exception e)
            {
                OnErrorOccurred(new ErrorEventArgs($"从远程流媒体服务器获取到异常数据:{e.Message}", ErrorTypes.Receive));
            }
        }
 IPreprocessingStep IPreprocessingManagerExtension.DetectFormat(PreprocessingStepParams fileInfo, IStreamHeader header)
 {
     if (IsWebrtcInternalsDump(header))
     {
         return(new JsonUnpackPreprocessingStep(preprocessingStepsFactory, fileInfo));
     }
     return(null);
 }
 IPreprocessingStep IPreprocessingManagerExtension.DetectFormat(PreprocessingStepParams fileInfo, IStreamHeader header)
 {
     if (IsHttpArchiveFormat(header))
     {
         return(new TextConversionPreprocessingStep(preprocessingStepsFactory, harLogsFactory, fileInfo));
     }
     return(null);
 }
Exemplo n.º 16
0
 IPreprocessingStep IPreprocessingManagerExtension.DetectFormat(PreprocessingStepParams fileInfo, IStreamHeader header)
 {
     if (IsChromeDriverFormat(header))
     {
         return(new TimeFixerPreprocessingStep(preprocessingStepsFactory, chromeDriverLogsFactory, fileInfo));
     }
     return(null);
 }
Exemplo n.º 17
0
 IPreprocessingStep IPreprocessingManagerExtension.DetectFormat(PreprocessingStepParams param, IStreamHeader header)
 {
     return(null);
 }
        IPreprocessingStep IPreprocessingManagerExtension.DetectFormat(PreprocessingStepParams fileInfo, IStreamHeader header)
        {
            if (tshark.IsAvailable)
            {
                if (IsPcap(header))
                {
                    return new SaveParamsStep()
                           {
                               state = preprocessingsState, pcap = fileInfo
                           }
                }
                ;
                else if (IsKeys(header))
                {
                    return new SaveParamsStep()
                           {
                               state = preprocessingsState, key = fileInfo
                           }
                }
                ;
            }
            return(null);
        }

        IPreprocessingStep IPreprocessingManagerExtension.CreateStepByName(string stepName, PreprocessingStepParams stepParams)
        {
            if (stepName == PcapUnpackPreprocessingStep.stepName)
            {
                return(preprocessingStepsFactory.CreatePcapUnpackStep(stepParams, null));
            }
            return(null);
        }

        IPreprocessingStep IPreprocessingManagerExtension.TryParseLaunchUri(Uri url)
        {
            return(null);
        }

        Task IPreprocessingManagerExtension.FinalizePreprocessing(IPreprocessingStepCallback callback)
        {
            if (preprocessingsState.preprocessings.TryRemove(callback.Owner, out var prepState))
            {
                foreach (var pcap in prepState.pcaps)
                {
                    callback.YieldNextStep(preprocessingStepsFactory.CreatePcapUnpackStep(pcap, prepState.keys.ToArray()));
                }
            }
            return(Task.FromResult(0));
        }