Software development industry analysis by Larry O'Brien, the former editor of Software Development and Computer Language
Friday, January 13, 2006

O Lazy Web, I Invoke Thee:

 

I am trying to call a function in a DLL that I’ve injected into an arbitrary number of processes.

 

I need to call a function on that instance of the DLL running in the target process. So, I tried…

 

//hookedProcesses == List<ProcessModule> as you’d expect

//myDll == string initialized to path of my injected DLL, as you’d expect

//delegate void VoidDelegate() as you’d expect

foreach(ProcessModule process in hookedProcesses)

{

   if(module.FileName == myDll)

  {

    IntPtr dllHandle = Interop.GetModuleHandle(filename); //Interop to Win32 GetModuleHandle()

    IntPtr funcPtr = Interop.GetProcAddress(dllHandle, “MyFunction”); //Interop to Win32 GetProcAddress()

    VoidDelegate func = (VoidDelegate) Marshall.GetDelegateForFunctionPointer(funcPtr, typeof(VoidDelegate));

           

    // EVERYTHING WORKS TO THIS POINT.

   func(); //ß Causes segfault / “corrupted memory” error

 

What I’m wondering is if I’m just ignorant of some Windows protection feature that says “Hey, you can’t just go run functions across process boundaries.”? Is there some obvious thing that I’m missing? I almost wonder if I have to use some kind of mutex or somesuch to signal across instances of the .DLL running in different processes?

Friday, January 13, 2006 6:28:29 PM (Hawaiian Standard Time, UTC-10:00) |  Disqus link  | #
Search
About Larry...
Flickr photostream
Subscribe: RSS 2.0 Atom 1.0
Popular Articles
Programming Sabre with Java, C#, and XML
Genetic Programming in C#
15 Exercises To Know A Programming Language
Top 10 Things I've Learned About Computers From the Movies and Any Episode of "24"
Recently Published Articles
HI
KonaKoder
Categories
Archive
Admin Login
Sign In
Toolroll