From 2d389ec5287edeab2e3372d905bc0173b2f74bb8 Mon Sep 17 00:00:00 2001 From: morkt Date: Thu, 11 Jan 2018 20:22:53 +0400 Subject: [PATCH] (LST): fixed decryption for names containing characters identical to encryption key. --- ArcFormats/ArcLST.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ArcFormats/ArcLST.cs b/ArcFormats/ArcLST.cs index 814fab66..3faf05f6 100644 --- a/ArcFormats/ArcLST.cs +++ b/ArcFormats/ArcLST.cs @@ -81,7 +81,7 @@ namespace GameRes.Formats.Nexton uint index_offset = 4; for (int i = 0; i < count; ++i) { - string name = ReadName (lst, index_offset+8, 0x24, 0xcccccccc, cp932); + string name = ReadName (lst, index_offset+8, 0x24, 0xcc, cp932); if (0 == name.Length) return null; var entry = FormatCatalog.Instance.Create (name); @@ -112,7 +112,7 @@ namespace GameRes.Formats.Nexton uint index_offset = 4; for (int i = 0; i < count; ++i) { - string name = ReadName (lst, index_offset+8, 0x40, key, cp932); + string name = ReadName (lst, index_offset+8, 0x40, (byte)key, cp932); if (0 == name.Length) return null; var entry = new NextonEntry { @@ -153,7 +153,7 @@ namespace GameRes.Formats.Nexton return new BinMemoryStream (data, entry.Name); } - private static string ReadName (ArcView view, long offset, uint size, uint key, Encoding enc) + private static string ReadName (ArcView view, long offset, uint size, byte key, Encoding enc) { byte[] buffer = new byte[size]; uint n; @@ -162,7 +162,9 @@ namespace GameRes.Formats.Nexton byte b = view.View.ReadByte (offset+n); if (0 == b) break; - buffer[n] = (byte)(b^key); + if (b != key) + b ^= key; + buffer[n] = b; } return enc.GetString (buffer, 0, (int)n); }