PDA

View Full Version : how to terminate debugee in safe mode


zqBugZ
June 23rd, 2008, 12:50
Hi there,
I have another question to ask about termination of debugee. Commonly I used TerminateProcess the debugee. For some applications, It complains that it terminated abnormally last time, and asks for recovery. How can I do to make the debugee exit gracefully more than terminating immediately?

Thanks a lot!

Jakor
June 23rd, 2008, 14:34
uh... close the program regularly. Most likely they have a couple ways to exit the program from inside. aka:

Code:
Die proc eCodeWORD
invoke ExitProcess,eCode
Die endp

Shutdown proc eCodeWORD
invoke ShutdownGFX
invoke ShutdownSound
invoke ShutdownWinsock
invoke SaveConfiguration,eCode
invoke ExitProcess,eCode
Shutdown endp


now this isn't exact, but as you can see one cleans itself up and the otherone just exits. Lets say their initialization check for "SaveConfiguration" to have been last called with "ERR_NOERROR" or "ERR_FIRSTRUN" and displays an abnormal shutdown if neither of these are found. After checking for that, it runs "SaveConfiguration,ERR_APPRUNNING" so that it can tell whether "Die" is called or "Shutdown,ERR_NOERROR" and change for the next time. Now when you "TerminateProcess" this would be the same as "Die" as you do not save the fact that you ended correctly.

so really if you end like this, just ignore the fact that it ended abnormally because it DID end "abnormally"

zqBugZ
June 23rd, 2008, 15:03
Quote:
[Originally Posted by Jakor;75358]...
so really if you end like this, just ignore the fact that it ended abnormally because it DID end "abnormally"


is there anyway to let it exit by itself? Like send it a WM_CLOSE something like that? sorry I am not a windows guy, please forgive me if that is stupid.

dELTA
June 24th, 2008, 03:11
Yes. that would probably be recommended way. That could result in interactive messages from the program though (like "Do you want to save the unsaved xxx?). It will be equal to clicking the "X" in the program's main window.

zqBugZ
June 24th, 2008, 09:10
Thanks a lot! that is really helpful. But I notice that SendMessage uses HWND as parameter. How can I get it given thread id or process id? is FindWindowA the only way to get a hwnd?

Silver
June 24th, 2008, 12:38
Go back the other way - GetWindowThreadProcessId()

*edit* should have made that clearer, enumerate all the windows and then use that function to compare ids...

zqBugZ
June 26th, 2008, 10:12
Great!, it works now. Thanks a lot, guys!