atom0s / Steamless

Steamless is a DRM remover of the SteamStub variants. The goal of Steamless is to make a single solution for unpacking all Steam DRM-packed files. Steamless aims to support as many games as possible.
Other
3.08k stars 195 forks source link

3.1 x86 - fails to decrypt .text section if byte count of data is not aligned to 16 bytes #109

Closed szlobipeti closed 5 months ago

szlobipeti commented 5 months ago

Issue encountered while trying to unpack Saboteur.exe from The Saboteur Steam version.

Issue location: Steamless.API.Crypto.AesHelper.cs line 157

cStream.Read throws an exception after reading the entirety of the .text section. Since the data in this section is not 16 bytes aligned for some reason, the decryption throws.

Manually setting the raw size of codeSectionData in Steamless.Unpacker.Variant31.x86.Main.cs line 407 to be aligned to 16 bytes (adding +1 while debug break) fixed the issue and the executable was correctly decrypted with no immediately obvious corruption resulting from the hacky fix.

szlobipeti commented 5 months ago

Upon closer inspection I am pretty sure that the last 16 bytes in the .text section did not decode correctly and were filled with seemingly random 0x10 bytes. I was able to manually fix this error using another .exe of the same game, but the naive solution of just extending the buffer will likely not suffice as a proper solution. That being said, as long as the game does not hit an execution where those last 16 bytes are relevant, the fix should work for other games that trip on this exception.

atom0s commented 5 months ago

Hello, can you please upload the game exe somewhere and link it here?

szlobipeti commented 5 months ago

Provided requested file in a private message on Discord.

atom0s commented 5 months ago

Thank you for the sample submission! This file has helped track down and fix a long-standing issue with the AES decryption handling for two of the unpackers. This file should now unpack properly using the latest update v3.1.0.5 (or newer).

https://github.com/atom0s/Steamless/releases/tag/v3.1.0.5