Homebrew WIP SXPD - Switch eXecutable Patch Delta, a new file format for exe patching + a patch utility.

  • Thread starter Thread starter SimonMKWii
  • Start date Start date
  • Views Views 18,469
  • Replies Replies 67
  • Likes Likes 11

SimonMKWii

Professional Idiot
Member
Joined
Nov 18, 2017
Messages
666
Reaction score
1,246
Trophies
0
Location
Melbourne, Victoria
XP
2,781
Country
Australia
This should make patching executables a lot easier (and a whole lot more legal!)

Switch eXecutable Patch Delta format notes:

For use with .elf files generated with nx2elf from an NSO.

Key: Start Offset, Length (in hex)

[HEADER, 0x00, 0x50]
0x0, 0x4 = Magic number: "SXPD"
0x4, 0x4 = Number of instructions to patch (in hex)
0x8, 0x20 = SHA256 hash of original .elf
0x28, 0x20 = SHA256 hash of patched .elf
0x48, 0x8 = Padding data, put whatever you want here

[LISTINGS, 0x50, (variable length)]
Each listing is 0x8 in length.
0x0, 0x4 = Offset of instruction (in the .elf)
0x4, 0x4 = ARM instruction (as hex)

Note: this format is specifically designed for ARM instructions, and could potentially be used for real-time patching.

Attached is a highly WIP utility (Sexep - Switch executable patcher) to patch games, it includes 2 sample patches for Super Mario Odyssey 1.2.0 (note: the god mode patch disables online functionality for obvious reasons).
Currently it can only patch games, but soon you will be able to make your own patches as well. (You can make them now if you follow the format notes!)
I'll be posting a few more sample patches a bit later on.
 

Attachments

Last edited by SimonMKWii,
Oh, didn't see that. I looked at it just now, it's python 2.7, and we all know how great python 2.7 is on Windows...
Also, there's no verification system in that script, whereas mine verifies it by generating a SHA256 of the input and output files and making sure it matches the correct values, which are hardcoded into each patch file.
Furthermore it doesn't have a specific file format, where mine does. But it's not a bad script, certainly cleaner than my code.
 
Incoming "VB SUXX SO YOUR APP SUXX"...
Oh, didn't see that. I looked at it just now, it's python 2.7, and we all know how great python 2.7 is on Windows...
Also, there's no verification system in that script, whereas mine verifies it by generating a SHA256 of the input and output files and making sure it matches the correct values, which are hardcoded into each patch file.
Furthermore it doesn't have a specific file format, where mine does. But it's not a bad script, certainly cleaner than my code.
Incoming: MY APP IS DA BEST, DE OTHA IS CRAP.

Now seriously.... Python2.7 works fine unless the user installed in it incorrectly. Also that app allows to browse files and replace them while for your app you need to craft a patch with offsets and all of that. That app is better for end users that want tot replace random files while yours is better for developers distributing a mod pack.
Edit: I confused it with the layeredfs temporal replacement to browse and change romfs files. In any case, hating other apps because you made a "better one" will make the scene look you as a bad developer. (Note that at any moment I said your app is bad).
 
Last edited by PabloMK7,
Incoming: MY APP IS DA BEST, DE OTHA IS CRAP.

Now seriously.... Python2.7 works fine unless the user installed in it incorrectly. Also that app allows to browse files and replace them while for your app you need to craft a patch with offsets and all of that. That app is better for end users that want tot replace random files while yours is better for developers distributing a mod pack.
Edit: I confused it with the layeredfs temporal replacement to browse and change romfs files. In any case, hating other apps because you made a "better one" will make the scene look you as a bad developer. (Note that at any moment I said your app is bad).
I literally said it's not bad, because it isn't, it's actually very good and well executed (see what I did there :)), I was just pointing out the lack of verification and how a major improvement would be to verify the files.
But mine's still da best
 
Couldn't you make the most significant bit in the address a flag, allowing it to do multiple consecutive patches?
EX: if the flag is set, a following variable specifies how many instructions will be consecutively patched at the address. Shortening the address by 1 bit should still allow for ~2GB files to be patched, but can save on the filesize of the actual patch.
 
you can't atm
Please don't spread misinformation.
On your Micro SD card, inside the Atmosphere/titles/ directory, make a new folder named the title ID of the game you wish to patch (I.E. Super Mario Odyssey, 0100000000010000).
Inside that folder, make another folder called "exefs" and put the patched NSO in, and make sure it's named "main".
Then run the hekate payload, go into CFW and run the game!
 
Very cool!
Your file format is much better for the end user so they don't accidentally apply patches to the wrong game.
I'll convert the patches I made and put them in some files here if people want to use them with your program
 
Oh, didn't see that. I looked at it just now, it's python 2.7, and we all know how great python 2.7 is on Windows...
Also, there's no verification system in that script, whereas mine verifies it by generating a SHA256 of the input and output files and making sure it matches the correct values, which are hardcoded into each patch file.
Furthermore it doesn't have a specific file format, where mine does. But it's not a bad script, certainly cleaner than my code.

Id rather use apps running in vb or c/c++ the python. The python engine has to be installed for it to work. I would rather have a complied program running natively. Thanks for the tool.
 
Please don't spread misinformation.
On your Micro SD card, inside the Atmosphere/titles/ directory, make a new folder named the title ID of the game you wish to patch (I.E. Super Mario Odyssey, 0100000000010000).
Inside that folder, make another folder called "exefs" and put the patched NSO in, and make sure it's named "main".
Then run the hekate payload, go into CFW and run the game!
A semiloader. I wish I could run a game completely from SD
 
Why is the sha256 of the patched file in the metadata? It's not like the same patch suddenly does something different if the source-file is confirmed to be the correct one.
Also having an human-readable patch-format wouldn't be that hard and makes combining patches much less painful.

Imo just including the old value (and a bit of the values around that, like gnu-patch does it) and then only applying if that matches would be much better since it would allow you to apply multiple patches to a game while still making sure that the patch isn't applied to an incompatible elf.

Also pretty much anything other than vb would have been better because vb is strictly windows-only so porting your tool essentially means a full rewrite.
 
Last edited by jakibaki,
Id rather use apps running in vb or c/c++ the python. The python engine has to be installed for it to work. I would rather have a complied program running natively. Thanks for the tool.
You can compile a python script into a binary too and run it without python installed.
 

Site & Scene News

Popular threads in this forum