Debug Windows Service Startup Without Using gflags
Thomas Ptacek | November 22nd, 2006 | Filed Under: Reversing, Uncategorized
You can’t run a Windows service on the command line the same way you can a Unix daemon. So what do you do if you need to debug the startup routine of a Windows service?
Microsoft has a knowledgebase article on this. The “official” answer is to use “gflags.exe”, which comes with the (excellent, free) windbg package. There’s an image execution option that tells Windows to start a program under the debugger.
I can’t get this to work for me. So I asked a friend, and got an easy answer that did work:
Set, say, Ollydbg as your JIT debugger.
Make sure “Allow service to interact with desktop” is enabled under the service options.
Open the service’s image file in an editor. The (excellent, free) “hte” works perfectly.
Find some code that runs early in startup. Replace an instruction with INT 3 (0xCC). I just swapped an xor-to-zero.
Start the service; it’ll pop up under the debugger. Make sure you set the register you skipped to zero.
Since I’m already cough tweaking this application with hte anyways, this was a perfect solution.


Add New Comment
Viewing 1 Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment
Trackbacks