The latest version of MojoELF can be found at:
https://github.com/icculus/mojoelf
MojoELF is an ELF binary loader that runs in your application,
instead of as part of the C runtime. Its most useful feature is that,
unlike the standard dlopen(), it can load an ELF file from
a place other than the filesystem. Notably, it can load one from a
buffer in memory.
It can also be useful for overriding specific parts of the dependency management process, such as loading a replacement library or quietly replacing a function, etc.
To use MojoELF:
#define MOJOELF_SUPPORT_DLERROR 0 // remove MOJOELF_dlerror() + lots of strings.
#define MOJOELF_SUPPORT_DLOPEN_FILE 0 // remove MOJOELF_dlopen_file()
#define MOJOELF_REDUCE_LIBC_DEPENDENCIES 0 // use less libc calls. Scary!
#define NDEBUG 1 // Turns off assert, which removes libc dependencies.#include mojoelf.h - Put your
ELF library in memory, and call MOJOELF_dlopen_mem() with the address of
the memory buffer, the size of the buffer, and (optionally), callbacks
that handle symbol resolution (they can be NULL). Refer to the
documentation on MOJOELF_LoaderCallback, MOJOELF_ResolverCallback, and MOJOELF_UnloaderCallback for
details.typedef int (*my_fn_type)(int argument);
my_fn_type my_function = (my_fn_type) MOJOELF_dlsym(lib, "AwesomeFunc");
if (my_function == NULL) {
printf("couldn't find AwesomeFunc!\n");
} else {
printf("AwesomeFunc() returns %d\n", my_function(123));
}MOJOELF_dlclose() to free any resources. All pointers
returned by MOJOELF_dlsym() for this library are invalid
after this call. - Other fun stuff: MOJOELF_getentry() gets
you the entry point for the ELF file (which isn't useful on shared
libraries, but is how you eventually get to main() in an
executable).Thread safety:
MojoELF provides no locking mechanisms, and has a piece of global state that almost any function can set (the MOJOELF_dlerror() state). As such, the app is responsible for providing a serialization method if they plan to use MojoELF from multiple threads at once.
Other stuff:
Please see the file LICENSE.txt in the source's root directory for licensing and redistribution rights.