Beispiel #1
0
            public FileStructureExtraData(Stream stream, CustomBinaryReader reader, int extra_length)
            {
                var end = stream.Position + extra_length;

                _UnknownID = reader.ReadInt16();
                StructureSizeAfterHeader = reader.ReadInt16();

                UncompressedFileLength = reader.ReadInt32();
                _UnknownD            = reader.ReadInt32();
                CompressedFileLength = reader.ReadInt32();
                _UnknownF            = reader.ReadInt32();

                var data_offset_ldword = (Int64)reader.ReadUInt32();
                var data_offset_hdword = (Int64)reader.ReadUInt32();

                DataOffset = data_offset_ldword + (data_offset_hdword << 32);

                _UnknownG = reader.ReadInt32();
                _Timestamp_Maybe_But_Not_Sure = reader.ReadInt32();

                // here be demons and lots of padding
                // make sure we read this to ensure the stream position is correct

                var padding_length = end - stream.Position;
                var data           = reader.ReadBytes((int)padding_length);

                if (stream.Position % 0x1000 != 0)
                {
                    throw new Exception("File Data Section Alignment Error (End Extra Read)");
                }

                FileDataOffset = stream.Position;
            }
 public CentralDirectoryEnd(Stream stream, CustomBinaryReader reader)
 {
     DiskNumber             = reader.ReadInt16();
     DiskNumberWithCD       = reader.ReadInt16();
     DiskEntries            = reader.ReadInt16();
     TotalEntries           = reader.ReadInt16();
     CentralDirectorySize   = reader.ReadInt32();
     OffsetOfCdStartingDisk = reader.ReadInt32();
     CommentLength          = reader.ReadInt16();
     Comment = reader.ReadString(CommentLength);
 }
 public CentralDirectoryLocator(Stream stream, CustomBinaryReader reader)
 {
     unknownA = reader.ReadInt32();
     unknownB = reader.ReadInt32();
     unknownC = reader.ReadInt16();
     unknownD = reader.ReadInt16();
     unknownE = reader.ReadInt32();
     unknownF = reader.ReadInt32();
     DontentDictionaryCount = reader.ReadInt32();
     unknownG = reader.ReadInt32();
     ContentDictionaryCount2 = reader.ReadInt32();
     unknownH = reader.ReadInt32();
     ContentDictionarySize = reader.ReadInt32();
     unknownI = reader.ReadInt32();
     ContentDirectoryOffset = reader.ReadInt64();
 }
Beispiel #4
0
        public FileStructure(Stream stream, CustomBinaryReader reader)
        {
            if ((stream.Position - 4) % 0x1000 != 0)
            {
                throw new Exception("File Data Section Alignment Error (Pre Read)");
            }

            Version          = reader.ReadInt16();
            Flags            = reader.ReadInt16();
            CompressionMode  = (FileCompressionMode)reader.ReadInt16();
            ModificationTime = reader.ReadUInt16();
            ModificationDate = reader.ReadUInt16();
            CRC32            = reader.ReadInt32();
            CompressedSize   = reader.ReadInt32();
            UncompressedSize = reader.ReadInt32();
            FilenameLength   = reader.ReadInt16();
            ExtraLength      = reader.ReadInt16();

            Filename = reader.ReadString(FilenameLength);
            Extra    = new FileStructureExtraData(stream, reader, ExtraLength);
        }
Beispiel #5
0
        public object ReadPK(Stream stream, CustomBinaryReader reader, Int64 offset)
        {
            stream.Seek(offset, SeekOrigin.Begin);

            var magic = reader.ReadInt16();

            if (magic != 0x4B50)
            {
                throw new Exception("Invalid PK offset");
            }

            Signature signature = (Signature)reader.ReadInt16();

            switch (signature)
            {
            case Signature.CentralDirectory:

                CentralDirectory centralDirectory = new CentralDirectory(stream, reader);

                if (Logging)
                {
                    Console.WriteLine($"Found CentralDirectory {centralDirectory.Filename}");
                }
                if (Logging)
                {
                    Console.WriteLine($"Searching for FileStructure @{centralDirectory.Extra.data_offset.ToString("X")}");
                }

                return(centralDirectory);

            case Signature.FileStructure:

                FileStructure fileStructure = new FileStructure(stream, reader);

                if (Logging)
                {
                    Console.WriteLine($"Found FileStructure {fileStructure.Filename}");
                }


                return(fileStructure);

            case Signature.CentralDirectoryLocator:

                CentralDirectoryLocator centralDirectoryLocator = new CentralDirectoryLocator(stream, reader);

                if (Logging)
                {
                    Console.WriteLine($"Found CentralDirectoryLocator @{offset}");
                }

                return(centralDirectoryLocator);

            case Signature.CentralDirectoryLocatorOffset:

                CentralDirectoryLocatorOffset centralDirectoryLocatorOffset = new CentralDirectoryLocatorOffset(stream, reader);

                if (Logging)
                {
                    Console.WriteLine($"Found CentralDirectoryLocatorOffset @{offset}");
                }

                return(centralDirectoryLocatorOffset);

            case Signature.CentralDirectoryEnd:

                CentralDirectoryEnd centralDirectoryEnd = new CentralDirectoryEnd(stream, reader);

                if (Logging)
                {
                    Console.WriteLine($"Found CentralDirectoryEnd @{offset}");
                }

                return(centralDirectoryEnd);

            default:
                throw new NotImplementedException();
            }
        }