예제 #1
0
파일: TGPUnpacker.cs 프로젝트: darkstar/gus
        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            byte[] buf = new byte[4];
            BinaryReader rd = new BinaryReader(strm);
            int numFiles;
            List<FileEntry> results = new List<FileEntry>();

            rd.Read(buf, 0, 4);
            if (Encoding.ASCII.GetString(buf, 0, 4) != "TGP0")
                return results;

            if (rd.ReadInt32() != 1)  // version check
                return results;

            if (rd.ReadInt32() != 0)  // should be zero
                return results;

            numFiles = rd.ReadInt32();
            buf = new byte[0x60];
            for (int i = 0; i < numFiles; i++)
            {
                FileEntry ent = new FileEntry();

                rd.Read(buf, 0, 0x60);
                ent.Filename = Encoding.ASCII.GetString(buf);
                ent.Filename = ent.Filename.Substring(0, ent.Filename.IndexOf('\0'));
                ent.Offset = rd.ReadInt64();
                ent.UncompressedSize = rd.ReadInt64();

                results.Add(ent);
            }

            return results;
        }
예제 #2
0
파일: ZIPUnpacker.cs 프로젝트: darkstar/gus
        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            ZipEntry ze;
            ZipInputStream zstrm = new ZipInputStream(strm, true);
            List<FileEntry> results = new List<FileEntry>();
            FileEntry fe;

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

                if (ze.IsDirectory)
                    continue;

                fe = new FileEntry();
                fe.Filename = ze.FileName;
                fe.UncompressedSize = ze.UncompressedSize;
                fe.Timestamp = ze.LastModified;
                results.Add(fe);
            };

            return results;
        }
예제 #3
0
파일: OAFUnpacker.cs 프로젝트: darkstar/gus
        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);
            }
        }
예제 #4
0
파일: ARJUnpacker.cs 프로젝트: darkstar/gus
        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            if (CRCCalculator == null) // should not happen, but who knows...
                CRCCalculator = callbacks.GetCRCAlgorithm("CRC-32");

            return GetDirectory(strm);
        }
예제 #5
0
파일: ARJUnpacker.cs 프로젝트: darkstar/gus
        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");
                }
            }
        }
예제 #6
0
파일: ZIPUnpacker.cs 프로젝트: darkstar/gus
 public bool IsSupported(Stream strm, Callbacks callbacks)
 {
     SetupZIPParams();
     BinaryReader rd = new BinaryReader(strm);
     Int32 sig = rd.ReadInt32();
     return (sig == ZipConstants.ZipEntrySignature);
 }
예제 #7
0
        public bool IsSupported(Stream strm, Callbacks callbacks)
        {
            byte[] header = new byte[14];

            strm.Read(header, 0, 14);
            return Encoding.ASCII.GetString(header, 0, 14) == "SBPAK V 1.0\r\n\0";
        }
예제 #8
0
        public void PackFiles(Stream strm, List<PackFileEntry> filesToPack, Callbacks callbacks)
        {
            BinaryWriter bw = new BinaryWriter(strm);
            Int32 FileOffset;

            bw.Write(new char[] { 'Y', 'P', 'A', 'C' });
            bw.Write((Int32)1);
            bw.Write((Int32)filesToPack.Count);
            bw.Write((Int32)0);

            // write the directory
            FileOffset = 16 + 7 * 16 * filesToPack.Count; // this will be the offset for the first file
            for (int i = 0; i < filesToPack.Count; i++)
            {
                string targetFileName = "\\" + filesToPack[i];
                byte[] nameBuf = new byte[6 * 16];
                Int64 Length;

                Encoding.ASCII.GetBytes(targetFileName, 0, targetFileName.Length, nameBuf, 0);
                bw.Write(nameBuf);
                bw.Write((Int64)FileOffset);
                Length = filesToPack[i].fileSize;
                bw.Write((Int64)Length);
                FileOffset += (Int32)Length;
            }

            // write the actual file data
            for (int i = 0; i < filesToPack.Count; i++)
            {
                byte[] fileData = callbacks.ReadData(filesToPack[i].relativePathName);
                strm.Write(fileData, 0, fileData.Length);
            }
        }
예제 #9
0
파일: KOMUnpacker.cs 프로젝트: darkstar/gus
        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
파일: LODUnpacker.cs 프로젝트: darkstar/gus
 public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
 {
     foreach (FileEntry ent in GetDirectory(strm))
     {
         yield return ent;
     }
 }
예제 #11
0
파일: YSFUnpacker.cs 프로젝트: darkstar/gus
 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);
     }
 }
예제 #12
0
파일: AFSUnpacker.cs 프로젝트: darkstar/gus
        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);
            }
        }
예제 #13
0
파일: PVZUnpacker.cs 프로젝트: darkstar/gus
        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);
            }
        }
예제 #14
0
파일: PACUnpacker.cs 프로젝트: darkstar/gus
        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);
            }
        }
예제 #15
0
파일: OAFUnpacker.cs 프로젝트: darkstar/gus
        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            ArcEntry[] entries = GetDirectory(strm, false);
            List<FileEntry> results = new List<FileEntry>();

            for (int i = 0; i < entries.Length; i++)
            {
                FileEntry fe = new FileEntry();
                fe.Filename = NormalizeFileName(entries[i].Filename);
                fe.UncompressedSize = entries[i].UncompressedLength;
                yield return fe;
            }
        }
예제 #16
0
파일: CPKUnpacker.cs 프로젝트: darkstar/gus
        public bool IsSupported(Stream strm, Callbacks callbacks)
        {
            byte[] id = new byte[4];

            strm.Read(id, 0, 4);
            if (Encoding.ASCII.GetString(id) != "CPK ")
                return false;
            // skip over the next 12 bytes
            strm.Seek(12, SeekOrigin.Current);

            Table tbl = ReadTable(strm);

            return false;
        }
예제 #17
0
파일: YSFUnpacker.cs 프로젝트: darkstar/gus
        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            List<FileEntry> results = new List<FileEntry>();

            foreach (ArcEntry ae in GetDirectory(strm, false))
            {
                FileEntry fe = new FileEntry();
                fe.Filename = ae.Filename;
                fe.UncompressedSize = ae.Length;
                results.Add(fe);
            }

            return results;
        }
예제 #18
0
        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            ArcEntry[] files = GetDirectory(strm);
            List<FileEntry> results = new List<FileEntry>();

            for (int i = 0; i < files.Length; i++)
            {
                FileEntry fe = new FileEntry();
                fe.Filename = files[i].FileName;
                fe.UncompressedSize = files[i].Length;
                results.Add(fe);
            }

            return results;
        }
예제 #19
0
파일: GLBUnpacker.cs 프로젝트: darkstar/gus
        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);
            }
        }
예제 #20
0
파일: VISUnpacker.cs 프로젝트: darkstar/gus
        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            DirEntry[] files = GetDirectory(strm, false);
            List<FileEntry> fes = new List<FileEntry>();

            for (int i = 0; i < files.Length; i++)
            {
                FileEntry fe = new FileEntry();

                fe.Filename = String.Format("{0:x8}.{1}", i, GetExtension(files[i].Flags));
                fe.UncompressedSize = files[i].Size;

                fes.Add(fe);
            }

            return fes;
        }
예제 #21
0
파일: KOMUnpacker.cs 프로젝트: darkstar/gus
        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            List<FileEntry> results = new List<FileEntry>();

            if (!ReadHeader(strm))
                return null;

            foreach (System.Xml.XmlElement elt in fileList.SelectNodes("Files/File"))
            {
                FileEntry f = new FileEntry();
                f.Filename = elt.SelectNodes("@Name").Item(0).InnerText;
                f.UncompressedSize = Convert.ToInt64(elt.SelectNodes("@Size").Item(0).InnerText);
                results.Add(f);
            }

            return results;
        }
예제 #22
0
파일: ZIPUnpacker.cs 프로젝트: darkstar/gus
        public void PackFiles(Stream strm, List<PackFileEntry> filesToPack, Callbacks callbacks)
        {
            SetupZIPParams();
            using (ZipOutputStream zstrm = new ZipOutputStream(strm, false))
            {
                // always use multithreaded compression
                zstrm.ParallelDeflateThreshold = 0;

                foreach (PackFileEntry pfe in filesToPack)
                {
                    zstrm.PutNextEntry(pfe.relativePathName);
                    byte[] data = callbacks.ReadData(pfe.relativePathName);
                    zstrm.Write(data, 0, data.Length);
                }
            }
            // stream is closed automatically
        }
예제 #23
0
        public IEnumerable<FileEntry> ListFiles(Stream strm, Callbacks callbacks)
        {
            ArchiveFile afile;

            if (!IsTankFile(strm))
                yield break;

            afile = ReadDirectory(strm);

            foreach (FileSetEntry fse in afile.FileSet.Entries)
            {
                FileEntry fe = new FileEntry();
                fe.UncompressedSize = fse.Size;
                fe.Filename = GetRelPath(afile, fse);

                yield return fe;
            }
        }
예제 #24
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);
                }
            }
        }
예제 #25
0
파일: TGPUnpacker.cs 프로젝트: darkstar/gus
        public bool IsSupported(Stream strm, Callbacks callbacks)
        {
            byte[] buf = new byte[4];
            BinaryReader rd = new BinaryReader(strm);
            int numFiles;

            rd.Read(buf, 0, 4);  // magic check
            if (Encoding.ASCII.GetString(buf, 0, 4) != "TGP0")
                return false;

            if (rd.ReadInt32() != 1)  // version check
                return false;

            if (rd.ReadInt32() != 0)  // should be zero
                return false;

            numFiles = rd.ReadInt32();
            if ((numFiles <= 0) || (numFiles > 100000))  // some sanity checks
                return false;

            return true;
        }
예제 #26
0
파일: LODUnpacker.cs 프로젝트: darkstar/gus
        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);
            }
        }
예제 #27
0
        List<FileEntry> ReadDirectory(Stream strm, Callbacks callbacks)
        {
            List<FileEntry> results = new List<FileEntry>();
            BinaryReader rd = new BinaryReader(strm);
            Int32 numFiles;

            if (rd.ReadUInt32() != 0x5041434b)
                return null;

            numFiles = rd.ReadInt32();
            if (numFiles > 100000)
                return null;

            for (int i = 0; i < numFiles; i++)
            {
                FileEntry ent = new FileEntry();
                byte[] namebuf = new byte[24];

                ent.LongData["type"] = rd.ReadUInt32(); // 0x0, 0x1 = file, 0xcccccccc = dir?
                if ((ent.LongData["type"] != 1) && (ent.LongData["type"] != 0) && (ent.LongData["type"] != 0xcccccccc))
                    return null;

                rd.Read(namebuf, 0, 24);
                ent.Filename = Encoding.GetEncoding("SJIS").GetString(namebuf).TrimEnd('\0');
                ent.Offset = rd.ReadUInt32();
                ent.UncompressedSize = rd.ReadUInt32();
                if (ent.UncompressedSize > 1024 * 1024 * 1024)
                    return null;
                if (ent.Offset > 1024 * 1024 * 1024)
                    return null;

                results.Add(ent);
            }

            return results;
        }
예제 #28
0
 public void PackFiles(Stream strm, List<PackFileEntry> filesToPack, Callbacks callbacks)
 {
     throw new NotImplementedException();
 }
예제 #29
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));
            }
        }
예제 #30
0
 public bool IsSupported(Stream strm, Callbacks callbacks)
 {
     return IsTankFile(strm);
 }