From 4b945bc46afd6ada2a166e29c918dafc185c8c0f Mon Sep 17 00:00:00 2001 From: morkt Date: Sat, 4 Jun 2016 20:01:19 +0400 Subject: [PATCH] implemented SZS archives and TIG images. --- ArcFormats/ArcFormats.csproj | 2 + ArcFormats/Slg/ArcSZS.cs | 76 ++++++++++++++++++++++++++++ ArcFormats/Slg/ImageTIG.cs | 98 ++++++++++++++++++++++++++++++++++++ supported.html | 8 ++- 4 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 ArcFormats/Slg/ArcSZS.cs create mode 100644 ArcFormats/Slg/ImageTIG.cs diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index 3804cb54..8769bcfa 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -120,8 +120,10 @@ + + diff --git a/ArcFormats/Slg/ArcSZS.cs b/ArcFormats/Slg/ArcSZS.cs new file mode 100644 index 00000000..7939a1fd --- /dev/null +++ b/ArcFormats/Slg/ArcSZS.cs @@ -0,0 +1,76 @@ +//! \file ArcSZS.cs +//! \date Sat Jun 04 17:31:59 2016 +//! \brief SLG system resource archive. +// +// Copyright (C) 2016 by morkt +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.IO; +using System.Security.Cryptography; + +namespace GameRes.Formats.Slg +{ + [Export(typeof(ArchiveFormat))] + public class SzsOpener : ArchiveFormat + { + public override string Tag { get { return "SZS"; } } + public override string Description { get { return "SLG system resource archive"; } } + public override uint Signature { get { return 0x31535A53; } } // 'SZS1' + public override bool IsHierarchic { get { return false; } } + public override bool CanCreate { get { return false; } } + + public override ArcFile TryOpen (ArcView file) + { + int version = file.View.ReadByte (4) - '0'; + if (version < 0 || !file.View.AsciiEqual (5, "0__")) + return null; + int count = file.View.ReadInt16 (0xC); + if (!IsSaneCount (count)) + return null; + + uint index_offset = 0x10; + var dir = new List (count); + for (int i = 0; i < count; ++i) + { + var name = file.View.ReadString (index_offset, 0x100); + if (string.IsNullOrWhiteSpace (name)) + return null; + index_offset += 0x100; + var entry = FormatCatalog.Instance.Create (name); + entry.Offset = file.View.ReadInt64 (index_offset); + entry.Size = file.View.ReadUInt32 (index_offset+8); + if (!entry.CheckPlacement (file.MaxOffset)) + return null; + dir.Add (entry); + index_offset += 0x10; + } + return new ArcFile (file, this, dir); + } + + public override Stream OpenEntry (ArcFile arc, Entry entry) + { + var input = arc.File.CreateStream (entry.Offset, entry.Size); + return new CryptoStream (input, new XorTransform (0x90), CryptoStreamMode.Read); + } + } +} diff --git a/ArcFormats/Slg/ImageTIG.cs b/ArcFormats/Slg/ImageTIG.cs new file mode 100644 index 00000000..2dcf5492 --- /dev/null +++ b/ArcFormats/Slg/ImageTIG.cs @@ -0,0 +1,98 @@ +//! \file ImageTIG.cs +//! \date Sat Jun 04 18:00:15 2016 +//! \brief SLG system encrypted PNG images. +// +// Copyright (C) 2016 by morkt +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to +// deal in the Software without restriction, including without limitation the +// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +// sell copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +// IN THE SOFTWARE. +// + +using System.ComponentModel.Composition; +using System.IO; +using System.Security.Cryptography; + +namespace GameRes.Formats.Slg +{ + [Export(typeof(ImageFormat))] + public class TigFormat : PngFormat + { + public override string Tag { get { return "TIG"; } } + public override string Description { get { return "SLG system encrypted PNG image"; } } + public override uint Signature { get { return 0x7CF3C28B; } } + + public override ImageMetaData ReadMetaData (Stream stream) + { + using (var proxy = new ProxyStream (stream, true)) + using (var input = new CryptoStream (proxy, new TigTransform(), CryptoStreamMode.Read)) + return base.ReadMetaData (input); + } + + public override ImageData Read (Stream stream, ImageMetaData info) + { + using (var proxy = new ProxyStream (stream, true)) + using (var input = new CryptoStream (proxy, new TigTransform(), CryptoStreamMode.Read)) + return base.Read (input, info); + } + + public override void Write (Stream file, ImageData image) + { + throw new System.NotImplementedException ("TigFormat.Write not implemented"); + } + } + + internal sealed class TigTransform : ICryptoTransform + { + const int BlockSize = 256; + uint m_key; + + public bool CanReuseTransform { get { return true; } } + public bool CanTransformMultipleBlocks { get { return true; } } + public int InputBlockSize { get { return BlockSize; } } + public int OutputBlockSize { get { return BlockSize; } } + + public TigTransform () + { + m_key = 0x7F7F7F7F; + } + + public int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount, + byte[] outputBuffer, int outputOffset) + { + for (int i = 0; i < inputCount; ++i) + { + m_key *= 0x343FD; + m_key += 0x269EC3; + outputBuffer[outputOffset+i] = (byte)(inputBuffer[inputOffset+i] - (m_key >> 16)); + } + return inputCount; + } + + public byte[] TransformFinalBlock (byte[] inputBuffer, int inputOffset, int inputCount) + { + byte[] outputBuffer = new byte[inputCount]; + TransformBlock (inputBuffer, inputOffset, inputCount, outputBuffer, 0); + return outputBuffer; + } + + public void Dispose () + { + System.GC.SuppressFinalize (this); + } + } +} diff --git a/supported.html b/supported.html index 537fcf66..86181010 100644 --- a/supported.html +++ b/supported.html @@ -364,6 +364,7 @@ Lovers Collection
Nachtmusik
Nachtmusik Another
Oto☆Puri
+Rakuen no Rukia ~Blood Moon Rising~
Samayou Mitama ni Yasuragi no Toki wo
Time Trouble ~Marie ni Kubikkake~
@@ -579,6 +580,7 @@ Before Dawn Daybreak ~Shinen no Utahime~
Gun-Katana
Jishou Seirei Majutsushi vs Shinsei Daiikkyuu Akuma
Kurogane no Tsubasa ~The Alchemist's Story~
+Mushitsukai
Yami no Koe series
*.dwqBMP
JPEG
PNG
JPEG+MASK
PACKBMP+MASK
No @@ -638,6 +640,7 @@ Cross Quartz
Hyakki Yakou
Saikyou Goshujin-sama! -Mighty My Master-
Saiminjutsu Re
+Wizard Links
*.medMDNo *.tcdTCD3NoTopCat @@ -809,9 +812,12 @@ Tokyo Necro
Thanatos no Koi ~In Ane Otouto Soukan~
*.gpsGPSNo -*.albALB1.21NoSLG system +*.szsSZS100__NoSLG system +Sengoku Hime
Shihen 69 ~Shinen no Messiah~
+*.tig\x7C\xF3\xC2\x8BNo +*.albALB1.21No *.voi-No *.wagIAF_NoHexenhaus Angenehm Platz -Kleiner Garten Sie Erstellen-