Click here to Skip to main content
15,884,836 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionprint it only if it is not a duplicate [modified][solved] Pin
Omegaclass15-Nov-09 14:01
Omegaclass15-Nov-09 14:01 
AnswerRe: print it only if it is not a duplicate Pin
Chris Losinger15-Nov-09 15:16
professionalChris Losinger15-Nov-09 15:16 
GeneralRe: print it only if it is not a duplicate Pin
Omegaclass19-Nov-09 20:56
Omegaclass19-Nov-09 20:56 
GeneralRe: print it only if it is not a duplicate Pin
Chris Losinger20-Nov-09 4:32
professionalChris Losinger20-Nov-09 4:32 
GeneralRe: print it only if it is not a duplicate Pin
Omegaclass20-Nov-09 14:56
Omegaclass20-Nov-09 14:56 
GeneralRe: print it only if it is not a duplicate Pin
Chris Losinger20-Nov-09 15:16
professionalChris Losinger20-Nov-09 15:16 
GeneralRe: print it only if it is not a duplicate Pin
Omegaclass21-Nov-09 20:31
Omegaclass21-Nov-09 20:31 
QuestionHooking CreateRemoteThread [modified] Pin
hxhl9515-Nov-09 13:50
hxhl9515-Nov-09 13:50 
I seem to have an abundancy of questions at this time of year. Laugh | :laugh:

Anyways, I have a CreateRemoteThread hook that refuses to work. Here's the code:

HANDLE WINAPI MyCreateRemoteThread(HANDLE hProcess, 
				LPSECURITY_ATTRIBUTES lpThreadAttributes, 
				SIZE_T dwStackSize, 
				LPTHREAD_START_ROUTINE lpStartAddress, 
				LPVOID lpParameter, 
				DWORD dwCreationFlags, 
				LPDWORD lpThreadId)
{
	if (GetpIDFromHandle(hProcess)==SelfpID){
		SetLastError(ERROR_ACCESS_DENIED);
		return NULL;
	}
	else {
	/* Call real CreateRemoteThread and return normally */ }


This format seems to work for every other function I've thought of so far (the ones in KERNEL32.DLL, at least), but it doesn't work for CreateRemoteThread. Sure, the hook is reached and if another process is trying to create a thread in my process's context the SetLastError is executed, but then the calling process crashes. I thought it was a problem with the calling process at first (I wrote one just to test), so I took another program that uses CreateRemoteThread and it crashed too.

Is there anything wrong with my code? Thanks in advance.

EDIT: Clarification - GetpIDFromHandle returns the process ID given a process handle (this works perfectly fine) and SelfpID is a global variable containing the self process ID.

modified on Sunday, November 15, 2009 11:34 PM

AnswerRe: Hooking CreateRemoteThread Pin
Naveen15-Nov-09 16:56
Naveen15-Nov-09 16:56 
GeneralRe: Hooking CreateRemoteThread Pin
hxhl9515-Nov-09 17:09
hxhl9515-Nov-09 17:09 
GeneralRe: Hooking CreateRemoteThread Pin
Naveen15-Nov-09 17:17
Naveen15-Nov-09 17:17 
GeneralRe: Hooking CreateRemoteThread Pin
hxhl9515-Nov-09 17:20
hxhl9515-Nov-09 17:20 
GeneralRe: Hooking CreateRemoteThread Pin
Naveen15-Nov-09 17:32
Naveen15-Nov-09 17:32 
GeneralRe: Hooking CreateRemoteThread Pin
hxhl9515-Nov-09 17:39
hxhl9515-Nov-09 17:39 
GeneralRe: Hooking CreateRemoteThread Pin
Naveen15-Nov-09 17:59
Naveen15-Nov-09 17:59 
QuestionWhat Windows API function is called to create / show a dialog box. Pin
hongheo7615-Nov-09 11:43
hongheo7615-Nov-09 11:43 
AnswerRe: What Windows API function is called to create / show a dialog box. Pin
Code-o-mat15-Nov-09 20:25
Code-o-mat15-Nov-09 20:25 
QuestionProblem debugging an app with VC++ Pin
timbk15-Nov-09 10:09
timbk15-Nov-09 10:09 
AnswerRe: Problem debugging an app with VC++ Pin
Chris Losinger15-Nov-09 10:58
professionalChris Losinger15-Nov-09 10:58 
GeneralRe: Problem debugging an app with VC++ Pin
timbk15-Nov-09 14:23
timbk15-Nov-09 14:23 
GeneralRe: Problem debugging an app with VC++ Pin
Chris Losinger15-Nov-09 14:43
professionalChris Losinger15-Nov-09 14:43 
GeneralRe: Problem debugging an app with VC++ Pin
timbk15-Nov-09 15:01
timbk15-Nov-09 15:01 
GeneralRe: Problem debugging an app with VC++ Pin
Chris Losinger15-Nov-09 15:06
professionalChris Losinger15-Nov-09 15:06 
GeneralRe: Problem debugging an app with VC++ Pin
timbk15-Nov-09 15:24
timbk15-Nov-09 15:24 
GeneralRe: Problem debugging an app with VC++ Pin
Richard MacCutchan15-Nov-09 21:36
mveRichard MacCutchan15-Nov-09 21:36 

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.