Files

575 lines
14 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* Copyright (c) 2022 Winsider Seminars & Solutions, Inc. All rights reserved.
*
* This file is part of System Informer.
*
* Authors:
*
* wj32 2011-2013
* dmex 2015-2026
*
*/
#ifndef WNDEXP_H
#define WNDEXP_H
#define PH_PROPSHEET_NEW 1
#include <phdk.h>
#include <phapppub.h>
#include <phappresource.h>
#include <settings.h>
#include <searchbox.h>
#include <mapldr.h>
#include "resource.h"
#include "prpsh.h"
#include "wndtree.h"
extern PPH_PLUGIN PluginInstance;
#define PLUGIN_NAME L"WindowExplorer"
#define SETTING_NAME_SHOW_DESKTOP_WINDOWS (PLUGIN_NAME L".ShowDesktopWindows")
#define SETTING_NAME_WINDOW_ENUM_ALTERNATE (PLUGIN_NAME L".EnableAltEnumWindow")
#define SETTING_NAME_WINDOW_ENUM_MESSAGEONLY (PLUGIN_NAME L".EnumMessageOnly")
#define SETTING_NAME_WINDOW_ENUM_NONVISIBLE (PLUGIN_NAME L".EnumNonVisible")
#define SETTING_NAME_WINDOW_HIGHLIGHT_MESSAGEONLY (PLUGIN_NAME L".HighlightMessageOnly")
#define SETTING_NAME_WINDOW_HIGHLIGHT_MESSAGEONLY_COLOR (PLUGIN_NAME L".HighlightMessageOnlyColor")
#define SETTING_NAME_WINDOW_HIGHLIGHT_DEFAULTIME (PLUGIN_NAME L".HighlightDefaultIme")
#define SETTING_NAME_WINDOW_HIGHLIGHT_DEFAULTIME_COLOR (PLUGIN_NAME L".HighlightDefaultImeColor")
#define SETTING_NAME_WINDOW_HIGHLIGHT_LAYERED (PLUGIN_NAME L".HighlightLayered")
#define SETTING_NAME_WINDOW_ENABLE_ICONS (PLUGIN_NAME L".EnableIcons")
#define SETTING_NAME_WINDOW_ENABLE_ICONS_INTERNAL (PLUGIN_NAME L".EnableIconsInternal")
#define SETTING_NAME_WINDOW_FIND_SNAPSHOT (PLUGIN_NAME L".FindWindowSnapshot")
#define SETTING_NAME_WINDOW_TREE_LIST_COLUMNS (PLUGIN_NAME L".WindowTreeListColumns")
#define SETTING_NAME_WINDOWS_WINDOW_POSITION (PLUGIN_NAME L".WindowsWindowPosition")
#define SETTING_NAME_WINDOWS_WINDOW_SIZE (PLUGIN_NAME L".WindowsWindowSize")
#define SETTING_NAME_WINDOWS_PROPERTY_COLUMNS (PLUGIN_NAME L".WindowsPropertyColumns")
#define SETTING_NAME_WINDOWS_PROPERTY_POSITION (PLUGIN_NAME L".WindowsPropertyPosition")
#define SETTING_NAME_WINDOWS_PROPERTY_SIZE (PLUGIN_NAME L".WindowsPropertySize")
#define SETTING_NAME_WINDOWS_PROPERTY_PAGE (PLUGIN_NAME L".WindowsPropertyPage")
#define SETTING_NAME_WINDOWS_PROPLIST_COLUMNS (PLUGIN_NAME L".WindowsPropListColumns")
#define SETTING_NAME_WINDOWS_PROPSTORAGE_COLUMNS (PLUGIN_NAME L".WindowsPropStorageColumns")
#define SETTING_NAME_WINDOWS_DWMATTRIBUTES_COLUMNS (PLUGIN_NAME L".WindowsDwmAttributesColumns")
#define SETTING_NAME_WINDOWS_UIA_COLUMNS (PLUGIN_NAME L".WindowsUiaColumns")
#define SETTING_NAME_WINDOWS_CHILDREN_COLUMNS (PLUGIN_NAME L".WindowsChildrenColumns")
#define SETTING_NAME_APPLICATIONS_TREE_LIST_COLUMNS (PLUGIN_NAME L".ApplicationsTreeListColumns")
#define WE_WM_WINDOWS_UPDATED (WM_APP + 301)
typedef struct _WE_WINDOW_PROVIDER *PWE_WINDOW_PROVIDER;
typedef struct _WINDOWS_CONTEXT
{
HWND WindowHandle;
HWND TreeNewHandle;
HWND SearchBoxHandle;
HFONT TreeWindowFont;
HWND FindWindowButtonHandle;
HWND PauseResumeButtonHandle;
WNDPROC FindWindowButtonWindowProc;
PH_CALLBACK_REGISTRATION WindowNotifyCallbackRegistration;
PH_CALLBACK_REGISTRATION WindowProviderAddedRegistration;
PH_CALLBACK_REGISTRATION WindowProviderModifiedRegistration;
PH_CALLBACK_REGISTRATION WindowProviderRemovedRegistration;
PH_CALLBACK_REGISTRATION WindowProviderUpdatedRegistration;
WE_WINDOW_TREE_CONTEXT TreeContext;
WE_WINDOW_SELECTOR Selector;
PH_LAYOUT_MANAGER LayoutManager;
HWND HighlightingWindow;
ULONG HighlightingWindowCount;
HWND HighlightingOverlayWindow;
BOOLEAN HighlightingOverlay;
BOOLEAN TargetingWindow;
BOOLEAN TargetingCurrentWindowDraw;
BOOLEAN TargetingCompleted;
HWND TargetingCurrentWindow;
PVOID UIAutomationPtr;
COLORREF ColorNew;
COLORREF ColorRemoved;
ULONG HighlightingDuration;
BOOLEAN NodesNeedRestructure;
ULONG WindowProviderRunCount;
PWE_WINDOW_PROVIDER WindowProvider;
PH_PROVIDER_THREAD ProviderThread;
PH_PROVIDER_REGISTRATION ProviderRegistration;
PH_PROVIDER_EVENT_QUEUE EventQueue;
BOOLEAN ProviderPaused;
} WINDOWS_CONTEXT, *PWINDOWS_CONTEXT;
// wnddlg
VOID WepFillWindowInfo(
_In_ PWE_WINDOW_TREE_CONTEXT Context,
_In_ PWE_WINDOW_NODE Node
);
PWE_WINDOW_NODE WepAddChildWindowNode(
_In_ PWE_WINDOW_TREE_CONTEXT Context,
_In_opt_ PWE_WINDOW_NODE ParentNode,
_In_ HWND WindowHandle
);
VOID WepAddEnumWindowsByViewMode(
_In_ PWINDOWS_CONTEXT Context
);
VOID WepInsertWindowNodeByZOrder(
_In_ PWE_WINDOW_TREE_CONTEXT Context,
_In_opt_ PWE_WINDOW_NODE ParentNode,
_In_ PWE_WINDOW_NODE WindowNode
);
VOID WepEnumerateParentChildWindows(
_In_ PWINDOWS_CONTEXT Context,
_In_opt_ HANDLE FilterProcessId,
_In_opt_ HANDLE FilterThreadId
);
VOID WepEnumerateZOrderWindows(
_In_ PWINDOWS_CONTEXT Context,
_In_opt_ HANDLE FilterProcessId,
_In_opt_ HANDLE FilterThreadId
);
VOID WepEnumerateOwnerChainWindows(
_In_ PWINDOWS_CONTEXT Context,
_In_opt_ HANDLE FilterProcessId,
_In_opt_ HANDLE FilterThreadId
);
VOID WeShowWindowsDialog(
_In_ HWND ParentWindowHandle,
_In_ PWE_WINDOW_SELECTOR Selector
);
VOID WeShowWindowsPropPage(
_In_ PPH_PLUGIN_PROCESS_PROPCONTEXT Context,
_In_ PWE_WINDOW_SELECTOR Selector
);
// wndprp
typedef struct _WINDOW_PROPERTIES_CONTEXT
{
HWND WindowHandle;
HWND ParentWindowHandle;
HWND PropertySheetHandle;
HWND OptionsButtonHandle;
WNDPROC PropertySheetWindowProcedure;
HFONT TreeWindowFont;
HICON WindowIcon;
ULONG PropsListCount;
HWND HighlightingWindow;
ULONG HighlightingWindowCount;
HWND HighlightingOverlayWindow;
BOOLEAN HighlightingOverlay;
CLIENT_ID ClientId;
PH_INITONCE SymbolProviderInitOnce;
PPH_SYMBOL_PROVIDER SymbolProvider;
LIST_ENTRY ResolveListHead;
PH_QUEUED_LOCK ResolveListLock;
PPH_STRING WndProcSymbol;
ULONG WndProcResolving;
PPH_STRING DlgProcSymbol;
ULONG DlgProcResolving;
PPH_STRING ClassWndProcSymbol;
ULONG ClassWndProcResolving;
ULONG_PTR WndProc;
ULONG_PTR DlgProc;
RTL_ATOM ClassAtom;
WNDCLASSEX ClassInfo;
LONG PreviewScrollX;
LONG PreviewScrollY;
LONG PreviewImageWidth;
LONG PreviewImageHeight;
HANDLE DxSharedSurface;
LUID DxAdapterLuid;
ULONG DxgiFormat;
UINT64 DxUpdateId;
BOOL DxSurfaceValid;
} WINDOW_PROPERTIES_CONTEXT, *PWINDOW_PROPERTIES_CONTEXT;
BOOLEAN WeShowWindowProperties(
_In_ HWND ParentWindowHandle,
_In_ HWND WindowHandle
);
PPH_EMENU WepCreateWindowMenu(
_In_ PPH_EMENU WindowMenu,
_In_ BOOLEAN IncludeProperties,
_In_ BOOLEAN IncludeCopy
);
VOID WepSetWindowMenuState(
_In_ PPH_EMENU WindowMenu,
_In_ HWND WindowHandle
);
BOOLEAN WepExecuteWindowCommand(
_In_ HWND ParentWindowHandle,
_In_ HWND WindowHandle,
_In_ ULONG CommandId
);
// utils
typedef struct _WINDOWCOMPOSITIONATTRIBUTEDATA WINDOWCOMPOSITIONATTRIBDATA;
typedef ULONG (WINAPI *PFN_GetWindowBand)(
_In_ HWND WindowHandle
);
typedef BOOL (WINAPI *PFN_IsShellManagedWindow)(
_In_ HWND WindowHandle
);
typedef BOOL (WINAPI *PFN_GetWindowCompositionAttribute)(
_In_ HWND WindowHandle,
_Inout_ WINDOWCOMPOSITIONATTRIBDATA *Data
);
typedef BOOL (WINAPI *PFN_IsShellFrameWindow)(
_In_ HWND WindowHandle
);
typedef BOOL (WINAPI *PFN_GetModernAppWindow)(
_In_ HANDLE ProcessHandle,
_Out_ HWND *WindowHandle
);
NTSTATUS WeWindowEndTask(
_In_ HWND WindowHandle,
_In_ BOOL Force
);
VOID WeSetWindowToDpiForTesting(
_In_ HWND WindowHandle,
_In_ LONG WindowDPI
);
NTSTATUS WeDestroyRemoteWindow(
_In_ HWND TargetWindow,
_In_ HANDLE ProcessId
);
BOOL WeIsTopLevelWindow(
_In_ HWND WindowHandle
);
BOOL WeIsInDesktopWindowBand(
_In_ HWND WindowHandle
);
HICON WeGetInternalWindowIcon(
_In_ HWND WindowHandle,
_In_ UINT IconType
);
HICON WeGetWindowIcon(
_In_ HWND WindowHandle
);
PPH_STRING WeHashWindowExtraBytes(
_In_ HWND WindowHandle
);
BOOLEAN WeWindowHasAutomationProvider(
_In_ HWND WindowHandle
);
BOOLEAN WeIsWindowCloaked(
_In_ HWND WindowHandle
);
ULONG WeGetWindowBand(
_In_ HWND WindowHandle
);
BOOLEAN WeIsWindowEffectivelyVisible(
_In_ HWND WindowHandle
);
VOID WeDrawWindowBorderForTargeting(
_In_ HWND WindowHandle
);
VOID WeInvertWindowBorder(
_In_ HWND hWnd
);
VOID WeShowWindowHighlightOverlay(
_Inout_ HWND *OverlayWindow,
_In_ HWND TargetWindow
);
VOID WeHideWindowHighlightOverlay(
_Inout_ HWND *OverlayWindow
);
VOID WeStartWindowHighlight(
_Inout_ HWND *OverlayWindow,
_Inout_ HWND *HighlightingWindow,
_Inout_ PULONG HighlightingWindowCount,
_Inout_ PBOOLEAN HighlightingOverlay,
_In_ HWND TargetWindow
);
BOOLEAN WeUpdateWindowHighlight(
_Inout_ HWND *OverlayWindow,
_Inout_ HWND *HighlightingWindow,
_Inout_ PULONG HighlightingWindowCount,
_Inout_ PBOOLEAN HighlightingOverlay
);
VOID WeStopWindowHighlight(
_Inout_ HWND *OverlayWindow,
_Inout_ HWND *HighlightingWindow,
_Inout_ PULONG HighlightingWindowCount,
_Inout_ PBOOLEAN HighlightingOverlay
);
NTSTATUS CallerIdentityIsHostedWindow(
_In_ HWND WindowHandle,
_Out_ PULONG IsHosted
);
// apptab
VOID WeInitializeApplicationsTab(
VOID
);
typedef enum _WE_WINDOW_SUBGROUP
{
WeWindowSubgroupNone = 0,
WeWindowSubgroupStandard = 4,
WeWindowSubgroupShell = 8,
WeWindowSubgroupSystem = 0x400000,
WeWindowSubgroupUnknown = 0x8000000
} WE_WINDOW_SUBGROUP;
typedef struct _WE_APPLICATION_INFO
{
PPH_STRING ExistingDisplayName;
PPH_STRING RelaunchDisplayName;
} WE_APPLICATION_INFO, *PWE_APPLICATION_INFO;
NTSTATUS WeEnumerateWindowTabs(
_In_ HWND WindowHandle,
_Out_ PPH_LIST *WindowList
);
WE_WINDOW_SUBGROUP WeDetermineWindowSubgroup(
_In_ HWND WindowHandle,
_Out_ HWND *ResolvedWindow
);
NTSTATUS WeDetermineDllhostProcessNameFromWindow(
_In_ HWND WindowHandle,
_Inout_ PWE_APPLICATION_INFO AppInfo
);
// wndprv.c
typedef struct _WE_WINDOW_ITEM
{
HWND WindowHandle;
HWND ParentHandle;
PPH_STRING WindowText;
CLIENT_ID ClientId;
BOOLEAN WindowVisible;
BOOLEAN WindowMessageOnly;
BOOLEAN WindowDefaultIme;
USHORT WindowIndex;
USHORT WindowGeneration;
PPH_STRING WindowClassText;
} WE_WINDOW_ITEM, *PWE_WINDOW_ITEM;
typedef struct _WE_WINDOW_PROVIDER
{
PPH_HASHTABLE WindowHashtable;
PH_QUEUED_LOCK WindowHashtableLock;
PH_CALLBACK WindowAddedEvent;
PH_CALLBACK WindowModifiedEvent;
PH_CALLBACK WindowRemovedEvent;
PH_CALLBACK WindowUpdatedEvent;
} WE_WINDOW_PROVIDER, *PWE_WINDOW_PROVIDER;
PWE_WINDOW_PROVIDER WeCreateWindowProvider(
VOID
);
VOID WeDeleteWindowProvider(
_In_ PWE_WINDOW_PROVIDER Provider
);
PWE_WINDOW_ITEM WeCreateWindowItem(
_In_ HWND WindowHandle
);
VOID WeDeleteWindowItem(
_In_ PWE_WINDOW_ITEM WindowItem
);
PWE_WINDOW_ITEM WeReferenceWindowItem(
_In_ PWE_WINDOW_PROVIDER Provider,
_In_ HWND WindowHandle
);
VOID WeEnumWindowItems(
_In_ PWE_WINDOW_PROVIDER Provider,
_Out_opt_ PWE_WINDOW_ITEM **WindowItems,
_Out_ PULONG NumberOfWindowItems
);
_Function_class_(PH_PROVIDER_FUNCTION)
VOID WeWindowProviderUpdate(
_In_ PVOID Object
);
// wndprop.c - Window Property Wrapper Functions
typedef struct _WE_PROPERTY_INFO
{
PPH_STRING Name;
HANDLE Value;
BOOLEAN IsAtom;
USHORT AtomValue;
PVOID TypeInfo; // For future extension
} WE_PROPERTY_INFO, *PWE_PROPERTY_INFO;
typedef struct _WE_PROPERTY_STATISTICS
{
ULONG TotalProperties;
ULONG StringProperties;
ULONG AtomProperties;
ULONG UxthemeProperties;
SIZE_T TotalMemoryUsed;
ULONG MaxPropertyNameLength;
} WE_PROPERTY_STATISTICS, *PWE_PROPERTY_STATISTICS;
// Uxtheme atom values based on analysis
// uxtheme.dll uses predefined atoms in the range 0xA910–0xA922
// for theme state management window properties
typedef enum _WE_UXTHEME_ATOM
{
WeUxthemeAtomThemeWnd = 0xA910, // Theme window object
WeUxthemeAtomThemeMetrics = 0xA914, // Theme metrics object
WeUxthemeAtomCShakeWnd = 0xA91A, // CShakeWnd object
WeUxthemeAtomCThemeWnd = 0xA91C, // CThemeWnd object
WeUxthemeAtomThemeProps = 0xA922, // Theme properties object
// Additional uxtheme atoms in the 0xA910–0xA922 range
WeUxthemeAtomMin = 0xA910,
WeUxthemeAtomMax = 0xA922
} WE_UXTHEME_ATOM;
// Basic Property Access Wrappers
HANDLE WeGetWindowProperty(
_In_ HWND WindowHandle,
_In_ PCWSTR PropertyNameOrAtom
);
BOOL WeSetWindowProperty(
_In_ HWND WindowHandle,
_In_ PCWSTR PropertyNameOrAtom,
_In_ HANDLE PropertyValue
);
HANDLE WeRemoveWindowProperty(
_In_ HWND WindowHandle,
_In_ PCWSTR PropertyNameOrAtom
);
// Enhanced Property Information Functions
NTSTATUS WeGetWindowPropertyInfo(
_In_ HWND WindowHandle,
_In_ PCWSTR PropertyNameOrAtom,
_Out_opt_ PPH_STRING *PropertyName,
_Out_opt_ PHANDLE PropertyValue,
_Out_opt_ PBOOLEAN IsAtom,
_Out_opt_ PUSHORT AtomValue
);
// Property enumeration callback type
typedef BOOL (CALLBACK *WE_PROPSENUMPROC)(
_In_ HWND WindowHandle,
_In_ PCWSTR PropertyName,
_In_ HANDLE PropertyValue,
_In_ BOOLEAN IsAtom,
_In_ USHORT AtomValue,
_In_opt_ PVOID Context
);
NTSTATUS WeEnumWindowProperties(
_In_ HWND WindowHandle,
_In_ WE_PROPSENUMPROC Callback,
_In_opt_ PVOID Context
);
// Uxtheme-specific Functions
NTSTATUS WeGetUxthemeProperty(
_In_ HWND WindowHandle,
_In_ WE_UXTHEME_ATOM Atom,
_Out_opt_ PPH_STRING *ObjectType,
_Out_opt_ PHANDLE PropertyValue
);
BOOLEAN WeWindowHasUxthemeProperties(
_In_ HWND WindowHandle
);
// Property Analysis Functions
NTSTATUS WeAnalyzeWindowProperties(
_In_ HWND WindowHandle,
_Out_ PPH_LIST *PropertyList,
_Out_opt_ PULONG UxthemePropertyCount,
_Out_opt_ PULONG StringPropertyCount,
_Out_opt_ PULONG AtomPropertyCount
);
NTSTATUS WeGetWindowPropertyStatistics(
_In_ HWND WindowHandle,
_Out_ PWE_PROPERTY_STATISTICS Statistics
);
// Utility Functions
BOOLEAN WeIsPropertyAtom(
_In_ PCWSTR PropertyNameOrAtom,
_Out_opt_ PUSHORT AtomValue
);
PPH_STRING WeFormatAtomString(
_In_ USHORT AtomValue
);
PPH_STRING WeGetUxthemeAtomName(
_In_ WE_UXTHEME_ATOM Atom
);
#endif