Guest User

Untitled

a guest
Jul 26th, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. #define skip_notspace(a) \
  6. while (!isspace(*(a)))   \
  7. {                        \
  8.   a++;                   \
  9. }                        \
  10.  
  11. #define skip_space(a) \
  12. while (isspace(*(a))) \
  13. {                     \
  14.   a++;                \
  15. }                     \
  16.  
  17. char* find_ld_lib_maps(char *);
  18.  
  19. // this thing give pointer to beginning of line where "/ld-" occures
  20. char* find_ld_lib_maps(char *a)
  21. {
  22.   start:
  23.   if (*a == '\0')
  24.   {
  25.     return NULL;
  26.   }
  27.   skip_notspace(a);
  28.   skip_space(a);
  29.   if (a[2] == 'x')
  30.   {
  31.     skip_notspace(a);
  32.     skip_space(a);
  33.     skip_notspace(a);
  34.     skip_space(a);
  35.     skip_notspace(a);
  36.     skip_space(a);
  37.     skip_notspace(a);
  38.     skip_space(a);
  39.     while ( *a != '\n')
  40.     {
  41.       if(
  42.            ( a[0] == '/') &&
  43.            ( a[1] == 'l') &&
  44.            ( a[2] == 'd') &&
  45.            ( a[3] == '-')
  46.         )
  47.         {
  48.           while (a[-1] != '\n') // go to start of line
  49.           { a--; }
  50.           return a;
  51.         }
  52.       a++;
  53.     }
  54.     a++;
  55.     goto start;
  56.   }
  57.   while ( *a != '\n')
  58.   { a++; }
  59.   a++;
  60.   goto start;
  61. }
  62.  
  63. int main(void)
  64. {
  65.   char buf[1000000] = {}, *pos;
  66.   buf[0] = '\n';
  67.   FILE *file1;
  68.   size_t len;
  69.   file1 = fopen("/proc/self/maps", "r");
  70.   len = fread(buf+1, 1, sizeof(buf)-1, file1);
  71.   pos = find_ld_lib_maps(buf+1);
  72.  
  73.   while ( *pos != '\n')
  74.   {
  75.     putchar(*pos);
  76.     pos++;
  77.   }
  78.   putchar('\n');
  79.  
  80.   return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment