Last active
July 25, 2020 08:25
-
-
Save harieamjari/8c816f39fe04d38d83022301872272ea to your computer and use it in GitHub Desktop.
example plugin
This file contains hidden or 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 <stdio.h> | |
#include "main.h" | |
void some_func(){ | |
burger += 10; | |
} |
This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> // for exit() | |
#include <dlfcn.h> | |
#include "main.h" | |
int burger = 3; | |
int main(){ | |
void (*ptr_func)(); | |
void *handle; | |
handle = dlopen("./libfunc.so", RTLD_NOW); | |
if (!handle) { | |
fprintf(stderr, "%s\n", dlerror()); | |
exit(1); | |
} | |
*(void**)(&ptr_func) = dlsym(handle, "some_func"); | |
if (!ptr_func){ | |
fprintf(stderr, "%s\n", dlerror()); | |
dlclose(handle); | |
exit(1); | |
} | |
printf("before ptr_func %d\n", burger); | |
ptr_func(); | |
printf("after %d\n", burger); | |
return 0; | |
} |
This file contains hidden or 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
#ifndef MAIN_H__ | |
#define MAIN_H__ | |
extern int burger; | |
#endif |
This file contains hidden or 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
all : main libfunc.so | |
.PHONY : all | |
main : main.c | |
$(CC) -rdynamic $^ -o $@ | |
libfunc.so : func.c | |
$(CC) -shared -fPIC $^ -o $@ | |
.PHONY : clean | |
clean : | |
rm main libfunc.so |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment