Pages

Monday, March 20, 2006

Relinking binaries

AIX never ceases to amaze. During the course of brushing up for a presentation on AIX, this turned up in the ld man page.

The ld command can relink a program without requiring that you list all input object files again. For example, if one object file from a large program has changed, you can relink the program by listing the new object file and the old program on the command line, along with any shared libraries required by the program.

AIX is THE only Unix that can do that. Doesn't that means limitless possibilities ? It turns the whole idea of binary editing upside down. As an example, let us say we have a "test" program consisting of 2 different functions main and testfn, contained in main.c and testfn.c.

I want to override testfn. I can do that so easily, by writing testfn in a new file, say newfn.c and relinking the binary.

$ xlc -o test newfn.c test

Can we use this to extract code from binaries ? Don't know, lets figure out.