(WARC): another decryptor.

This commit is contained in:
morkt 2018-04-01 08:03:29 +04:00
parent 4bfad9536c
commit c38c84a422

View File

@ -797,16 +797,7 @@ namespace GameRes.Formats.ShiinaRio
return; return;
if ((flags & 0x202) == 0x202) if ((flags & 0x202) == 0x202)
{ {
int sum = 0; int sum = RotateBytesRight (data, index, 0x100);
int bit = 0;
for (int i = 0; i < 0x100; ++i)
{
byte v = data[index+i];
sum += v >> 1;
data[index+i] = (byte)(v >> 1 | bit);
bit = v << 7;
}
data[index] |= (byte)bit;
data[index + 0x104] ^= (byte)sum; data[index + 0x104] ^= (byte)sum;
data[index + 0x105] ^= (byte)(sum >> 8); data[index + 0x105] ^= (byte)(sum >> 8);
} }
@ -817,19 +808,68 @@ namespace GameRes.Formats.ShiinaRio
if (length < 0x200) if (length < 0x200)
return; return;
if ((flags & 0x102) == 0x102) if ((flags & 0x102) == 0x102)
{
int sum = RotateBytesLeft (data, index, 0x100);
data[index + 0x104] ^= (byte)sum;
data[index + 0x105] ^= (byte)(sum >> 8);
}
}
internal int RotateBytesRight (byte[] data, int index, int length)
{ {
int sum = 0; int sum = 0;
int bit = 0; int bit = 0;
for (int i = 0xFF; i >= 0; --i) for (int i = 0; i < length; ++i)
{
byte v = data[index+i];
sum += v >> 1;
data[index+i] = (byte)(v >> 1 | bit);
bit = v << 7;
}
data[index] |= (byte)bit;
return sum;
}
internal int RotateBytesLeft (byte[] data, int index, int length)
{
int sum = 0;
int bit = 0;
for (int i = length-1; i >= 0; --i)
{ {
byte v = data[index+i]; byte v = data[index+i];
sum += v & 0x7F; sum += v & 0x7F;
data[index+i] = (byte)(v << 1 | bit); data[index+i] = (byte)(v << 1 | bit);
bit = v >> 7; bit = v >> 7;
} }
data[index + 0xFF] |= (byte)bit; data[index + length-1] |= (byte)bit;
data[index + 0x104] ^= (byte)sum; return sum;
data[index + 0x105] ^= (byte)(sum >> 8); }
}
[Serializable]
public class NyaruCrypt : MajimeCrypt, IDecryptExtra
{
new public void Decrypt (byte[] data, int index, uint length, uint flags)
{
if (length < 0x200)
return;
if ((flags & 0x204) == 0x204)
{
int sum = RotateBytesRight (data, index, 0x100);
data[index + 0x100] ^= (byte)sum;
data[index + 0x101] ^= (byte)(sum >> 8);
}
}
new public void Encrypt (byte[] data, int index, uint length, uint flags)
{
if (length < 0x200)
return;
if ((flags & 0x104) == 0x104)
{
int sum = RotateBytesLeft (data, index, 0x100);
data[index + 0x100] ^= (byte)sum;
data[index + 0x101] ^= (byte)(sum >> 8);
} }
} }
} }