The idea of LD_PRELOAD
is to load a shared library before the original shared library, for example I can compile mylib.so
to load it before libc.so
, so when process wants to use printf
it searches in the so
that loaded one by one and finds it in mylib.so
(because this so
was loaded first) instead of libc.so
, so it uses the printf
in mylib.so
instead of printf
in libc.so
.
I understand why this works on functions that are implemented in a so
like printf
in libc.so
.
But when I want to hook on write
function or another syscall
function, why does it work? The process does not search the function in the so
, it goes directly to the kernel.
Does
LD_PRELOAD
work on a binary that is compiled statically? Why? In this replay https://stackoverflow.com/a/13866611 mentioned thatLD PRELOAD
Doesn't work on statically binaryWhy does
LD_PRELOAD
work on a binary compiled dynamically to make hooks on syscalls?
The architecture is ARM.