void CReadDOS_headDlg::OnBtnRead()
{
/*
CFile f;
CFileException e;
// 打开文件
char buffPath[256];
this->GetDlgItemText(IDC_FILE_PATH,buffPath,sizeof(buffPath));
int openRet;
if (!(openRet=f.Open(buffPath, CFile::modeRead, &e)))
{
TCHAR szError[1024];
e.GetErrorMessage(szError, 1024);
AfxMessageBox(szError);
return;
}
*/
// 打开文件
char buffPath[256];
this->GetDlgItemText(IDC_FILE_PATH,buffPath,sizeof(buffPath));
HANDLE hFile = ::CreateFile(buffPath,
GENERIC_READ ,//| GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
// Create a file-mapping object for the file.
HANDLE hFileMapping = ::CreateFileMapping(hFile,
NULL,
PAGE_WRITECOPY,
0, 0,
NULL);
LPVOID lpBase=::MapViewOfFile(hFileMapping, FILE_MAP_COPY, 0, 0, 0);
if(lpBase==NULL)
{
//printf("MapViewOfFile Failed\n");
MessageBox("MapViewOfFile Failed");
return ;
}
IMAGE_DOS_HEADER *pheader;
/*
char FileBuff[5*1024];
memset((void*)FileBuff,0,sizeof(FileBuff));
f.Read((void*)FileBuff, sizeof(FileBuff));
pheader=(IMAGE_DOS_HEADER *)FileBuff;
*/
pheader=(IMAGE_DOS_HEADER *)lpBase;
char buffOutput[512];
sprintf(buffOutput, \
" \
WORD e_magic:%d\r\n \
WORD e_cblp:%d\r\n \
WORD e_cp:%d\r\n \
WORD e_crlc:%d\r\n \
WORD e_cparhdr:%d\r\n \
WORD e_minalloc:%d\r\n \
WORD e_maxalloc:%d\r\n \
WORD e_ss:%d\r\n \
WORD e_sp:%d\r\n \
WORD e_csum:%d\r\n \
WORD e_ip:%d\r\n \
WORD e_cs:%d\r\n \
WORD e_lfarlc:%d\r\n \
WORD e_ovno:%d\r\n \
WORD e_oemid:%d\r\n \
WORD e_oeminfo:%d\r\n \
LONG e_lfanew:%d",
pheader->e_magic,
pheader->e_cblp,
pheader->e_cp,
pheader->e_crlc,
pheader->e_cparhdr,
pheader->e_minalloc,
pheader->e_maxalloc,
pheader->e_ss,
pheader->e_sp,
pheader->e_csum,
pheader->e_ip,
pheader->e_cs,
pheader->e_lfarlc,
pheader->e_ovno,
pheader->e_oemid,
pheader->e_oeminfo,
pheader->e_lfanew);
this->SetDlgItemText(IDC_DOS_HEADER,buffOutput);
{
//IDC_IMAGE_TYPE
char buff[256];
unsigned long ret=ImageFileType(pheader);
switch(ret)
{
case IMAGE_DOS_SIGNATURE://MZ
//cout<<"IMAGE_DOS_SIGNATURE"<<endl;
sprintf(buff,"IMAGE_DOS_SIGNATURE");
break;
case IMAGE_OS2_SIGNATURE://NE
//cout<<"IMAGE_OS2_SIGNATURE"<<endl;
sprintf(buff,"IMAGE_OS2_SIGNATURE");
break;
case IMAGE_OS2_SIGNATURE_LE:
//cout<<"IMAGE_OS2_SIGNATURE_LE"<<endl;
sprintf(buff,"IMAGE_OS2_SIGNATURE_LE");
break;
case IMAGE_NT_SIGNATURE:
//cout<<"IMAGE_NT_SIGNATURE"<<endl;
sprintf(buff,"IMAGE_NT_SIGNATURE");
break;
default:
sprintf(buff,"default:%x",ret);
break;
}
this->SetDlgItemText(IDC_IMAGE_TYPE,buff);
}
//f.Close();
::UnmapViewOfFile(lpBase);
::CloseHandle(hFileMapping);
::CloseHandle(hFile);
}