problem regrading PIMAGE_DOS_HEADER
My program code is given bellow.....
Code:
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include<winnt.h>
#define BUF_SIZE 256
TCHAR szName[]=TEXT("process.c");
TCHAR szMsg[]=TEXT("Message from first process");
int main()
{
HANDLE hMapFile;
LPCTSTR pBuf;
PIMAGE_NT_HEADERS pimage_nt_headers;
hMapFile = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // max. object size
BUF_SIZE, // buffer size
szName); // name of mapping object
if (hMapFile == NULL || hMapFile == INVALID_HANDLE_VALUE)
{
printf("Could not create file mapping object (%d).\n",
GetLastError());
return 1;
}
pBuf = (LPTSTR) MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
BUF_SIZE);
printf("%d",pBuf);
if (pBuf == NULL)
{
printf("Could not map view of file (%d).\n",
GetLastError());
return 2;
}
CopyMemory((PVOID)pBuf, szMsg, strlen(szMsg));
PIMAGE_DOS_HEADER pimage_dos_header = PIMAGE_DOS_HEADER(pBuf);
pimage_nt_headers = (PIMAGE_NT_HEADERS)
(pBuf + pimage_dos_header->e_lfanew);
printf("\n%d\n",pimage_nt_headers);
DWORD it_voffset = pimage_nt_headers->OptionalHeader.
DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
printf("%d",it_voffset);
getch();
UnmapViewOfFile(pBuf);
CloseHandle(hMapFile);
return 0;
}
when i am displaying the value in it_voffset .....it is showing 0.
why it is so ?
can anyone explain this.......
pBuf is having valid value......