예제 #1
0
        public GFLXPack(string path)
        {
            Files = new List <byte[]>();
            Names = new List <string>();
            using (BinaryReader br = new BinaryReader(File.Open(path, FileMode.Open)))
            {
                //Read container header
                Magic = br.ReadChars(8).ToString();
                br.ReadUInt64();
                FileCnt = br.ReadUInt32();
                br.ReadUInt32();
                InfoOff = br.ReadUInt64();
                br.ReadUInt64();
                br.ReadUInt64();
                br.ReadUInt64();

                for (int i = 0; i < FileCnt; i++)
                {
                    br.BaseStream.Position = (long)InfoOff + (i * 0x18);
                    //Read file header
                    br.ReadUInt32();
                    UInt32 size  = br.ReadUInt32();
                    UInt32 zsize = br.ReadUInt32();
                    br.ReadUInt32(); //dummy
                    UInt64 offset = br.ReadUInt64();
                    br.BaseStream.Position = (long)offset;
                    byte[] compData   = br.ReadBytes((int)zsize);
                    byte[] decompData = LZ4.Decompress(compData, (int)size);
                    string ext        = string.Empty;
                    switch (BitConverter.ToUInt32(decompData, 0))
                    {
                    case 0x58544E42:
                        ext = ".btnx";
                        break;

                    case 0x48534E42:
                        ext = ".bnsh";
                        break;

                    case 0x20:
                        ext = ".gfbmdl";
                        break;

                    default:
                        ext = ".bin";
                        break;
                    }
                    Names.Add(offset.ToString("X8") + ext);
                    Files.Add(decompData);
                }
            }
        }
예제 #2
0
파일: LZTests.cs 프로젝트: wabberz/Kuriimu
        static void Test(byte[] bytes, Method method)
        {
            byte[] bytes2 = new byte[bytes.Length];

            switch (method)
            {
            case Method.LZ10:
                bytes2 = LZ10.Decompress(new MemoryStream(LZ10.Compress(new MemoryStream(bytes))), bytes.Length);
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZ11:
                bytes2 = LZ11.Decompress(new MemoryStream(LZ11.Compress(new MemoryStream(bytes))), bytes.Length);
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZ40:
                bytes2 = LZ40.Decompress(new MemoryStream(LZ40.Compress(new MemoryStream(bytes))), bytes.Length);
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZ77:
                bytes2 = LZ77.Decompress(new MemoryStream(LZ77.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.RevLZ77:
                bytes2 = RevLZ77.Decompress(new MemoryStream(RevLZ77.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZ4:
                bytes2 = LZ4.Decompress(new MemoryStream(LZ4.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZECD:
                bytes2 = LZECD.Decompress(new MemoryStream(LZECD.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZOvl:
                bytes2 = LZOvl.Decompress(new MemoryStream(LZOvl.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.MIO0:
                bytes2 = MIO0.Decompress(new MemoryStream(MIO0.Compress(new MemoryStream(bytes), ByteOrder.LittleEndian)), ByteOrder.LittleEndian);
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;
            }
        }
 public Byte[] Decomporess(Byte[] data)
 {
     return(LZ4.Decompress(data));
 }
예제 #4
0
        /// <summary>
        /// Loads entries from a binary file
        /// </summary>
        /// <param name="fileName">File to load from</param>
        public void LoadBinary(string fileName)
        {
            try
            {
                using (var fileReader = new BinaryReader(File.OpenRead(fileName)))
                {
                    var magic            = fileReader.ReadUInt64();
                    var compression      = fileReader.ReadUInt64();
                    var compressedSize   = fileReader.ReadInt64();
                    var decompressedSize = fileReader.ReadInt64();

                    byte[] buffer = null;

                    switch (compression)
                    {
                    case 0: buffer = fileReader.ReadBytes((int)compressedSize); break;

                    case 1: buffer = ZLIB.Decompress(fileReader.ReadBytes((int)compressedSize)); break;

                    case 2: buffer = ZStandard.Decompress(fileReader.ReadBytes((int)compressedSize)); break;

                    case 3: buffer = LZ4.Decompress(fileReader.ReadBytes((int)compressedSize), (int)decompressedSize); break;

                    default: throw new Exception("Invalid cache compression");
                    }


                    using (var reader = new BinaryReader(new MemoryStream(buffer)))
                    {
                        var count = (int)reader.ReadUInt64();

                        switch (magic)
                        {
                        // 32Bit Cache
                        case 0x3130454843414354:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                Entries[reader.ReadUInt32()] = reader.ReadNullTerminatedString();
                            }

                            break;
                        }

                        // 64Bit Cache
                        case 0x3230454843414354:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                Entries[reader.ReadUInt64()] = reader.ReadNullTerminatedString();
                            }

                            break;
                        }
                        }
                    }
                }
            }
#if DEBUG
            catch (Exception e)
            {
                Console.WriteLine("Failed to load {0}: {1}", fileName, e);
            }
#else
            catch { }
#endif
        }