잠토의 잠망경

MMF의 다른 용도. GetMoudleHandle을 이용 본문

공부/API

MMF의 다른 용도. GetMoudleHandle을 이용

잠수함토끼 2008. 8. 29. 15:41
#undef UNICODE

#include 
#include 

int main(void)
{
	char szWindowsDirectoryPath[1000]={0,};
	char szKernelDll[1000]={0,};
	
	//윈도우의 패스를 얻기위한 함수이다.
	GetWindowsDirectory(szWindowsDirectoryPath,1000);
	sprintf(szKernelDll,"%s\\system32\\kernel32.dll",szWindowsDirectoryPath);
	
	//파일을 읽기위한 용도로 열었다.
	HANDLE hFile=CreateFile(szKernelDll, GENERIC_READ,FILE_SHARE_READ, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
	if(hFile==NULL)
		printf("CreateFile error\n");
	
	//파일 매핑을 위하여 생성
	HANDLE hFileMap=CreateFileMapping(hFile, NULL, PAGE_READONLY, 0,0,NULL);
	if(hFileMap == NULL)
		printf("CreateFileMapping error\n");
	
	//파일의 사이즈를 읽어들인다.
	DWORD dwSize=GetFileSize(hFile,0);

	//파일의 전체 뷰를 만듬
	char *pMapFile=(char*)MapViewOfFile(hFileMap, FILE_MAP_READ, 0,0,dwSize);
	if(pMapFile == NULL)
		printf("MapViewofFile- error\n");

	//모둘에서 엔트리 포인터를 반환해준다.
	char *pDll=(char*)GetModuleHandle(szKernelDll);
	if(pDll == NULL)
		printf("GetMoudleHandle error\n");
	
	//두 버퍼가 같은가를 확인한다.
	if(!memcmp(pDll,pMapFile, dwSize/2))
		printf("Same");
	else
		printf("Different");

	
	UnmapViewOfFile(pMapFile);
	CloseHandle(hFileMap);
	CloseHandle(hFile);

	return 0;
}
Comments