Advertisement
AcidShout

StackOverflow question

May 9th, 2014
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. // functions
  7. bool file_exists(const char* f);
  8.  
  9. int main(int argc, char* argv[]){
  10.     if(argc != 2){
  11.         cerr << "Usage: fuzz \"file.jpg\"";
  12.         return 0;
  13.     }
  14.  
  15.     if(!file_exists(argv[1])){
  16.         cerr << "Specified file doesn't exist.";
  17.         return 1;
  18.     }
  19.  
  20.     // Read source file
  21.     FILE *fSource;
  22.     fSource = fopen(argv[1], "r+");
  23.     if(fSource == NULL){
  24.         cerr << "Can't open file " << argv[1];
  25.         return 2;
  26.     }
  27.  
  28.     // Loop source file
  29.     int byte;
  30.     int i = 0;
  31.     while((byte = fgetc(fSource)) != EOF){
  32.         fseek(fSource, i++, SEEK_SET);
  33.         fputc(byte ^ 0x13, fSource);
  34.         fseek(fSource, i, SEEK_SET);
  35.     }
  36.  
  37.     fclose(fSource);
  38.     cout << "Fuzzed.";
  39.  
  40.     return 0;
  41. }
  42.  
  43. bool file_exists(const char* f){
  44.     ifstream file(f);
  45.     return (bool) file;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement