Guest User

unitybugworkaround.c

a guest
Oct 18th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #define _GNU_SOURCE
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <dlfcn.h>
  5.  
  6. static FILE *opened_file = NULL;
  7.  
  8. FILE *fopen(const char *pathname, const char *mode) {
  9. static FILE *(*real_fopen)(const char *, const char *) = NULL;
  10. if (!real_fopen)
  11. {
  12. printf("Intecepting fopen() calls! \n");
  13. real_fopen = dlsym(RTLD_NEXT, "fopen");
  14. }
  15. opened_file = NULL;
  16.  
  17. FILE* ret_val = real_fopen(pathname, mode);
  18.  
  19. if (strncmp(pathname, "/proc/", 6) == 0) {
  20. // remember fopen() calls to /proc...
  21. opened_file = ret_val;
  22. }
  23.  
  24. return ret_val;
  25. }
  26.  
  27. FILE *fopen64(const char *pathname, const char *mode) {
  28. static FILE *(*real_fopen64)(const char *, const char *) = NULL;
  29. if (!real_fopen64)
  30. {
  31. printf("Intecepting fopen64() calls! \n");
  32. real_fopen64 = dlsym(RTLD_NEXT, "fopen64");
  33. }
  34. opened_file = NULL;
  35.  
  36. FILE* ret_val = real_fopen64(pathname, mode);
  37.  
  38. if (strncmp(pathname, "/proc/", 6) == 0)
  39. {
  40. // remember fopen() calls to /proc...
  41. opened_file = ret_val;
  42. }
  43.  
  44. return ret_val;
  45. }
  46.  
  47. size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) {
  48. static size_t (*real_fread)(void *, size_t, size_t, FILE *) = NULL;
  49. if (!real_fread)
  50. {
  51. printf("Intecepting fread() calls! \n");
  52. real_fread = dlsym(RTLD_NEXT, "fread");
  53. }
  54.  
  55. size_t ret_val = real_fread(ptr, size, nmemb, stream);
  56.  
  57. if (stream == opened_file && strncmp(ptr, "/proc/self/exe", 14) == 0)
  58. {
  59. printf("Faking fread() return value! \n");
  60. memcpy(ptr, "/wutevawutevawuteva", 14);
  61. }
  62.  
  63. return ret_val;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment