mon / BemaniPatcher

Web based DLL binary patcher
MIT License
211 stars 136 forks source link

Fix copying original bytes in dynamic patches #355

Closed aixxe closed 2 months ago

aixxe commented 2 months ago

Was originally going to make an issue for this but I ended up fixing it in the process. Original text detailing the bug below:


I think I've run into a bug with the output file when using dynamic patches. Here's one I wrote for the INFINITAS launcher:

{
    type: 'dynamic',
    name: 'Bypass Game File Validation',
    tooltip: 'Ignore expected SHA-256 from server, allowing the game to launch with a modified executable',
    patches: [
        {
            off: [0x74, 'XX', 0xB9, 'XX', 'XX', 'XX', 'XX', 0xE8, 'XX', 'XX', 'XX', 'XX', 0x48, 0x8B, 0x7D],
            on: [0xEB, 'XX', 0xB9, 'XX', 'XX', 'XX', 'XX', 0xE8, 'XX', 'XX', 'XX', 'XX', 0x48, 0x8B, 0x7D],
        },
    ],
},

I'm only replacing the first byte, so the rest is just there to make it sufficiently unique. I kept the wildcards in the on patch as XX assuming it would only change the first byte and leave the rest untouched.

After enabling the patch and saving the file, the output was a little different to what I expected.

It seems like the wildcard bytes are getting replaced with 00 instead of the original contents:

WinMergeU_C1xZ5dc1d4

mon commented 2 months ago

Huh, that's super weird, I would have expected the closure's variables to appropriately shadow the patch variable. I'll take your word for it as being fixed - even if it's a red herring, byte is a much better name for that argument!