Exemplo n.º 1
0
        public static byte[] DecryptFileTable(IPackStream stream, System.IO.Stream buffer)
        {
            if (stream.CompressedDataSize > 0 && stream.EncodedDataSize > 0 && stream.DataSize > 0)
            {
                byte[] src = new byte[stream.EncodedDataSize];

                if ((ulong)buffer.Read(src, 0, (int)stream.EncodedDataSize) == stream.EncodedDataSize)
                {
                    return(Decrypt(stream.Version, (uint)stream.EncodedDataSize,
                                   (uint)stream.CompressedDataSize, Encryption.Aes | Encryption.Zlib, src));
                }
            }

            throw new Exception("ERROR decrypting file table: the size of the table is invalid.");
        }
Exemplo n.º 2
0
        private static List <PackFileEntry> ReadFile(Stream headerFile)
        {
            using var headerReader = new BinaryReader(headerFile);
            var stream = IPackStream.CreateStream(headerReader);

            string fileString =
                Encoding.UTF8.GetString(CryptoManager.DecryptFileString(stream, headerReader.BaseStream));

            stream.FileList.AddRange(PackFileEntry.CreateFileList(fileString));
            stream.FileList.Sort();

            // Load the file allocation table and assign each file header to the entry within the list
            byte[] fileTable = CryptoManager.DecryptFileTable(stream, headerReader.BaseStream);

            using var tableStream = new MemoryStream(fileTable);
            using var reader      = new BinaryReader(tableStream);
            stream.InitFileList(reader);

            return(stream.FileList);
        }
Exemplo n.º 3
0
        public M2dReader(string path)
        {
            m2dFile = MemoryMappedFile.CreateFromFile(path);

            // Create an index from the header file
            using var headerReader = new BinaryReader(System.IO.File.OpenRead(path.Replace(".m2d", ".m2h")));
            var stream = IPackStream.CreateStream(headerReader);

            string fileString =
                Encoding.UTF8.GetString(CryptoManager.DecryptFileString(stream, headerReader.BaseStream));

            stream.FileList.AddRange(PackFileEntry.CreateFileList(fileString));
            stream.FileList.Sort();

            // Load the file allocation table and assign each file header to the entry within the list
            byte[] fileTable = CryptoManager.DecryptFileTable(stream, headerReader.BaseStream);

            using var tableStream = new MemoryStream(fileTable);
            using var reader      = new BinaryReader(tableStream);
            stream.InitFileList(reader);

            Files = stream.FileList;
        }