עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

בעיה עם hook dll עבור shell hook ב c++

Featured Replies

פורסם

שלום לכולם

כתבתי dll פשוט שמטרתו לשלוח הודעה לחלון שקרא לו בכל פעם שנוצר חלון חדש במערכת בעזרת קביעת hook.

זה הקוד של ה cpp של ה dll:

#include "stdafx.h"
#include "HookManager.h"

#ifdef _MANAGED
#pragma managed(push, off)
#endif

#pragma data_seg(".SHARED")
HWND hCallerWnd = NULL;
#pragma data_seg()
#pragma comment("linker, /section:.SHARED,rws")

HINSTANCE hInstance;
HHOOK hkShellHook;
UINT KBWM_WINDOWCREATED;

BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch(ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
KBWM_WINDOWCREATED = RegisterWindowMessage(KBWM_WINDOWCREATED_MSG);
hInstance = (HINSTANCE) hModule;
break;
case DLL_PROCESS_DETACH:
UnhookWindowsHookEx(hkShellHook);
break;
}
return TRUE;
}

LRESULT CALLBACK ShellProc(UINT nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode == HSHELL_WINDOWCREATED)
PostMessage(hCallerWnd, KBWM_WINDOWCREATED, wParam, 0);

return CallNextHookEx(hkShellHook, nCode, wParam, lParam);
}

__declspec(dllexport) BOOL SetHook(HWND caller)
{
hCallerWnd = caller;
hkShellHook = ::SetWindowsHookEx(WH_SHELL, (HOOKPROC) ShellProc, hInstance, 0);
return (hkShellHook != NULL);
}

#ifdef _MANAGED
#pragma managed(pop)
#endif

וה header של ה dll:

#define KBWM_WINDOWCREATED_MSG _T("KBWM_WINDOWCREATED_MSG-{49E9712B-372A-4873-A1BE-84D40C56916E}")

__declspec(dllexport) BOOL SetHook(HWND caller);

כדי לבדוק אותו יצרתי פרוייקט mfc שאמור להראות רשימה של החלונות שנוצרים. אלה הקטעים הרלוונטיים מהקוד שלו:

#include "..\HookManager\HookManager.h"

...

const UINT KBWM_WINDOWCREATED = ::RegisterWindowMessage(KBWM_WINDOWCREATED_MSG);

...

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_REGISTERED_MESSAGE(KBWM_WINDOWCREATED, OnHookWindowCreated)
END_MESSAGE_MAP()


BOOL CTestDlg::OnInitDialog()
{
...

SetHook(GetSafeHwnd());

...
}


LRESULT CTestDlg::OnHookWindowCreated(WPARAM wParam, LPARAM lParam)
{
HWND hwnd = (HWND)wParam;

TCHAR text[255];
::GetWindowText(hwnd, text, 255);

m_appsList.AddString(text);

return TRUE;
}

הבעיה היא שאני מקבל הודעות רק עבור חלונות שנוצרים בתוכנה שלי ולא עבור כל המערכת, מה שאומר שמשום מה ה hook הגלובלי לא עובד. מישהו יודע למה זה קורה?

תודה

עריכה: הבעיה נפתרה. שברתי את הראש שעות בגלל גרשיים שלא היו במקום :s07:. השורה:

#pragma comment("linker, /section:.SHARED,rws")

צריכה להיות:

#pragma comment(linker, "/section:.SHARED,rws")

מה שגרם לכך שה hwnd של החלון שקרא ל dll לא שותף כמו שצריך בין המופעים השונים של ה dll והיה תקף רק ב process בו נמצא החלון.

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.