From e98910ac0c839605f25041d91b66eb9df386a781 Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 21 Apr 2017 08:56:00 +0400 Subject: [PATCH] (ShiinaRio): another decryption class. made KeyDecryptBase more flexible to allow extensions. --- ArcFormats/ShiinaRio/WarcEncryption.cs | 36 +++++++++++++++++++++----- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/ArcFormats/ShiinaRio/WarcEncryption.cs b/ArcFormats/ShiinaRio/WarcEncryption.cs index fa0f0355..75b41240 100644 --- a/ArcFormats/ShiinaRio/WarcEncryption.cs +++ b/ArcFormats/ShiinaRio/WarcEncryption.cs @@ -653,6 +653,7 @@ namespace GameRes.Formats.ShiinaRio protected readonly uint Seed; protected readonly byte[] DecodeTable; protected uint MinLength = 0x400; + protected int PostDataOffset = 0x200; public KeyDecryptBase (uint seed, byte[] decode_bin) { @@ -674,26 +675,29 @@ namespace GameRes.Formats.ShiinaRio { if (length < MinLength) return; - if ((flags & 0x102) == 0x102) - DecryptPre (data, index, length); if ((flags & 0x104) == 0x104) DecryptPost (data, index, length); + if ((flags & 0x102) == 0x102) + DecryptPre (data, index, length); } protected abstract void DecryptPre (byte[] data, int index, uint length); protected virtual void DecryptPost (byte[] data, int index, uint length) { - data[index + 0x200] ^= (byte)Seed; - data[index + 0x201] ^= (byte)(Seed >> 8); - data[index + 0x202] ^= (byte)(Seed >> 16); - data[index + 0x203] ^= (byte)(Seed >> 24); + int pos = index + PostDataOffset; + data[pos ] ^= (byte)Seed; + data[pos+1] ^= (byte)(Seed >> 8); + data[pos+2] ^= (byte)(Seed >> 16); + data[pos+3] ^= (byte)(Seed >> 24); } } [Serializable] public abstract class KeyDecryptExtra : KeyDecryptBase { + protected int EncryptedSize = 0xFF; + public KeyDecryptExtra (uint seed, byte[] decode_bin) : base (seed, decode_bin) { } @@ -702,7 +706,7 @@ namespace GameRes.Formats.ShiinaRio { var k = new uint[4]; InitKey (Seed, k); - for (int i = 0; i < 0xFF; ++i) + for (int i = 0; i < EncryptedSize; ++i) { uint j = k[3] ^ (k[3] << 11) ^ k[0] ^ ((k[3] ^ (k[3] << 11) ^ (k[0] >> 11)) >> 8); k[3] = k[2]; @@ -732,6 +736,24 @@ namespace GameRes.Formats.ShiinaRio } } + [Serializable] + public class YuruPlusCrypt : KeyDecryptExtra + { + public YuruPlusCrypt (uint key, byte[] bin) : base (key, bin) + { + EncryptedSize = 0x100; + PostDataOffset = 0x204; + } + + protected override void InitKey (uint key, uint[] k) + { + k[0] = key + 4; + k[1] = key + 3; + k[2] = key + 2; + k[3] = key + 1; + } + } + [Serializable] public class TestamentCrypt : KeyDecryptExtra // Shinigami no Testament {