示例#1
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            if (CRCCalculator == null) // should not happen, but who knows...
                CRCCalculator = callbacks.GetCRCAlgorithm("CRC-32");
            List<FileEntry> files = GetDirectory(strm);

            foreach (FileEntry ent in files)
            {
                FileHeader fh = ent.ObjectData["FileHeader"] as FileHeader;
                byte[] buf = new byte[fh.CompressedSize];

                strm.Seek(fh.FileDataStartOffset, SeekOrigin.Begin);
                if (strm.Read(buf, 0, (int)fh.CompressedSize) != fh.CompressedSize)
                    throw new Exception("Read error");

                switch (fh.Method)
                {
                    case 0:
                        // uncompressed data
                        callbacks.WriteData(fh.Filename, buf);
                        break;
                    case 1:
                    case 2:
                    case 3:
                        // decode
                        break;
                    case 4:
                        break;
                    default:
                        throw new Exception("Unknown pack method");
                }
            }
        }
示例#2
0
 public void UnpackFiles(Stream strm, Callbacks callbacks)
 {
     foreach (ArcEntry ae in GetDirectory(strm, false))
     {
         byte[] buf = new byte[ae.Length];
         strm.Seek(ae.Offset, SeekOrigin.Begin);
         strm.Read(buf, 0, ae.Length);
         callbacks.WriteData(ae.Filename, buf);
     }
 }
示例#3
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            foreach (FileEntry fe in GetDirectory(strm))
            {
                byte[] buf = new byte[fe.UncompressedSize];

                strm.Seek(fe.Offset, SeekOrigin.Begin);
                strm.Read(buf, 0, (int)fe.UncompressedSize);
                callbacks.WriteData(fe.Filename, buf);
            }
        }
示例#4
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            XORStream xstrm = new XORStream(strm, callbacks.TransformerRegistry, 0xf7);

            foreach (ArcEntry ae in GetDirectory(xstrm, false))
            {
                xstrm.Seek(ae.Offset, SeekOrigin.Begin);
                byte[] buf = new byte[ae.Length];
                xstrm.Read(buf, 0, ae.Length);
                callbacks.WriteData(ae.FileName, buf);
            }
        }
示例#5
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            byte[] buf;

            foreach (FileEntry ent in GetDirectory(strm))
            {
                strm.Seek(ent.Offset, SeekOrigin.Begin);
                buf = new byte[ent.CompressedSize];
                strm.Read(buf, 0, (int)ent.CompressedSize);
                callbacks.WriteData(ent.Filename, buf);
            }
        }
示例#6
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            byte[] buf;

            foreach (FileEntry ent in GetDirectory(strm))
            {
                strm.Seek(ent.Offset, SeekOrigin.Begin);
                buf = new byte[ent.UncompressedSize];
                strm.Read(buf, 0, (int)ent.UncompressedSize);
                if (ent.LongData["encrypted"] == 1)
                    buf = DecryptBuffer(buf, "32768GLB");

                callbacks.WriteData(ent.Filename, buf);
            }
        }
示例#7
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            byte[] buffer;

            foreach (FileEntry ent in ReadDirectory(strm, callbacks))
            {
                strm.Seek(ent.Offset, SeekOrigin.Begin);
                if (ent.LongData["type"] == 0xcccccccc)
                {
                    // skip for now
                }
                else
                {
                    buffer = new byte[ent.UncompressedSize];
                    strm.Read(buffer, 0, (int)ent.UncompressedSize);
                    // TODO: This is not the whole story. Some files are compressed by some form of RLE
                    // Need to figure this out
                    callbacks.WriteData(ent.Filename, buffer);
                }
            }
        }
示例#8
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            List<ArcEntry> files = ReadDirectory(strm);
            byte[] buf;

            foreach (ArcEntry ae in files)
            {
                strm.Seek(ae.Offset, SeekOrigin.Begin);
                buf = new byte[ae.Length];
                strm.Read(buf, 0, ae.Length);
                callbacks.WriteData(ae.Filename, buf);
            }
        }
示例#9
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            string dstFileName;
            int csize, usize, actualsize;
            BinaryReader rd = new BinaryReader(strm);
            IDataTransformer decompressor = callbacks.TransformerRegistry.GetTransformer("zlib_dec");

            if (!ReadHeader(strm))
                return;

            // the order is important, that's why we don't use "foreach" here...
            System.Xml.XmlNodeList allFiles = fileList.SelectNodes("Files/File");
            for (int i = 0; i < allFiles.Count; i++)
            {
                System.Xml.XmlNode elt = allFiles.Item(i);

                dstFileName = elt.SelectNodes("@Name").Item(0).InnerText;
                usize = Convert.ToInt32(elt.SelectNodes("@Size").Item(0).InnerText);
                csize = Convert.ToInt32(elt.SelectNodes("@CompressedSize").Item(0).InnerText);

                byte[] cdata = rd.ReadBytes(csize);
                byte[] udata = new byte[usize];
                actualsize = usize;
                decompressor.TransformData(cdata, udata, csize, ref actualsize);
                callbacks.WriteData(dstFileName, udata);
            }
        }
示例#10
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            List<FileEntry> files = GetDirectory(strm, callbacks.TransformerRegistry.GetTransformer("zlib_dec"));
            byte[] data;

            foreach (FileEntry ent in files)
            {
                long toCopy = ent.UncompressedSize;
                int startIdx = 0;

                if (ent.ObjectData.ContainsKey("prefix"))
                {
                    startIdx = (ent.ObjectData["prefix"] as byte[]).Length;
                    data = new byte[toCopy + startIdx];
                    (ent.ObjectData["prefix"] as byte[]).CopyTo(data, 0);
                }
                else
                {
                    data = new byte[toCopy];
                }
                strm.Seek(ent.Offset, SeekOrigin.Begin);
                strm.Read(data, startIdx, data.Length);
                callbacks.WriteData(ent.Filename, data);
            }
        }
示例#11
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            DirEntry[] files = GetDirectory(strm, false);
            IDataTransformer trn = callbacks.TransformerRegistry.GetTransformer("zlib_dec");
            string key;

            // base offset = 4 bytes magic "VIS3" + 4 bytes #files + 3 bytes "HDR" marker + 16 bytes üer file + 3 bytes "END" marker
            strm.Seek(8 + 3 + files.Length * 16 + 3, SeekOrigin.Begin);
            for (int i = 0; i < files.Length; i++)
            {
                byte[] file = new byte[files[i].CompressedSize];

                strm.Read(file, 0, file.Length);
                key = "xxxxxxxx";
                if ((files[i].Flags & 0x2) != 0)
                {
                    // TODO: decrypt using our predefined key
                }

                if (files[i].CompressedSize != files[i].Size)
                {
                    // compressed -> decompress
                    byte[] unc = new byte[files[i].Size];
                    int usize = files[i].Size;
                    trn.TransformData(file, unc, files[i].CompressedSize, ref usize);
                    file = unc;
                }
                if (files[i].Flags == 0x08)
                {
                    // PNG file. Fix the scrambled dimensions
                    // find IHDR
                    int hdrpos = -1;
                    for (int j = 0; j < 32; j++)
                    {
                        if (Encoding.ASCII.GetString(file, j, 4) == "IHDR")
                        {
                            hdrpos = j - 4;
                            break;
                        }
                    }
                    if (hdrpos > 0)
                    {
                        // valid IHDR found. now try to fix it
                        int len = (int)(file[hdrpos] << 24) | (int)(file[hdrpos + 1] << 16) | (int)(file[hdrpos + 2]) << 8 | (int)(file[hdrpos + 3]);
                        byte[] hdr = new byte[len + 8];
                        byte[] fixed_hdr;

                        // copy to temporary array
                        Array.Copy(file, hdrpos + 4, hdr, 0, hdr.Length);
                        //.. and fix it by guessing
                        fixed_hdr = FixPngHdr(hdr, ref key, callbacks.GetCRCAlgorithm("CRC-32"));
                        if (fixed_hdr != null)
                        {
                            // could be fixed? great! then overwrite the old data with the fixed header
                            Array.Copy(fixed_hdr, 0, file, hdrpos + 4, fixed_hdr.Length);
                        }
                    }
                }
                callbacks.WriteData(String.Format("{0:x8}_{2}.{1}", i, GetExtension(files[i].Flags), key), file);
            }
        }
示例#12
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            ArcEntry[] entries = GetDirectory(strm, false);
            byte[] buf;
            long readBytes;
            IDataTransformer uncompress = callbacks.TransformerRegistry.GetTransformer("zlib_dec");

            for (int i = 0; i < entries.Length; i++)
            {
                strm.Seek(entries[i].StartOffset, SeekOrigin.Begin);
                readBytes = entries[i].Flags == 0x10000000 ? entries[i].CompressedLength : entries[i].UncompressedLength;
                buf = new byte[readBytes];

                // read (possibly compressed) data
                strm.Read(buf, 0, (int)readBytes);

                // uncompress if neccessary
                if (entries[i].Flags == 0x10000000)
                {
                    byte[] buf2 = new byte[entries[i].UncompressedLength];
                    int outlen = buf2.Length;
                    uncompress.TransformData(buf, buf2, buf.Length, ref outlen);
                    buf = buf2;
                }

                callbacks.WriteData(NormalizeFileName(entries[i].Filename), buf);
            }
        }
示例#13
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            IDataTransformer xor = callbacks.TransformerRegistry.GetTransformer("xor");

            foreach (FileEntry ent in ListFiles(strm, callbacks))
            {
                xor.SetOption("value", m_XORValue);
                strm.Seek(ent.Offset, SeekOrigin.Begin);
                byte[] buf = new byte[ent.UncompressedSize];
                strm.Read(buf, 0, buf.Length);
                if (ent.Filename.ToLower().EndsWith(".bik"))
                    callbacks.WriteData(ent.Filename, buf);
                else
                {
                    byte[] buf2 = new byte[buf.Length];
                    int len = buf.Length;
                    xor.TransformData(buf, buf2, len, ref len);
                    callbacks.WriteData(ent.Filename, buf2);
                }
            }
        }
示例#14
0
 public void UnpackFiles(Stream strm, Callbacks callbacks)
 {
     foreach (FileEntry ent in ListFiles(strm, callbacks))
     {
         strm.Seek(ent.Offset, SeekOrigin.Begin);
         byte[] buf = new byte[ent.UncompressedSize];
         strm.Read(buf, 0, buf.Length);
         callbacks.WriteData(ent.Filename, buf);
     }
 }
示例#15
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            ZipEntry ze;
            ZipInputStream zstrm = new ZipInputStream(strm, true);
            List<FileEntry> results = new List<FileEntry>();

            SetupZIPParams();
            while (true)
            {
                ze = zstrm.GetNextEntry();
                if (ze == null)
                    break;

                if (ze.IsDirectory)
                    continue;

                byte[] data = new byte[ze.UncompressedSize];
                zstrm.Read(data, 0, (int)ze.UncompressedSize);
                callbacks.WriteData(ze.FileName, data);
            };
        }
示例#16
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            byte[] buf;
            IDataTransformer decompressor = callbacks.TransformerRegistry.GetTransformer("zlib_dec");

            foreach (FileEntry ent in GetDirectory(strm))
            {
                buf = new byte[ent.UncompressedSize];
                bool decompressionFailed = false;
                strm.Seek(ent.Offset, SeekOrigin.Begin);
                strm.Read(buf, 0, (int)ent.UncompressedSize);
                if (ent.Filename.ToLower().EndsWith(".blv") || ent.Filename.ToLower().EndsWith(".dlv")
                    || ent.Filename.ToLower().EndsWith(".odm") || ent.Filename.ToLower().EndsWith(".ddm"))
                {
                    // transparently uncompress the 3D map files in Games.LOD if possible (some files don't pass zlib's CRC checksum)
                    Int32 compressedSize = (Int32)((UInt32)(buf[0]) | ((UInt32)(buf[1]) << 8) | ((UInt32)(buf[2]) << 16) | ((UInt32)(buf[3]) << 24));
                    Int32 uncompressedSize = (Int32)((UInt32)(buf[4]) | ((UInt32)(buf[5]) << 8) | ((UInt32)(buf[6]) << 16) | ((UInt32)(buf[7]) << 24));
                    if (compressedSize + 8 != ent.UncompressedSize)
                        throw new Exception("Invalid compressed data in LOD subfile");

                    byte[] cdata = new byte[compressedSize];
                    Array.Copy(buf, 8, cdata, 0, compressedSize);
                    byte[] udata = new byte[uncompressedSize];
                    try
                    {
                        decompressor.TransformData(cdata, udata, compressedSize, ref uncompressedSize);
                        buf = udata;
                    }
                    catch
                    {
                        decompressionFailed = true;
                    }
                }

                callbacks.WriteData(ent.Filename + (decompressionFailed ? ".BAD" : ""), buf);
            }
        }
示例#17
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            ArchiveFile afile;
            IDataTransformer zdec = callbacks.TransformerRegistry.GetTransformer("zlib_dec");

            if (!IsTankFile(strm))
                return;

            afile = ReadDirectory(strm);

            foreach (FileSetEntry fse in afile.FileSet.Entries)
            {
                string path = GetRelPath(afile, fse);
                if (fse.Format == 0)
                {
                    // RAW
                    if (fse.ChunkSize == 0)
                    {
                        // direct extract
                        byte[] data = new byte[fse.Size];
                        strm.Seek(fse.Offset + afile.Header.DataOffset, SeekOrigin.Begin);
                        strm.Read(data, 0, (int)fse.Size);
                        callbacks.WriteData(path, data);
                    }
                    else
                    {
                        throw new Exception(String.Format("uncompressed chunked format not yet supported for file {0}", path));
                    }
                }
                else if (fse.Format == 1)
                {
                    // zlib
                    if (fse.ChunkSize == 0)
                    {
                        throw new Exception(String.Format("compressed unchunked format not yet supported for file {0}", path));
                    }
                    else
                    {
                        // uncompress chunked data, this is a bit involved but oh well
                        byte[] compressed;
                        int writeOffset = 0;
                        byte[] uncompressed = new byte[fse.ChunkSize];
                        byte[] extradata = new byte[fse.ChunkSize];
                        byte[] file = new byte[fse.Size];              // the final (uncompressed) file data

                        for (int chunk = 0; chunk < fse.NumChunks; chunk++)
                        {
                            ChunkHeader ch = fse.ChunkHeaders[chunk];
                            compressed = new byte[ch.CompressedSize];
                            int outLength = (int)ch.UncompressedSize;

                            // seek to compressed data
                            //if (fse.Name == "b_c_edm_shard-04-static.raw")
                                //System.Diagnostics.Debugger.Break();

                            // seek to the beginning of the chunk
                            strm.Seek(afile.Header.DataOffset + fse.Offset + ch.Offset, SeekOrigin.Begin);

                            // read the compressed portion
                            strm.Read(compressed, 0, (int)ch.CompressedSize);

                            if (ch.CompressedSize != ch.UncompressedSize)
                            {
                                // a compressed chunk
                                zdec.TransformData(compressed, uncompressed, (int)ch.CompressedSize, ref outLength);

                                // ...read the extra data (if required)
                                strm.Read(extradata, 0, (int)ch.ExtraBytes);

                                // combine both in final data
                                Array.Copy(uncompressed, 0, file, writeOffset, outLength);
                                writeOffset += outLength;
                                Array.Copy(extradata, 0, file, writeOffset, ch.ExtraBytes);
                                writeOffset += (int)ch.ExtraBytes;
                            }
                            else
                            {
                                // an uncompressed chunk, copy directly to output
                                Array.Copy(compressed, 0, file, writeOffset, ch.CompressedSize);
                                writeOffset += (int)ch.CompressedSize;
                            }
                        }
                        callbacks.WriteData(path, file);
                    }
                }
                else if (fse.Format == 2)
                {
                    // lzo
                    throw new Exception(String.Format("LZO decompression is not yet supported for file {0}", path));
                }
                else
                    throw new Exception(String.Format("Unknown compression format {0} for file {1}", fse.Format, path));
            }
        }
示例#18
0
        public void UnpackFiles(Stream strm, Callbacks callbacks)
        {
            ArcEntry[] files = GetDirectory(strm);
            IDataTransformer unpacker = callbacks.TransformerRegistry.GetTransformer("zlib_dec");
            BinaryReader rd = new BinaryReader(strm);

            for (int i = 0; i < files.Length; i++)
            {
                if (files[i].IsCompressed)
                {
                    strm.Seek(files[i].Offset, SeekOrigin.Begin);
                    int clen = rd.ReadInt32();
                    if (clen != files[i].Length)
                        throw new Exception(String.Format("Mismatch on file #{0} offset {1:x8}: header={2:x8} file={3:x8}", i, files[i].Offset, files[i].Length, clen));
                    byte[] cbuf = new byte[files[i].CompressedLength - 4];
                    byte[] buf = new byte[files[i].Length];
                    int dst_len = files[i].Length;

                    strm.Read(cbuf, 0, files[i].CompressedLength - 4);
                    unpacker.TransformData(cbuf, buf, files[i].CompressedLength - 4, ref dst_len);

                    callbacks.WriteData(GenerateFilename(files[i]), buf);
                }
                else
                {
                    strm.Seek(files[i].Offset, SeekOrigin.Begin);
                    byte[] buf = new byte[files[i].Length];
                    strm.Read(buf, 0, files[i].Length);
                    callbacks.WriteData(GenerateFilename(files[i]), buf);
                }
            }
        }