Guest User

Nuclei

a guest
May 1st, 2009
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. //Program written to write 0xFF to all bytes within a given file.
  2. #include <iostream>
  3. #include <string>
  4. #include <fstream>
  5. #include <limits>
  6.  
  7. using namespace std;
  8.  
  9. string filepath;
  10.  
  11. int main()
  12. {
  13.     cout << "Enter the directory of the file you wish to write to:\n"; //Ask for the directory
  14.     cin >> filepath; //Store the directory in filpath
  15.     ofstream file; //Set file as a file
  16.     file.open (filepath,ios::in|ios::out|ios::binary|ios::trunc); //Open filepath in binary mode, with in/out, and truncating the existing text.
  17.     long int * memory, *p, x; //Create memorycheck, memory, and p pointers
  18.     memory = new long int[0]; //Request 1 byte of dynamic memory
  19.     p = memory;
  20.     x = &p;
  21.     for (; x > 0; ); //Write 0xFF to the address P, move on to the previous byte, and repeat until beginning of file reached.
  22.     {
  23.         *p = 0xFF;
  24.         x--;
  25.         &p = x;
  26.     }
  27.     file << memory[p]; //Write all the newly overwritten memory to the file.. I think.
  28.     cout << "0 written to all bytes. Press [Enter] to exit..\n"; //Displaying the finished message.
  29.     std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ); //Thanks, Duoas. xD..
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment