Share data between C# and Delphi with madshi IPC

c++ / delphi package - dll injection and api hooking

Share data between C# and Delphi with madshi IPC

Postby ExPx » Mon Sep 24, 2018 10:29 am

Hi All,

Is it possible to use madshi IPC to share data between C# and Delphi.
ExPx
 
Posts: 28
Joined: Fri Oct 21, 2016 3:20 pm

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

Postby madshi » Tue Sep 25, 2018 8:29 am

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

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

Postby ExPx » Tue Sep 25, 2018 10:10 am

Between 2 different processes. One is Delphi and other c# app. Sometimes I need to use mini C# apps to use specific .net apis.
ExPx
 
Posts: 28
Joined: Fri Oct 21, 2016 3:20 pm

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

Postby madshi » Tue Sep 25, 2018 10:18 am

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

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

Postby ExPx » Tue Sep 25, 2018 1:07 pm

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;

ExPx
 
Posts: 28
Joined: Fri Oct 21, 2016 3:20 pm

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

Postby madshi » Tue Sep 25, 2018 2:13 pm

Which part crashes? The hook dll calling SendIpcMessage? Or your application receiving it?
madshi
Site Admin
 
Posts: 9810
Joined: Sun Mar 21, 2004 5:25 pm

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

Postby ExPx » Tue Sep 25, 2018 2:14 pm

Receiver part crashes.
ExPx
 
Posts: 28
Joined: Fri Oct 21, 2016 3:20 pm

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

Postby madshi » Tue Sep 25, 2018 2:18 pm

Do you have madExcept installed? If so, do you get a madExcept crash report from the receiver?
madshi
Site Admin
 
Posts: 9810
Joined: Sun Mar 21, 2004 5:25 pm

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

Postby ExPx » Tue Sep 25, 2018 2:35 pm

I attached it.
Attachments
bugreport.zip
Bug report
(7.01 KiB) Downloaded 6 times
ExPx
 
Posts: 28
Joined: Fri Oct 21, 2016 3:20 pm

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

Postby madshi » Tue Sep 25, 2018 2:39 pm

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

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

Postby ExPx » Tue Sep 25, 2018 3:38 pm

Crash continues with empty callback
ExPx
 
Posts: 28
Joined: Fri Oct 21, 2016 3:20 pm

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

Postby madshi » Tue Sep 25, 2018 3:40 pm

How does your InjectLibrary() call look like?
madshi
Site Admin
 
Posts: 9810
Joined: Sun Mar 21, 2004 5:25 pm

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

Postby ExPx » Tue Sep 25, 2018 3:47 pm

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

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

Postby ExPx » Thu Sep 27, 2018 7:29 am

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: 28
Joined: Fri Oct 21, 2016 3:20 pm

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

Postby ExPx » Mon Oct 01, 2018 11:26 am

Hi madshi,

Any progress for this issue ?
ExPx
 
Posts: 28
Joined: Fri Oct 21, 2016 3:20 pm

Next

Return to madCodeHook

Who is online

Users browsing this forum: Google [Bot] and 5 guests