public void TestGetDataPacketFragmented()
        {
            IDataPacket dataPacket = _dataReader.GetDataPacket(70, 70);

            Assert.IsTrue(dataPacket.GetFragment(0).Equals(TestFramework.CreateDataPacket(InputFile, 80, 43)), "GetDataPacket() for fragmented packet (a)");
            Assert.IsTrue(dataPacket.GetFragment(43).Equals(TestFramework.CreateDataPacket(InputFile, 151, 27)), "GetDataPacket() for fragmented packet (b)");
        }
Пример #2
0
        public void GetFragment()
        {
            IDataPacket fragment = _dataPacket.GetFragment(FragmentOffset);

            Assert.IsInstanceOfType(typeof(DataPacket), fragment, "Type");
            Assert.AreSame(_inputFile1, fragment.InputFile, "InputFile");
            Assert.AreEqual((Length - FragmentOffset), fragment.Length, "Length");
            Assert.AreEqual((StartOffset + FragmentOffset), fragment.StartOffset, "StartOffset");
            Assert.AreEqual(EndOffset, fragment.EndOffset, "EndOffset");
        }
Пример #3
0
            /// <summary>Create a list that contains the origin of all bytes in the result file</summary>
            /// <param name="dataPacket">the data packet that makes up the result file</param>
            /// <param name="forensicLogType">the type of data being logged</param>
            internal void WriteDetailInformation(IDataPacket dataPacket, ForensicLogType forensicLogType)
            {
                _textWriter.WriteLine();

                string sourceHeaderText;

                if (forensicLogType == ForensicLogType.CopiedData)
                {
                    sourceHeaderText = "Build-up of resulting file:";
                }
                else if (forensicLogType == ForensicLogType.ConvertedData)
                {
                    sourceHeaderText = "Build-up of source data (before being converted by FFmpeg):";
                }
                else
                {
                    sourceHeaderText = string.Empty;
                }

                _textWriter.WriteLine(sourceHeaderText);
                _textWriter.WriteLine("From byte location:{0}To byte location:{1}Length:{2}Maps to source file(s):{3}From byte location:{4}To byte location:", SeparatorChar, SeparatorChar, SeparatorChar, SeparatorChar, SeparatorChar);

                for (long offset = 0L; offset < dataPacket.Length;)
                {
                    IDataPacket subpacket = dataPacket.GetFragment(offset);
                    _textWriter.WriteLine("{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}",
                                          offset, SeparatorChar, offset + subpacket.Length, SeparatorChar, subpacket.Length,
                                          SeparatorChar, subpacket.InputFile.Name, SeparatorChar, subpacket.StartOffset,
                                          SeparatorChar, subpacket.EndOffset);
                    offset += subpacket.Length;
                }
            }
Пример #4
0
        public int Read(byte[] array, int arrayOffset, int count)
        {
            PreConditions.Object(this).IsDisposedIf(_dataReaderPool == null);
            PreConditions.Argument("array").Value(array).IsNotNull();
            PreConditions.Argument("arrayOffset").Value(arrayOffset).InRange(0, array.Length);
            PreConditions.Argument("count").Value(count).InRange(0, (array.Length - arrayOffset));

            int totalBytesToRead = (int)Math.Min(count, (Length - Position));
            int bytesRead        = 0;

            while (bytesRead < totalBytesToRead)
            {
                IDataPacket fragment = _dataPacket.GetFragment(_position + bytesRead);

                int fragmentBytes     = (int)Math.Min((totalBytesToRead - bytesRead), fragment.Length);
                int fragmentBytesRead = _dataReaderPool.ReadInputFile(fragment.InputFile, fragment.StartOffset, array, (arrayOffset + bytesRead), fragmentBytes);
                bytesRead += fragmentBytesRead;

                // Completed or cancelled if not read the _entire_ fragment
                if (fragmentBytesRead != fragmentBytes)
                {
                    break;
                }
            }
            return(bytesRead);
        }
 public IDataPacket GetFragment(long offset)
 {
     if (Detector != null)
     {
         throw new ArgumentException("Can not append to a codec stream");
     }
     return(_dataPacket.GetFragment(offset));
 }
Пример #6
0
        /// <summary>
        /// Tests <c>GetDataPacket()</c> method for <paramref name="dataReader"/>.
        /// </summary>
        /// <param name="dataReader">the data reader</param>
        /// <param name="offset">the offset for the data packet</param>
        /// <param name="length">the length for the data packet</param>
        protected void TestDataReaderGetDataPacket(IDataReader dataReader, long offset, long length)
        {
            string      name       = dataReader.GetType().Name;
            IDataPacket dataPacket = dataReader.GetDataPacket(offset, length);

            Assert.IsNotNull(dataPacket.InputFile, "{0}.GetDataPacket().InputFile", name);
            Assert.AreEqual(offset, dataPacket.StartOffset, "{0}.GetDataPacket().StartOffset", name);
            Assert.AreEqual(length, dataPacket.Length, "{0}.GetDataPacket().Length", name);
            Assert.AreEqual(dataPacket.Length, dataPacket.GetFragment(0).Length, "{0}.GetDataPacket().GetFragment() - Single fragment (unfragmented)", name);
        }
Пример #7
0
        private static byte[] ReadDataPacketToByteArray(IDataPacket dataPacket, IDataReader dataReader)
        {
            var b = new byte[dataPacket.Length];

            for (int offset = 0; offset < dataPacket.Length;)
            {
                IDataPacket fragment = dataPacket.GetFragment(offset);
                dataReader.Position = fragment.StartOffset;
                dataReader.Read(b, offset, (int)fragment.Length);
                offset += (int)fragment.Length;
            }
            return(b);
        }
        public IDataPacket GetFragment(long offset)
        {
            PreConditions.Argument("offset").Value(offset).InRange(0L, (Length - 1L));

            long firstLength = _firstDataPacket.Length;

            if (offset < firstLength)
            {
                return(_firstDataPacket.GetFragment(offset));
            }

            return(_secondDataPacket.GetFragment((offset - firstLength)));
        }
Пример #9
0
        /// <summary>
        /// Creates a new <see cref="FileDataReader"/>.
        /// </summary>
        /// <param name="dataPacket">the data packet to read</param>
        /// <exception cref="ArgumentNullException">if <paramref name="dataPacket"/> is <c>null</c></exception>
        /// <exception cref="ArgumentException">if <paramref name="dataPacket"/> contains more than one <em>fragment</em></exception>
        /// <exception cref="ArgumentException">if <paramref name="dataPacket"/> extends beyond the end of the file</exception>
        /// <exception cref="FileNotFoundException">if <c>dataPacket.InputFile</c> does not exist</exception>
        public FileDataReader(IDataPacket dataPacket)
        {
            PreConditions.Argument("dataPacket").Value(dataPacket).IsNotNull();
            PreConditions.Argument("dataPacket").IsInvalidIf((dataPacket.GetFragment(0L) != dataPacket), "Data packet contains more than one fragment");

            _dataPacket = dataPacket;
            _fileStream = new FileStream(dataPacket.InputFile.Name, FileMode.Open, FileAccess.Read, FileShare.Read);
            if (dataPacket.EndOffset > _fileStream.Length)
            {
                throw new ArgumentException("Data packet extends beyond end-of-file.", "dataPacket");
            }

            Position = 0;               // This will also set the state
        }
Пример #10
0
            private static IEnumerable <IInputFile> GetInputFiles(IDataPacket dataPacket)
            {
                IList <IInputFile> inputFiles = new List <IInputFile> {
                    dataPacket.InputFile
                };
                IDataPacket subpacket;

                for (long relativeOffset = 0L; relativeOffset < dataPacket.Length; relativeOffset += subpacket.Length)
                {
                    subpacket = dataPacket.GetFragment(relativeOffset);

                    if (!inputFiles.Contains(subpacket.InputFile))
                    {
                        inputFiles.Add(subpacket.InputFile);
                    }
                }
                return(inputFiles);
            }
Пример #11
0
        private RangeList BuildRangeList(IDataPacket dataPacket)
        {
            RangeList ranges = new RangeList();

            if (dataPacket == null)
            {
                return(ranges);
            }

            long bytesRead = 0;

            while (bytesRead < dataPacket.Length)
            {
                IDataPacket fragment = dataPacket.GetFragment(bytesRead);
                ranges.Add(new Range(fragment.StartOffset, fragment.Length));
                bytesRead += fragment.Length;
            }
            return(ranges);
        }
 public IDataPacket GetFragment(long offset)
 {
     return(_dataPacket.GetFragment(offset));
 }
 public void GetFragmentFirstFragment()
 {
     _dataPacket1.Stub(x => x.GetFragment(SubPacketOffset)).Return(_subPacket1);
     Assert.AreSame(_subPacket1, _dataPacket.GetFragment(SubPacketOffset));
 }
Пример #14
0
 /// <summary>
 /// Tests whether <paramref name="dataPacket"/> is fragmented.
 /// </summary>
 /// <param name="dataPacket">the data packet to test</param>
 /// <return><c>true</c> if the packet is fragmented, <c>false</c> otherwise</return>
 public static bool IsFragmented(this IDataPacket dataPacket)
 {
     return(dataPacket.GetFragment(0).Length != dataPacket.Length);
 }