コード例 #1
0
 public byte[] GetData()
 {
     BinaryFile.BaseStream.Position = (long)Offset;
     byte[] numArray = BinaryFile.ReadBytes((int)CompressedSize);
     if (string.IsNullOrEmpty(OverwrittenFilePath))
     {
         if ((Flags & Flag.Encrypted) == Flag.Encrypted)
         {
             numArray = BinaryExtension.Decrypt(numArray, BinaryExtension.GetDecryptionSeed(Version));
         }
         if ((Flags & Flag.Compressed) == Flag.Compressed)
         {
             numArray = ZLib.ZLib.Uncompress(numArray, (int)UncompressedSize);
         }
     }
     return(numArray);
 }
コード例 #2
0
 public RDAMemoryResidentHelper(ulong offset, ulong datasize, ulong compressed, Stream datasource, BlockInfo info, FileHeader.Version version)
 {
     Offset     = offset;
     DataSize   = datasize;
     Compressed = compressed;
     Info       = info;
     Data       = new MemoryStream();
     byte[] numArray = new byte[compressed];
     datasource.Position = (long)offset;
     datasource.Read(numArray, 0, (int)compressed);
     if ((info.flags & 2) == 2)
     {
         numArray = BinaryExtension.Decrypt(numArray, BinaryExtension.GetDecryptionSeed(version));
     }
     if ((info.flags & 1) == 1)
     {
         numArray = ZLib.ZLib.Uncompress(numArray, (int)datasize);
     }
     Data.Write(numArray, 0, numArray.Length);
 }
コード例 #3
0
        private ulong ReadBlock(ulong Offset, ulong beginningOfDataSection)
        {
            UpdateOutput("----- Reading Block at " + Offset);
            read.BaseStream.Position = (long)Offset;

            BlockInfo blockInfo = new BlockInfo
            {
                flags            = read.ReadUInt32(),
                fileCount        = read.ReadUInt32(),
                directorySize    = ReadUIntVersionAware(read),
                decompressedSize = ReadUIntVersionAware(read),
                nextBlock        = ReadUIntVersionAware(read),
            };

            if ((blockInfo.flags & 8) != 8)
            {
                bool isMemoryResident = false;
                bool isEncrypted      = false;
                bool isCompressed     = false;
                if ((blockInfo.flags & 4) == 4)
                {
                    UpdateOutput("MemoryResident");
                    isMemoryResident = true;
                }
                if ((blockInfo.flags & 2) == 2)
                {
                    UpdateOutput("Encrypted");
                    isEncrypted = true;
                }
                if ((blockInfo.flags & 1) == 1)
                {
                    UpdateOutput("Compressed");
                    isCompressed = true;
                }
                if (blockInfo.flags == 0)
                {
                    UpdateOutput("No Flags");
                }

                int decryptionSeed = 0;
                if (isEncrypted)
                {
                    try {
                        decryptionSeed = BinaryExtension.GetDecryptionSeed(fileHeader.version);
                    } catch (ArgumentException e) {
                        UpdateOutput("Skipping (" + blockInfo.fileCount + " files) -- " + e.Message);
                        skippedDataSections.Add(new RDASkippedDataSection()
                        {
                            blockInfo = blockInfo,
                            offset    = beginningOfDataSection,
                            size      = (Offset - beginningOfDataSection),
                        });
                        return(blockInfo.nextBlock);
                    }
                }
                read.BaseStream.Position = (long)(Offset - blockInfo.directorySize);
                if (isMemoryResident)
                {
                    read.BaseStream.Position -= GetUIntSizeVersionAware() * 2;
                }
                byte[] numArray2 = read.ReadBytes((int)blockInfo.directorySize);
                if (isEncrypted)
                {
                    numArray2 = BinaryExtension.Decrypt(numArray2, decryptionSeed);
                }
                if (isCompressed)
                {
                    numArray2 = ZLib.ZLib.Uncompress(numArray2, (int)blockInfo.decompressedSize);
                }

                RDAMemoryResidentHelper mrm = null;
                if (isMemoryResident)
                {
                    ulong beginningOfHeader = (ulong)read.BaseStream.Position;
                    ulong compressedSize    = ReadUIntVersionAware(read);
                    ulong uncompressedSize  = ReadUIntVersionAware(read);
                    mrm = new RDAMemoryResidentHelper(beginningOfHeader - blockInfo.directorySize - compressedSize, uncompressedSize, compressedSize, read.BaseStream, blockInfo, fileHeader.version);
                }

                uint dirEntrySize = DirEntry.GetSize(fileHeader.version);
                if (blockInfo.fileCount * dirEntrySize != blockInfo.decompressedSize)
                {
                    throw new Exception("Unexpected directory entry size or count");
                }

                ++rdaReadBlocks;
                UpdateOutput("-- DirEntries:");
                ReadDirEntries(numArray2, blockInfo, mrm);
            }

            return(blockInfo.nextBlock);
        }