View Single Post
  #12  
Old 05-12-2016, 14:42
atom0s's Avatar
atom0s atom0s is online now
Family
 
Join Date: Jan 2015
Location: 127.0.0.1
Posts: 396
Rept. Given: 26
Rept. Rcvd 126 Times in 63 Posts
Thanks Given: 54
Thanks Rcvd at 730 Times in 279 Posts
atom0s Reputation: 100-199 atom0s Reputation: 100-199
Here is an example of hooking Win32 API without a trampoline since they are not always needed:
(Error checking code omitted for ease of reading.)

PHP Code:
extern "C"
{
    
HWND (WINAPI *Real_CreateWindowExA)(DWORDLPCSTRLPCSTRDWORDintintintintHWNDHMENUHINSTANCELPVOID) = CreateWindowExA;
};

/**
 * user32!CreateWindowExA detour callback.
 */
HWND __stdcall Mine_CreateWindowExA(DWORD dwExStyleLPCSTR lpClassNameLPCSTR lpWindowNameDWORD dwStyleint xint yint nWidthint nHeightHWND hWndParentHMENU hMenuHINSTANCE hInstanceLPVOID lpParam)
{
    
// Do your personal alterations and such here..
    
    
return Real_CreateWindowExA(dwExStylelpClassNamelpWindowNamedwStylexynWidthnHeighthWndParenthMenuhInstancelpParam);
}

// Attach the detour..
DetourTransactionBegin();
DetourUpdateThread(::GetCurrentThread());
DetourAttach(&(PVOID&)Real_CreateWindowExAMine_CreateWindowExA);
DetourTransactionCommit(); 
Reply With Quote
The Following 6 Users Say Thank You to atom0s For This Useful Post:
chants (09-02-2018), NeWOT (08-12-2016), sh3dow (05-13-2016), xenocidewiki (05-13-2016)