6

Can you use C# to call a function inside of another running process that is written in C/C++?

I know you can do this using C++ by injecting a DLL that starts a remote thread, listens for associated key-presses, and makes a call to the desired function whose signature and address has been defined.

The C++ to C++ tutorial is here: http://www.codeproject.com/Articles/29527/Reverse-Engineering-and-Function-Calling-by-Addres#Applying

If I remember correctly, I've also read in the past that you cannot inject a managed DLL (C#) into an unmanaged process (C++). But perhaps another way exists...

The reason that I'd like to do this is to reverse engineer a PC game and write little hacks in C#, a language I'm familiar with.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • Does it help? http://stackoverflow.com/questions/20023379/injecting-a-managed-dll-into-a-native-process – Michał Komorowski Mar 10 '16 at 08:28
  • There is another tutorial here:http://www.codeproject.com/Articles/607352/Injecting-Net-Assemblies-Into-Unmanaged-Processes – xanatos Mar 10 '16 at 08:38
  • @GediminasMasaitis No, the code in the example does everything. A little library in C/C++ is injected in the target process, that loads the CLR host in the target process and then loads the desidered .NET dll. – xanatos Mar 10 '16 at 08:47
  • @GediminasMasaitis If you look at the final image, you'll see that they inject a managed DLL into the Notepad++ (a program that isn't written in .NET) – xanatos Mar 10 '16 at 08:49
  • @xanatos Oh, my bad! The article began with using a CLR host, so I assumed that's what the tutorial is about, but that was just a test. Lesson learned - always read the full article! – Gediminas Masaitis Mar 10 '16 at 08:50
  • 2
    You have to know C++ pretty well to inject the CLR into another process and do so without doing too much damage. And COM, the assembly language of Windows. And above all, to know how to diagnose failure and find a way around it. And there *will* be failure, managed code likes to throw exceptions and that does **not** come to a good end when that happens inside a foreign process. As long as you have to know the language, you might as well use it and completely skip C#. – Hans Passant Mar 10 '16 at 08:52

1 Answers1

2

Take a look at the MemorySharp library, it does exactly what you want.

Mark Jansen
  • 1,491
  • 12
  • 24