SendIpcMessage under Win9X

c++ / delphi package - dll injection and api hooking
Post Reply
zcecil
Posts: 22
Joined: Thu Sep 09, 2004 8:16 am

SendIpcMessage under Win9X

Post by zcecil »

I have a problem using SendIpcMessage under win9x.(the same code works under windows 2k/xp)
The hook dll:

Code: Select all

typedef struct LFAStruct {
		BYTE type;
		CHAR from[4096+1];
		CHAR to[4096+1];
} *PLFAStruct;

bool SomeFunction( BYTE type, LPCSTR from, LPCSTR to )
{
	LFAStruct lfa;
	lfa.type = type;
	lstrcpynA( lfa.from, from, 4096);
	lstrcpynA( lfa.to, to, 4096);

	SendIpcMessage( "IPCNAME", &lfa, sizeof(lfa));

	return true;

}
the receiving app

Code: Select all

typedef struct LFAStruct {
		BYTE type;
		CHAR from[4096+1];
		CHAR to[4096+1];
} *PLFAStruct;

void WINAPI IpcHandler(LPSTR  pIpc,
                                PVOID   pMessageBuf,
                                UINT   dwMessageLen,
                                PVOID   pAnswerBuf,
                                UINT   dwAnswerLen)
{
    PLFAStruct lfa = (PLFAStruct)pMessageBuf;
    AnsiString msg ="[ipc]:[";
    msg = msg + lfa->from + "][";
    msg = msg + lfa->to + "]";
    Form1->Memo1->Lines->Add(msg);
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    if( !CreateIpcQueue( "IPCNAME", IpcHandler) ) {
        ShowMessage("create ipc queue failed");
        return;
    }

    InjectLibrary( ALL_SESSIONS | SYSTEM_PROCESSES, "hookdll.dll");
}
But the application can not receive anything from dll :cry:
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Your IPC callback in the exe is called in the context of a secondary thread. The VCL is not thread safe. So using VCL in there seems dangerous to me. Anyway, I'm not sure whether that is the real problem.

Does your application freeze? Or do the IPC messages simply seem to get lost?
zcecil
Posts: 22
Joined: Thu Sep 09, 2004 8:16 am

Post by zcecil »

It does not freeze, the IPCHandler just doesn't get called.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

What happens if you reduce the IPC packet size? Win9x doesn't like too big IPC messages.
zcecil
Posts: 22
Joined: Thu Sep 09, 2004 8:16 am

Post by zcecil »

Thanks, it worked wher I reduce the IPC packet size :D
zcecil
Posts: 22
Joined: Thu Sep 09, 2004 8:16 am

Post by zcecil »

sorry, problem again, this time it is under win xp.

i wrote a service program( running as LocalSystem) which inject the hook dll system-wide.
Then the service runs the application which CreateIpcQueue and waits for the dll to SendIpcMessage.

However, the application doesn't seem to receive anything from the dll.
I've tried running the application myself( as interactive user, local administrator), and it CAN receive ipc messages.

How can I fix this problem?
Thanks in advance.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

So you mean if that application is started from your service, then it doesn't work. But if you start it manually, then it does work? How do you know that it doesn't work? Are you logging the IPC message to a file or are you relying on message boxes?
zcecil
Posts: 22
Joined: Thu Sep 09, 2004 8:16 am

Post by zcecil »

Yes, I ShowMessage when the IPC handler is called, and I will log the messages to some files. I got no popup dialogs and no logs when the application is started from my service, but when I started it manually, it worked fine. :confused:
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

When your service starts the application, the app will most likely not run on the current desktop. So if you call ShowMessage there, the box will be invisible and nobody will close it. Get rid of those boxes, then it will probably work.
Post Reply