From bf24fae0f8b800e3802b8dfae875c5c1668ef2a1 Mon Sep 17 00:00:00 2001 From: Dohyeon An Date: Thu, 17 Mar 2022 09:00:17 +0900 Subject: [PATCH] Unencrypted save file support --- BinderTool.Core/Sl2/Sl2UserData.cs | 18 ++++++++++++++---- BinderTool/Program.cs | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/BinderTool.Core/Sl2/Sl2UserData.cs b/BinderTool.Core/Sl2/Sl2UserData.cs index 167bf11..678cc45 100644 --- a/BinderTool.Core/Sl2/Sl2UserData.cs +++ b/BinderTool.Core/Sl2/Sl2UserData.cs @@ -1,4 +1,5 @@ -using System.IO; +using System; +using System.IO; using System.Text; namespace BinderTool.Core.Sl2 @@ -6,24 +7,33 @@ namespace BinderTool.Core.Sl2 public class Sl2UserData { private const int UserDataIvSize = 16; - + private readonly byte[] _key; private readonly byte[] _iv; + private readonly bool _encrypted; + public Sl2UserData(byte[] key) { _key = key; _iv = new byte[UserDataIvSize]; + _encrypted = Equals(key, new byte[key.Length]) ? true : false; } public string Name { get; set; } public byte[] EncryptedUserData { get; private set; } - //public byte[] DecryptedUserData => CryptographyUtility.DecryptAesCbc(new MemoryStream(EncryptedUserData), _key, _iv).ToArray(); - public byte[] DecryptedUserData => null; + public byte[] DecryptedUserData() + { + if (!_encrypted) + return EncryptedUserData; + MemoryStream ms = new MemoryStream(); + CryptographyUtility.DecryptAesCbc(new MemoryStream(EncryptedUserData), _key, _iv).CopyTo(ms); + return ms.ToArray(); + } public static Sl2UserData ReadSl2UserData(Stream inputStream, byte[] key, int size, string name) { diff --git a/BinderTool/Program.cs b/BinderTool/Program.cs index e26e9f0..b27c190 100644 --- a/BinderTool/Program.cs +++ b/BinderTool/Program.cs @@ -596,7 +596,7 @@ private static void UnpackSl2File(Options options) foreach (var userData in sl2File.UserData) { string outputFilePath = Path.Combine(options.OutputPath, userData.Name); - File.WriteAllBytes(outputFilePath, userData.DecryptedUserData); + File.WriteAllBytes(outputFilePath, userData.DecryptedUserData()); } } }