Click here to Skip to main content
16,005,169 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How can i enumerate all users in PC? Pin
Anton Mikhalyov11-Mar-06 21:13
Anton Mikhalyov11-Mar-06 21:13 
AnswerRe: How can i enumerate all users in PC? Pin
Hamid_RT11-Mar-06 21:14
Hamid_RT11-Mar-06 21:14 
AnswerRe: How can i enumerate all users in PC? Pin
Hamid_RT11-Mar-06 21:24
Hamid_RT11-Mar-06 21:24 
AnswerRe: How can i enumerate all users in PC? Pin
John R. Shaw11-Mar-06 22:42
John R. Shaw11-Mar-06 22:42 
Questionmethod of hook dll Pin
HOW WHAT11-Mar-06 15:15
HOW WHAT11-Mar-06 15:15 
AnswerRe: method of hook dll Pin
Anton Mikhalyov11-Mar-06 18:17
Anton Mikhalyov11-Mar-06 18:17 
GeneralRe: method of hook dll Pin
HOW WHAT11-Mar-06 18:41
HOW WHAT11-Mar-06 18:41 
GeneralRe: method of hook dll Pin
Anton Mikhalyov11-Mar-06 20:52
Anton Mikhalyov11-Mar-06 20:52 
This example shows the hook of GetModuleHandleW in target process(process where you injected your dll). It works only in 32-bit windows.
If you injected your dll into multithreaded process you must synchronize execution of this code with other threads or program sometimes may crash.

<br />
#define BYTES_COUNT 0x05<br />
<br />
BYTE firstBytes[BYTES_COUNT];<br />
void *pfnGetModuleHandle;<br />
HANDLE __stdcall Handler(HANDLE hModule);<br />
<br />
// Only running process hook<br />
BOOL HookGetModuleHandle()<br />
{<br />
	HANDLE hKernel32;<br />
	DWORD dwOldProtect;<br />
<br />
	hKernel32 = LoadLibrary(_T("kernel32.dll"));<br />
	pfnGetModuleHandle = GetProcAddress((HMODULE)hKernel32, "GetModuleHandleW");<br />
<br />
	if (hKernel32 == NULL || pfnGetModuleHandle == NULL)<br />
	{<br />
		return FALSE;<br />
	}<br />
<br />
	memcpy(&firstBytes, pfnGetModuleHandle, BYTES_COUNT);<br />
<br />
	if (!VirtualProtect(pfnGetModuleHandle, BYTES_COUNT, PAGE_READWRITE, &dwOldProtect))<br />
	{<br />
		return FALSE;<br />
	}<br />
<br />
	*((BYTE*)pfnGetModuleHandle) = 0xE9;<br />
	*((DWORD*)(((BYTE*)pfnGetModuleHandle)+1)) = (DWORD)Handler - (DWORD)pfnGetModuleHandle - BYTES_COUNT;<br />
<br />
	if (!VirtualProtect(pfnGetModuleHandle, BYTES_COUNT, dwOldProtect, NULL))<br />
	{<br />
		return FALSE;<br />
	}<br />
<br />
	return TRUE;<br />
}<br />
<br />
BOOL UnhookGetModuleHandle()<br />
{<br />
	DWORD dwOldProtect;<br />
<br />
	if (!VirtualProtect(pfnGetModuleHandle, BYTES_COUNT, PAGE_READWRITE, &dwOldProtect))<br />
	{<br />
		return FALSE;<br />
	}<br />
<br />
	memcpy(pfnGetModuleHandle, &firstBytes, BYTES_COUNT);<br />
<br />
	if (!VirtualProtect(pfnGetModuleHandle, BYTES_COUNT, dwOldProtect, NULL))<br />
	{<br />
		return FALSE;<br />
	}<br />
<br />
	return TRUE;<br />
}<br />
<br />
HANDLE __stdcall Handler(HANDLE hModule)<br />
{<br />
	HANDLE returned;<br />
	printf("GetModuleHandleW call detected\n");<br />
	UnhookGetModuleHandle();<br />
	__asm {<br />
		push hModule<br />
		call pfnGetModuleHandle<br />
		mov returned, eax<br />
	}<br />
	HookGetModuleHandle();<br />
}<br />

GeneralRe: method of hook dll Pin
HOW WHAT12-Mar-06 1:24
HOW WHAT12-Mar-06 1:24 
GeneralRe: method of hook dll Pin
Anton Mikhalyov12-Mar-06 3:55
Anton Mikhalyov12-Mar-06 3:55 
GeneralRe: method of hook dll Pin
HOW WHAT12-Mar-06 4:52
HOW WHAT12-Mar-06 4:52 
GeneralRe: method of hook dll Pin
Anton Mikhalyov13-Mar-06 1:17
Anton Mikhalyov13-Mar-06 1:17 
QuestionALTER TABLE Pin
The Little Lloyd11-Mar-06 11:11
The Little Lloyd11-Mar-06 11:11 
AnswerRe: ALTER TABLE Pin
Jeremy Falcon11-Mar-06 15:12
professionalJeremy Falcon11-Mar-06 15:12 
GeneralRe: ALTER TABLE Pin
The Little Lloyd11-Mar-06 19:43
The Little Lloyd11-Mar-06 19:43 
GeneralRe: ALTER TABLE Pin
Jeremy Falcon11-Mar-06 20:07
professionalJeremy Falcon11-Mar-06 20:07 
GeneralRe: ALTER TABLE Pin
The Little Lloyd11-Mar-06 20:52
The Little Lloyd11-Mar-06 20:52 
GeneralRe: ALTER TABLE Pin
Jeremy Falcon12-Mar-06 11:19
professionalJeremy Falcon12-Mar-06 11:19 
QuestionBold text Pin
yaaqub11-Mar-06 10:22
yaaqub11-Mar-06 10:22 
AnswerRe: Bold text Pin
Chris Losinger11-Mar-06 10:37
professionalChris Losinger11-Mar-06 10:37 
GeneralRe: Bold text Pin
John R. Shaw11-Mar-06 22:55
John R. Shaw11-Mar-06 22:55 
AnswerRe: Bold text Pin
Jörgen Sigvardsson11-Mar-06 11:02
Jörgen Sigvardsson11-Mar-06 11:02 
GeneralRe: Bold text Pin
Hamid_RT11-Mar-06 17:17
Hamid_RT11-Mar-06 17:17 
GeneralRe: Bold text Pin
Jörgen Sigvardsson11-Mar-06 22:18
Jörgen Sigvardsson11-Mar-06 22:18 
AnswerRe: Bold text Pin
John R. Shaw11-Mar-06 22:48
John R. Shaw11-Mar-06 22:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.