31 #define NUMBER_OF_PAGES 4
32 #define WEM_RESOLVE_DONE (WM_APP + 1234)
34 typedef struct _WINDOW_PROPERTIES_CONTEXT
38 HWND ParentWindowHandle;
44 LIST_ENTRY ResolveListHead;
48 ULONG WndProcResolving;
50 ULONG DlgProcResolving;
52 ULONG ClassWndProcResolving;
54 BOOLEAN HookDataValid;
55 BOOLEAN HookDataSuccess;
61 typedef struct _SYMBOL_RESOLVE_CONTEXT
72 typedef struct _STRING_INTEGER_PAIR
112 _In_ LPPROPSHEETPAGE ppsp
147 #define DEFINE_PAIR(Symbol) { L#Symbol, Symbol }
221 _In_ HWND ParentWindowHandle,
222 _In_ HWND WindowHandle
229 if (!WePropertiesCreateList)
231 if (!WePropertiesWindowList)
242 context->RefCount = 1;
243 context->ParentWindowHandle = ParentWindowHandle;
244 context->WindowHandle = WindowHandle;
247 threadId = GetWindowThreadProcessId(WindowHandle, &processId);
248 context->ClientId.UniqueProcess = UlongToHandle(processId);
249 context->ClientId.UniqueThread = UlongToHandle(threadId);
258 PostThreadMessage(HandleToUlong(WePropertiesThreadClientId.
UniqueThread), WM_NULL, 0, 0);
265 _InterlockedIncrement(&Context->RefCount);
272 if (_InterlockedDecrement(&Context->RefCount) == 0)
274 PLIST_ENTRY listEntry;
280 listEntry = Context->ResolveListHead.Flink;
282 while (listEntry != &Context->ResolveListHead)
287 listEntry = listEntry->Flink;
305 PROPSHEETHEADER propSheetHeader = {
sizeof(propSheetHeader) };
308 propSheetHeader.dwFlags =
314 propSheetHeader.hwndParent = Context->ParentWindowHandle;
316 propSheetHeader.nPages = 0;
317 propSheetHeader.nStartPage = 0;
318 propSheetHeader.phpage = pages;
346 return (HWND)PropertySheet(&propSheetHeader);
357 case PSCB_INITIALIZED:
360 HWND refreshButtonHandle;
362 oldWndProc = (WNDPROC)GetWindowLongPtr(hwndDlg, GWLP_WNDPROC);
364 SetProp(hwndDlg, L
"OldWndProc", (HANDLE)oldWndProc);
367 ShowWindow(GetDlgItem(hwndDlg, IDCANCEL), SW_HIDE);
369 SetDlgItemText(hwndDlg, IDOK, L
"Close");
371 refreshButtonHandle = CreateWindow(L
"BUTTON", L
"Refresh", WS_CHILD | WS_TABSTOP | WS_VISIBLE, 0, 0, 3, 3, hwndDlg, (HMENU)
IDC_REFRESH,
373 SendMessage(refreshButtonHandle, WM_SETFONT, (WPARAM)SendMessage(GetDlgItem(hwndDlg, IDOK), WM_GETFONT, 0, 0),
FALSE);
388 WNDPROC oldWndProc = (WNDPROC)GetProp(hwnd, L
"OldWndProc");
394 SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)oldWndProc);
395 RemoveProp(hwnd, L
"OldWndProc");
396 RemoveProp(hwnd, L
"Moved");
401 if (!GetProp(hwnd, L
"Moved"))
409 SetProp(hwnd, L
"Moved", (HANDLE)1);
415 switch (LOWORD(wParam))
425 if (pageHandle = PropSheet_IndexToHwnd(hwnd, i))
426 SendMessage(pageHandle, WM_COMMAND,
IDC_REFRESH, 0);
435 return CallWindowProc(oldWndProc, hwnd, uMsg, wParam, lParam);
444 HPROPSHEETPAGE propSheetPageHandle;
445 PROPSHEETPAGE propSheetPage;
447 memset(&propSheetPage, 0,
sizeof(PROPSHEETPAGE));
448 propSheetPage.dwSize =
sizeof(PROPSHEETPAGE);
449 propSheetPage.dwFlags = PSP_USECALLBACK;
451 propSheetPage.pszTemplate = Template;
452 propSheetPage.pfnDlgProc = DlgProc;
453 propSheetPage.lParam = (LPARAM)Context;
456 propSheetPageHandle = CreatePropertySheetPage(&propSheetPage);
458 return propSheetPageHandle;
464 _In_ LPPROPSHEETPAGE ppsp
471 if (uMsg == PSPCB_ADDREF)
473 else if (uMsg == PSPCB_RELEASE)
491 WePropertiesThreadClientId = NtCurrentTeb()->ClientId;
494 PeekMessage(&message, NULL, WM_USER, WM_USER, PM_NOREMOVE);
497 while (result = GetMessage(&message, NULL, 0, 0))
502 if (WePropertiesCreateList->
Count != 0)
506 for (i = 0; i < WePropertiesCreateList->
Count; i++)
511 context = WePropertiesCreateList->
Items[i];
523 for (i = 0; i < WePropertiesWindowList->
Count; i++)
525 if (PropSheet_IsDialogMessage(WePropertiesWindowList->
Items[i], &message))
534 TranslateMessage(&message);
535 DispatchMessage(&message);
539 for (i = 0; i < WePropertiesWindowList->
Count; i++)
541 if (!PropSheet_GetCurrentPageHwnd(WePropertiesWindowList->
Items[i]))
543 DestroyWindow(WePropertiesWindowList->
Items[i]);
554 return STATUS_SUCCESS;
561 _Out_opt_ LPPROPSHEETPAGE *PropSheetPage,
565 LPPROPSHEETPAGE propSheetPage;
567 if (uMsg == WM_INITDIALOG)
569 propSheetPage = (LPPROPSHEETPAGE)lParam;
571 SetProp(hwndDlg, L
"PropSheetPage", (HANDLE)lParam);
575 propSheetPage = (LPPROPSHEETPAGE)GetProp(hwndDlg, L
"PropSheetPage");
577 if (uMsg == WM_DESTROY)
578 RemoveProp(hwndDlg, L
"PropSheetPage");
585 *PropSheetPage = propSheetPage;
592 static VOID WepEnsureHookDataValid(
596 if (!Context->HookDataValid)
600 HANDLE processHandle;
601 BOOLEAN isWow64 =
FALSE;
605 if (Context->WindowHandle == GetDesktopWindow())
607 Context->HookDataValid =
TRUE;
616 NtClose(processHandle);
625 Context->HookDataSuccess =
FALSE;
633 memcpy(&Context->ClassInfo, &data->
c.
ClassInfo,
sizeof(WNDCLASSEX));
634 Context->HookDataSuccess =
TRUE;
640 Context->HookDataValid =
TRUE;
644 static BOOLEAN NTAPI EnumGenericModulesCallback(
646 _In_opt_ PVOID Context
652 (ULONG64)Module->BaseAddress, Module->Size);
657 static NTSTATUS WepResolveSymbolFunction(
665 PhEnumGenericModules(context->Context->ClientId.UniqueProcess, NULL, 0, EnumGenericModulesCallback, context->Context);
670 context->Context->SymbolProvider,
671 (ULONG64)context->Address,
672 &context->ResolveLevel,
679 if (!context->Symbol)
683 return STATUS_SUCCESS;
687 InsertHeadList(&context->Context->ResolveListHead, &context->ListEntry);
694 return STATUS_SUCCESS;
697 static VOID WepQueueResolveSymbol(
699 _In_ HWND NotifyWindow,
700 _In_ ULONG64 Address,
706 if (!Context->SymbolProvider)
713 resolveContext->Address = Address;
714 resolveContext->Symbol = NULL;
716 resolveContext->NotifyWindow = NotifyWindow;
717 resolveContext->Context = Context;
719 resolveContext->Id = Id;
729 Rect->left, Rect->top, Rect->right, Rect->bottom,
730 Rect->right - Rect->left, Rect->bottom - Rect->top);
733 static VOID WepRefreshWindowGeneralInfoSymbols(
738 if (Context->WndProcResolving != 0)
740 else if (Context->WndProcSymbol)
742 else if (Context->WndProc != 0)
747 if (Context->DlgProcResolving != 0)
749 else if (Context->DlgProcSymbol)
751 else if (Context->DlgProc != 0)
753 else if (Context->WndProc != 0)
759 static VOID WepRefreshWindowGeneralInfo(
766 WINDOWINFO windowInfo = {
sizeof(WINDOWINFO) };
767 WINDOWPLACEMENT windowPlacement = {
sizeof(WINDOWPLACEMENT) };
768 MONITORINFO monitorInfo = {
sizeof(MONITORINFO) };
777 if (GetWindowInfo(Context->WindowHandle, &windowInfo))
788 if (GetWindowPlacement(Context->WindowHandle, &windowPlacement))
791 if (GetMonitorInfo(MonitorFromRect(&windowPlacement.rcNormalPosition, MONITOR_DEFAULTTOPRIMARY), &monitorInfo))
793 windowPlacement.rcNormalPosition.left += monitorInfo.rcWork.left;
794 windowPlacement.rcNormalPosition.top += monitorInfo.rcWork.top;
795 windowPlacement.rcNormalPosition.right += monitorInfo.rcWork.left;
796 windowPlacement.rcNormalPosition.bottom += monitorInfo.rcWork.top;
809 SetDlgItemText(hwndDlg,
IDC_UNICODE, IsWindowUnicode(Context->WindowHandle) ? L
"Yes" : L
"No");
811 WepEnsureHookDataValid(Context);
813 if (Context->WndProc != 0)
815 Context->WndProcResolving++;
816 WepQueueResolveSymbol(Context, hwndDlg, Context->WndProc, 1);
819 if (Context->DlgProc != 0)
821 Context->DlgProcResolving++;
822 WepQueueResolveSymbol(Context, hwndDlg, Context->DlgProc, 2);
825 WepRefreshWindowGeneralInfoSymbols(hwndDlg, Context);
844 WepRefreshWindowGeneralInfo(hwndDlg, context);
849 switch (LOWORD(wParam))
852 context->HookDataValid =
FALSE;
854 WepRefreshWindowGeneralInfo(hwndDlg, context);
863 if (resolveContext->Id == 1)
875 context->WndProcResolving--;
877 else if (resolveContext->Id == 2)
889 context->DlgProcResolving--;
892 WepRefreshWindowGeneralInfoSymbols(hwndDlg, context);
900 static VOID WepRefreshWindowStyles(
905 WINDOWINFO windowInfo = {
sizeof(WINDOWINFO) };
907 HWND extendedStylesListBox;
913 ListBox_ResetContent(stylesListBox);
914 ListBox_ResetContent(extendedStylesListBox);
916 if (GetWindowInfo(Context->WindowHandle, &windowInfo))
923 if (windowInfo.dwStyle & WepStylePairs[i].Integer)
927 if (WepStylePairs[i].Integer == WS_MAXIMIZEBOX ||
928 WepStylePairs[i].Integer == WS_MINIMIZEBOX)
930 if (windowInfo.dwStyle & WS_CHILD)
934 if (WepStylePairs[i].Integer == WS_TABSTOP ||
935 WepStylePairs[i].Integer == WS_GROUP)
937 if (!(windowInfo.dwStyle & WS_CHILD))
941 ListBox_AddString(stylesListBox, WepStylePairs[i].String);
947 if (windowInfo.dwExStyle & WepExtendedStylePairs[i].Integer)
949 ListBox_AddString(extendedStylesListBox, WepExtendedStylePairs[i].String);
976 WepRefreshWindowStyles(hwndDlg, context);
981 switch (LOWORD(wParam))
984 WepRefreshWindowStyles(hwndDlg, context);
994 static VOID WepRefreshWindowClassInfoSymbols(
999 if (Context->ClassWndProcResolving != 0)
1001 else if (Context->ClassWndProcSymbol)
1003 else if (Context->ClassInfo.lpfnWndProc)
1009 static VOID WepRefreshWindowClassInfo(
1014 WCHAR className[256];
1018 if (!GetClassName(Context->WindowHandle, className,
sizeof(className) /
sizeof(WCHAR)))
1021 WepEnsureHookDataValid(Context);
1023 if (!Context->HookDataSuccess)
1025 Context->ClassInfo.cbSize =
sizeof(WNDCLASSEX);
1026 GetClassInfoEx(NULL, className, &Context->ClassInfo);
1029 SetDlgItemText(hwndDlg,
IDC_NAME, className);
1041 if (Context->ClassInfo.style & WepClassStylePairs[i].Integer)
1066 if (Context->ClassInfo.lpfnWndProc)
1068 Context->ClassWndProcResolving++;
1069 WepQueueResolveSymbol(Context, hwndDlg, (ULONG_PTR)Context->ClassInfo.lpfnWndProc, 0);
1072 WepRefreshWindowClassInfoSymbols(hwndDlg, Context);
1091 WepRefreshWindowClassInfo(hwndDlg, context);
1096 switch (LOWORD(wParam))
1099 context->HookDataValid =
FALSE;
1101 WepRefreshWindowClassInfo(hwndDlg, context);
1117 PhMoveReference(&context->ClassWndProcSymbol, resolveContext->Symbol);
1120 context->ClassWndProcResolving--;
1121 WepRefreshWindowClassInfoSymbols(hwndDlg, context);
1129 static BOOL CALLBACK EnumPropsExCallback(
1131 _In_ LPTSTR lpszString,
1133 _In_ ULONG_PTR dwData
1140 propName = lpszString;
1142 if ((ULONG_PTR)lpszString < USHRT_MAX)
1156 static VOID WepRefreshWindowProps(
1158 _In_ HWND ListViewHandle,
1163 ListView_DeleteAllItems(ListViewHandle);
1164 EnumPropsEx(Context->WindowHandle, EnumPropsExCallback, (LPARAM)ListViewHandle);
1187 lvHandle = GetDlgItem(hwndDlg,
IDC_LIST);
1195 WepRefreshWindowProps(hwndDlg, lvHandle, context);
1200 switch (LOWORD(wParam))
1203 WepRefreshWindowProps(hwndDlg, GetDlgItem(hwndDlg,
IDC_LIST), context);