(ShiinaRio): another decryption class.

made KeyDecryptBase more flexible to allow extensions.
This commit is contained in:
morkt 2017-04-21 08:56:00 +04:00
parent 596915408e
commit e98910ac0c

View File

@ -653,6 +653,7 @@ namespace GameRes.Formats.ShiinaRio
protected readonly uint Seed; protected readonly uint Seed;
protected readonly byte[] DecodeTable; protected readonly byte[] DecodeTable;
protected uint MinLength = 0x400; protected uint MinLength = 0x400;
protected int PostDataOffset = 0x200;
public KeyDecryptBase (uint seed, byte[] decode_bin) public KeyDecryptBase (uint seed, byte[] decode_bin)
{ {
@ -674,26 +675,29 @@ namespace GameRes.Formats.ShiinaRio
{ {
if (length < MinLength) if (length < MinLength)
return; return;
if ((flags & 0x102) == 0x102)
DecryptPre (data, index, length);
if ((flags & 0x104) == 0x104) if ((flags & 0x104) == 0x104)
DecryptPost (data, index, length); DecryptPost (data, index, length);
if ((flags & 0x102) == 0x102)
DecryptPre (data, index, length);
} }
protected abstract void DecryptPre (byte[] data, int index, uint length); protected abstract void DecryptPre (byte[] data, int index, uint length);
protected virtual void DecryptPost (byte[] data, int index, uint length) protected virtual void DecryptPost (byte[] data, int index, uint length)
{ {
data[index + 0x200] ^= (byte)Seed; int pos = index + PostDataOffset;
data[index + 0x201] ^= (byte)(Seed >> 8); data[pos ] ^= (byte)Seed;
data[index + 0x202] ^= (byte)(Seed >> 16); data[pos+1] ^= (byte)(Seed >> 8);
data[index + 0x203] ^= (byte)(Seed >> 24); data[pos+2] ^= (byte)(Seed >> 16);
data[pos+3] ^= (byte)(Seed >> 24);
} }
} }
[Serializable] [Serializable]
public abstract class KeyDecryptExtra : KeyDecryptBase public abstract class KeyDecryptExtra : KeyDecryptBase
{ {
protected int EncryptedSize = 0xFF;
public KeyDecryptExtra (uint seed, byte[] decode_bin) : base (seed, decode_bin) public KeyDecryptExtra (uint seed, byte[] decode_bin) : base (seed, decode_bin)
{ {
} }
@ -702,7 +706,7 @@ namespace GameRes.Formats.ShiinaRio
{ {
var k = new uint[4]; var k = new uint[4];
InitKey (Seed, k); 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); uint j = k[3] ^ (k[3] << 11) ^ k[0] ^ ((k[3] ^ (k[3] << 11) ^ (k[0] >> 11)) >> 8);
k[3] = k[2]; 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] [Serializable]
public class TestamentCrypt : KeyDecryptExtra // Shinigami no Testament public class TestamentCrypt : KeyDecryptExtra // Shinigami no Testament
{ {