sp1d3o

mod_code v.2

Oct 27th, 2021 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>    
  4. #include<stdbool.h>
  5. #include<errno.h>
  6.  
  7. extern int errno;
  8.  
  9. void find_str(const char *str, const char *lookfor)
  10. {
  11.   char *expl = strstr(str, lookfor);
  12.  
  13.   if(!expl) {
  14.     fprintf(stderr, "Cannot find string");
  15.     exit(1);
  16.   }
  17. }
  18.  
  19. int main(int argc, char *argv[])
  20. {
  21.   if(argc != 2) {
  22.     fprintf(stderr, "Invalid input\n");
  23.     exit(1);
  24.   }
  25.  
  26.   FILE* fp;
  27.   char *orig = "func";
  28.   char *new = "printf";
  29.   char *fill = "function";
  30.    
  31.   int i;
  32.  
  33.   fp = fopen(argv[1], "r+");
  34.   if(fp = NULL) {
  35.     fprintf(stderr, "Cannot open file\n");
  36.     fclose(fp);
  37.     exit(1);
  38.   }
  39.   else if(errno != 0) {
  40.     fprintf(stderr, "Unexpected error\n");
  41.     fclose(fp);
  42.     exit(1);
  43.   }
  44.   else {
  45.     return 0;
  46.   }
  47.  
  48.   find_str(fill, "func");
  49.  
  50.   if(find_str) {
  51.     strcpy(orig, new);
  52.   }  
  53.   else {
  54.     fprintf(stderr, "Function failure\n");
  55.     fclose(fp);
  56.     exit(1);
  57.   }
  58.  
  59.   fclose(fp);
  60.  
  61.   fp = popen("gcc argv[1] -o compilated", "r");
  62.   if(fp == NULL) {
  63.     fprintf(stderr, "Fuck you bitch!\n");
  64.     pclose(fp);
  65.     return 1;
  66.   }
  67.  
  68.   pclose(fp);
  69.  
  70.   return 0;
  71. }
  72.  
Add Comment
Please, Sign In to add comment