示例#1
0
        public void Parse(byte[] headerData, int headerOffset, byte[] bodyData)
        {
            BasicHeaderSegment _headerSegment = new BasicHeaderSegment();

            _headerSegment.ReadFrom(headerData, headerOffset);

            if (_headerSegment.OpCode != OpCode.LoginResponse)
            {
                throw new InvalidProtocolException("Invalid opcode in response, expected " + OpCode.LoginResponse +
                                                   " was " + _headerSegment.OpCode);
            }

            UnpackState(headerData[headerOffset + 1]);
            MaxVersion                    = headerData[headerOffset + 2];
            ActiveVersion                 = headerData[headerOffset + 3];
            TargetSessionId               = EndianUtilities.ToUInt16BigEndian(headerData, headerOffset + 14);
            StatusPresent                 = true;
            StatusSequenceNumber          = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 24);
            ExpectedCommandSequenceNumber = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 28);
            MaxCommandSequenceNumber      = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 32);
            StatusClass                   = headerData[headerOffset + 36];
            StatusCode                    = (LoginStatusCode)EndianUtilities.ToUInt16BigEndian(headerData, headerOffset + 36);

            TextData = bodyData;
        }
示例#2
0
        public ushort VersionNum;    // 00 04

        public void ReadFrom(byte[] buffer, int offset)
        {
            Signature    = EndianUtilities.BytesToString(buffer, offset + 0x00, 4);
            NumVBlks     = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0x04);
            BlockSize    = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0x08);
            HeaderSize   = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0x0C);
            Unknown1     = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x10);
            VersionNum   = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x12);
            VersionDenom = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x14);
            GroupName    = EndianUtilities.BytesToString(buffer, offset + 0x16, 31).Trim('\0');
            DiskGroupId  = EndianUtilities.BytesToString(buffer, offset + 0x35, 0x40).Trim('\0');

            // May be wrong way round...
            CommittedSequence = EndianUtilities.ToInt64BigEndian(buffer, offset + 0x75);
            PendingSequence   = EndianUtilities.ToInt64BigEndian(buffer, offset + 0x7D);

            Unknown2 = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0x85);
            Unknown3 = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0x89);
            Unknown4 = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0x8D);
            Unknown5 = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0x91);
            Unknown6 = EndianUtilities.ToInt64BigEndian(buffer, offset + 0x95);
            Unknown7 = EndianUtilities.ToInt64BigEndian(buffer, offset + 0x9D);
            Unknown8 = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0xA5);
            Unknown9 = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0xA9);
            UnknownA = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0xAD);

            UnknownB = EndianUtilities.ToInt64BigEndian(buffer, offset + 0xB1);
            UnknownC = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0xB9);

            Timestamp = DateTime.FromFileTimeUtc(EndianUtilities.ToInt64BigEndian(buffer, offset + 0xBD));
        }
示例#3
0
        public ushort ReadUShort()
        {
            ushort result = EndianUtilities.ToUInt16BigEndian(_data, Position);

            Position += 2;
            return(result);
        }
示例#4
0
 public override int ReadFrom(byte[] buffer, int offset)
 {
     Freetag = EndianUtilities.ToUInt16BigEndian(buffer, offset);
     Length  = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x2);
     Tag     = EndianUtilities.ToUInt16BigEndian(buffer, offset + Length - 0x2);
     return(Size);
 }
示例#5
0
        public override string ToString()
        {
            OSClass      osClass = (OSClass)Suffix[0];
            OSIdentifier osId    = (OSIdentifier)EndianUtilities.ToUInt16BigEndian(Suffix, 0);

            return(string.Format(CultureInfo.InvariantCulture, "{0} [OS {1} {2}]", Identifier, osClass, osId));
        }
示例#6
0
 public override int ReadFrom(byte[] buffer, int offset)
 {
     this.keyLength = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0);
     this.forkType = buffer[offset + 2];
     this.NodeId = new CatalogNodeId(EndianUtilities.ToUInt32BigEndian(buffer, offset + 4));
     this.startBlock = EndianUtilities.ToUInt32BigEndian(buffer, offset + 8);
     return this.keyLength + 2;
 }
示例#7
0
        public override int ReadFrom(byte[] buffer, int offset)
        {
            _keyLength = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0);
            NodeId     = new CatalogNodeId(EndianUtilities.ToUInt32BigEndian(buffer, offset + 2));
            Name       = HfsUtilities.ReadUniStr255(buffer, offset + 6);

            return(_keyLength + 2);
        }
示例#8
0
        public int ReadFrom(byte[] buffer, int offset)
        {
            FileType    = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0);
            FileCreator = EndianUtilities.ToUInt32BigEndian(buffer, offset + 4);
            FinderFlags = (FinderFlags)EndianUtilities.ToUInt16BigEndian(buffer, offset + 8);
            Point       = EndianUtilities.ToStruct <Point>(buffer, offset + 10);

            return(16);
        }
示例#9
0
        public override int ReadFrom(byte[] buffer, int offset)
        {
            base.ReadFrom(buffer, offset);

            Flags   = EndianUtilities.ToUInt16BigEndian(buffer, offset + 2);
            Valence = EndianUtilities.ToUInt32BigEndian(buffer, offset + 4);

            return(0);
        }
示例#10
0
 public virtual int ReadFrom(byte[] buffer, int offset)
 {
     Magic           = EndianUtilities.ToUInt32BigEndian(buffer, offset);
     Level           = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x4);
     NumberOfRecords = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x6);
     LeftSibling     = EndianUtilities.ToInt64BigEndian(buffer, offset + 0x8);
     RightSibling    = EndianUtilities.ToInt64BigEndian(buffer, offset + 0xC);
     return(24);
 }
示例#11
0
        /// <inheritdoc/>
        public override int ReadFrom(byte[] buffer, int offset)
        {
            int read = base.ReadFrom(buffer, offset);

            this.Flags   = EndianUtilities.ToUInt16BigEndian(buffer, offset + 2);
            this.Valence = EndianUtilities.ToUInt32BigEndian(buffer, offset + 4);

            return(read + 6);
        }
示例#12
0
        private static int ADCDecompress(
            byte[] inputBuffer,
            int inputOffset,
            int inputCount,
            byte[] outputBuffer,
            int outputOffset)
        {
            int consumed = 0;
            int written = 0;

            while (consumed < inputCount)
            {
                byte focusByte = inputBuffer[inputOffset + consumed];
                if ((focusByte & 0x80) != 0)
                {
                    // Data Run
                    int chunkSize = (focusByte & 0x7F) + 1;
                    Array.Copy(inputBuffer, inputOffset + consumed + 1, outputBuffer, outputOffset + written, chunkSize);

                    consumed += chunkSize + 1;
                    written += chunkSize;
                }
                else if ((focusByte & 0x40) != 0)
                {
                    // 3 byte code
                    int chunkSize = (focusByte & 0x3F) + 4;
                    int offset = EndianUtilities.ToUInt16BigEndian(inputBuffer, inputOffset + consumed + 1);

                    for (int i = 0; i < chunkSize; ++i)
                    {
                        outputBuffer[outputOffset + written + i] =
                            outputBuffer[outputOffset + written + i - offset - 1];
                    }

                    consumed += 3;
                    written += chunkSize;
                }
                else
                {
                    // 2 byte code
                    int chunkSize = ((focusByte & 0x3F) >> 2) + 3;
                    int offset = ((focusByte & 0x3) << 8) + (inputBuffer[inputOffset + consumed + 1] & 0xFF);

                    for (int i = 0; i < chunkSize; ++i)
                    {
                        outputBuffer[outputOffset + written + i] =
                            outputBuffer[outputOffset + written + i - offset - 1];
                    }

                    consumed += 2;
                    written += chunkSize;
                }
            }

            return written;
        }
示例#13
0
        public override int ReadFrom(byte[] buffer, int offset)
        {
            this.keyLength  = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0);
            this.pad        = EndianUtilities.ToUInt16BigEndian(buffer, offset + 2);
            this.FileId     = new CatalogNodeId(EndianUtilities.ToUInt32BigEndian(buffer, offset + 4));
            this.startBlock = EndianUtilities.ToUInt32BigEndian(buffer, offset + 8);
            this.Name       = HfsPlusUtilities.ReadUniStr255(buffer, offset + 12);

            return(this.keyLength + 2);
        }
示例#14
0
        public override string ToString()
        {
            string       major   = ((uint)Suffix[1]).ToString("X", CultureInfo.InvariantCulture);
            string       minor   = ((uint)Suffix[0]).ToString("X", CultureInfo.InvariantCulture);
            OSClass      osClass = (OSClass)Suffix[2];
            OSIdentifier osId    = (OSIdentifier)EndianUtilities.ToUInt16BigEndian(Suffix, 2);

            return(string.Format(CultureInfo.InvariantCulture, "{0} [UDF {1}.{2} : OS {3} {4}]", Identifier, major,
                                 minor, osClass, osId));
        }
示例#15
0
        public override int ReadFrom(byte[] buffer, int offset)
        {
            Inode      = EndianUtilities.ToUInt64BigEndian(buffer, offset);
            NameLength = buffer[offset + 0x8];
            Name       = EndianUtilities.ToByteArray(buffer, offset + 0x9, NameLength);
            var padding = 6 - ((NameLength + 1) % 8);

            offset += padding;
            Tag     = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x9 + NameLength);
            return(Size);
        }
示例#16
0
        public int ReadFrom(byte[] buffer, int offset)
        {
            ForwardLink  = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0);
            BackwardLink = EndianUtilities.ToUInt32BigEndian(buffer, offset + 4);
            Kind         = (BTreeNodeKind)buffer[offset + 8];
            Height       = buffer[offset + 9];
            NumRecords   = EndianUtilities.ToUInt16BigEndian(buffer, offset + 10);
            Reserved     = EndianUtilities.ToUInt16BigEndian(buffer, offset + 12);

            return(14);
        }
示例#17
0
        public override int ReadFrom(byte[] buffer, int offset)
        {
            base.ReadFrom(buffer, offset);

            Flags    = EndianUtilities.ToUInt16BigEndian(buffer, offset + 2);
            FileInfo = EndianUtilities.ToStruct <FileInfo>(buffer, offset + 48);

            DataFork     = EndianUtilities.ToStruct <ForkData>(buffer, offset + 88);
            ResourceFork = EndianUtilities.ToStruct <ForkData>(buffer, offset + 168);

            return(0);
        }
示例#18
0
        public int ReadFrom(byte[] buffer, int offset)
        {
            Signature   = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0);
            BlockSize   = EndianUtilities.ToUInt16BigEndian(buffer, offset + 2);
            BlockCount  = EndianUtilities.ToUInt32BigEndian(buffer, offset + 4);
            DeviceType  = EndianUtilities.ToUInt16BigEndian(buffer, offset + 8);
            DeviceId    = EndianUtilities.ToUInt16BigEndian(buffer, offset + 10);
            DriverData  = EndianUtilities.ToUInt32BigEndian(buffer, offset + 12);
            DriverCount = EndianUtilities.ToUInt16LittleEndian(buffer, offset + 16);

            return(512);
        }
 public int ReadFrom(byte[] buffer, int offset)
 {
     NameLength = buffer[offset];
     Offset     = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x1);
     Name       = EndianUtilities.ToByteArray(buffer, offset + 0x3, NameLength);
     if (_useShortInode)
     {
         Inode = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0x3 + NameLength);
     }
     else
     {
         Inode = EndianUtilities.ToUInt64BigEndian(buffer, offset + 0x3 + NameLength);
     }
     return(Size);
 }
示例#20
0
        public int ReadFrom(byte[] buffer, int offset)
        {
            Signature          = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0);
            MapEntries         = EndianUtilities.ToUInt32BigEndian(buffer, offset + 4);
            PhysicalBlockStart = EndianUtilities.ToUInt32BigEndian(buffer, offset + 8);
            PhysicalBlocks     = EndianUtilities.ToUInt32BigEndian(buffer, offset + 12);
            Name = EndianUtilities.BytesToString(buffer, offset + 16, 32).TrimEnd('\0');
            Type = EndianUtilities.BytesToString(buffer, offset + 48, 32).TrimEnd('\0');
            LogicalBlockStart = EndianUtilities.ToUInt32BigEndian(buffer, offset + 80);
            LogicalBlocks     = EndianUtilities.ToUInt32BigEndian(buffer, offset + 84);
            Flags             = EndianUtilities.ToUInt32BigEndian(buffer, offset + 88);
            BootBlock         = EndianUtilities.ToUInt32BigEndian(buffer, offset + 92);
            BootBytes         = EndianUtilities.ToUInt32BigEndian(buffer, offset + 96);

            return(512);
        }
示例#21
0
        public int ReadFrom(byte[] buffer, int offset)
        {
            Signature = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0);
            if (!IsValid)
            {
                return(Size);
            }

            Version            = EndianUtilities.ToUInt16BigEndian(buffer, offset + 2);
            Attributes         = (VolumeAttributes)EndianUtilities.ToUInt32BigEndian(buffer, offset + 4);
            LastMountedVersion = EndianUtilities.ToUInt32BigEndian(buffer, offset + 8);
            JournalInfoBlock   = EndianUtilities.ToUInt32BigEndian(buffer, offset + 12);

            CreateDate  = HfsPlusUtilities.ReadHFSPlusDate(DateTimeKind.Local, buffer, offset + 16);
            ModifyDate  = HfsPlusUtilities.ReadHFSPlusDate(DateTimeKind.Utc, buffer, offset + 20);
            BackupDate  = HfsPlusUtilities.ReadHFSPlusDate(DateTimeKind.Utc, buffer, offset + 24);
            CheckedDate = HfsPlusUtilities.ReadHFSPlusDate(DateTimeKind.Utc, buffer, offset + 28);

            FileCount   = EndianUtilities.ToUInt32BigEndian(buffer, offset + 32);
            FolderCount = EndianUtilities.ToUInt32BigEndian(buffer, offset + 36);

            BlockSize   = EndianUtilities.ToUInt32BigEndian(buffer, offset + 40);
            TotalBlocks = EndianUtilities.ToUInt32BigEndian(buffer, offset + 44);
            FreeBlocks  = EndianUtilities.ToUInt32BigEndian(buffer, offset + 48);

            NextAllocation    = EndianUtilities.ToUInt32BigEndian(buffer, offset + 52);
            ResourceClumpSize = EndianUtilities.ToUInt32BigEndian(buffer, offset + 56);
            DataClumpSize     = EndianUtilities.ToUInt32BigEndian(buffer, offset + 60);
            NextCatalogId     = new CatalogNodeId(EndianUtilities.ToUInt32BigEndian(buffer, offset + 64));

            WriteCount      = EndianUtilities.ToUInt32BigEndian(buffer, offset + 68);
            EncodingsBitmap = EndianUtilities.ToUInt64BigEndian(buffer, offset + 72);

            FinderInfo = new uint[8];
            for (int i = 0; i < 8; ++i)
            {
                FinderInfo[i] = EndianUtilities.ToUInt32BigEndian(buffer, offset + 80 + i * 4);
            }

            AllocationFile = EndianUtilities.ToStruct <ForkData>(buffer, offset + 112);
            ExtentsFile    = EndianUtilities.ToStruct <ForkData>(buffer, offset + 192);
            CatalogFile    = EndianUtilities.ToStruct <ForkData>(buffer, offset + 272);
            AttributesFile = EndianUtilities.ToStruct <ForkData>(buffer, offset + 352);
            StartupFile    = EndianUtilities.ToStruct <ForkData>(buffer, offset + 432);

            return(512);
        }
示例#22
0
        public string ReadName()
        {
            StringBuilder sb = new StringBuilder();

            bool hasIndirected = false;
            int  readPos       = Position;

            while (_data[readPos] != 0)
            {
                byte len = _data[readPos];
                switch (len & 0xC0)
                {
                case 0x00:
                    sb.Append(Encoding.UTF8.GetString(_data, readPos + 1, len));
                    sb.Append(".");
                    readPos += 1 + len;
                    if (!hasIndirected)
                    {
                        Position = readPos;
                    }

                    break;

                case 0xC0:
                    if (!hasIndirected)
                    {
                        Position += 2;
                    }

                    hasIndirected = true;
                    readPos       = EndianUtilities.ToUInt16BigEndian(_data, readPos) & 0x3FFF;
                    break;

                default:
                    throw new NotImplementedException("Unknown control flags reading label");
                }
            }

            if (!hasIndirected)
            {
                Position++;
            }

            return(sb.ToString());
        }
示例#23
0
 public int ReadFrom(byte[] buffer, int offset)
 {
     Level           = EndianUtilities.ToUInt16BigEndian(buffer, offset);
     NumberOfRecords = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x2);
     offset         += 0x4;
     Keys            = new ulong[NumberOfRecords];
     Pointer         = new ulong[NumberOfRecords];
     for (int i = 0; i < NumberOfRecords; i++)
     {
         Keys[i] = EndianUtilities.ToUInt64BigEndian(buffer, offset + i * 0x8);
     }
     offset += ((buffer.Length - offset) / 16) * 8;
     for (int i = 0; i < NumberOfRecords; i++)
     {
         Pointer[i] = EndianUtilities.ToUInt64BigEndian(buffer, offset + i * 0x8);
     }
     return(Size);
 }
示例#24
0
        public virtual int ReadFrom(byte[] buffer, int offset)
        {
            Magic           = EndianUtilities.ToUInt32BigEndian(buffer, offset);
            Level           = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x4);
            NumberOfRecords = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0x6);
            LeftSibling     = EndianUtilities.ToInt32BigEndian(buffer, offset + 0x8);
            RightSibling    = EndianUtilities.ToInt32BigEndian(buffer, offset + 0xC);
            if (SbVersion >= 5)
            {
                Bno      = EndianUtilities.ToUInt64BigEndian(buffer, offset + 0x10);
                Lsn      = EndianUtilities.ToUInt64BigEndian(buffer, offset + 0x18);
                UniqueId = EndianUtilities.ToGuidBigEndian(buffer, offset + 0x20);
                Owner    = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0x30);
                Crc      = EndianUtilities.ToUInt32BigEndian(buffer, offset + 0x34);
            }

            return(Size);
        }
示例#25
0
        public void Parse(byte[] headerData, int headerOffset)
        {
            BasicHeaderSegment _headerSegment = new BasicHeaderSegment();

            _headerSegment.ReadFrom(headerData, headerOffset);

            if (_headerSegment.OpCode != OpCode.LogoutResponse)
            {
                throw new InvalidProtocolException("Invalid opcode in response, expected " + OpCode.LogoutResponse +
                                                   " was " + _headerSegment.OpCode);
            }

            Response                      = (LogoutResponseCode)headerData[headerOffset + 2];
            StatusSequenceNumber          = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 24);
            ExpectedCommandSequenceNumber = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 28);
            MaxCommandSequenceNumber      = EndianUtilities.ToUInt32BigEndian(headerData, headerOffset + 32);
            Time2Wait                     = EndianUtilities.ToUInt16BigEndian(headerData, headerOffset + 40);
            Time2Retain                   = EndianUtilities.ToUInt16BigEndian(headerData, headerOffset + 42);
        }
示例#26
0
        public override int ReadFrom(byte[] buffer, int offset)
        {
            TreeDepth      = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0);
            RootNode       = EndianUtilities.ToUInt32BigEndian(buffer, offset + 2);
            NumLeafRecords = EndianUtilities.ToUInt32BigEndian(buffer, offset + 6);
            FirstLeafNode  = EndianUtilities.ToUInt32BigEndian(buffer, offset + 10);
            LastLeafNode   = EndianUtilities.ToUInt32BigEndian(buffer, offset + 14);
            NodeSize       = EndianUtilities.ToUInt16BigEndian(buffer, offset + 18);
            MaxKeyLength   = EndianUtilities.ToUInt16BigEndian(buffer, offset + 20);
            TotalNodes     = EndianUtilities.ToUInt16BigEndian(buffer, offset + 22);
            FreeNodes      = EndianUtilities.ToUInt32BigEndian(buffer, offset + 24);
            Res1           = EndianUtilities.ToUInt16BigEndian(buffer, offset + 28);
            ClumpSize      = EndianUtilities.ToUInt32BigEndian(buffer, offset + 30);
            TreeType       = buffer[offset + 34];
            KeyCompareType = buffer[offset + 35];
            Attributes     = EndianUtilities.ToUInt32BigEndian(buffer, offset + 36);

            return(104);
        }
示例#27
0
        public int ReadFrom(byte[] buffer, int offset)
        {
            /*
             * struct ExtDescriptor
             * size: 4 bytes
             * description:
             *
             * BP  Size  Type    Identifier   Description
             * ----------------------------------------------------------
             * 0   2     UInt16  xdrStABN     first allocation block
             * 2   2     UInt16  xdrNumABlks  number of allocation blocks
             */


            StartBlock = EndianUtilities.ToUInt16BigEndian(buffer, offset + 0);
            BlockCount = EndianUtilities.ToUInt16BigEndian(buffer, offset + 2);

            return(4);
        }
示例#28
0
        /// <summary>
        /// Initializes a new instance of the ZlibStream class.
        /// </summary>
        /// <param name="stream">The stream to compress of decompress.</param>
        /// <param name="mode">Whether to compress or decompress.</param>
        /// <param name="leaveOpen">Whether closing this stream should leave <c>stream</c> open.</param>
        public ZlibStream(Stream stream, CompressionMode mode, bool leaveOpen)
        {
            _stream = stream;
            _mode   = mode;

            if (mode == CompressionMode.Decompress)
            {
                // We just sanity check against expected header values...
                byte[] headerBuffer = StreamUtilities.ReadExact(stream, 2);
                ushort header       = EndianUtilities.ToUInt16BigEndian(headerBuffer, 0);

                if (header % 31 != 0)
                {
                    throw new IOException("Invalid Zlib header found");
                }

                if ((header & 0x0F00) != 8 << 8)
                {
                    throw new NotSupportedException("Zlib compression not using DEFLATE algorithm");
                }

                if ((header & 0x0020) != 0)
                {
                    throw new NotSupportedException("Zlib compression using preset dictionary");
                }
            }
            else
            {
                ushort header =
                    (8 << 8)    // DEFLATE
                    | (7 << 12) // 32K window size
                    | 0x80;     // Default algorithm
                header |= (ushort)(31 - header % 31);

                byte[] headerBuffer = new byte[2];
                EndianUtilities.WriteBytesBigEndian(header, headerBuffer, 0);
                stream.Write(headerBuffer, 0, 2);
            }

            _deflateStream = new DeflateStream(stream, mode, leaveOpen);
            _adler32       = new Adler32();
        }
示例#29
0
        protected override int ReadGrain(byte[] buffer, int bufferOffset, long grainStart, int grainOffset,
                                         int numToRead)
        {
            if ((_hostedHeader.Flags & HostedSparseExtentFlags.CompressedGrains) != 0)
            {
                _fileStream.Position = grainStart;

                byte[] readBuffer         = StreamUtilities.ReadExact(_fileStream, CompressedGrainHeader.Size);
                CompressedGrainHeader hdr = new CompressedGrainHeader();
                hdr.Read(readBuffer, 0);

                readBuffer = StreamUtilities.ReadExact(_fileStream, hdr.DataSize);

                // This is really a zlib stream, so has header and footer.  We ignore this right now, but we sanity
                // check against expected header values...
                ushort header = EndianUtilities.ToUInt16BigEndian(readBuffer, 0);

                if (header % 31 != 0)
                {
                    throw new IOException("Invalid ZLib header found");
                }

                if ((header & 0x0F00) != 8 << 8)
                {
                    throw new NotSupportedException("ZLib compression not using DEFLATE algorithm");
                }

                if ((header & 0x0020) != 0)
                {
                    throw new NotSupportedException("ZLib compression using preset dictionary");
                }

                Stream        readStream    = new MemoryStream(readBuffer, 2, hdr.DataSize - 2, false);
                DeflateStream deflateStream = new DeflateStream(readStream, CompressionMode.Decompress);

                // Need to skip some bytes, but DefaultStream doesn't support seeking...
                StreamUtilities.ReadExact(deflateStream, grainOffset);

                return(deflateStream.Read(buffer, bufferOffset, numToRead));
            }
            return(base.ReadGrain(buffer, bufferOffset, grainStart, grainOffset, numToRead));
        }
示例#30
0
        public static UnixFileSystemInfo ReadBsdInfo(byte[] buffer, int offset, out uint special)
        {
            UnixFileSystemInfo result = new UnixFileSystemInfo();

            result.UserId  = EndianUtilities.ToInt32BigEndian(buffer, offset + 0);
            result.GroupId = EndianUtilities.ToInt32BigEndian(buffer, offset + 4);

            ushort fileMode = EndianUtilities.ToUInt16BigEndian(buffer, offset + 8);

            result.FileType    = (UnixFileType)((fileMode >> 12) & 0xF);
            result.Permissions = (UnixFilePermissions)(fileMode & 0xFFF);

            special = EndianUtilities.ToUInt32BigEndian(buffer, offset + 10);
            if (result.FileType == UnixFileType.Block || result.FileType == UnixFileType.Character)
            {
                result.DeviceId = special;
            }

            return(result);
        }