public void TestSubstDETMultipleDetectors()
        {
            String parameters = "-a [DET]";

            IResultNode top1   = MockRepository.GenerateStub <IResultNode>();
            IResultNode top2   = MockRepository.GenerateStub <IResultNode>();
            IResultNode child1 = MockRepository.GenerateStub <IResultNode>();

            top1.Stub(t => t.Children).Return(new IResultNode[] { child1 });
            child1.Stub(c => c.Children).Return(new IResultNode[0]);
            top2.Stub(t => t.Children).Return(new IResultNode[0]);
            _selection.Stub(s => s.Results).Return(new IResultNode[] { top1, top2 });

            ICodecDetector okDetector = MockRepository.GenerateStub <ICodecDetector>();

            okDetector.Stub(d => d.Name).Return("ok detector");
            IDetector notOkDetector = MockRepository.GenerateStub <IDetector>();

            notOkDetector.Stub(d => d.Name).Return("not ok detector");

            top1.Stub(t => t.Detectors).Return(new IDetector[] { okDetector });
            top2.Stub(t => t.Detectors).Return(new IDetector[] { notOkDetector });
            child1.Stub(t => t.Detectors).Return(new IDetector[] { okDetector });

            String subst = _checker.Substitute(parameters, _selection, _dataPacket, outputFilename);

            Assert.AreEqual(subst, "-a \"ok detector\"");
        }
Example #2
0
        private void SaveCurrentBitmapToFile(string filePath, ImageFormat format, bool createForensicIntegrityLog)
        {
            if (_ffmpegResult != null && _ffmpegResult.SourcePacket != null && _ffmpegResult.Bitmap != null)
            {
                _ffmpegResult.Bitmap.Save(filePath, format);

                if (createForensicIntegrityLog)
                {
                    if (_ffmpegResult.SourcePacket != null)
                    {
                        IResultNode    headerSourceResult = _ffmpegResult.HeaderSource ?? _ffmpegResult.SourcePacket;
                        ICodecDetector codecDetector      = headerSourceResult.Detectors.FirstOrDefault() as ICodecDetector;
                        if (codecDetector == null)
                        {
                            return;
                        }
                        // FIXME: The detectors of the video headers cannot be determined (for forensic logging purposes)!!
                        IDataPacket usedBitmapHeaders = codecDetector.GetVideoHeaders(headerSourceResult);

                        string logFileName = string.Format("{0}.csv", filePath);
                        using (FileStream fs = new FileStream(logFileName, FileMode.Create, FileAccess.Write, FileShare.Read))
                        {
                            IDataPacket allUsedBitmapNodes = _ffmpegResult.SourcePacket;
                            // Prefix with bitmap headers (if any)
                            if (usedBitmapHeaders != null)
                            {
                                allUsedBitmapNodes = usedBitmapHeaders.Append(allUsedBitmapNodes);
                            }
                            // Append child nodes and determine detectors that were used
                            var detectors = new HashSet <IDetector>(_ffmpegResult.SourcePacket.Detectors);
                            foreach (var dataPacket in _ffmpegResult.SourcePacket.Children)
                            {
                                allUsedBitmapNodes = allUsedBitmapNodes.Append(dataPacket);
                                foreach (IDetector detector in dataPacket.Detectors)
                                {
                                    detectors.Add(detector);
                                }
                            }
                            _forensicIntegrityLog.Log(allUsedBitmapNodes, detectors, filePath, fs, ForensicLogType.ConvertedData);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Can't save integrity log. There is no packetdata available for the active bitmap.", "Save Integrity Log", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("There is no frame opened, can't save empty frame to image.", "Save Image", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Example #3
0
        /// <summary>
        /// This method reads the video Data/headers from the file and creates a buffer.
        /// The buffer is added to the '_videoMemoryStreams' Dictionary so it can be used at one of the FFmpeg callback methods.
        /// </summary>
        /// <param name="dataPacket">Contains the frame Data.</param>
        /// <param name="headerPacket">Contains the header Data, when null, dataPacket is used as headersource.</param>
        /// <returns></returns>
        private bool PacketDataToBuffer(IResultNode dataPacket, IResultNode headerPacket)
        {
            // Find current codec detector in packet
            ICodecDetector codecDetector = (ICodecDetector)dataPacket.Detectors.Where(d => d is ICodecDetector).FirstOrDefault();

            if (codecDetector == null)
            {
                return(false);
            }

            // Resolve frame header info
            IDataPacket videoHeaders = codecDetector.GetVideoHeaders(headerPacket);
            IDataPacket videoData    = codecDetector.GetVideoData(dataPacket);

            if (videoData == null)
            {
                return(false);
            }

            // Copy all the Data, both header- and framedata, to a buffer.
            byte[] dataBuf = ReadDataPacket(videoData);
            if (IsH264NalUnitResult(dataPacket))
            {
                // Automatically convert H.264 'NAL unit stream' to 'byte stream', because FFmpeg
                // does not support the 'NAL unit stream' format.
                dataBuf = ConvertH264NalUnitStreamVideoDataToByteStream(dataBuf);
            }
            if (videoHeaders != null)
            {
                byte[] headerData = ReadDataPacket(videoHeaders);
                if (IsH264NalUnitResult(headerPacket))
                {
                    // Automatically convert H.264 'NAL unit stream' to 'byte stream', because FFmpeg
                    // does not support the 'NAL unit stream' format.
                    headerData = ConvertH264NalUnitStreamHeaderDataToByteStream(headerData);
                }

                dataBuf = headerData.Concat(dataBuf).ToArray();
            }

            // Put the Data in a memory stream, used by FFmpeg to read the 'file' from memory.
            lock (_videoMemoryStreams)
            {
                _convertId = _nextConvertId;
                _nextConvertId++;

                _videoMemoryStreams.Add(_convertId, new MemoryStream(dataBuf));
            }
            return(true);
        }
Example #4
0
 private void AddKeyFramesToList(IResultNode node, KeyFrameList keyFrames)
 {
     if (node.IsKeyframe())
     {
         ICodecDetector detector = node.Detectors.Where(d => d is ICodecDetector).SingleOrDefault() as ICodecDetector;
         keyFrames.Add(new KeyFrame(BuildRangeList(detector.GetVideoHeaders(node)), BuildRangeList(detector.GetVideoData(node))));
     }
     else
     {
         foreach (var childNode in node.Children)
         {
             AddKeyFramesToList(childNode, keyFrames);
         }
     }
 }
Example #5
0
        private static string GetDefaultHeaders(ICodecDetector detector)
        {
            var sb = new StringBuilder();

            if (detector.ReferenceHeaders != null)
            {
                foreach (IReferenceHeader referenceHeader in detector.ReferenceHeaders)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(", ");
                    }


                    sb.Append(GetDescriptiveName(referenceHeader));
                }
            }
            return(sb.ToString());
        }
Example #6
0
        public IReferenceHeader AddHeader(ICodecDetector detector, string filename)
        {
            IInputFile inputFile = _createInputFile(new Project(_createInputFile, "dummy.xml"), filename);

            using (var dataReader = inputFile.CreateDataReader())
            {
                var         codecParametersBuilder = new CodecParametersBuilder();
                IDataPacket headerData             = detector.FindReferenceHeader(dataReader, codecParametersBuilder);
                if (headerData == null)
                {
                    return(null);                    // No header detected
                }

                byte[] b      = ReadDataPacketToByteArray(headerData, dataReader);
                var    header = new ReferenceHeader(b, codecParametersBuilder.Build());
                // Use the filename as 'Setting' and leave 'Brand' and 'Model' as undefined.
                header.Setting = Path.GetFileNameWithoutExtension(filename);

                _referenceHeaders.Add(header);
                return(header);
            }
        }
 internal CodecDetectorWrapper(ICodecDetector detector) : base(detector)
 {
     _codecDetector = detector;
 }