From 14c0481c1baa921542cd3447ec1618adca34f47a Mon Sep 17 00:00:00 2001 From: morkt Date: Wed, 28 Feb 2018 11:42:41 +0400 Subject: [PATCH] (WARC): another IDecryptExtra implementation. --- ArcFormats/ShiinaRio/WarcEncryption.cs | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/ArcFormats/ShiinaRio/WarcEncryption.cs b/ArcFormats/ShiinaRio/WarcEncryption.cs index 2d03ab9e..74555b42 100644 --- a/ArcFormats/ShiinaRio/WarcEncryption.cs +++ b/ArcFormats/ShiinaRio/WarcEncryption.cs @@ -1181,4 +1181,41 @@ namespace GameRes.Formats.ShiinaRio data[index + 0x104] ^= count_FF; } } + + [Serializable] + public class UshimitsuCrypt : IDecryptExtra + { + protected readonly uint m_key; + + public UshimitsuCrypt (uint key) + { + m_key = key; + } + + public void Decrypt (byte[] data, int index, uint length, uint flags) + { + if ((flags & 0x204) == 0x204) + DoCrypt (data, index, length); + } + + public void Encrypt (byte[] data, int index, uint length, uint flags) + { + if ((flags & 0x104) == 0x104) + DoCrypt (data, index, length); + } + + unsafe void DoCrypt (byte[] data, int index, uint length) + { + if (length < 0x100) + return; + fixed (byte* data8 = &data[index]) + { + uint* data32 = (uint*)data8; + for (int i = 0; i < 0x40; ++i) + { + data32[i] ^= m_key; + } + } + } + } }