Beispiel #1
0
 public void Dispose()
 {
     Header = null;
     ESpecStringTable.Clear();
     ESpecStringTable.TrimExcess();
     ESpecStringTable = null;
     CEKeys.Clear();
     CEKeys = null;
     EKeys.Clear();
     EKeys = null;
 }
Beispiel #2
0
 public void Dispose()
 {
     Header = null;
     LayoutStringTable.Clear();
     LayoutStringTable.TrimExcess();
     LayoutStringTable = null;
     Data.Clear();
     Data = null;
     Layout.Clear();
     Layout = null;
 }
Beispiel #3
0
 public EncodingHandler()
 {
     Header      = new EncodingHeader();
     EncodingMap = new[]
     {
         new EncodingMap(EncodingType.None, 6),
         new EncodingMap(EncodingType.ZLib, 9),
         new EncodingMap(EncodingType.None, 6),
         new EncodingMap(EncodingType.None, 6),
         new EncodingMap(EncodingType.None, 6),
         new EncodingMap(EncodingType.None, 6),
         new EncodingMap(EncodingType.ZLib, 9),
     };
 }
Beispiel #4
0
        public EncodingHandler(BLTEStream blte)
        {
            if (blte.Length != long.Parse(CASContainer.BuildConfig["encoding-size"][0]))
            {
                CASContainer.Settings?.Logger.LogAndThrow(Logging.LogType.Critical, "Encoding File is corrupt.");
            }

            BinaryReader stream = new BinaryReader(blte);

            Header = new EncodingHeader()
            {
                Magic          = stream.ReadBytes(2),
                Version        = stream.ReadByte(),
                ChecksumSizeC  = stream.ReadByte(),
                ChecksumSizeE  = stream.ReadByte(),
                PageSizeCEKey  = stream.ReadUInt16(),
                PageSizeEKey   = stream.ReadUInt16(),
                PageCountCEKey = stream.ReadUInt32BE(),
                PageCountEKey  = stream.ReadUInt32BE(),
                Unknown_x11    = stream.ReadByte(),
                ESpecBlockSize = stream.ReadUInt32BE()
            };

            // ESpec string table
            ESpecStringTable.AddRange(Encoding.ASCII.GetString(stream.ReadBytes((int)Header.ESpecBlockSize)).Split('\0'));

            // skip CE page table lookup
            stream.ReadBytes((int)Header.PageCountCEKey * 32);

            // read CE page table data
            for (int i = 0; i < Header.PageCountCEKey; i++)
            {
                long start = stream.BaseStream.Position;

                ushort keysCount;
                while ((keysCount = stream.ReadUInt16()) != 0)
                {
                    var entry = new EncodingCEKeyPageTable()
                    {
                        DecompressedSize = stream.ReadUInt32BE(),
                        CKey             = new MD5Hash(stream)
                    };

                    for (int ki = 0; ki < keysCount; ki++)
                    {
                        entry.EKeys.Add(new MD5Hash(stream));
                    }

                    CEKeys.Add(entry.CKey, entry);
                }

                if (stream.BaseStream.Position % CHUNK_SIZE != 0)
                {
                    stream.BaseStream.Position += CHUNK_SIZE - ((stream.BaseStream.Position - start) % CHUNK_SIZE);
                }
            }

            // skip EKey page table lookup
            stream.ReadBytes((int)Header.PageCountEKey * 32);

            // read EKey page table data
            for (int i = 0; i < Header.PageCountEKey; i++)
            {
                long start = stream.BaseStream.Position;

                MD5Hash hash;
                while (!(hash = new MD5Hash(stream)).IsEmpty)
                {
                    var entry = new EncodingEKeyPageTable()
                    {
                        EKey             = hash,
                        ESpecStringIndex = stream.ReadUInt32BE(),
                        FileSize         = stream.ReadUInt40BE()
                    };

                    EKeys.Add(entry.EKey, entry);
                }

                if (stream.BaseStream.Position % CHUNK_SIZE != 0)
                {
                    stream.BaseStream.Position += CHUNK_SIZE - ((stream.BaseStream.Position - start) % CHUNK_SIZE);
                }
            }

            // Encoding file ESpecStringTable
            stream.ReadBytes((int)(stream.BaseStream.Length - stream.BaseStream.Position));

            EncodingMap = blte.EncodingMap.ToArray();

            blte?.Dispose();
            stream?.Dispose();
        }
Beispiel #5
0
        public EncodingHandler(BLTEStream blte)
        {
            if (blte.Length != long.Parse(CASContainer.BuildConfig["encoding-size"][0]))
            {
                CASContainer.Settings?.Logger.LogAndThrow(Logging.LogType.Critical, "Encoding File is corrupt.");
            }

            BinaryReader stream = new BinaryReader(blte);

            Header = new EncodingHeader()
            {
                Magic           = stream.ReadBytes(2),
                Version         = stream.ReadByte(),
                ChecksumSizeA   = stream.ReadByte(),
                ChecksumSizeB   = stream.ReadByte(),
                FlagsA          = stream.ReadUInt16(),
                FlagsB          = stream.ReadUInt16(),
                NumEntriesA     = stream.ReadUInt32BE(),
                NumEntriesB     = stream.ReadUInt32BE(),
                StringBlockSize = stream.ReadUInt40BE()
            };

            // stringTableA
            LayoutStringTable.AddRange(Encoding.ASCII.GetString(stream.ReadBytes((int)Header.StringBlockSize)).Split('\0'));

            // skip header block A
            stream.ReadBytes((int)Header.NumEntriesA * 32);

            // encoding table entry block
            for (int i = 0; i < Header.NumEntriesA; i++)
            {
                long start = stream.BaseStream.Position;

                ushort keysCount;
                while ((keysCount = stream.ReadUInt16()) != 0)
                {
                    EncodingEntry entry = new EncodingEntry()
                    {
                        DecompressedSize = stream.ReadUInt32BE(),
                        Hash             = new MD5Hash(stream)
                    };

                    for (int ki = 0; ki < keysCount; ki++)
                    {
                        entry.Keys.Add(new MD5Hash(stream));
                    }

                    Data.Add(entry.Hash, entry);
                }

                if (stream.BaseStream.Position % CHUNK_SIZE != 0)
                {
                    stream.BaseStream.Position += CHUNK_SIZE - ((stream.BaseStream.Position - start) % CHUNK_SIZE);
                }
            }

            // skip header block B
            stream.ReadBytes((int)Header.NumEntriesB * 32);

            // layout table entry block
            for (int i = 0; i < Header.NumEntriesB; i++)
            {
                long start = stream.BaseStream.Position;

                MD5Hash hash;
                while (!(hash = new MD5Hash(stream)).IsEmpty)
                {
                    var entry = new EncodingLayout()
                    {
                        Hash        = hash,
                        StringIndex = stream.ReadUInt32BE(),
                        Size        = stream.ReadUInt40BE()
                    };

                    Layout.Add(entry.Hash, entry);
                }

                if (stream.BaseStream.Position % CHUNK_SIZE != 0)
                {
                    stream.BaseStream.Position += CHUNK_SIZE - ((stream.BaseStream.Position - start) % CHUNK_SIZE);
                }
            }

            stream.ReadBytes((int)(stream.BaseStream.Length - stream.BaseStream.Position)); //EncodingStringTable

            EncodingMap = blte.EncodingMap.ToArray();

            blte?.Dispose();
            stream?.Dispose();
        }