Prevent circular links "ld-wrap"

I use the GNU ld "-wrap" option to intercept calls in applications, but I came across a script where the code that implements the shell indirectly calls a wrapped function, creating a circular reference.

Example

The goal is to wrap the read calls that occur in a Foo program. This code can be recompiled / reloaded, but not changed.

Program foo

main() {
    ...
    read(fd, buf, size);
    ...
}

The shell here will intercept calls in libc read in Program Foo using "-wrap read".

Packing

extern int __real_read(...);
int __wrap_read(...) {
    bar();
    __real_read(...);
}

However, the library library called from the shell must use the libc read () function without going through the shell (thereby causing a circular dependency).

Library panel

void bar(void) {
    read(fd, buf, size)
}

__real_read() , , , .

- , , . , , .

??? :)

... -n

+3
2

, read() . linux, windows wrapping DLL , Bar DLL read() .

+1

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


All Articles