コード例 #1
0
 public PreviewForm(ArchiveFile file)
 {
     InitializeComponent();
     dataText.Text = Encoding.ASCII.GetString(file.Data);
     this.file     = file;
     this.Text     = file.Name;
 }
コード例 #2
0
ファイル: DWFBArchive.cs プロジェクト: ThemeParkWorld/WADView
        private void ReadArchive()
        {
            memoryStream.Seek(0, SeekOrigin.Begin);

            /* Header:
             * 4 - magic number ('DWFB')
             * 4 - version
             * 64 - padding??
             * 4 - file count
             * 4 - file list offset
             * 4 - file list length
             * 4 - null
             */

            var magicNumber = memoryStream.ReadString(4);

            if (magicNumber != "DWFB")
            {
                throw new NotDWFBException($"Magic number did not match: {magicNumber}");
            }
            version = memoryStream.ReadInt32();
            memoryStream.Seek(64, SeekOrigin.Current); // Skip padding
            var fileCount = memoryStream.ReadInt32();

            var fileDirectoryOffset = memoryStream.ReadInt32();
            var fileDirectoryLength = memoryStream.ReadInt32();

            memoryStream.Seek(4, SeekOrigin.Current); // Skip 'null'

            uint lowestUnk = uint.MaxValue;

            // Details directory
            // See DWFBFile for more info
            for (int i = 0; i < fileCount; ++i)
            {
                GC.Collect();
                // Save the current position so that we can go back to it later
                var initialPos = memoryStream.Position;

                ArchiveFile newFile = new ArchiveFile();

                var unknown = memoryStream.ReadUInt32();
                if (unknown < lowestUnk)
                {
                    lowestUnk = unknown;
                }

                var filenameOffset = memoryStream.ReadUInt32();
                var filenameLength = memoryStream.ReadUInt32();
                var dataOffset     = memoryStream.ReadUInt32();
                var dataLength     = memoryStream.ReadUInt32();

                newFile.IsCompressed     = memoryStream.ReadUInt32() == 4;
                newFile.DecompressedSize = memoryStream.ReadUInt32();

                // Set file's name
                memoryStream.Seek(filenameOffset, SeekOrigin.Begin);
                newFile.Name = memoryStream.ReadString((int)filenameLength).Replace("\0", "");

                // Get file's raw data
                memoryStream.Seek(dataOffset, SeekOrigin.Begin);
                newFile.Data = memoryStream.ReadBytes((int)dataLength);

                newFile.ArchiveOffset = (int)dataOffset;
                newFile.ParentArchive = this;

                newFile.Unknown = unknown;

                files.Add(newFile);
                memoryStream.Seek(initialPos + 40, SeekOrigin.Begin); // Return to initial position, skip to the next file's data
            }

            MessageBox.Show($"Lowest unknown: {lowestUnk}");
        }
コード例 #3
0
        private void ReadArchive()
        {
            memoryStream.Seek(0, SeekOrigin.Begin);

            /* Header:
             * 4 - magic number ('FKNL')
             * 4 - flags
             * 4 - data offset
             *  if flags & 2
             *      4 - size
             *      4 - zsize
             *      4 - files
             *      4 - dummy
             * 4 - dummy
             * 4 - filename dictionary offset
             * 4 - ??
             * 4 - ??
             * 4 - ??
             */

            /* Details directory
             * for each file:
             * 4 - filename size?
             * 4 - filename offset
             * 4 - file offset (relative to file data start)
             * 4 - file length
             */

            var magicNumber = memoryStream.ReadString(4);

            if (magicNumber != "FKNL")
            {
                throw new NotDWFBException($"Magic number did not match: {magicNumber}");
            }
            version = memoryStream.ReadInt32();

            var firstFileOffset = memoryStream.ReadInt32();

            var fileDirectoryOffset = memoryStream.ReadInt32();
            var fileDirectoryLength = memoryStream.ReadInt32();

            memoryStream.Seek(4, SeekOrigin.Current); // Skip 'null'

            // Details directory
            // See DWFBFile for more info
            for (int i = 0; i < 1; ++i)
            {
                GC.Collect();
                // Save the current position so that we can go back to it later
                var initialPos = memoryStream.Position;

                ArchiveFile newFile        = new ArchiveFile();
                var         filenameLength = memoryStream.ReadUInt32();
                var         filenameOffset = memoryStream.ReadUInt32();
                var         dataOffset     = memoryStream.ReadUInt32();
                var         dataLength     = memoryStream.ReadUInt32();

                newFile.IsCompressed     = memoryStream.ReadUInt32() == 4;
                newFile.DecompressedSize = memoryStream.ReadUInt32();

                // Set file's name
                memoryStream.Seek(filenameOffset, SeekOrigin.Begin);
                newFile.Name = memoryStream.ReadString((int)filenameLength);

                // Get file's raw data
                memoryStream.Seek(dataOffset, SeekOrigin.Begin);
                newFile.Data = memoryStream.ReadBytes((int)dataLength);

                newFile.ArchiveOffset = (int)dataOffset;
                newFile.ParentArchive = this;

                files.Add(newFile);
                memoryStream.Seek(initialPos + 40, SeekOrigin.Begin); // Return to initial position, skip to the next file's data
            }
        }