Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <limits.h>
- enum
- {
- NAME_SIZE = 24,
- INTEGER_BASE = 10
- };
- int
- main(int argc, char *argv[])
- {
- int fd_r = open("/dev/urandom", O_RDONLY);
- unsigned long long num_r;
- read(fd_r, &num_r, sizeof(num_r));
- close(fd_r);
- char filename[NAME_SIZE];
- snprintf(filename, NAME_SIZE, "%llu%s", num_r, ".py");
- char fullpath[PATH_MAX];
- char *env = getenv("XDG_RUNTIME_DIR");
- if (env != NULL) {
- snprintf(fullpath, PATH_MAX, "%s/%s", env, filename);
- } else if ((env = getenv("TMPDIR")) != NULL) {
- snprintf(fullpath, PATH_MAX, "%s/%s", env, filename);
- } else {
- env = "/tmp";
- snprintf(fullpath, PATH_MAX, "%s/%s", env, filename);
- }
- int fd = open(fullpath, O_CREAT | O_WRONLY | O_CLOEXEC, 0755);
- char string_beg[] = "#! /usr/bin/python3 \nimport os, math\nl = [";
- dprintf(fd, "%s", string_beg);
- for (int i = 1; i < argc; ++i) {
- dprintf(fd, "%s,", argv[i]);
- }
- char string_end[] = "]\nprint(math.prod(l)) \nos.remove(__file__)\n";
- dprintf(fd, "%s", string_end);
- close(fd);
- execlp(fullpath, filename, NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement