From b02b95cbf18ffc236ab948de6d1d2ceda57f0f42 Mon Sep 17 00:00:00 2001 From: morkt Date: Sun, 5 Feb 2017 02:28:02 +0400 Subject: [PATCH] (XP3): threat non-'File' index records as hashed names. added NoCryptTitles to Xp3Scheme. --- ArcFormats/KiriKiri/ArcXP3.cs | 47 +++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/ArcFormats/KiriKiri/ArcXP3.cs b/ArcFormats/KiriKiri/ArcXP3.cs index 1fc1e0ad..64649cbd 100644 --- a/ArcFormats/KiriKiri/ArcXP3.cs +++ b/ArcFormats/KiriKiri/ArcXP3.cs @@ -71,7 +71,8 @@ namespace GameRes.Formats.KiriKiri [Serializable] public class Xp3Scheme : ResourceScheme { - public Dictionary KnownSchemes; + public IDictionary KnownSchemes; + public ISet NoCryptTitles; } // Archive version 1: encrypt file first, then calculate checksum @@ -153,20 +154,7 @@ namespace GameRes.Formats.KiriKiri if (entry_size < 0) return null; dir_offset += 12 + entry_size; - if (0x6E666E68 == entry_signature // "hnfn" - || 0x6C696D73 == entry_signature // "smil" - || 0x46696C65 == entry_signature) // "eliF" - { - uint hash = header.ReadUInt32(); - int name_size = header.ReadInt16(); - entry_size -= 6; - if (name_size * 2 <= entry_size) - { - var filename = new string (header.ReadChars (name_size)); - filename_map.Add (hash, filename); - } - } - else if (0x656C6946 == entry_signature) // "File" + if (0x656C6946 == entry_signature) // "File" { var entry = new Xp3Entry(); while (entry_size > 0) @@ -262,6 +250,24 @@ namespace GameRes.Formats.KiriKiri dir.Add (entry); } } + else if (entry_size > 7) + { + // 0x6E666E68 == entry_signature // "hnfn" + // 0x6C696D73 == entry_signature // "smil" + // 0x46696C65 == entry_signature // "eliF" + // 0x757A7559 == entry_signature // "Yuzu" + uint hash = header.ReadUInt32(); + int name_size = header.ReadInt16(); + if (name_size > 0) + { + entry_size -= 6; + if (name_size * 2 <= entry_size) + { + var filename = new string (header.ReadChars (name_size)); + filename_map.Add (hash, filename); + } + } + } NextEntry: header.BaseStream.Position = dir_offset; } @@ -740,12 +746,16 @@ NextEntry: var title = FormatCatalog.Instance.LookupGame (file.Name); if (string.IsNullOrEmpty (title)) return null; - return GetScheme (title); + ICrypt algorithm; + if (!KnownSchemes.TryGetValue (title, out algorithm) && NoCryptTitles.Contains (title)) + algorithm = NoCryptAlgorithm; + return algorithm; } static Xp3Scheme KiriKiriScheme = new Xp3Scheme { KnownSchemes = new Dictionary(), + NoCryptTitles = new HashSet() }; public static IDictionary KnownSchemes @@ -753,6 +763,11 @@ NextEntry: get { return KiriKiriScheme.KnownSchemes; } } + public static ISet NoCryptTitles + { + get { return KiriKiriScheme.NoCryptTitles; } + } + public override ResourceScheme Scheme { get { return KiriKiriScheme; }