Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <winuser.h>
- #include <fstream>
- #include <climits>
- using namespace std;
- int main()
- {
- std::ifstream is ("tiny.exe", std::ifstream::binary);
- if (is) {
- // get length of file:
- is.seekg (0, is.end);
- int length = is.tellg();
- is.seekg (0, is.beg);
- char * buffer = new char [length];
- std::cout << "Reading " << length << " characters... ";
- // read data as a block:
- is.read (buffer,length);
- if (is)
- std::cout << "all characters read successfully.";
- else
- std::cout << "error: only " << is.gcount() << " could be read";
- is.close();
- // ...buffer contains the entire file...
- cout << std::endl;
- for(int i = 0; i < length; i++)
- {
- int x = int(*(buffer+i));
- if(x < 0)
- x = x^0xffffff00;
- if(x < 16)
- cout << "0";
- cout << std::hex << x << " ";
- if(!((i+1)%16))
- cout << std::endl;
- }
- delete[] buffer;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement