Advertisement
wowonline

Untitled

Nov 21st, 2021
845
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <unistd.h>
  2. #include <fcntl.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <limits.h>
  6.  
  7. enum
  8. {
  9.     NAME_SIZE = 24,
  10.     INTEGER_BASE = 10
  11. };
  12.  
  13. int
  14. main(int argc, char *argv[])
  15. {
  16.     int fd_r = open("/dev/urandom", O_RDONLY);
  17.     unsigned long long num_r;
  18.     read(fd_r, &num_r, sizeof(num_r));
  19.     close(fd_r);
  20.  
  21.     char filename[NAME_SIZE];
  22.     snprintf(filename, NAME_SIZE, "%llu%s", num_r, ".py");
  23.  
  24.     char fullpath[PATH_MAX];
  25.     char *env = getenv("XDG_RUNTIME_DIR");
  26.     if (env != NULL) {
  27.         snprintf(fullpath, PATH_MAX, "%s/%s", env, filename);
  28.     } else if ((env = getenv("TMPDIR")) != NULL) {
  29.         snprintf(fullpath, PATH_MAX, "%s/%s", env, filename);
  30.     } else {
  31.         env = "/tmp";
  32.         snprintf(fullpath, PATH_MAX, "%s/%s", env, filename);
  33.     }
  34.     int fd = open(fullpath, O_CREAT | O_WRONLY | O_CLOEXEC, 0755);
  35.  
  36.     char string_beg[] = "#! /usr/bin/python3 \nimport os, math\nl = [";
  37.     dprintf(fd, "%s", string_beg);
  38.    
  39.     for (int i = 1; i < argc; ++i) {
  40.         dprintf(fd, "%s,", argv[i]);
  41.     }
  42.  
  43.     char string_end[] = "]\nprint(math.prod(l)) \nos.remove(__file__)\n";
  44.     dprintf(fd, "%s", string_end);
  45.     close(fd);
  46.     execlp(fullpath, filename, NULL);
  47. }
Advertisement
RAW Paste Data Copied
Advertisement