Skip to content

cquaid/lib_loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lib_loader

This is my attempt at an rtld (RunTime Link eDitor)

It mostly works... it requires a number of "fixups" to be defined before loading a library.

The way the fixup function code works you can substitute a function for another. If you're library requires the malloc symbol and you want to hook it with something else:

 #include "librtld.h"
 /* ... */
 void* my_malloc(size_t l){ /* ... */ }
 /* ... */
 Anchor malloc_fixup = { "malloc", my_malloc };
 /* ... */
 add_fixup_anchor(&malloc_fixup);

To use a list of anchors, add_fixup_anchor_list expects { NULL, NULL } to be the last Anchor in the list:

 #include <stdlib.h>
 #include "librtld.h"
 /* ... */
 Anchor anchor_list[] = {
	{ "malloc", malloc },
	{ "free", free },
    { NULL, NULL }
 };
 /* ... */
 add_fixup_anchor_list(anchor_list);

The test/zlib/lizb_loader.c has a good example of how to do the fixup.

There isn't an install rule yet, so to use the tests you'll need to do

LD_LIBRARY_PATH=$(pwd)/lib:$LD_LIBRARY_PATH

before running the tests (assuming you're in the root source directory)

To test test_loader:

 run make
 ./test/lib_test/test_loader ./test/lib_test/lib.so

To test libz_loader:

 modify test/zlib/libz_loader.c to include the path to your libz.so
 run make
 to deflate: test zlib/libz_loader < to_compress > ouput_file
 to inflate: test/zlib/libz_loader -d < compressed_file > decompressed_file

Things that need to be done:

 * Write documentation
 * Refactor the code
 * Test everything

If there's an issue where you can't initialize an Anchor for stdout, stdin, or stderr:

 Anchor a = { "stdin", NULL };
 /* ... */
 a.symbol = (void *)stdin;

The reason for this is the standard FILE*s arn't required to be static but they have to be, to be used in an initializer.

About

This is my attempt at an rtld (RunTime Link eDitor)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages