Created
July 7, 2017 04:05
-
-
Save orivej/0c7c51a6bbf06ce55d8da7a99e2d8cff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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