Skip to content

Instantly share code, notes, and snippets.

@orivej
Created July 7, 2017 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orivej/0c7c51a6bbf06ce55d8da7a99e2d8cff to your computer and use it in GitHub Desktop.
Save orivej/0c7c51a6bbf06ce55d8da7a99e2d8cff to your computer and use it in GitHub Desktop.
#include <assert.h>
#include <dlfcn.h>
int main() {
void *handle = dlopen("./test.so", RTLD_NOW);
assert(handle);
void (*memzero)(void* src, size_t len) = dlsym(handle, "memzero");
assert(memzero);
char c;
memzero(&c, 1);
assert(!dlclose(handle));
}
CFLAGS = -g
LD = ld.lld
LDLIBS = /lib/x86_64-linux-gnu/libdl.so.2 /lib/x86_64-linux-gnu/libc.so.6
default: main test.so
clean:
rm main test.so main.o test.o
main: main.o
test.so: test.o
$(LD) -shared -o $@ $^ $(LDLIBS)
#include <string.h>
void memzero(void* src, size_t len) {
static void* (*const volatile memsetv)(void*, int, size_t) = &memset;
memsetv(src, 0, len);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment