/// <summary> /// /// </summary> /// <param name="isInflated"></param> /// <returns></returns> public List <V8FileSystemReference> ReadFileSystemReferences(bool isInflated = true) { V8BlockHeader blockHeader = ReadBlockHeader(); Int32 dataSize = blockHeader.DataSize; Int32 capacity = (int)(dataSize / V8FileSystemReference.Size()); byte[] bytes = ReadBytes(blockHeader); List <V8FileSystemReference> references = new List <V8FileSystemReference>(capacity); Int32 bytesReaded = 0; while (dataSize > bytesReaded) { V8FileSystemReference reference = ReadFileSystemReference(bytes, bytesReaded); // Seek to reference block header Seek(reference.RefToHeader, SeekOrigin.Begin); reference.FileHeader = ReadFileHeader(ReadBlockHeader().DataSize); reference.IsInFlated = isInflated; references.Add(reference); bytesReaded += V8FileSystemReference.Size(); } return(references); }
/// <summary> /// Reads <see cref="V8Commit.Entities.V8FileSystem.V8BlockHeader"/> /// from <see cref="_reader"/> /// </summary> /// <returns> /// Returns <see cref="V8Commit.Entities.V8FileSystem.V8BlockHeader"/> /// with data /// </returns> /// <permission cref="System.Security.PermissionSet">Everyone /// can access this method. /// </permission> public V8BlockHeader ReadBlockHeader() { char[] Block = _reader.ReadChars(V8BlockHeader.Size()); if (Block[0] != 0x0d || Block[1] != 0x0a || Block[10] != 0x20 || Block[19] != 0x20 || Block[28] != 0x20 || Block[29] != 0x0d || Block[30] != 0x0a) { throw new NotImplementedException(); } string HexDataSize = new string(Block, 2, 8); string HexPageSize = new string(Block, 11, 8); string HexNextPage = new string(Block, 20, 8); V8BlockHeader header = new V8BlockHeader(); header.DataSize = Convert.ToInt32(HexDataSize, 16); header.PageSize = Convert.ToInt32(HexPageSize, 16); header.RefToNextPage = Convert.ToInt32(HexNextPage, 16); return(header); }
/// <summary> /// /// </summary> /// <param name="blockHeader"></param> /// <returns></returns> public byte[] ReadBytes(V8BlockHeader blockHeader) { Int32 bytesReaded = 0; Int32 bytesToRead = 0; Int32 dataSize = blockHeader.DataSize; byte[] bytes = new byte[dataSize]; while (dataSize > bytesReaded) { bytesToRead = Math.Min(blockHeader.PageSize, dataSize - bytesReaded); _reader.Read(bytes, bytesReaded, bytesToRead); bytesReaded += bytesToRead; if (blockHeader.RefToNextPage != 0x7FFFFFFF) { // Seek to next block header Seek(blockHeader.RefToNextPage, SeekOrigin.Begin); blockHeader = ReadBlockHeader(); } } return(bytes); }
/// <summary> /// Checks the stream matching 1CV8 file /// </summary> /// <param name="stream"> /// <see cref="System.IO.MemoryStream"/>, passed by reference, /// that contains the data to be checked /// </param> /// <returns> /// Returns the result of the comparison /// <see cref="System.IO.MemoryStream"/> with file description 1CV8 /// </returns> /// <example> This sample shows how to use /// the IsV8FileSystem method from your plugin /// <code> /// /// using (FileV8Reader v8Reader = new FileV8Reader(Input)) /// { /// var fileSystem = v8Reader.ReadV8FileSystem(); /// foreach (var reference in fileSystem.References) /// { /// v8Reader.Seek(reference.RefToData, SeekOrigin.Begin); /// using (MemoryStream memStream = new MemoryStream()) /// { /// using (MemoryStream memReader = new MemoryStream(v8Reader.ReadBytes(v8Reader.ReadBlockHeader()))) /// { /// if (reference.IsInFlated) /// { /// using (DeflateStream deflateStream = new DeflateStream(memReader, CompressionMode.Decompress)) /// { /// deflateStream.CopyTo(memStream); /// } /// } /// else /// { /// memReader.CopyTo(memStream); /// } /// } /// /// if (v8Reader.IsV8FileSystem(memStream)) /// { /// // some yours сode /// } /// else /// { /// // some yours сode /// } /// } /// } /// } /// /// </code> /// </example> /// <permission cref="System.Security.PermissionSet">Everyone /// can access this method. /// </permission> public bool IsV8FileSystem(MemoryStream stream) { if (stream.Capacity < V8ContainerHeader.Size() + V8BlockHeader.Size()) { return(false); } stream.Seek(0, SeekOrigin.Begin); using (FileV8Reader tmpV8Reader = new FileV8Reader(new BinaryReader(stream, Encoding.Default, true))) { try { tmpV8Reader.ReadContainerHeader(); tmpV8Reader.ReadBlockHeader(); } catch { return(false); } } return(true); }