Пример #1
0
 private void Convert(Stream iStream, BXML_TYPE iType, Stream oStream, BXML_TYPE oType)
 {
     if ((iType == BXML_TYPE.BXML_PLAIN && oType == BXML_TYPE.BXML_BINARY) || (iType == BXML_TYPE.BXML_BINARY && oType == BXML_TYPE.BXML_PLAIN))
     {
         BXML bns_xml = new BXML(XOR_KEY);
         bns_xml.Load(iStream, iType);
         bns_xml.Save(oStream, oType);
     }
     else
     {
         iStream.CopyTo(oStream);
     }
 }
Пример #2
0
        public void CompressFiles(string FileName, Dictionary <string, byte[]> filesToReplace, bool is64 = false, int compressionLevel = 1)
        {
            MemoryStream memoryStream1 = new MemoryStream(File.ReadAllBytes(FileName));
            BinaryReader binaryReader1 = new BinaryReader((Stream)memoryStream1);

            byte[] buffer1 = binaryReader1.ReadBytes(8);
            uint   num1    = binaryReader1.ReadUInt32();

            byte[] buffer2 = binaryReader1.ReadBytes(5);
            int    num2    = is64 ? (int)binaryReader1.ReadInt64() : binaryReader1.ReadInt32();
            int    num3    = is64 ? (int)binaryReader1.ReadInt64() : binaryReader1.ReadInt32();
            bool   flag1   = (int)binaryReader1.ReadByte() == 1;
            bool   flag2   = (int)binaryReader1.ReadByte() == 1;

            byte[] buffer3      = binaryReader1.ReadBytes(62);
            int    num4         = is64 ? (int)binaryReader1.ReadInt64() : binaryReader1.ReadInt32();
            int    sizeUnpacked = is64 ? (int)binaryReader1.ReadInt64() : binaryReader1.ReadInt32();

            byte[] buffer4  = binaryReader1.ReadBytes(num4);
            int    num5     = is64 ? (int)binaryReader1.ReadInt64() : binaryReader1.ReadInt32();
            int    position = (int)binaryReader1.BaseStream.Position;

            byte[]          buffer5       = this.Unpack(buffer4, num4, num4, sizeUnpacked, flag2, flag1);
            byte[]          numArray1     = (byte[])null;
            MemoryStream    memoryStream2 = new MemoryStream(buffer5);
            BinaryReader    binaryReader2 = new BinaryReader((Stream)memoryStream2);
            List <BPKG_FTE> bpkgFteList   = new List <BPKG_FTE>();
            MemoryStream    memoryStream3 = new MemoryStream();
            BinaryWriter    binaryWriter1 = new BinaryWriter((Stream)memoryStream3);
            MemoryStream    memoryStream4 = new MemoryStream();
            BinaryWriter    binaryWriter2 = new BinaryWriter((Stream)memoryStream4);

            byte[] numArray2;
            for (int index = 0; index < num3; ++index)
            {
                BPKG_FTE bpkgFte = new BPKG_FTE();
                bpkgFte.FilePathLength       = is64 ? (int)binaryReader2.ReadInt64() : binaryReader2.ReadInt32();
                bpkgFte.FilePath             = Encoding.Unicode.GetString(binaryReader2.ReadBytes(bpkgFte.FilePathLength * 2));
                bpkgFte.Unknown_001          = binaryReader2.ReadByte();
                bpkgFte.IsCompressed         = (int)binaryReader2.ReadByte() == 1;
                bpkgFte.IsEncrypted          = (int)binaryReader2.ReadByte() == 1;
                bpkgFte.Unknown_002          = binaryReader2.ReadByte();
                bpkgFte.FileDataSizeUnpacked = is64 ? (int)binaryReader2.ReadInt64() : binaryReader2.ReadInt32();
                bpkgFte.FileDataSizeSheared  = is64 ? (int)binaryReader2.ReadInt64() : binaryReader2.ReadInt32();
                bpkgFte.FileDataSizeStored   = is64 ? (int)binaryReader2.ReadInt64() : binaryReader2.ReadInt32();
                bpkgFte.FileDataOffset       = (is64 ? (int)binaryReader2.ReadInt64() : binaryReader2.ReadInt32()) + position;
                bpkgFte.Padding = binaryReader2.ReadBytes(60);
                if (bpkgFte.FilePath != null && filesToReplace.Keys.Contains <string>(bpkgFte.FilePath.ToLower()))
                {
                    MemoryStream memoryStream5 = new MemoryStream(filesToReplace[bpkgFte.FilePath.ToLower()]);
                    MemoryStream memoryStream6 = new MemoryStream();
                    if (bpkgFte.FilePath.ToLower().EndsWith(".xml") || bpkgFte.FilePath.ToLower().EndsWith(".x16"))
                    {
                        BXML bxml = new BXML(this.XOR_KEY);
                        this.Convert((Stream)memoryStream5, bxml.DetectType((Stream)memoryStream5), (Stream)memoryStream6, BXML_TYPE.BXML_BINARY);
                    }
                    else
                    {
                        memoryStream5.CopyTo((Stream)memoryStream6);
                    }
                    memoryStream5.Close();
                    bpkgFte.FileDataOffset       = (int)binaryWriter1.BaseStream.Position;
                    bpkgFte.FileDataSizeUnpacked = (int)memoryStream6.Length;
                    byte[] array = memoryStream6.ToArray();
                    memoryStream6.Close();
                    byte[] buffer6 = this.Pack(array, bpkgFte.FileDataSizeUnpacked, out bpkgFte.FileDataSizeSheared, out bpkgFte.FileDataSizeStored, bpkgFte.IsEncrypted, bpkgFte.IsCompressed, compressionLevel);
                    numArray2 = (byte[])null;
                    binaryWriter1.Write(buffer6);
                    numArray1 = (byte[])null;
                    bpkgFteList.Add(bpkgFte);
                }
                else
                {
                    binaryReader1.BaseStream.Position = (long)bpkgFte.FileDataOffset;
                    bpkgFte.FileDataOffset            = (int)binaryWriter1.BaseStream.Position;
                    bpkgFteList.Add(bpkgFte);
                    binaryWriter1.Write(binaryReader1.ReadBytes(bpkgFte.FileDataSizeStored));
                }
            }
            binaryReader2.Close();
            memoryStream2.Close();
            binaryReader1.Close();
            memoryStream1.Close();
            foreach (BPKG_FTE bpkgFte in bpkgFteList)
            {
                if (is64)
                {
                    binaryWriter2.Write((long)bpkgFte.FilePathLength);
                }
                else
                {
                    binaryWriter2.Write(bpkgFte.FilePathLength);
                }
                binaryWriter2.Write(Encoding.Unicode.GetBytes(bpkgFte.FilePath));
                binaryWriter2.Write(bpkgFte.Unknown_001);
                binaryWriter2.Write(bpkgFte.IsCompressed);
                binaryWriter2.Write(bpkgFte.IsEncrypted);
                binaryWriter2.Write(bpkgFte.Unknown_002);
                if (is64)
                {
                    binaryWriter2.Write((long)bpkgFte.FileDataSizeUnpacked);
                }
                else
                {
                    binaryWriter2.Write(bpkgFte.FileDataSizeUnpacked);
                }
                if (is64)
                {
                    binaryWriter2.Write((long)bpkgFte.FileDataSizeSheared);
                }
                else
                {
                    binaryWriter2.Write(bpkgFte.FileDataSizeSheared);
                }
                if (is64)
                {
                    binaryWriter2.Write((long)bpkgFte.FileDataSizeStored);
                }
                else
                {
                    binaryWriter2.Write(bpkgFte.FileDataSizeStored);
                }
                if (is64)
                {
                    binaryWriter2.Write((long)bpkgFte.FileDataOffset);
                }
                else
                {
                    binaryWriter2.Write(bpkgFte.FileDataOffset);
                }
                binaryWriter2.Write(bpkgFte.Padding);
            }
            MemoryStream memoryStream7 = new MemoryStream();
            BinaryWriter binaryWriter3 = new BinaryWriter((Stream)memoryStream7);

            binaryWriter3.Write(buffer1);
            binaryWriter3.Write(num1);
            binaryWriter3.Write(buffer2);
            int length1 = (int)binaryWriter1.BaseStream.Length;

            if (is64)
            {
                binaryWriter3.Write((long)length1);
                binaryWriter3.Write((long)num3);
            }
            else
            {
                binaryWriter3.Write(length1);
                binaryWriter3.Write(num3);
            }
            binaryWriter3.Write(flag1);
            binaryWriter3.Write(flag2);
            binaryWriter3.Write(buffer3);
            int length2     = (int)binaryWriter2.BaseStream.Length;
            int sizeSheared = length2;
            int sizeStored  = length2;

            byte[] array1 = memoryStream4.ToArray();
            binaryWriter2.Close();
            memoryStream4.Close();
            byte[] buffer7 = this.Pack(array1, length2, out sizeSheared, out sizeStored, flag2, flag1, compressionLevel);
            numArray2 = (byte[])null;
            if (is64)
            {
                binaryWriter3.Write((long)sizeStored);
            }
            else
            {
                binaryWriter3.Write(sizeStored);
            }
            if (is64)
            {
                binaryWriter3.Write((long)length2);
            }
            else
            {
                binaryWriter3.Write(length2);
            }
            binaryWriter3.Write(buffer7);
            numArray1 = (byte[])null;
            int num6 = (int)memoryStream7.Position + (is64 ? 8 : 4);

            if (is64)
            {
                binaryWriter3.Write((long)num6);
            }
            else
            {
                binaryWriter3.Write(num6);
            }
            byte[] array2 = memoryStream3.ToArray();
            binaryWriter1.Close();
            memoryStream3.Close();
            binaryWriter3.Write(array2);
            numArray1 = (byte[])null;
            File.WriteAllBytes(FileName, memoryStream7.ToArray());
            binaryWriter3.Close();
            memoryStream7.Close();
        }
Пример #3
0
        //new
        public Dictionary <string, byte[]> ExtractFile(string FileName, List <string> filesToExtract, bool is64 = false)
        {
            Dictionary <string, byte[]> dictionary = new Dictionary <string, byte[]>();
            FileStream   fileStream    = new FileStream(FileName, FileMode.Open);
            BinaryReader binaryReader1 = new BinaryReader((Stream)fileStream);

            binaryReader1.ReadBytes(8);
            int num1 = (int)binaryReader1.ReadUInt32();

            binaryReader1.ReadBytes(5);
            if (!is64)
            {
                binaryReader1.ReadInt32();
            }
            else
            {
                binaryReader1.ReadInt64();
            }
            int  num2         = is64 ? (int)binaryReader1.ReadInt64() : binaryReader1.ReadInt32();
            bool isCompressed = (int)binaryReader1.ReadByte() == 1;
            bool isEncrypted  = (int)binaryReader1.ReadByte() == 1;

            binaryReader1.ReadBytes(62);
            int num3         = is64 ? (int)binaryReader1.ReadInt64() : binaryReader1.ReadInt32();
            int sizeUnpacked = is64 ? (int)binaryReader1.ReadInt64() : binaryReader1.ReadInt32();

            byte[] buffer1  = binaryReader1.ReadBytes(num3);
            int    num4     = is64 ? (int)binaryReader1.ReadInt64() : binaryReader1.ReadInt32();
            int    position = (int)binaryReader1.BaseStream.Position;

            byte[]       buffer2       = Unpack(buffer1, num3, num3, sizeUnpacked, isEncrypted, isCompressed);
            byte[]       numArray      = (byte[])null;
            MemoryStream memoryStream1 = new MemoryStream(buffer2);
            BinaryReader binaryReader2 = new BinaryReader((Stream)memoryStream1);
            int          num5          = 0;

            for (int index = 0; index < num2 && num5 != filesToExtract.Count; ++index)
            {
                BPKG_FTE bpkgFte = new BPKG_FTE();
                bpkgFte.FilePathLength       = is64 ? (int)binaryReader2.ReadInt64() : binaryReader2.ReadInt32();
                bpkgFte.FilePath             = Encoding.Unicode.GetString(binaryReader2.ReadBytes(bpkgFte.FilePathLength * 2));
                bpkgFte.Unknown_001          = binaryReader2.ReadByte();
                bpkgFte.IsCompressed         = (int)binaryReader2.ReadByte() == 1;
                bpkgFte.IsEncrypted          = (int)binaryReader2.ReadByte() == 1;
                bpkgFte.Unknown_002          = binaryReader2.ReadByte();
                bpkgFte.FileDataSizeUnpacked = is64 ? (int)binaryReader2.ReadInt64() : binaryReader2.ReadInt32();
                bpkgFte.FileDataSizeSheared  = is64 ? (int)binaryReader2.ReadInt64() : binaryReader2.ReadInt32();
                bpkgFte.FileDataSizeStored   = is64 ? (int)binaryReader2.ReadInt64() : binaryReader2.ReadInt32();
                bpkgFte.FileDataOffset       = (is64 ? (int)binaryReader2.ReadInt64() : binaryReader2.ReadInt32()) + position;
                bpkgFte.Padding = binaryReader2.ReadBytes(60);
                if (bpkgFte.FilePath != null && filesToExtract.Contains(bpkgFte.FilePath.ToLower()))
                {
                    binaryReader1.BaseStream.Position = (long)bpkgFte.FileDataOffset;
                    byte[] buffer3 = Unpack(binaryReader1.ReadBytes(bpkgFte.FileDataSizeStored), bpkgFte.FileDataSizeStored, bpkgFte.FileDataSizeSheared, bpkgFte.FileDataSizeUnpacked, bpkgFte.IsEncrypted, bpkgFte.IsCompressed);
                    numArray = (byte[])null;
                    if (bpkgFte.FilePath.ToLower().EndsWith("xml") || bpkgFte.FilePath.ToLower().EndsWith("x16"))
                    {
                        MemoryStream memoryStream2 = new MemoryStream();
                        MemoryStream memoryStream3 = new MemoryStream(buffer3);
                        BXML         bxml          = new BXML(this.XOR_KEY);
                        Convert((Stream)memoryStream3, bxml.DetectType((Stream)memoryStream3), (Stream)memoryStream2, BXML_TYPE.BXML_PLAIN);
                        memoryStream3.Close();
                        buffer3 = memoryStream2.ToArray();
                        memoryStream2.Close();
                    }
                    dictionary.Add(bpkgFte.FilePath, buffer3);
                    ++num5;
                }
            }
            binaryReader2.Close();
            memoryStream1.Close();
            binaryReader1.Close();
            fileStream.Close();
            return(dictionary);
        }
Пример #4
0
        public void Compress(string Folder, Action <int, int> processedEvent, bool is64 = false, int compression = 9)
        {
            string file_path;

            byte[] buffer_packed;
            byte[] buffer_unpacked;
            //Stopwatch stopWatch = new Stopwatch();

            string[] files = Directory.EnumerateFiles(Folder, "*", SearchOption.AllDirectories).ToArray();

            int FileCount = files.Count();

            BPKG_FTE     FileTableEntry = new BPKG_FTE();
            MemoryStream mosTablems     = new MemoryStream();
            BinaryWriter mosTable       = new BinaryWriter(mosTablems);
            MemoryStream mosFilesms     = new MemoryStream();
            BinaryWriter mosFiles       = new BinaryWriter(mosFilesms);

            for (int i = 0; i < FileCount; i++)
            {
                file_path = files[i].Replace(Folder, "").TrimStart('\\');
                FileTableEntry.FilePathLength = file_path.Length;

                if (is64)
                {
                    mosTable.Write((long)FileTableEntry.FilePathLength);
                }
                else
                {
                    mosTable.Write(FileTableEntry.FilePathLength);
                }

                FileTableEntry.FilePath = file_path;
                mosTable.Write(Encoding.Unicode.GetBytes(FileTableEntry.FilePath));
                FileTableEntry.Unknown_001 = 2;
                mosTable.Write(FileTableEntry.Unknown_001);
                FileTableEntry.IsCompressed = true;
                mosTable.Write(FileTableEntry.IsCompressed);
                FileTableEntry.IsEncrypted = true;
                mosTable.Write(FileTableEntry.IsEncrypted);
                FileTableEntry.Unknown_002 = 0;
                mosTable.Write(FileTableEntry.Unknown_002);

                FileStream   fis = new FileStream(files[i], FileMode.Open);
                MemoryStream tmp = new MemoryStream();


                //stopWatch.Start();
                //Console.Write("\rCompressing Files: {0}/{1}", (i + 1), FileCount);
                processedEvent((i + 1), FileCount);

                if (file_path.EndsWith(".xml") || file_path.EndsWith(".x16"))
                {
                    // encode bxml
                    BXML bxml = new BXML(XOR_KEY);
                    Convert(fis, bxml.DetectType(fis), tmp, BXML_TYPE.BXML_BINARY);
                }
                else
                {
                    // compress raw
                    fis.CopyTo(tmp);
                }
                fis.Close();
                fis = null;

                FileTableEntry.FileDataOffset       = (int)mosFiles.BaseStream.Position;
                FileTableEntry.FileDataSizeUnpacked = (int)tmp.Length;

                if (is64)
                {
                    mosTable.Write((long)FileTableEntry.FileDataSizeUnpacked);
                }
                else
                {
                    mosTable.Write(FileTableEntry.FileDataSizeUnpacked);
                }

                buffer_unpacked = tmp.ToArray();
                tmp.Close();
                tmp             = null;
                buffer_packed   = Pack(buffer_unpacked, FileTableEntry.FileDataSizeUnpacked, out FileTableEntry.FileDataSizeSheared, out FileTableEntry.FileDataSizeStored, FileTableEntry.IsEncrypted, FileTableEntry.IsCompressed, compression);
                buffer_unpacked = null;
                mosFiles.Write(buffer_packed);
                buffer_packed = null;

                if (is64)
                {
                    mosTable.Write((long)FileTableEntry.FileDataSizeSheared);
                }
                else
                {
                    mosTable.Write(FileTableEntry.FileDataSizeSheared);
                }

                if (is64)
                {
                    mosTable.Write((long)FileTableEntry.FileDataSizeStored);
                }
                else
                {
                    mosTable.Write(FileTableEntry.FileDataSizeStored);
                }

                if (is64)
                {
                    mosTable.Write((long)FileTableEntry.FileDataOffset);
                }
                else
                {
                    mosTable.Write(FileTableEntry.FileDataOffset);
                }

                FileTableEntry.Padding = new byte[60];
                mosTable.Write(FileTableEntry.Padding);
            }

            //Console.Write("\nWriting File Entries...\n");
            //processedEvent(0,0,"\nWriting File Entries...\n");

            MemoryStream output = new MemoryStream();
            BinaryWriter bw     = new BinaryWriter(output);

            byte[] Signature = new byte[8] {
                (byte)'U', (byte)'O', (byte)'S', (byte)'E', (byte)'D', (byte)'A', (byte)'L', (byte)'B'
            };
            bw.Write(Signature);
            int Version = 2;

            bw.Write(Version);
            byte[] Unknown_001 = new byte[5] {
                0, 0, 0, 0, 0
            };
            bw.Write(Unknown_001);
            int FileDataSizePacked = (int)mosFiles.BaseStream.Length;

            if (is64)
            {
                bw.Write((long)FileDataSizePacked);
                bw.Write((long)FileCount);
            }
            else
            {
                bw.Write(FileDataSizePacked);
                bw.Write(FileCount);
            }

            bool IsCompressed = true;

            bw.Write(IsCompressed);
            bool IsEncrypted = true;

            bw.Write(IsEncrypted);
            byte[] Unknown_002 = new byte[62];
            bw.Write(Unknown_002);

            int FileTableSizeUnpacked = (int)mosTable.BaseStream.Length;
            int FileTableSizeSheared  = FileTableSizeUnpacked;
            int FileTableSizePacked   = FileTableSizeUnpacked;

            buffer_unpacked = mosTablems.ToArray();
            mosTable.Close();
            mosTablems.Close();
            mosTable        = null;
            mosTablems      = null;
            buffer_packed   = Pack(buffer_unpacked, FileTableSizeUnpacked, out FileTableSizeSheared, out FileTableSizePacked, IsEncrypted, IsCompressed, compression);
            buffer_unpacked = null;

            if (is64)
            {
                bw.Write((long)FileTableSizePacked);
            }
            else
            {
                bw.Write(FileTableSizePacked);
            }

            if (is64)
            {
                bw.Write((long)FileTableSizeUnpacked);
            }
            else
            {
                bw.Write(FileTableSizeUnpacked);
            }

            bw.Write(buffer_packed);
            buffer_packed = null;

            int OffsetGlobal = (int)output.Position + (is64 ? 8 : 4);

            if (is64)
            {
                bw.Write((long)OffsetGlobal);
            }
            else
            {
                bw.Write(OffsetGlobal);
            }

            buffer_packed = mosFilesms.ToArray();
            mosFiles.Close();
            mosFilesms.Close();
            mosFiles   = null;
            mosFilesms = null;
            bw.Write(buffer_packed);
            buffer_packed = null;
            File.WriteAllBytes(Folder.Replace(".files", ""), output.ToArray());
            bw.Close();
            output.Close();
            bw           = null;
            output       = null;
            Main.BdatSts = "Done!!";
        }
Пример #5
0
        public void Extract(string FileName, Action <int, int> processedEvent, bool is64 = false)
        {
            FileStream   fs = new FileStream(FileName, FileMode.Open);
            BinaryReader br = new BinaryReader(fs);
            string       file_path;

            byte[] buffer_packed;
            byte[] buffer_unpacked;

            byte[] Signature = br.ReadBytes(8);
            uint   Version   = br.ReadUInt32();

            byte[] Unknown_001        = br.ReadBytes(5);
            int    FileDataSizePacked = is64 ? (int)br.ReadInt64() : br.ReadInt32();
            int    FileCount          = is64 ? (int)br.ReadInt64() : br.ReadInt32();
            bool   IsCompressed       = br.ReadByte() == 1;
            bool   IsEncrypted        = br.ReadByte() == 1;

            byte[] Unknown_002           = br.ReadBytes(62);
            int    FileTableSizePacked   = is64 ? (int)br.ReadInt64() : br.ReadInt32();
            int    FileTableSizeUnpacked = is64 ? (int)br.ReadInt64() : br.ReadInt32();

            buffer_packed = br.ReadBytes(FileTableSizePacked);
            int OffsetGlobal = is64 ? (int)br.ReadInt64() : br.ReadInt32();

            OffsetGlobal = (int)br.BaseStream.Position; // don't trust value, read current stream location.

            byte[] FileTableUnpacked = Unpack(buffer_packed, FileTableSizePacked, FileTableSizePacked, FileTableSizeUnpacked, IsEncrypted, IsCompressed);
            buffer_packed = null;
            MemoryStream ms  = new MemoryStream(FileTableUnpacked);
            BinaryReader br2 = new BinaryReader(ms);

            for (int i = 0; i < FileCount; i++)
            {
                BPKG_FTE FileTableEntry = new BPKG_FTE();
                FileTableEntry.FilePathLength       = is64 ? (int)br2.ReadInt64() : br2.ReadInt32();
                FileTableEntry.FilePath             = Encoding.Unicode.GetString(br2.ReadBytes(FileTableEntry.FilePathLength * 2));
                FileTableEntry.Unknown_001          = br2.ReadByte();
                FileTableEntry.IsCompressed         = br2.ReadByte() == 1;
                FileTableEntry.IsEncrypted          = br2.ReadByte() == 1;
                FileTableEntry.Unknown_002          = br2.ReadByte();
                FileTableEntry.FileDataSizeUnpacked = is64 ? (int)br2.ReadInt64() : br2.ReadInt32();
                FileTableEntry.FileDataSizeSheared  = is64 ? (int)br2.ReadInt64() : br2.ReadInt32();
                FileTableEntry.FileDataSizeStored   = is64 ? (int)br2.ReadInt64() : br2.ReadInt32();
                FileTableEntry.FileDataOffset       = (is64 ? (int)br2.ReadInt64() : br2.ReadInt32()) + OffsetGlobal;
                FileTableEntry.Padding = br2.ReadBytes(60);

                file_path = string.Format("{0}.files\\{1}", FileName, FileTableEntry.FilePath);
                if (!Directory.Exists((new FileInfo(file_path)).DirectoryName))
                {
                    Directory.CreateDirectory((new FileInfo(file_path)).DirectoryName);
                }

                // Console.Write("\rExtracting Files: {0}/{1}", (i + 1), FileCount);

                br.BaseStream.Position = FileTableEntry.FileDataOffset;
                buffer_packed          = br.ReadBytes(FileTableEntry.FileDataSizeStored);
                buffer_unpacked        = Unpack(buffer_packed, FileTableEntry.FileDataSizeStored, FileTableEntry.FileDataSizeSheared, FileTableEntry.FileDataSizeUnpacked, FileTableEntry.IsEncrypted, FileTableEntry.IsCompressed);
                buffer_packed          = null;
                FileTableEntry         = null;

                if (file_path.EndsWith("xml") || file_path.EndsWith("x16"))
                {
                    // decode bxml
                    MemoryStream temp    = new MemoryStream();
                    MemoryStream temp2   = new MemoryStream(buffer_unpacked);
                    BXML         bns_xml = new BXML(XOR_KEY);
                    Convert(temp2, bns_xml.DetectType(temp2), temp, BXML_TYPE.BXML_PLAIN);
                    temp2.Close();
                    File.WriteAllBytes(file_path, temp.ToArray());
                    temp.Close();
                    buffer_unpacked = null;
                }
                else
                {
                    // extract raw
                    File.WriteAllBytes(file_path, buffer_unpacked);
                    buffer_unpacked = null;
                }
                processedEvent((i + 1), FileCount);
            }

            br2.Close();
            ms.Close();
            br2 = null;
            ms  = null;
            br.Close();
            fs.Close();
            br = null;
            fs = null;
            //Console.Write("\rDone!!");
            Main.BdatSts = "Done!!";
        }