Advertisement
Guest User

Untitled

a guest
Mar 26th, 2013
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <winuser.h>
  4. #include <fstream>
  5. #include <climits>
  6. using namespace std;
  7.  
  8.  
  9.  
  10. int main()
  11. {
  12.   std::ifstream is ("tiny.exe", std::ifstream::binary);
  13.   if (is) {
  14.     // get length of file:
  15.     is.seekg (0, is.end);
  16.     int length = is.tellg();
  17.     is.seekg (0, is.beg);
  18.  
  19.     char * buffer = new char [length];
  20.  
  21.     std::cout << "Reading " << length << " characters... ";
  22.     // read data as a block:
  23.     is.read (buffer,length);
  24.  
  25.     if (is)
  26.       std::cout << "all characters read successfully.";
  27.     else
  28.       std::cout << "error: only " << is.gcount() << " could be read";
  29.     is.close();
  30.  
  31.     // ...buffer contains the entire file...
  32.     cout << std::endl;
  33.     for(int i = 0; i < length; i++)
  34.     {
  35.         int x = int(*(buffer+i));
  36.         if(x < 0)
  37.             x = x^0xffffff00;
  38.         if(x < 16)
  39.             cout << "0";
  40.         cout << std::hex << x << " ";
  41.         if(!((i+1)%16))
  42.            cout << std::endl;
  43.     }
  44.  
  45.     delete[] buffer;
  46.   }
  47.   return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement