Skip to content

This repository is an example of how LD_PRELOAD works to overload functions using the dynamic linker

License

Notifications You must be signed in to change notification settings

probsJustin/LD_PRELOAD-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

LD_PRELOAD-Example

This repository is an example of how LD_PRELOAD works to overload functions using the dynamic linker

About:

This example repository is based on the following tutorial: https://catonmat.net/simple-ld-preload-tutorial

As you can see, fopen got replaced with our own version that is always failing.

This is really handy if you need to debug or replace certain parts of programs or libraries that you didn't write.

Man page for ld.so/LD_PRELOAD

Steps:

$ ls
prog.c  test.txt
$ gcc prog.c -o prog
$ ls
prog  prog.c  test.txt
$ ./prog
Calling the fopen() function...
fopen() succeeded

Let's compile it as a shared library called myfopen.so:


gcc -Wall -fPIC -shared -o myfopen.so myfopen.c
$ LD_PRELOAD=./myfopen.so ./prog
Calling the fopen() function...
Always failing fopen
fopen() returned NULL

About

This repository is an example of how LD_PRELOAD works to overload functions using the dynamic linker

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages