public HFSFile(BinaryReader reader, bool slim = false) { if (reader.ReadInt32() != HFHeader) { throw new HFSException(HFSError.HFSFileMismatch); } ExtractVersion = reader.ReadInt16(); BitFlag = reader.ReadInt16(); Contract.Assert(BitFlag == 0, "BitFlag == 0"); CompressionMethod = (HFSCompressionMethod)reader.ReadInt16(); Contract.Assert(CompressionMethod == HFSCompressionMethod.Store, "CompressionMethod == Store"); ModFileTime = reader.ReadInt16(); ModFileDate = reader.ReadInt16(); int position; if (!slim) { Checksum = reader.ReadInt32(); CompressedSize = reader.ReadInt32(); DecompressedSize = reader.ReadInt32(); var filenameLength = reader.ReadInt16(); var extraLength = reader.ReadInt16(); position = (int)reader.BaseStream.Position; Filename = HFS.XorStringWithKey(reader.ReadBytes(filenameLength), HFSXorTruths.KeyTable, position); position = (int)reader.BaseStream.Position; Extra = HFS.XorStringWithKey(reader.ReadBytes(extraLength), HFSXorTruths.KeyTable, position); } else { CompressedSize = DecompressedSize = (int)(reader.BaseStream.Length - reader.BaseStream.Position); Filename = "unknown.bin"; } position = (int)reader.BaseStream.Position; Data = HFS.XorBlockWithKey(reader.ReadBytes(CompressedSize), HFSXorTruths.KeyTable, position); if (Filename.EndsWith(".comp")) { using (var ms = new MemoryStream(Data)) using (var msReader = new BinaryReader(ms)) { ms.Position = 0; var compressionHeader = msReader.ReadInt32(); var compressionSize = msReader.ReadInt32(); if (compressionHeader == CompHeader) { ms.Position += 2; DecompressedSize = compressionSize; Filename = Path.GetFileNameWithoutExtension(Filename); using (var zip = new DeflateStream(ms, CompressionMode.Decompress)) { Data = new byte[compressionSize]; zip.Read(Data, 0, compressionSize); } } } } }
public HFSIndex(BinaryReader reader) { if (reader.ReadInt32() != HFIndexHeader) { throw new HFSException(HFSError.HFSIndexMismatch); } IndexNumber = reader.ReadInt16(); PartitionNumber = reader.ReadInt16(); Contract.Assert(IndexNumber == PartitionNumber, "IndexNumber == DirectoryIndex"); DirectoryCount = reader.ReadInt16(); DirectoryPartition = reader.ReadInt16(); Contract.Assert(DirectoryCount == DirectoryPartition, "DirectoryCount == DirectoryNumber"); DirectoryBlockSize = reader.ReadInt32(); DirectoryOffset = reader.ReadInt32(); var length = reader.ReadInt16(); var position = (int)reader.BaseStream.Position; Comment = HFS.XorStringWithKey(reader.ReadBytes(length), HFSXorTruths.KeyTable, position); }
public HFSDirectory(BinaryReader reader) { if (reader.ReadInt32() != HFSFile.HFHeader) { throw new HFSException(HFSError.HFSDirectoryMismatch); } Version = reader.ReadInt16(); ExtractVersion = reader.ReadInt16(); BitFlag = reader.ReadInt16(); CompressionMethod = (HFSCompressionMethod)reader.ReadInt16(); Contract.Assert(CompressionMethod == HFSCompressionMethod.Store, "CompressionMethod == Store"); ModFileTime = reader.ReadInt16(); ModFileDate = reader.ReadInt16(); Checksum = reader.ReadInt32(); CompressedSize = reader.ReadInt32(); DecompressedSize = reader.ReadInt32(); var filenameLength = reader.ReadInt16(); var extraLength = reader.ReadInt16(); var commentLength = reader.ReadInt16(); PartitionNumber = reader.ReadInt16(); InternalAttributes = reader.ReadInt16(); Attributes = reader.ReadInt32(); DataOffset = reader.ReadInt32(); var position = (int)reader.BaseStream.Position; Filename = HFS.XorStringWithKey(reader.ReadBytes(filenameLength), HFSXorTruths.KeyTable, position); position = (int)reader.BaseStream.Position; Extra = HFS.XorStringWithKey(reader.ReadBytes(extraLength), HFSXorTruths.KeyTable, position); position = (int)reader.BaseStream.Position; Comment = HFS.XorStringWithKey(reader.ReadBytes(commentLength), HFSXorTruths.KeyTable, position); position = (int)reader.BaseStream.Position; reader.BaseStream.Position = DataOffset; File = new HFSFile(reader); reader.BaseStream.Position = position; }