示例#1
0
        public void Extract(BUNDLEEntry file, string destination)
        {
            if (!Directory.Exists(destination))
            {
                Directory.CreateDirectory(destination);
            }

            using (MemoryStream msOutput = new MemoryStream())
            {
                if (file.HeaderSize > 0)
                {
                    using (FileStream fs = new FileStream(Path.Combine(Location, $"{Name}{Extension}"), FileMode.Open))
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            br.BaseStream.Seek(file.HeaderOffset + 2, SeekOrigin.Begin);

                            using (MemoryStream ms = new MemoryStream(br.ReadBytes(file.HeaderSizeCompressed - 2)))
                                using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress))
                                {
                                    byte[] data = new byte[file.HeaderSize];
                                    ds.Read(data, 0, file.HeaderSize);
                                    msOutput.Write(data, 0, data.Length);
                                }
                        }
                }

                if (file.DataSize > 0)
                {
                    using (FileStream fs = new FileStream(Path.Combine(Location, $"{Name}{Extension}"), FileMode.Open))
                        using (BinaryReader br = new BinaryReader(fs))
                        {
                            br.BaseStream.Seek(file.DataOffset + 2, SeekOrigin.Begin);

                            using (MemoryStream ms = new MemoryStream(br.ReadBytes(file.DataSizeCompressed - 2)))
                                using (DeflateStream ds = new DeflateStream(ms, CompressionMode.Decompress))
                                {
                                    byte[] data = new byte[file.DataSize];
                                    ds.Read(data, 0, file.DataSize);
                                    msOutput.Write(data, 0, data.Length);
                                }
                        }
                }

                Console.WriteLine("{0}\t{1}\t{2}\t{3}", file.Type, file.Name, file.HeaderSize, file.DataSize);
                msOutput.Flush();
                msOutput.WriteTo(new FileStream(destination + "\\" + file.Type + "-" + file.Name, FileMode.Create));
            }
        }
示例#2
0
        public static BUNDLE Load(string path)
        {
            FileInfo fi = new FileInfo(path);
            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            BUNDLE bundle = new BUNDLE();

            bundle.name = Path.GetFileNameWithoutExtension(path);
            bundle.extension = Path.GetExtension(path);
            bundle.location = Path.GetDirectoryName(path) + "\\";

            using (var br = new BinaryReader(fi.OpenRead()))
            {
                if (br.ReadByte() != 98 ||
                    br.ReadByte() != 110 ||
                    br.ReadByte() != 100 ||
                    br.ReadByte() != 50)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid BUNDLE file", path);
                    return null;
                }

                bundle.version = (int)br.ReadInt32();
                br.ReadInt32();
                bundle.size = (int)br.ReadInt32();
                int fileCount = (int)br.ReadInt32();
                int tableOffset = (int)br.ReadInt32();
                int headerOffset = (int)br.ReadInt32();
                int bodyOffset = (int)br.ReadInt32();
                int dataEnd = (int)br.ReadInt32();
                br.ReadInt32();
                bundle.flags = (int)br.ReadInt32();
                br.ReadInt32();

                for (int i = 0; i < fileCount; i++)
                {
                    var entry = new BUNDLEEntry { Name = i.ToString("00000") };

                    Console.WriteLine("{0}:", entry.Name);
                    br.ReadInt32(); // CRC
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    br.ReadInt32(); // LinkID
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    entry.HeaderSize = ((int)br.ReadInt32() << 8) >> 8;
                    entry.DataSize = ((int)br.ReadInt32() << 8) >> 8;
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    entry.HeaderSizeCompressed = (int)br.ReadInt32();
                    entry.DataSizeCompressed = (int)br.ReadInt32();
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    entry.HeaderOffset = headerOffset + (int)br.ReadInt32();
                    entry.DataOffset = bodyOffset + (int)br.ReadInt32();
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    entry.Type = br.ReadInt16();
                    entry.Count = br.ReadInt16();
                    Console.WriteLine("{0} == 0", br.ReadInt32());

                    bundle.Contents.Add(entry);
                }
            }

            return bundle;
        }
示例#3
0
        public void Extract(BUNDLEEntry file, string destination)
        {
            if (!Directory.Exists(destination)) { Directory.CreateDirectory(destination); }

            using (var msOutput = new MemoryStream())
            {
                if (file.HeaderSize > 0)
                {
                    using (var br = new BinaryReader(new FileStream(this.location + this.name + this.extension, FileMode.Open)))
                    {
                        br.BaseStream.Seek(file.HeaderOffset + 2, SeekOrigin.Begin);

                        using (var ms = new MemoryStream(br.ReadBytes(file.HeaderSizeCompressed - 2)))
                        using (var ds = new DeflateStream(ms, CompressionMode.Decompress))
                        {
                            var data = new byte[file.HeaderSize];
                            ds.Read(data, 0, file.HeaderSize);
                            msOutput.Write(data, 0, data.Length);
                        }
                    }
                }

                if (file.DataSize > 0)
                {
                    using (var br = new BinaryReader(new FileStream(this.location + this.name + this.extension, FileMode.Open)))
                    {
                        br.BaseStream.Seek(file.DataOffset + 2, SeekOrigin.Begin);

                        using (var ms = new MemoryStream(br.ReadBytes(file.DataSizeCompressed - 2)))
                        using (var ds = new DeflateStream(ms, CompressionMode.Decompress))
                        {
                            var data = new byte[file.DataSize];
                            ds.Read(data, 0, file.DataSize);
                            msOutput.Write(data, 0, data.Length);
                        }
                    }
                }

                Console.WriteLine("{0}\t{1}\t{2}\t{3}", file.Type, file.Name, file.HeaderSize, file.DataSize);
                msOutput.Flush();
                msOutput.WriteTo(new FileStream(destination + "\\" + file.Type + "-" + file.Name, FileMode.Create));
            }
        }
示例#4
0
        public static BUNDLE Load(string path)
        {
            FileInfo fi = new FileInfo(path);

            Logger.LogToFile(Logger.LogLevel.Info, "{0}", path);
            BUNDLE bundle = new BUNDLE
            {
                Name      = Path.GetFileNameWithoutExtension(path),
                Extension = Path.GetExtension(path),
                Location  = Path.GetDirectoryName(path)
            };

            using (BinaryReader br = new BinaryReader(fi.OpenRead()))
            {
                if (br.ReadByte() != 0x62 ||
                    br.ReadByte() != 0x6e ||
                    br.ReadByte() != 0x64 ||
                    br.ReadByte() != 0x32)
                {
                    Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid BUNDLE file", path);
                    return(null);
                }

                bundle.Version = br.ReadInt32();
                br.ReadInt32();
                bundle.Size = br.ReadInt32();
                int fileCount = br.ReadInt32();
                br.ReadInt32();         // table offset
                int headerOffset = br.ReadInt32();
                int bodyOffset   = br.ReadInt32();
                br.ReadInt32();         // data end
                br.ReadInt32();
                bundle.Flags = br.ReadInt32();
                br.ReadInt32();

                for (int i = 0; i < fileCount; i++)
                {
                    BUNDLEEntry entry = new BUNDLEEntry {
                        Name = i.ToString("00000")
                    };

                    Console.WriteLine("{0}:", entry.Name);
                    br.ReadInt32(); // CRC
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    br.ReadInt32(); // LinkID
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    entry.HeaderSize = ((int)br.ReadInt32() << 8) >> 8;
                    entry.DataSize   = ((int)br.ReadInt32() << 8) >> 8;
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    entry.HeaderSizeCompressed = (int)br.ReadInt32();
                    entry.DataSizeCompressed   = (int)br.ReadInt32();
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    entry.HeaderOffset = headerOffset + (int)br.ReadInt32();
                    entry.DataOffset   = bodyOffset + (int)br.ReadInt32();
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    Console.WriteLine("{0} == 0", br.ReadInt32());
                    entry.Type  = br.ReadInt16();
                    entry.Count = br.ReadInt16();
                    Console.WriteLine("{0} == 0", br.ReadInt32());

                    bundle.Contents.Add(entry);
                }
            }

            return(bundle);
        }