Skip to content

Commit

Permalink
Merge pull request #46 from gomsoup/elden-ring
Browse files Browse the repository at this point in the history
Unencrypted save file support
  • Loading branch information
Atvaark authored Mar 17, 2022
2 parents 7731d94 + bf24fae commit 1879ffb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions BinderTool.Core/Sl2/Sl2UserData.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,39 @@
using System.IO;
using System;
using System.IO;
using System.Text;

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)
{
Expand Down
2 changes: 1 addition & 1 deletion BinderTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down

0 comments on commit 1879ffb

Please sign in to comment.