Skip to content

Commit

Permalink
Add hooks for CreateWindowEx*, calls to these functions can result in…
Browse files Browse the repository at this point in the history
… over 50 other API calls that clutter up the registry summary and confuse beginner analysts
  • Loading branch information
brad-sp committed Nov 10, 2014
1 parent 05060e8 commit 3e4f081
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cuckoomon.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ static hook_t g_hooks[] = {
// Window Hooks
//

HOOK(user32, CreateWindowExA),
HOOK(user32, CreateWindowExW),
HOOK(user32, FindWindowA),
HOOK(user32, FindWindowW),
HOOK(user32, FindWindowExA),
Expand Down
56 changes: 56 additions & 0 deletions hook_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,59 @@ HOOKDEF(BOOL, WINAPI, EnumWindows,
LOQ_bool("windows", "");
return ret;
}

HOOKDEF(HWND, WINAPI, CreateWindowExA,
__in DWORD dwExStyle,
__in_opt LPCSTR lpClassName,
__in_opt LPCSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam
) {
HWND ret = Old_CreateWindowExA(dwExStyle, lpClassName,
lpWindowName, dwStyle, x, y, nWidth, nHeight,
hWndParent, hMenu, hInstance, lpParam);
// lpClassName can be one of the predefined window controls.. which lay in
// the 0..ffff range
if (((DWORD_PTR)lpClassName & 0xffff) == (DWORD_PTR)lpClassName) {
LOQ_nonnull("windows", "ls", "ClassName", lpClassName, "WindowName", lpWindowName);
}
else {
LOQ_nonnull("windows", "ss", "ClassName", lpClassName, "WindowName", lpWindowName);
}
return ret;
}

HOOKDEF(HWND, WINAPI, CreateWindowExW,
__in DWORD dwExStyle,
__in_opt LPWSTR lpClassName,
__in_opt LPWSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam
) {
HWND ret = Old_CreateWindowExW(dwExStyle, lpClassName,
lpWindowName, dwStyle, x, y, nWidth, nHeight,
hWndParent, hMenu, hInstance, lpParam);
// lpClassName can be one of the predefined window controls.. which lay in
// the 0..ffff range
if (((DWORD_PTR)lpClassName & 0xffff) == (DWORD_PTR)lpClassName) {
LOQ_nonnull("windows", "lu", "ClassName", lpClassName, "WindowName", lpWindowName);
}
else {
LOQ_nonnull("windows", "uu", "ClassName", lpClassName, "WindowName", lpWindowName);
}
return ret;
}
30 changes: 30 additions & 0 deletions hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,36 @@ extern HOOKDEF(NTSTATUS, WINAPI, NtSaveKeyEx,
// Window Hooks
//

extern HOOKDEF(HWND, WINAPI, CreateWindowExA,
__in DWORD dwExStyle,
__in_opt LPCSTR lpClassName,
__in_opt LPCSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam
);

extern HOOKDEF(HWND, WINAPI, CreateWindowExW,
__in DWORD dwExStyle,
__in_opt LPWSTR lpClassName,
__in_opt LPWSTR lpWindowName,
__in DWORD dwStyle,
__in int x,
__in int y,
__in int nWidth,
__in int nHeight,
__in_opt HWND hWndParent,
__in_opt HMENU hMenu,
__in_opt HINSTANCE hInstance,
__in_opt LPVOID lpParam
);

extern HOOKDEF(HWND, WINAPI, FindWindowA,
__in_opt LPCTSTR lpClassName,
__in_opt LPCTSTR lpWindowName
Expand Down

0 comments on commit 3e4f081

Please sign in to comment.