How to hook method with diferent name

Oct 15, 2013 at 5:37 PM
Edited Oct 15, 2013 at 5:46 PM
Hi,

I like to hook some method like this name @Class@methodName$something

i can do this
LocalHook.Create(LocalHook.GetProcAddress("MyLib.bpl", "@Class@methodName$something"), new nameIWantTo(lib_func_hooked), this);
But how i can import the original function?

I know that this code work
[DllImport("MyLib.bpl",
            CharSet = CharSet.Auto,
            SetLastError = true,
            CallingConvention = CallingConvention.StdCall)]
        private static extern IntPtr SimpleFunction(string str);
So, How can i import this method?

if its impossible to do like this
[DllImport("MyLib.bpl",
            CharSet = CharSet.Auto,
            SetLastError = true,
            CallingConvention = CallingConvention.StdCall)]
        private static extern IntPtr @Class@methodName$something(string str);
Oct 17, 2013 at 10:39 AM
Try setting the "EntryPoint" property of the DllImport.

E.g.
    [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "MessageBox")]
    public static extern int MyNewMessageBoxMethod(IntPtr hWnd, String text, String caption, uint type);
Oct 17, 2013 at 1:17 PM
Edited Oct 17, 2013 at 1:20 PM
Hi Spazzaram it works thank you.

Just one more question, when i stop to hooking some function of the host process and close my hooker app i can see that injected DLLs still in host process. How i can deatch these dlls ? I can see that Dispose() just stop the hook but don't deatch the dll injected.

I mean, if a make some changes in hooker app i have to finish the host process for the changes to take effect.
Oct 17, 2013 at 5:31 PM
Edited Oct 17, 2013 at 9:02 PM
I tried inside of the injected dll use GetModuleHandle("EasyHook.dll") but it returns 0, im sure that EasyHook.dll is loaded into host process. The idea was find EasyHook module handle then close the handle, but how i can do that?