Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //http://waleedassar.blogspot.com
- //http://www.twitter.com/waleedassar
- HANDLE h=CreateFile(buffer,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);
- if(h==INVALID_HANDLE_VALUE) return false;
- unsigned long FileSize=GetFileSize(h,0);
- if(FileSize<0x40)
- {
- CloseHandle(h);
- return false;
- }
- unsigned long DOSFileSize=0;
- IMAGE_DOS_HEADER DOS={0};
- unsigned long read;
- ReadFile(h,&DOS,0x40,&read,0);
- IMAGE_DOS_HEADER* pDos=&DOS;
- if(pDos->e_cblp==0) DOSFileSize=(pDos->e_cp)*512;
- else DOSFileSize= ((pDos->e_cp-1)*512)+pDos->e_cblp;
- if(FileSize<DOSFileSize)
- {
- CloseHandle(h);
- return false;
- }
- if(pDos->e_lfarlc>DOSFileSize)
- {
- CloseHandle(h);
- return false;
- }
- CloseHandle(h);
- return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement