r/C_Programming • u/iLoveNintend0 • 20d ago
Video Unity-style variable editor for C programs with zero runtime cost
Enable HLS to view with audio, or disable this notification
SRL lets you define global variables to be exported to the editor with a simple macro like `SRL_INT(name, value)`. The macro adds another global symbol marking your variable, which the editor can later search for in the binary's ELF data section.
The editor can modify the marked variables (by directly editing the data section), export the new patched binary to a file, and even change the variables at runtime via `process_vm_writev` (or `ptrace` when you require atomicity).
All you have to do is include a tiny 20-line header in your program. It doesn't add a single line of code, even for the patched binary, and works perfectly fine with the editor (apart from adding an unused global)
18
u/questron64 20d ago
I do something similar, though with structs and their fields. Generating reflection information and the code to set/get fields by name, and another layer on top of that to generate serializers and deserializers. Just because C is primitive doesn't mean you can't build systems on top of that.
4
u/floatfloatjam 20d ago
You're a maniac and I like it
1
u/alkavan 20d ago
very cool! will it be open source or public?
2
u/Ashken 20d ago
Iām completely new to C so no offense intended but why is this useful? Iām also not familiar with macros so I may just be missing something.
1
u/septum-funk 20d ago
saving for later
1
u/Flimsy_Iron8517 16d ago
Looks good.
12
u/MidnightClubSCS 20d ago
that's a cool ass hack, i love it