Advertisement
LightningStalker

corrupt.cpp - File Corrupter (ROMs or whatever)

Jul 26th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. /*
  2.   Batch File Corruptor v1.2
  3.   Made by Liquos, with help from /sci/
  4.   Cleaning by The Lightning Stalker
  5. */
  6.  
  7. #include <fstream>
  8. #include <cstdlib>
  9. #include <iostream>
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12.  
  13. using namespace std;
  14.  
  15. int fileSize(const char * szFileName){
  16.   struct stat fileStat;
  17.   int err = stat(szFileName, &fileStat);
  18.   if (0 != err) return 0;
  19.   return fileStat.st_size;
  20. }
  21.  
  22. int corruptFile(string fileName, int pad, int freq, int passes){
  23.     unsigned int corBytes = 0;
  24.     fstream cfile;
  25.     cfile.open(fileName.c_str());
  26.        
  27.     char randByte;
  28.     unsigned long long pPos;
  29. /*  struct stat buff; */
  30.     unsigned long long size = fileSize(fileName.c_str());
  31.  
  32.     cout << "Corrupting " << fileName << endl;
  33.     for(int curPass = 0; curPass < passes; curPass++){
  34.         pPos = pad+(rand()%freq);
  35.    
  36.         while(pPos < size - pad){
  37.             cfile.seekp(pPos);
  38.        
  39.             randByte = (rand()%255);
  40.             cfile.put(randByte);
  41.                    
  42.             pPos += (rand()%freq)+1;
  43.             corBytes++;
  44.         }
  45.     }
  46.     cfile.close();
  47.     cout << corBytes << " bytes corrupted." << endl << endl;
  48.     return 0;
  49. }
  50.  
  51. int main(int argc, char* argv[]){
  52.     srand(time(NULL));
  53.     int pad, freq, passes;
  54.     cout << "Padding(x32): ";
  55.     cin >> pad;
  56.     cout << "Frequency (lower = more corruption): ";
  57.     cin >> freq;
  58.     cout << "Passes: ";
  59.     cin >> passes;
  60.    
  61.     freq *= 128;
  62.     pad *= 32;
  63.    
  64.     for(int curFile = 1; curFile < argc; curFile++){
  65.         corruptFile(argv[curFile], pad, freq, passes);
  66.     }
  67.    
  68.     system("pause");
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement