OutputDebugString replacement

c++ / delphi package - dll injection and api hooking
Post Reply
edotan
Posts: 10
Joined: Mon Dec 10, 2007 9:40 pm

OutputDebugString replacement

Post by edotan »

Hi,

I'm wondering -- since OutputDebugString is problematic inside hooks, has anyone written an alternative OutputDebugString + DbgView tool, for example by using SendIpcMessage?
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I'm usually using good old file based logging (CreateFile + WriteFile + CloseHandle).
dcsoft
Posts: 380
Joined: Sat Dec 11, 2004 2:11 am
Location: San Francisco Bay Area, CA USA
Contact:

Post by dcsoft »

I log messages using SendMessage(WM_COPYDATA, ...) and wrote a viewer app similar to DbgView to receive the messages and display the strings. I could post that, if there's any interest.

The advantage of this is that it works in file hooks like CreateFile() which is not permissible to call OutputDebugString() due to that function internally calling CreateFile() and causing recursion. Of course, my solution has the same issue when used in hooks like for SendMessage!

-- David
edotan
Posts: 10
Joined: Mon Dec 10, 2007 9:40 pm

Post by edotan »

It's OK, I ended up writing an app that does just this. Thanks anyway:

CreateIpcQueueEx("MyDebug", GetDbgMsg, 1);

...

VOID _stdcall
GetDbgMsg(
LPCSTR Name,
PVOID pMessageBuf,
DWORD cbMessageBuf,
PVOID pAnswerBuf,
DWORD cbAnswerBuf )
{
OutputDebugString((WCHAR*)pMessageBuf);
}

...

ShellExecute(0, NULL, L"DbgView.exe", NULL, NULL, SW_SHOWMAXIMIZED);
while (TRUE)
{
Sleep(500);
}
mikec
Posts: 166
Joined: Sun Jul 16, 2006 9:01 pm
Location: UK

Post by mikec »

Hay dcsoft,

I'd be interested in your debug viewer - i was just about to start writing something myself but if you have a working system, it might be a great help.

Any idea if WM_COPYDATA works across session boundries in Vista / WIndows 7 - i have a feeling it doesnt :sorry:
Nico Bendlin
Posts: 46
Joined: Fri Apr 28, 2006 1:17 pm

Post by Nico Bendlin »

Window handles are only valid inside a session (desktop). So the answer is no.
Post Reply