I am trying to hook a member function of a class which is exported from a dll.
Code: Select all
void (WINAPI *UnhookCMainFrame)(LPVOID THIS,char ch,int num,DWORD cls ,HWND *hwnd);
void WINAPI NewCMainFrame(LPVOID THIS,char ch,int num,DWORD cls,HWND *hwnd)
{
MessageBox(0,"IN NewCMainFrame","FUN",0);
return UnhookCMainFrame(THIS,ch, num, cls, hwnd);
}
LPVOID Address_Of_Function = GetProcAddress(GetModuleHandleA("XYZ.dll"), "_Mangled_Name_Of_exported_Class_MemberFunction");
Example;-
LPVOID m_pFcn1 = GetProcAddress(GetModuleHandleA("XYZ.dll"), "??0CMainFrame@@QAE@DHPAVCMyUIThread@@PAUHWND__@@@Z");
//i get magled name of above function from dependency walker/depends.
int res=HookCode(m_pFcn1,NewCMainFrame ,(PVOID*) &UnhookCMainFrame);
The issue is the application get crashed at the time of UnhookCMainFrame.
I get same address from some API tools also. So I think my address is correct.
I also tried with different combination of function declarations, that is by removing WINAPI and LPVOID THIS parameter, but the result is same.
Regards,
Ameet