3 ms·
Can you/someone explain for this noob why you can't redefine a function, etc.? I'm not a programmer, so I'm imagining you hook in to the call that addresses th
by pbhjpbhj 8y ago
Can you/someone explain for this noob why you can't redefine a function, etc.?
I'm not a programmer, so I'm imagining you hook in to the call that addresses the function (like modify a jump instruction), overwrite any registers that need changing, nullify caches, so the program runs new code -- this I think is how some hacks work?
Ultimately couldn't you just write NOP to addresses used for a function?
Is it something structural about C/C++ that stops this, like the ownership of memory (I'm assuming a superuser can tell the computer to ignore that addresses written to are reserved for the program being modified).
How does the computer know that you pushed a different long jump in to a particular address and stop working, rather than keep going processing instructions.
Apologies if I've misunderstood, please be gentle.
- lisper 8y agoIt's a good question, and I'm a little disappointed no one has answered this yet. There is no reason you couldn't redefine a function in C. It's really more of a cultural constraint than a technical one. It's a little tricky, but it could be done. It just so happens that C programmers don't think in terms of interactive programming because C started out as a non-interactive language, and so it has remained mostly a non-interactive language. Lisp, by way of contrast, was interactive and dynamic on day 1, and it has stayed that way. In the early days that made C substantially faster than Lisp, but that performance gap has mostly closed. However, there are some things that Lisp does that are actually impossible in C. The two most notable ones are garbage collection and tail recursion. It's impossible to write a proper GC in portable C because there is no way to walk the stack, and there is no way to compile a tail-call unless you put the entire program inside the body of a single function.