Example #1
0
        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);
        }
Example #2
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");
                }
            }
        }
Example #3
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);
            }
        }
Example #4
0
 public bool IsSupported(Stream strm, Callbacks callbacks)
 {
     if (CRCCalculator == null)
         CRCCalculator = callbacks.GetCRCAlgorithm("CRC-32");
     return GetDirectory(strm) != null;
 }