Esempio n. 1
0
        private static string ReadEncryptedString(BinaryReader br, RgssDecryptionKey key)
        {
            int dataLenght = ReadEncryptedInt(br, key);
            var bytes      = br.ReadBytes(dataLenght);

            return(DecryptString(bytes, key));
        }
Esempio n. 2
0
        private static int DecryptInt(int input, RgssDecryptionKey key)
        {
            var dec = (int)(input ^ key.Current());

            key.Step();
            return(dec);
        }
Esempio n. 3
0
 public RgssFileStream(RgssFilePointer fp)
 {
     _fileStream = File.OpenRead(fp.Source.DataPath);
     _decKey     = new RgssDecryptionKey(7, 3);
     _decKey.PushState(fp.Key);
     _fileRange = new RangeStream(_fileStream, fp.Offset, fp.Size);
 }
Esempio n. 4
0
 private static string DecryptString(byte[] input, RgssDecryptionKey key)
 {
     byte[] decBytes = new byte[input.Length];
     for (int i = 0; i < decBytes.Length; i++)
     {
         decBytes[i] = (byte)(input[i] ^ (key.Current() & 0xFF));
         key.Step();
     }
     return(Encoding.UTF8.GetString(decBytes));
 }
Esempio n. 5
0
        private static string DecryptString(byte[] input, RgssDecryptionKey key)
        {
            byte[] decBytes = new byte[input.Length];
            var    j        = 0;

            for (var i = 0; i < decBytes.Length; i++)
            {
                decBytes[i] = (byte)(input[i] ^ ((key.Current() >> 8 * j) & 0xFF));
                j          += 1;
                j          %= 4;
            }
            return(Encoding.UTF8.GetString(decBytes));
        }
Esempio n. 6
0
        public RgssArchiveV3(string path) : base(path)
        {
            using (var fs = File.OpenRead(path))
            {
                switch (CheckVersion(path, 3))
                {
                case -1:
                    throw new InvalidDataException("Invalid RGSS Data");

                case 0:
                    throw new InvalidDataException("Invalid RGSSAD Version");

                case 1:
                default:
                    break;
                }
                using (var br = new BinaryReader(fs))
                {
                    fs.Position = 8;
                    var dKey = new RgssDecryptionKey(9, 3);
                    dKey.PushState(br.ReadUInt32());
                    dKey.Step();

                    while (true)
                    {
                        var fp = new RgssFilePointer();

                        fp.Offset = ReadEncryptedInt(br, dKey);
                        if (fp.Offset == 0)
                        {
                            break;
                        }

                        fp.Source = this;
                        fp.Size   = ReadEncryptedInt(br, dKey);
                        fp.Key    = (uint)ReadEncryptedInt(br, dKey);
                        fp.Name   = ReadEncryptedString(br, dKey);

                        FilePointers.Add(fp);
                    }
                }
            }
        }
Esempio n. 7
0
        public RgssArchiveV1(string path) : base(path)
        {
            using (var fs = File.OpenRead(path))
            {
                switch (CheckVersion(path, 1))
                {
                case -1:
                    throw new InvalidDataException("Invalid RGSS Data");

                case 0:
                    throw new InvalidDataException("Invalid RGSSAD Version");

                case 1:
                default:
                    break;
                }
                using (var br = new BinaryReader(fs))
                {
                    fs.Position = 8;
                    var dKey = new RgssDecryptionKey(7, 3);
                    dKey.PushState(0xDEADCAFE);

                    while (fs.Length - fs.Position > 0)
                    {
                        var fp = new RgssFilePointer();

                        fp.Source    = this;
                        fp.Name      = ReadEncryptedString(br, dKey);
                        fp.Size      = ReadEncryptedInt(br, dKey);
                        fp.Offset    = fs.Position;
                        fp.Key       = dKey.Current();
                        fs.Position += fp.Size;

                        FilePointers.Add(fp);
                    }
                }
            }
        }
Esempio n. 8
0
 private static int ReadEncryptedInt(BinaryReader br, RgssDecryptionKey key)
 {
     return(DecryptInt(br.ReadInt32(), key));
 }
Esempio n. 9
0
 private static int DecryptInt(int input, RgssDecryptionKey key)
 {
     return((int)(input ^ key.Current()));
 }