Thealexbarney / PqSave

Pokémon Quest save reader and writer
MIT License
32 stars 13 forks source link

CryptographicException: Padding is invalid and cannot be removed #10

Open comigor opened 6 years ago

comigor commented 6 years ago

I'm getting Unhandled Exception: System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed. while trying to decrypt my save file (which has already been modified using this tool, played for many hours, then I'm trying to modify it once again).

My save file, for reference: user.zip

Thealexbarney commented 6 years ago

Your save isn't loading in Pokemon Quest on my Switch. Maybe something went wrong when dumping it

Acefkor commented 6 years ago

Hi! Same error here:

PqSave.NET.Core$ dotnet PqSave.dll s ../user ../user_modified tickets.csx items.csx 

Unhandled Exception: System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed.
   at Internal.Cryptography.UniversalCryptoDecryptor.DepadBlock(Byte[] block, Int32 offset, Int32 count)
   at Internal.Cryptography.UniversalCryptoDecryptor.UncheckedTransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
   at Internal.Cryptography.UniversalCryptoTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
   at System.Security.Cryptography.CryptoStream.FlushFinalBlock()
   at PqSave.Encryption.Transform(Byte[] data, Int32 index, Int32 length, Mode mode) in C:\Users\Develop\Source\Repos\PqSave\PqSave\Encryption.cs:line 55
   at PqSave.SaveManager..ctor(Byte[] saveEnc) in C:\Users\Develop\Source\Repos\PqSave\PqSave\SaveManager.cs:line 12
   at PqSave.Program.Run(String[] args) in C:\Users\Develop\Source\Repos\PqSave\PqSave\Program.cs:line 52
   at PqSave.Program.Main(String[] args) in C:\Users\Develop\Source\Repos\PqSave\PqSave\Program.cs:line 18
Aborted (core dumped)

I'm on Ubuntu 16.04 with .NET Core 2.1 installed. The save file i'm trying to edit is the same file that i modified on Windows and it was successfully edited. I don't know what i'm doing wrong.

Thealexbarney commented 6 years ago

@Acefkor Do you have your save file before and after you edited it that you could upload? And does the same save file that doesn't work with .NET Core on Linux work on Windows?

Acefkor commented 6 years ago

@Thealexbarney here are both files files.zip Yeah, is exactly the same file. I tried to modified the file first on Linux but the error was always the same, after that, I modified it on Windows, restored it on my Switch and it works perfect.

Thealexbarney commented 6 years ago

@Acefkor Is that unmodified file directly dumped from a working save off your Switch? Just like Igor1201's save the encryption doesn't appear to be valid and the save won't load on my Switch. Somewhere in the middle of the save the encryption gets messed up

Acefkor commented 6 years ago

@Thealexbarney yes, is directly from a working save. I'm going to try it again and see what happen 'cause like @Igor1201, i dumped the original file, modified it on Windows for the very first time and it works perfectly, and now that I want to modify it again on Linux (for the second time), it doesn't work but on Windows does. I'm going to test it again tomorrow.

Thealexbarney commented 6 years ago

@Acefkor and @Igor1201, what program are you using to dump your saves? I'm suspecting that something might be wrong with the save dumper. Both of your saves have the same issue about halfway through the file

comigor commented 6 years ago

The fact you can still edit the file on Windows is really weird. I tried to edit mine on both W10 and macOS without success.

@Thealexbarney I'm using latest Checkpoint (3.2.0) to dump them. I'll try a new dump after restarting the switch a couple of times to see if it changes something (I couldn't load the saves if I didn't restart it twice: again, weird behavior).

comigor commented 6 years ago

Just to make sure, can you guys decrypt/edit my latest save file: user.zip? It works for me.

I've just dumped it after restarting the switch twice (played the game on CFW, restart, played the game on Horizon, restart on CFW, dump); and I had to do something similar to restore the save (dump, reboot, restore, reboot again, start game).

That's probably an issue with Checkpoint or with Checkpoint on system 5.1.0. Thanks for pointing it out, @Thealexbarney.

I'll leave this issue open while @Acefkor confirms he has the same issue (or doesn't). Thanks again!

Acefkor commented 6 years ago

@Igor1201 I tried your file and it works for me, even on Linux. As you said, maybe is a problem with Checkpoint on 5.1.0. I've been on CFW since June 4th and today i made a new dump and it works perfectly on Linux, really weird behavior. Now, all is working fine. Thanks for your replies.

Thealexbarney commented 6 years ago

Works for me too. The above saves that didn't work should fail to decrypt on both Linux and Windows, and fail to load when restored to the Switch

s1rleblanc commented 6 years ago

Hi every one.. i had the same error than @Igor1201 and i updated checkpoint to the last version and now i have this one:

$ dotnet PqSave.dll x user user.json

Unhandled Exception: System.ArgumentOutOfRangeException: Non-negative number required.

Parameter name: count at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.PqSave.ConfigData$Formatter.Deserialize(Byte[]& , Int32 , DirtyTracker , Int32& ) at ZeroFormatter.Segments.ObjectSegmentHelper.DeserializeSegment[TTypeResolver,T](ArraySegment1 originalBytes, Int32 index, Int32 lastIndex, DirtyTracker tracker) at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.PqSave.SerializeData..ctor(DirtyTracker , ArraySegment1 ) at ZeroFormatter.DynamicObjectSegments.ZeroFormatter_Formatters_DefaultResolver.PqSave.SerializeData$Formatter.Deserialize(Byte[]& , Int32 , DirtyTracker , Int32& ) at ZeroFormatter.ZeroFormatterSerializer.CustomSerializer`1.Deserialize[T](Byte[] bytes, Int32 offset) at PqSave.SaveManager..ctor(Byte[] saveEnc) in C:\Users\Develop\Source\Repos\PqSave\PqSave\SaveManager.cs:line 12 at PqSave.Program.Run(String[] args) in C:\Users\Develop\Source\Repos\PqSave\PqSave\Program.cs:line 41 at PqSave.Program.Main(String[] args) in C:\Users\Develop\Source\Repos\PqSave\PqSave\Program.cs:line 18 Abort trap: 6

i already mod my save file in windows successfully but now i tried on macOS and show me this.

would @Thealexbarney please help me to fix it ?