From 891b602a7f8dd33b24aa56492fc0c14ceaf3b468 Mon Sep 17 00:00:00 2001 From: morkt Date: Thu, 28 Jul 2016 20:30:25 +0400 Subject: [PATCH] (KiriKiri): another encryption scheme. --- ArcFormats/KiriKiri/CryptAlgorithms.cs | 46 ++++++++++++++++++++++++++ supported.html | 2 ++ 2 files changed, 48 insertions(+) diff --git a/ArcFormats/KiriKiri/CryptAlgorithms.cs b/ArcFormats/KiriKiri/CryptAlgorithms.cs index 6e0061dc..ea3d6e9f 100644 --- a/ArcFormats/KiriKiri/CryptAlgorithms.cs +++ b/ArcFormats/KiriKiri/CryptAlgorithms.cs @@ -24,6 +24,8 @@ // using System; +using System.Collections.Generic; +using System.Linq; using GameRes.Utility; namespace GameRes.Formats.KiriKiri @@ -696,4 +698,48 @@ namespace GameRes.Formats.KiriKiri Decrypt (entry, offset, buffer, pos, count); } } + + [Serializable] + public class AkabeiCrypt : ICrypt + { + private readonly uint m_seed; + + public AkabeiCrypt (uint seed) + { + m_seed = seed; + } + + public override byte Decrypt (Xp3Entry entry, long offset, byte value) + { + int key_pos = (int)offset & 0x1F; + var key = GetKey (entry.Hash).ElementAt (key_pos); + return (byte)(value ^ key); + } + + public override void Decrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count) + { + var key = GetKey (entry.Hash).ToArray(); + int key_pos = (int)offset; + for (int i = 0; i < count; ++i) + { + buffer[pos+i] ^= key[key_pos++ & 0x1F]; + } + } + + public override void Encrypt (Xp3Entry entry, long offset, byte[] buffer, int pos, int count) + { + Decrypt (entry, offset, buffer, pos, count); + } + + IEnumerable GetKey (uint hash) + { + hash = (hash ^ m_seed) & 0x7FFFFFFF; + hash = hash << 31 | hash; + for (int i = 0; i < 0x20; ++i) + { + yield return (byte)hash; + hash = (hash & 0xFFFFFFFE) << 23 | hash >> 8; + } + } + } } diff --git a/supported.html b/supported.html index d72ade10..2356eaac 100644 --- a/supported.html +++ b/supported.html @@ -258,6 +258,7 @@ Se-kirara
Sharin no Kuni, Himawari no Shoujo
Shokusai no Miyako
Swan Song
+Teakamamire no Tenshi
Zecchou Spiral!!
*.tlgTLG0.0
TLG5.0
TLG6.0No @@ -632,6 +633,7 @@ Answer Dead
Houou Senki Maimu
Kango Sentai Nurse Ranger
Megami Taisen
+Shouryuu Senki Tenmu
*.abmBMNo *.arc
*.xarc
*.binMIKO
KOTORI
XARCNoXuse
ETERNAL