diff --git a/ArcFormats/ArcFormats.csproj b/ArcFormats/ArcFormats.csproj index d82775d1..2bffdb84 100644 --- a/ArcFormats/ArcFormats.csproj +++ b/ArcFormats/ArcFormats.csproj @@ -91,6 +91,7 @@ + diff --git a/ArcFormats/ArcIKS.cs b/ArcFormats/ArcIKS.cs new file mode 100644 index 00000000..a3871fcd --- /dev/null +++ b/ArcFormats/ArcIKS.cs @@ -0,0 +1,124 @@ +//! \file ArcIKS.cs +//! \date Wed Jul 08 07:07:09 2015 +//! \brief [IKS] archives implementation. +// +// Copyright (C) 2015 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; +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.IO; +using System.Linq; +using System.Security.Cryptography; +using GameRes.Utility; + +namespace GameRes.Formats.X +{ + [Export(typeof(ArchiveFormat))] + public class IksOpener : ArchiveFormat + { + public override string Tag { get { return "IKS"; } } + public override string Description { get { return "X[iks] resource archive"; } } + public override uint Signature { get { return 0x5253504E; } } // 'NPSR' + public override bool IsHierarchic { get { return false; } } + public override bool CanCreate { get { return false; } } + + public static Dictionary KnownKeys = new Dictionary() { + { "Shikkan ~Hazukashimerareta Karada, Oreta Kokoro~", 0x66 }, + }; + + public override ArcFile TryOpen (ArcView file) + { + int count = file.View.ReadInt32 (4); + if (count <= 0 || count > 0xfffff) + return null; + uint index_offset = 0x10; + uint index_size = (uint)(0x28 * count); + if (index_size > file.View.Reserve (index_offset, index_size)) + return null; + long data_offset = index_offset + index_size; + var dir = new List (count); + var name_buffer = new byte[0x18]; + for (int i = 0; i < count; ++i) + { + byte name_length = Math.Min ((byte)0x17, file.View.ReadByte (index_offset)); + if (name_length > name_buffer.Length) + return null; + file.View.Read (index_offset+1, name_buffer, 0, name_length); + string name = Encodings.cp932.GetString (name_buffer, 0, name_length); + var entry = FormatCatalog.Instance.CreateEntry (name); + entry.Offset = file.View.ReadUInt32 (index_offset+0x20); + entry.Size = file.View.ReadUInt32 (index_offset+0x1C); + if (entry.Offset < data_offset || !entry.CheckPlacement (file.MaxOffset)) + return null; + dir.Add (entry); + index_offset += 0x28; + } + return new ArcFile (file, this, dir); + } + + public override Stream OpenEntry (ArcFile arc, Entry entry) + { + byte key = KnownKeys.First().Value; + var input = arc.File.CreateStream (entry.Offset, entry.Size); + return new CryptoStream (input, new XorTransform (key), CryptoStreamMode.Read); + } + } + + public sealed class XorTransform : ICryptoTransform + { + private const int BlockSize = 256; + private byte 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 XorTransform (byte key) + { + m_key = key; + } + + public int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount, + byte[] outputBuffer, int outputOffset) + { + for (int i = 0; i < inputCount; ++i) + { + outputBuffer[outputOffset++] = (byte)(m_key ^ inputBuffer[inputOffset+i]); + } + 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/ArcFormats/Properties/AssemblyInfo.cs b/ArcFormats/Properties/AssemblyInfo.cs index 3f6d90b1..0b1ec475 100644 --- a/ArcFormats/Properties/AssemblyInfo.cs +++ b/ArcFormats/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion ("1.0.7.74")] -[assembly: AssemblyFileVersion ("1.0.7.74")] +[assembly: AssemblyVersion ("1.0.7.75")] +[assembly: AssemblyFileVersion ("1.0.7.75")] diff --git a/supported.html b/supported.html index e5f97fc1..91c2405f 100644 --- a/supported.html +++ b/supported.html @@ -238,6 +238,7 @@ Jokei Kazoku ~Inbou~
*.gccG24n
G24m
R24n
R24mNo *.arc-NoTumugiKimi no Omoi, Sono Negai +*.iksNPSRNoX[iks]Shikkan ~Hazukashimerareta Karada, Oreta Kokoro~

[1] Non-encrypted only