Share data between C# and Delphi with madshi IPC

c++ / delphi package - dll injection and api hooking
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Share data between C# and Delphi with madshi IPC

Post by ExPx »

Hi All,

Is it possible to use madshi IPC to share data between C# and Delphi.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post 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#.
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post 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.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post 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.
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post 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;

madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post by madshi »

Which part crashes? The hook dll calling SendIpcMessage? Or your application receiving it?
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

Receiver part crashes.
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post by madshi »

Do you have madExcept installed? If so, do you get a madExcept crash report from the receiver?
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

I attached it.
Attachments
bugreport.zip
Bug report
(6.98 KiB) Downloaded 404 times
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post 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?
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

Crash continues with empty callback
madshi
Site Admin
Posts: 10754
Joined: Sun Mar 21, 2004 5:25 pm

Re: Share data between C# and Delphi with madshi IPC

Post by madshi »

How does your InjectLibrary() call look like?
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

Let me create app for reproduce.
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post 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
ExPx
Posts: 34
Joined: Fri Oct 21, 2016 3:20 pm

Re: Share data between C# and Delphi with madshi IPC

Post by ExPx »

Hi madshi,

Any progress for this issue ?
Post Reply