예제 #1
0
        public byte[] GetPackedFile(JMDPackedFileInfo info)
        {
            FileStream fs = new FileStream(Path, FileMode.Open);

            if (info.CryptMode == CryptMode.None)
            {
                JMDStreamInfo streaminfo = this.GetStreamInfo(info.Index);
                fs.Seek(streaminfo.Offset, SeekOrigin.Begin);
                byte[] data = new byte[streaminfo.Size];
                fs.Read(data, 0, data.Length);
                fs.Close();
                return(data);
            }
            else if (info.CryptMode == CryptMode.FullCryption)
            {
                JMDStreamInfo streaminfo = this.GetStreamInfo(info.Index);
                fs.Seek(streaminfo.Offset, SeekOrigin.Begin);
                byte[] data = new byte[streaminfo.Size];
                fs.Read(data, 0, data.Length);
                fs.Close();
                uint key = Crypt.KeyGenerator.GetDataKey(HeaderKey, info);
                data = RhoCrypt.Decrypt(data, key);
                return(data);
            }
            else if (info.CryptMode == CryptMode.PartCryption)
            {
                List <byte>   output     = new List <byte>();
                JMDStreamInfo streaminfo = this.GetStreamInfo(info.Index);
                fs.Seek(streaminfo.Offset, SeekOrigin.Begin);
                byte[] data = new byte[streaminfo.Size];
                fs.Read(data, 0, data.Length);
                uint key = Crypt.KeyGenerator.GetDataKey(HeaderKey, info);
                data = RhoCrypt.Decrypt(data, key);
                output.AddRange(data);
                streaminfo = this.GetStreamInfo(info.Index + 1);
                fs.Seek(streaminfo.Offset, SeekOrigin.Begin);
                data = new byte[streaminfo.Size];
                fs.Read(data, 0, data.Length);
                output.AddRange(data);
                fs.Close();
                return(output.ToArray());
            }
            else
            {
                fs.Close();
                throw new Exception("Unknown CryptMode.");
            }
        }
예제 #2
0
        public byte[] GetPackedFile(RhoPackedFileInfo info)
        {
            FileStream fs = new FileStream(Path, FileMode.Open);

            if (info.CryptMode == CryptMode.None || (int)info.CryptMode == -1)
            {
                RhoStreamInfo streaminfo = this.GetStreamInfo(info.Index);
                fs.Seek(streaminfo.Offset, SeekOrigin.Begin);
                byte[] data = new byte[streaminfo.FileSize];
                fs.Read(data, 0, data.Length);
                fs.Close();
                if (info.CryptMode != CryptMode.None)
                {
                    Debug.Print($"File: {info.FileName} is encrypted by a unsupport encryption method: {info.CryptMode}.");
                }
                return(data);
            }
            else if (info.CryptMode == CryptMode.FullCryption)
            {
                RhoStreamInfo streaminfo = this.GetStreamInfo(info.Index);
                fs.Seek(streaminfo.Offset, SeekOrigin.Begin);
                byte[] data = new byte[streaminfo.FileSize];
                fs.Read(data, 0, data.Length);
                fs.Close();
                uint key = Crypt.KeyGenerator.GetDataKey(HeaderKey, info);
                data = RhoCrypt.Decrypt(data, key);
                return(data);
            }
            else if (info.CryptMode == CryptMode.PartCryption)
            {
                List <byte>   output     = new List <byte>();
                RhoStreamInfo streaminfo = this.GetStreamInfo(info.Index);
                fs.Seek(streaminfo.Offset, SeekOrigin.Begin);
                byte[] data = new byte[streaminfo.FileSize];
                fs.Read(data, 0, data.Length);
                uint key = Crypt.KeyGenerator.GetDataKey(HeaderKey, info);
                data = RhoCrypt.Decrypt(data, key);
                output.AddRange(data);
                streaminfo = this.GetStreamInfo(info.Index + 1);
                fs.Seek(streaminfo.Offset, SeekOrigin.Begin);
                data = new byte[streaminfo.FileSize];
                fs.Read(data, 0, data.Length);
                output.AddRange(data);
                fs.Close();
                return(output.ToArray());
            }
            else if (info.CryptMode == CryptMode.CompressedNonCryption)
            {
                RhoStreamInfo streaminfo = this.GetStreamInfo(info.Index);
                fs.Seek(streaminfo.Offset, SeekOrigin.Begin);
                byte[] data = new byte[(int)streaminfo.FileSize];
                byte[] buf  = new byte[(int)streaminfo.OriginalSize];
                fs.Read(data, 0, (int)streaminfo.FileSize);
                fs.Close();
                using (MemoryStream ms = new MemoryStream(data))
                {
                    Ionic.Zlib.ZlibStream zs = new ZlibStream(ms, CompressionMode.Decompress);
                    zs.Read(buf, 0, buf.Length);
                    Debug.Print($"Method: 01 output:{streaminfo.OriginalSize} totalOutput:{zs.TotalOut}");
                }
                return(buf);
            }
            else if (info.CryptMode == CryptMode.CompressedFullCryption)
            {
                RhoStreamInfo streaminfo = this.GetStreamInfo(info.Index);
                fs.Seek(streaminfo.Offset, SeekOrigin.Begin);
                byte[] data = new byte[streaminfo.FileSize];
                byte[] buf  = new byte[(int)streaminfo.OriginalSize];
                fs.Read(data, 0, (int)streaminfo.FileSize);
                fs.Close();
                using (MemoryStream ms = new MemoryStream(data))
                {
                    Ionic.Zlib.ZlibStream zs = new ZlibStream(ms, CompressionMode.Decompress);
                    zs.Read(buf, 0, buf.Length);
                    Debug.Print($"Method: 06 output:{streaminfo.OriginalSize} totalOutput:{zs.TotalOut}");
                }
                uint key = Crypt.KeyGenerator.GetDataKey(HeaderKey, info);
                buf = RhoCrypt.Decrypt(buf, key);
                return(buf);
            }
            else
            {
                fs.Close();
                throw new Exception("Unknown CryptMode.");
            }
        }