Ejemplo n.º 1
0
        private void UnpackFile(FileInPakLocation fipl, FileStream fs)
        {
            string outputFileName = this.UnpackFolder + Path.DirectorySeparatorChar + fipl.FileName.Replace('/', '\\');

            FileInfo file = new FileInfo(outputFileName);

            file.Directory.Create();
            string fullName = file.FullName;

            byte[] buffer = new byte[fipl.ReadSize];
            fs.Seek(fipl.FileOffset, SeekOrigin.Begin);
            fs.Read(buffer, 0, fipl.ReadSize);

            if (fipl.Encrypted)
            {
                buffer = Decrypt(buffer, fipl.FileSize);
            }

            FileStream ofs = new FileStream(fullName, FileMode.Create, FileAccess.Write, FileShare.None);

            ofs.Write(buffer, 0, fipl.FileSize);
            ofs.Close();

            buffer = null;
        }
Ejemplo n.º 2
0
        private void RunUnpack()
        {
            while (File.Exists(this.PakFile + ".bak"))
            {
                File.Delete(this.PakFile + ".bak");
                Thread.Sleep(10);
            }

            while (File.Exists(this.SigFile + ".bak"))
            {
                File.Delete(this.SigFile + ".bak");
                Thread.Sleep(10);
            }

            File.Move(this.PakFile, this.PakFile + ".bak");
            File.Move(this.SigFile, this.SigFile + ".bak");

            List <FileInPakLocation> files = new List <FileInPakLocation>();

            FileStream   fs = new FileStream(this.PakFile + ".bak", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            BinaryReader br = new BinaryReader(fs);

            if (fs.Length < 100)
            {
                FinishThreadSafe();
                fs.Close();
                Close();
            }

            br.BaseStream.Seek(-0x2C, SeekOrigin.End);
            uint magic = br.ReadUInt32();

            if (magic != 0x5A6F12E1)
            {
                FinishThreadSafe();
                fs.Close();
                Close();
            }
            br.ReadUInt32();
            long offset = br.ReadInt64();
            long size   = br.ReadInt64();

            br.BaseStream.Seek(offset, SeekOrigin.Begin);
            ReadName(br);

            int fileCount = br.ReadInt32();

            for (int i = 0; i < fileCount; i++)
            {
                string fileName = ReadName(br);
                long   pos      = br.BaseStream.Position;

                long fOffset     = br.ReadInt64();
                long fZSize      = br.ReadInt64();
                long fSize       = br.ReadInt64();
                int  compression = br.ReadInt32();

                long hashLocation = br.BaseStream.Position;
                br.BaseStream.Seek(20, SeekOrigin.Current);

                byte enc       = br.ReadByte();
                int  chunkSize = br.ReadInt32();

                bool encrypted = (enc != 0);
                int  eSize     = (int)fSize;

                if (encrypted)
                {
                    if (eSize % 16 > 0)
                    {
                        eSize = ((eSize / 16) + 1) * 16;
                    }
                }

                long bPos = br.BaseStream.Position;
                fOffset += (bPos - pos);

                files.Add(new FileInPakLocation(fileName, fOffset, (int)fSize, eSize, hashLocation, (enc != 0)));
            }

            int fCount = files.Count;

            for (int i = 0; i < fCount; i++)
            {
                FileInPakLocation fipl = files[i];
                this.ShowProgressThreadSafe(i, fCount);
                UnpackFile(fipl, fs);
            }

            br = null;
            fs.Close();

            FinishThreadSafe();
        }