Tell me, how can I call a function from a DLL injected into the process?

  • 2
    Give pzhlsta minimum set of code, what do you mean by injecting into the DLL process? - Alexcei Shmakov
  • Injection assumes that the source program knows nothing about the injected DLL. Therefore, it may or may not cause. Need to detail the question. - nick_n_a
  • one
    The entry point for the DLL is defined - the DllMain function. With a call to this function, the dll begins. The function is called with the DLL_PROCESS_ATTACH parameter when your dll is being loaded by the injection process. The main process code knows nothing about your dll and cannot call it (except if your dll does not replace the functions of other libraries / code used by the process). If you want to implement the ability to call the functions of your dll from the outside, then you need to do acc. interface using IPC. Be careful, the range of functions that can be used in DllMain is limited. - goldstar_labs
  • I meant loading dll function LoadLibrary - Deonix Hooh
  • call the function which one? Or mean how to call LoadLibrary itself? So on Habré is well described. - nick_n_a

1 answer 1

If you know the prototype of the functions buried in the dll, then use the extern modifier ( link )

 class ExternTest { [DllImport("User32.dll", CharSet=CharSet.Unicode)] public static extern int MessageBox(IntPtr h, string m, string c, int type); static int Main() { string myString; Console.Write("Enter your message: "); myString = Console.ReadLine(); return MessageBox((IntPtr)0, myString, "My Message Box", 0); } } 
  • one
    It is not the answer to the question. - LLENN