How to fix Unix startup code

Say you have a function foo () compiled into a program running on Unix.

While the program is running, can you replace the foo function by dynamically loading the object file containing the modified version of foo ()?

On the embedded system that I worked on in the past, we could unprotect the text segment and then essentially “fix” the address foo () to point to the recently changed foo ().

It was used for debugging on occasion and with many special restrictions on client sites.

Is this possible on Unix?

+3
source share
3 answers

, . , Erlang Ruby. C .

+1

. , , gdb.

+1

In short, yes, of course, it is possible. The question really has to be "how complicated?"

You can load and unload the shared libraries (.so and .DLL) that you want on Linux and Windows. Specific UNIX variants, I'm not sure. This will be the easiest way to achieve your goal.

If you don't mind keeping your hands dirty, you can always fix the code segment to move to another place on the heap. I do not recommend it.

0
source

Source: https://habr.com/ru/post/1730949/


All Articles