Advertisement
Frumkin

Untitled

Jun 30th, 2022
827
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dlfcn.h>
  4.  
  5. static const char* LIB_NAME = "?.so";
  6.  
  7. int main(int argc, char** argv) {
  8.     void* handle;
  9.     double (*cosine)(double);
  10.     char* error;
  11.  
  12.     handle = dlopen(LIB_NAME, RTLD_LAZY);
  13.     if (!handle) {
  14.         fprintf(stderr, "%s\n", dlerror());
  15.         return EXIT_FAILURE;
  16.     }
  17.  
  18.     dlerror();
  19.  
  20.     cosine = (double(*)(double)) dlsym(handle, "cos");
  21.  
  22.     *(void**)(&cosine) = dlsym(handle, "cos");
  23.  
  24.     error = dlerror();
  25.     if (error) {
  26.         fprintf(stderr, "%s\n", error);
  27.         return EXIT_FAILURE;
  28.     }
  29.  
  30.     printf("%f\n", (*cosine)(2.0));
  31.     dlclose(handle);
  32.  
  33.     return EXIT_SUCCESS;
  34. }
Advertisement
RAW Paste Data Copied
Advertisement