KiK0S

main for ku5-5

Apr 12th, 2021
596
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stddef.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <sys/mman.h>
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8. #include <errno.h>
  9.  
  10.  
  11. typedef uint32_t (*sumfunc_t)(void);
  12. sumfunc_t generate(void *buf, size_t bufsize, uint32_t *array, size_t size) ;
  13.  
  14. uint32_t array[] = {1, 2, 3, 4, 5};
  15. size_t size = 5;
  16.  
  17. int main() {
  18.     int fd = open("tmp.txt", O_RDWR | O_CREAT | O_TRUNC);
  19.     int ufd = fd;
  20.     for (int i = 0; i < 4096; i++) {
  21.         write(fd, array, 1);
  22.     }
  23.     fd = ufd;
  24.     unsigned char * buf = mmap (NULL, 4096, PROT_WRITE|PROT_EXEC, MAP_SHARED|MAP_ANONYMOUS, fd, 0);
  25.     if (buf == MAP_FAILED) {
  26.         printf ("%i\n", errno);
  27.         printf ("error\n");
  28.         return 0;
  29.     }
  30.     uint32_t (*f1)(void) = generate(buf, 4096, array, size);
  31.     printf("%u\n", f1());
  32.     munmap(buf, 4096);
  33.     close(fd);
  34.  }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×