Page 1 of 2
Share data between C# and Delphi with madshi IPC
Posted: Mon Sep 24, 2018 10:29 am
by ExPx
Hi All,
Is it possible to use madshi IPC to share data between C# and Delphi.
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 8:29 am
by madshi
Can you be a bit more specific? Are we talking about 2 different processes? Or about different DLLs within the same process?
Generally, the IPC should work fine, regardless of which language you use it in. However, madCodeHook does not come with C# headers. I've zero knowledge about C#, so I'm not sure if you can use madCodeHook with C#.
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 10:10 am
by ExPx
Between 2 different processes. One is Delphi and other c# app. Sometimes I need to use mini C# apps to use specific .net apis.
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 10:18 am
by madshi
The key problem will be how to make madCodeHook accessible from within your C# app. I suppose you could create a little win32 helper DLL with C++, which your C# app might then be able to use to do IPC communication? Please be careful, though, that you don't export madCodeHook APIs directly in the DLL, otherwise other developers (e.g. malware devs) could simply copy your DLL and use it for their own purposes.
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 1:07 pm
by ExPx
Thanks for reply.
I have another question.
I have made a sample app with Delphi XE2. It creates IPC queue and receives ipc messages from hooked Chrome(64bit). 64bit build seems working but 32bit build crashes after 4-5 message. Do you anything to recommend me to check ? My IPC callback :
Code: Select all
procedure IPC_Callback(lpName: PChar;
lpMessageBuf: PWChar;
dwMessageLen: DWORD;
lpAnswerBuf: Pointer;
dwAnswerLen: DWORD;
lpContext: Pointer); stdcall;
begin
try
PINT(lpAnswerBuf)^ := SendMessage(HostApplicationMain.Handle, WM_USER + 777, NativeInt(lpMessageBuf), $777);
finally
end;
end;
procedure THostApplicationMain.HandleIPC(var Message: TMessage);
Var
ParamList : TstringList;
begin
ParamList := TstringList.Create;
ParamList.Text := PWChar(pointer(Message.wParam));
//do something
ParamList.Free;
Message.Result := 1;
end;
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 2:13 pm
by madshi
Which part crashes? The hook dll calling SendIpcMessage? Or your application receiving it?
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 2:14 pm
by ExPx
Receiver part crashes.
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 2:18 pm
by madshi
Do you have madExcept installed? If so, do you get a madExcept crash report from the receiver?
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 2:35 pm
by ExPx
I attached it.
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 2:39 pm
by madshi
That looks weird. Maybe some buffer overrun somewhere, or something like that? What happens if you empty the IPC callback function? Does the problem go away then?
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 3:38 pm
by ExPx
Crash continues with empty callback
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 3:40 pm
by madshi
How does your InjectLibrary() call look like?
Re: Share data between C# and Delphi with madshi IPC
Posted: Tue Sep 25, 2018 3:47 pm
by ExPx
Let me create app for reproduce.
Re: Share data between C# and Delphi with madshi IPC
Posted: Thu Sep 27, 2018 7:29 am
by ExPx
sample project link
http://zipansion.com/45Q4C
Steps
1. Run Chrome.
2. Run 64 bit test app. This will inject 64bit dll to chrome processes.
3. Run 32 bit test app. This will create IPC channel.
4. Browse randomly on Chrome.
Test environment
OS : Windows 10 x64
madCodeHook : 3.1.18
Delphi : XE2
Re: Share data between C# and Delphi with madshi IPC
Posted: Mon Oct 01, 2018 11:26 am
by ExPx
Hi madshi,
Any progress for this issue ?