Guest User

Untitled

a guest
Jan 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <unistd.h>
  3. #include <stdint.h>
  4. using namespace std;
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. if (argc < 2)
  9. {
  10. const int s_argc = 137; // ¯\_(ツ)_/¯
  11. char **s_argv = (char **)malloc(sizeof(char *) * (s_argc + 1));
  12. s_argv[s_argc - 1] = NULL; // nullptr;
  13. const string arg_text = "the quick brown fox n stuff" +
  14. string(sysconf(_SC_PAGESIZE), 'A') +
  15. string(1, '\0');
  16. for (int i = 0; i < (s_argc - 1); ++i)
  17. {
  18. char *tmp = (char *)malloc(arg_text.size());
  19. arg_text.copy(tmp, arg_text.size());
  20. s_argv[i] = tmp;
  21. }
  22. // for(int i=0;i<s_argc;++i){cout << s_argv[i] << endl;}
  23. cout << __FILE__ << ":" << __LINE__ << endl;
  24. execv(argv[0], s_argv);
  25. cout << __FILE__ << ":" << __LINE__ << endl;
  26. }
  27. else
  28. {
  29. uintptr_t lowest_p = UINTPTR_MAX;
  30. int lowest_argc = -1;
  31. cout << "argc: " << argc << " argument positions from lowest to highest: ";
  32. for (int i = 1; i < argc; ++i)
  33. {
  34. for (int i = 1; i < argc; ++i)
  35. {
  36. if (argv[i] == NULL)
  37. {
  38. continue;
  39. }
  40. if (uintptr_t(argv[i]) < lowest_p)
  41. {
  42. lowest_p = uintptr_t(argv[i]);
  43. lowest_argc = i;
  44. }
  45. }
  46. cout << lowest_argc << " - " << std::flush;
  47. argv[lowest_argc] = NULL;
  48. lowest_p = UINTPTR_MAX;
  49. lowest_argc = -1;
  50. }
  51. }
  52. }
Add Comment
Please, Sign In to add comment