#include <iostream>
#include <fstream>
#include <windows.h>
using namespace std;
static char * ReadAllBytes(const char * filename, int * read)
{
ifstream ifs(filename, ios::binary|ios::ate);
ifstream::pos_type pos = ifs.tellg();
int length = pos;
char *pChars = new char[length];
ifs.seekg(0, ios::beg);
ifs.read(pChars, length);
ifs.close();
*read = length;
return pChars;
}
int main(int argc, char** argv) {
const int SIGN_LEN = 4;
const char signaturePeHeader[SIGN_LEN] = {'\x50', '\x45', '\x00', '\x00'};
const char * filename = "c:\\rev\\RegisterMe.exe";
int read;
char * pChars = ReadAllBytes(filename, &read);
char * chTmp = pChars;
bool find = false;
int offset_AddressOfEntryPoint = 0;
for(int i=0; i<read && find != true; i++){
*chTmp++;
offset_AddressOfEntryPoint++;
for(int j=0; j<SIGN_LEN; j++){
if(*chTmp==signaturePeHeader[j]){
*chTmp++;
i++;
offset_AddressOfEntryPoint++;
}
else{
break;
}
if(j==SIGN_LEN-1){
find = true;
}
}
}
if (find) {
cout << "FIND: " << find << endl;
cout << hex << (offset_AddressOfEntryPoint + 36) << endl;
} else{
cout<<"sosat'";
}
delete[] pChars;
system("pause");
return 0;
}