Hooking custom methods in an .exe

Dec 17, 2011 at 4:27 PM


I have made an .exe application in C# and now I want to call my own functions inside of it by injecting a .DLL with EasyHook.

But since I hard-coded the function in my application I need to get the address of the function through the .exe instead of the .DLL. Normall, if you hook a method inside a .dll you do this:

ChangeNumberHook = LocalHook.Create(LocalHook.GetProcAddress("CallMyFunctions.dll", "ChangeNumber"), new DChangeNumber(ChangeNumber_Hooked), this);

But since I got a .exe I need to get the function from the .exe, I use a program to view a process' modules and function names, but when I click in the CallMyFunction.exe module inside the process I don't ge a list of available methods. When I click any other .dll I do ge the functions I can hook. So even though I can't see it I still tried to hook it:

ChangeNumberHook = LocalHook.Create(LocalHook.GetProcAddress("CallMyFunctions.exe", "ChangeNumber"), new DChangeNumber(ChangeNumber_Hooked), this);
But I get an exception saying the method does not exist. So how do I call custom functions that are not inside a .DLL? I've tried to open CallMyFuncions with IDA and see where my function is located to copy the address from there and hard-code it in the injected .DLL. What looked like this:

ChangeNumberHook = LocalHook.Create(
                    new DChangeNumber(ChangeNumber_Hooked),

But this crashes my CallMyFunctions.exe app and messageboxes me with: "Assertion failed!". Can someone tell me how I can solve this problem?


Thanks in advance,

Diede Apers

Jul 9, 2012 at 11:33 PM

Can you bump here? i really want this function too!

Jul 17, 2012 at 2:08 AM
Edited Jul 17, 2012 at 2:08 AM

Executables do not export any methods in the way DLL's do. Therefore you cannot use the GetProcAddress.

I haven't tried this but you should be able to do what was tried last except also add the executables base address to your offset e.g.:


ChangeNumberHook = LocalHook.Create(
                    (IntPtr)(0x000003FD + baseAddressOfExe),
                    new DChangeNumber(ChangeNumber_Hooked),
Jul 17, 2012 at 12:18 PM

Ahh, the Assertion failed message.  I just checked in a bit more verbosing on the assertion.