Generate a DSO at runtime and load symbols from it using dlsym(), without creating an actual ELF or touching the filesystem
Go to file
Triss 8dc14dcb5f now in library form 2020-12-28 00:12:29 +01:00
.gitignore now in library form 2020-12-28 00:12:29 +01:00
LICENSE now in library form 2020-12-28 00:12:29 +01:00
Makefile now in library form 2020-12-28 00:12:29 +01:00
README.md now in library form 2020-12-28 00:12:29 +01:00
dynso.c now in library form 2020-12-28 00:12:29 +01:00
dynso.h now in library form 2020-12-28 00:12:29 +01:00
dynso_internal.h now in library form 2020-12-28 00:12:29 +01:00
example.c now in library form 2020-12-28 00:12:29 +01:00

README.md

dynso

Define dynamic shared objects and resolvable symbols at runtime, without creating an ELF file anywhere or touching the filesystem.

It works by manipulating ld.so's internal data structures. (That is, if it works at all). It also only works on glibc, it will explode in your face if you try to run it with eg. musl.

Usage

If you ever use this in production, you, together with everyone else using it, will die.

Other than that, here's an example:

// create a library
struct dynso_lib* l;
dynso_create(&l, 0,
	(char*)"this is just a display name", "libtest", /* latter is the soname */
	NULL, LM_ID_BASE /* from dlfcn.h, you need to define _GNU_SOURCE first! */);

// define some symbols...
dynso_add_sym(l, "testsym", (void*)0x694201337);
dynso_add_sym_ex(l, "testfunction", a_function,
	STT_FUNC /* from elf.h */, 32 /* symbol size */);

// this loads all symbols into the global context, which means they can now
// be looked up by dlsym(), and be resolved by other dynamic libraries that
// depend on it. adding more symbols won't be possible anymore, though.
dynso_bind(l);

void* x = dlsym(RTLD_DEFAULT, "testsym");
printf("  dlsym(\"testsym\") = %p\n", x);
x = dlsym(RTLD_DEFAULT, "testfunction");
printf("  dlsym(\"testfunction\") = %p\n", x);

void (*somefunc)(void) = x;
printf("calling the resolved function:\n");
somefunc();

// free the used memory
dynso_remove(l);

Dependencies

glibc, seems to work with 2.30.

Compilation

make

Installation

no

License

be gay, do crimes, death to america