// ==WindhawkMod== // @id explorer-group-counters-diagnostic // @name Explorer Group Counters - Diagnostic // @description Diagnoses Explorer folder grouping through IFolderView2 and UI Automation // @version 2.21 // @author Custom // @include explorer.exe // @compilerOptions -lole32 -loleaut32 -luuid -lpropsys -luiautomationcore // ==/WindhawkMod== #include #include #include #include #include #include #include #include #include static void LogHresult(const wchar_t* label, HRESULT hr) { Wh_Log(L"%s: HRESULT=0x%08X", label, (unsigned int)hr); } static const wchar_t* GetGroupingRangeName(PROPDESC_GROUPING_RANGE range) { switch (range) { case PDGR_DISCRETE: return L"DISCRETE"; case PDGR_ALPHANUMERIC: return L"ALPHANUMERIC"; case PDGR_SIZE: return L"SIZE"; case PDGR_DYNAMIC: return L"DYNAMIC"; case PDGR_DATE: return L"DATE"; case PDGR_PERCENT: return L"PERCENT"; case PDGR_ENUMERATED: return L"ENUMERATED"; default: return L"UNKNOWN"; } } static void InspectPropertyGroupingRange(const PROPERTYKEY& groupKey) { Wh_Log(L"---------- PROPERTY GROUPING DESCRIPTION ----------"); IPropertyDescription* propertyDescription = nullptr; HRESULT hr = PSGetPropertyDescription( groupKey, IID_PPV_ARGS(&propertyDescription) ); if (FAILED(hr) || !propertyDescription) { LogHresult(L"PSGetPropertyDescription", hr); return; } LPWSTR canonicalName = nullptr; hr = propertyDescription->GetCanonicalName(&canonicalName); if (SUCCEEDED(hr) && canonicalName) { Wh_Log(L"Property canonical name: %s", canonicalName); CoTaskMemFree(canonicalName); } else { LogHresult(L"IPropertyDescription::GetCanonicalName", hr); } PROPDESC_GROUPING_RANGE groupingRange = PDGR_DISCRETE; hr = propertyDescription->GetGroupingRange(&groupingRange); if (SUCCEEDED(hr)) { Wh_Log( L"Property grouping range: %s (%d)", GetGroupingRangeName(groupingRange), (int)groupingRange ); } else { LogHresult(L"IPropertyDescription::GetGroupingRange", hr); } propertyDescription->Release(); Wh_Log(L"----------------------------------------------------"); } static void InspectPropertyFormattedValue( const PROPERTYKEY& groupKey, const PROPVARIANT& value, int itemIndex) { LPWSTR displayValue = nullptr; HRESULT hr = PSFormatForDisplayAlloc( groupKey, value, PDFF_DEFAULT, &displayValue ); if (SUCCEEDED(hr) && displayValue) { Wh_Log( L"Item %d: Formatted group value = \"%s\"", itemIndex, displayValue ); CoTaskMemFree(displayValue); } else { Wh_Log( L"Item %d: PSFormatForDisplayAlloc failed: 0x%08X", itemIndex, (unsigned int)hr ); } } static HWND FindDescendantWindowByClass(HWND parent, const wchar_t* className) { HWND child = FindWindowExW(parent, nullptr, nullptr, nullptr); while (child) { wchar_t currentClass[128] = {}; GetClassNameW(child, currentClass, ARRAYSIZE(currentClass)); if (wcscmp(currentClass, className) == 0) return child; HWND result = FindDescendantWindowByClass(child, className); if (result) return result; child = FindWindowExW(parent, child, nullptr, nullptr); } return nullptr; } static const wchar_t* GetUIAControlTypeName(int controlType) { switch (controlType) { case UIA_ButtonControlTypeId: return L"Button"; case UIA_CalendarControlTypeId: return L"Calendar"; case UIA_CheckBoxControlTypeId: return L"CheckBox"; case UIA_ComboBoxControlTypeId: return L"ComboBox"; case UIA_EditControlTypeId: return L"Edit"; case UIA_HyperlinkControlTypeId: return L"Hyperlink"; case UIA_ImageControlTypeId: return L"Image"; case UIA_ListControlTypeId: return L"List"; case UIA_ListItemControlTypeId: return L"ListItem"; case UIA_MenuControlTypeId: return L"Menu"; case UIA_MenuItemControlTypeId: return L"MenuItem"; case UIA_TextControlTypeId: return L"Text"; case UIA_TreeControlTypeId: return L"Tree"; case UIA_TreeItemControlTypeId: return L"TreeItem"; case UIA_CustomControlTypeId: return L"Custom"; case UIA_GroupControlTypeId: return L"Group"; case UIA_DataGridControlTypeId: return L"DataGrid"; case UIA_DataItemControlTypeId: return L"DataItem"; case UIA_WindowControlTypeId: return L"Window"; case UIA_PaneControlTypeId: return L"Pane"; case UIA_HeaderControlTypeId: return L"Header"; case UIA_HeaderItemControlTypeId: return L"HeaderItem"; case UIA_TableControlTypeId: return L"Table"; case UIA_TitleBarControlTypeId: return L"TitleBar"; case UIA_SeparatorControlTypeId: return L"Separator"; case UIA_StatusBarControlTypeId: return L"StatusBar"; case UIA_ToolBarControlTypeId: return L"ToolBar"; default: return L"Unknown"; } } static void InspectUIAElement(IUIAutomationElement* element, int index) { if (!element) return; int controlType = 0; BSTR name = nullptr; BSTR automationId = nullptr; BSTR className = nullptr; HRESULT hr = element->get_CurrentControlType(&controlType); if (FAILED(hr)) LogHresult(L"IUIAutomationElement::get_CurrentControlType", hr); element->get_CurrentName(&name); element->get_CurrentAutomationId(&automationId); element->get_CurrentClassName(&className); Wh_Log( L"UIA[%d]: Type=%d (%s) Name=\"%s\" AutomationId=\"%s\" ClassName=\"%s\"", index, controlType, GetUIAControlTypeName(controlType), name ? name : L"", automationId ? automationId : L"", className ? className : L""); if (name) SysFreeString(name); if (automationId) SysFreeString(automationId); if (className) SysFreeString(className); } static void InspectUIAGroupHeader( IUIAutomationElement* headerElement) { if (!headerElement) return; BSTR name = nullptr; BSTR automationId = nullptr; BSTR className = nullptr; BOOL isEnabled = FALSE; UIA_HWND nativeWindowHandle = nullptr; headerElement->get_CurrentName(&name); headerElement->get_CurrentAutomationId(&automationId); headerElement->get_CurrentClassName(&className); headerElement->get_CurrentIsEnabled(&isEnabled); headerElement->get_CurrentNativeWindowHandle(&nativeWindowHandle); Wh_Log( L"========== UIA GROUP HEADER INSPECTION: Name=\"%s\" AutomationId=\"%s\" ClassName=\"%s\" ==========", name ? name : L"", automationId ? automationId : L"", className ? className : L""); Wh_Log( L"Header state: IsEnabled=%d NativeWindowHandle=%p", isEnabled, nativeWindowHandle); IUIAutomationValuePattern* valuePattern = nullptr; HRESULT hr = headerElement->GetCurrentPattern( UIA_ValuePatternId, reinterpret_cast(&valuePattern)); if (SUCCEEDED(hr) && valuePattern) { BSTR value = nullptr; BOOL isReadOnly = FALSE; HRESULT valueHr = valuePattern->get_CurrentValue(&value); HRESULT readOnlyHr = valuePattern->get_CurrentIsReadOnly(&isReadOnly); if (SUCCEEDED(valueHr)) { Wh_Log( L"Header ValuePattern: SUPPORTED, CurrentValue=\"%s\"", value ? value : L""); } else { LogHresult( L"Header ValuePattern::get_CurrentValue", valueHr); } if (SUCCEEDED(readOnlyHr)) { Wh_Log( L"Header ValuePattern: CurrentIsReadOnly=%d", isReadOnly); } else { LogHresult( L"Header ValuePattern::get_CurrentIsReadOnly", readOnlyHr); } if (value) SysFreeString(value); valuePattern->Release(); } else { Wh_Log( L"Header ValuePattern: NOT SUPPORTED (HRESULT=0x%08X)", (unsigned int)hr); } IUIAutomationLegacyIAccessiblePattern* legacyPattern = nullptr; hr = headerElement->GetCurrentPattern( UIA_LegacyIAccessiblePatternId, reinterpret_cast(&legacyPattern)); if (SUCCEEDED(hr) && legacyPattern) { BSTR legacyName = nullptr; BSTR legacyValue = nullptr; BSTR legacyDefaultAction = nullptr; BSTR legacyKeyboardShortcut = nullptr; int legacyChildId = 0; DWORD legacyRole = 0; DWORD legacyState = 0; HRESULT nameHr = legacyPattern->get_CurrentName(&legacyName); HRESULT valueHr = legacyPattern->get_CurrentValue(&legacyValue); HRESULT childIdHr = legacyPattern->get_CurrentChildId(&legacyChildId); HRESULT roleHr = legacyPattern->get_CurrentRole(&legacyRole); HRESULT stateHr = legacyPattern->get_CurrentState(&legacyState); HRESULT actionHr = legacyPattern->get_CurrentDefaultAction(&legacyDefaultAction); HRESULT shortcutHr = legacyPattern->get_CurrentKeyboardShortcut(&legacyKeyboardShortcut); if (SUCCEEDED(nameHr)) { Wh_Log( L"Header LegacyIAccessible Name=\"%s\"", legacyName ? legacyName : L""); } else { LogHresult( L"Header LegacyIAccessible::get_CurrentName", nameHr); } if (SUCCEEDED(valueHr)) { Wh_Log( L"Header LegacyIAccessible Value=\"%s\"", legacyValue ? legacyValue : L""); } else { LogHresult( L"Header LegacyIAccessible::get_CurrentValue", valueHr); } if (SUCCEEDED(childIdHr)) { Wh_Log( L"Header LegacyIAccessible ChildId=%d", legacyChildId); } else { LogHresult( L"Header LegacyIAccessible::get_CurrentChildId", childIdHr); } if (SUCCEEDED(roleHr)) { Wh_Log( L"Header LegacyIAccessible Role=%d", legacyRole); } else { LogHresult( L"Header LegacyIAccessible::get_CurrentRole", roleHr); } if (SUCCEEDED(stateHr)) { Wh_Log( L"Header LegacyIAccessible State=0x%08X", (unsigned int)legacyState); } else { LogHresult( L"Header LegacyIAccessible::get_CurrentState", stateHr); } if (SUCCEEDED(actionHr)) { Wh_Log( L"Header LegacyIAccessible DefaultAction=\"%s\"", legacyDefaultAction ? legacyDefaultAction : L""); } else { LogHresult( L"Header LegacyIAccessible::get_CurrentDefaultAction", actionHr); } if (SUCCEEDED(shortcutHr)) { Wh_Log( L"Header LegacyIAccessible KeyboardShortcut=\"%s\"", legacyKeyboardShortcut ? legacyKeyboardShortcut : L""); } else { LogHresult( L"Header LegacyIAccessible::get_CurrentKeyboardShortcut", shortcutHr); } // Probe SetValue non-destructively by writing the value that is // already exposed by the header (currently expected to be empty). HRESULT setValueHr = legacyPattern->SetValue( legacyValue ? legacyValue : L""); LogHresult( L"Header LegacyIAccessible::SetValue(current value)", setValueHr); if (legacyName) SysFreeString(legacyName); if (legacyValue) SysFreeString(legacyValue); if (legacyDefaultAction) SysFreeString(legacyDefaultAction); if (legacyKeyboardShortcut) SysFreeString(legacyKeyboardShortcut); legacyPattern->Release(); } else { Wh_Log( L"Header LegacyIAccessiblePattern: NOT SUPPORTED (HRESULT=0x%08X)", (unsigned int)hr); } IUIAutomationTextPattern* textPattern = nullptr; hr = headerElement->GetCurrentPattern( UIA_TextPatternId, reinterpret_cast(&textPattern)); if (SUCCEEDED(hr) && textPattern) { Wh_Log(L"Header TextPattern: SUPPORTED"); IUIAutomationTextRange* documentRange = nullptr; HRESULT rangeHr = textPattern->get_DocumentRange(&documentRange); if (SUCCEEDED(rangeHr) && documentRange) { BSTR rangeText = nullptr; HRESULT textHr = documentRange->GetText(-1, &rangeText); if (SUCCEEDED(textHr)) { Wh_Log( L"Header TextPattern DocumentRange text=\"%s\"", rangeText ? rangeText : L""); } else { LogHresult( L"Header TextRange::GetText", textHr); } if (rangeText) SysFreeString(rangeText); documentRange->Release(); } else { LogHresult( L"Header TextPattern::get_DocumentRange", rangeHr); } textPattern->Release(); } else { Wh_Log( L"Header TextPattern: NOT SUPPORTED (HRESULT=0x%08X)", (unsigned int)hr); } if (name) SysFreeString(name); if (automationId) SysFreeString(automationId); if (className) SysFreeString(className); Wh_Log(L"--------------------------------------------------------------------------"); } static void InspectUIAPropertyInternals( IUIAutomationElement* propertyElement) { if (!propertyElement) return; Wh_Log( L"========== UIA PROPERTY INTERNALS =========="); int processId = 0; int controlType = 0; BOOL isOffscreen = FALSE; BOOL hasKeyboardFocus = FALSE; BOOL isKeyboardFocusable = FALSE; HRESULT hr = propertyElement->get_CurrentProcessId(&processId); if (SUCCEEDED(hr)) { Wh_Log(L"Property ProcessId=%d", processId); } else { LogHresult( L"UIProperty::get_CurrentProcessId", hr); } hr = propertyElement->get_CurrentControlType(&controlType); if (SUCCEEDED(hr)) { Wh_Log( L"Property ControlType=%d (%s)", controlType, GetUIAControlTypeName(controlType)); } else { LogHresult( L"UIProperty::get_CurrentControlType", hr); } BSTR frameworkId = nullptr; hr = propertyElement->get_CurrentFrameworkId(&frameworkId); if (SUCCEEDED(hr)) { Wh_Log( L"Property FrameworkId=\"%s\"", frameworkId ? frameworkId : L""); } else { LogHresult( L"UIProperty::get_CurrentFrameworkId", hr); } BSTR providerDescription = nullptr; hr = propertyElement->get_CurrentProviderDescription( &providerDescription); if (SUCCEEDED(hr)) { Wh_Log( L"Property ProviderDescription=\"%s\"", providerDescription ? providerDescription : L""); } else { LogHresult( L"UIProperty::get_CurrentProviderDescription", hr); } hr = propertyElement->get_CurrentIsOffscreen(&isOffscreen); if (SUCCEEDED(hr)) { Wh_Log( L"Property IsOffscreen=%d", isOffscreen); } else { LogHresult( L"UIProperty::get_CurrentIsOffscreen", hr); } hr = propertyElement->get_CurrentHasKeyboardFocus( &hasKeyboardFocus); if (SUCCEEDED(hr)) { Wh_Log( L"Property HasKeyboardFocus=%d", hasKeyboardFocus); } else { LogHresult( L"UIProperty::get_CurrentHasKeyboardFocus", hr); } hr = propertyElement->get_CurrentIsKeyboardFocusable( &isKeyboardFocusable); if (SUCCEEDED(hr)) { Wh_Log( L"Property IsKeyboardFocusable=%d", isKeyboardFocusable); } else { LogHresult( L"UIProperty::get_CurrentIsKeyboardFocusable", hr); } RECT boundingRectangle = {}; hr = propertyElement->get_CurrentBoundingRectangle( &boundingRectangle); if (SUCCEEDED(hr)) { Wh_Log( L"Property BoundingRectangle: left=%ld top=%ld right=%ld bottom=%ld", boundingRectangle.left, boundingRectangle.top, boundingRectangle.right, boundingRectangle.bottom); } else { LogHresult( L"UIProperty::get_CurrentBoundingRectangle", hr); } struct PatternInfo { int id; const wchar_t* name; }; const PatternInfo patterns[] = { {UIA_InvokePatternId, L"Invoke"}, {UIA_SelectionPatternId, L"Selection"}, {UIA_ValuePatternId, L"Value"}, {UIA_RangeValuePatternId, L"RangeValue"}, {UIA_ScrollPatternId, L"Scroll"}, {UIA_ExpandCollapsePatternId, L"ExpandCollapse"}, {UIA_GridPatternId, L"Grid"}, {UIA_GridItemPatternId, L"GridItem"}, {UIA_MultipleViewPatternId, L"MultipleView"}, {UIA_WindowPatternId, L"Window"}, {UIA_SelectionItemPatternId, L"SelectionItem"}, {UIA_DockPatternId, L"Dock"}, {UIA_TablePatternId, L"Table"}, {UIA_TableItemPatternId, L"TableItem"}, {UIA_TextPatternId, L"Text"}, {UIA_TogglePatternId, L"Toggle"}, {UIA_TransformPatternId, L"Transform"}, {UIA_ScrollItemPatternId, L"ScrollItem"}, {UIA_LegacyIAccessiblePatternId, L"LegacyIAccessible"}, {UIA_ItemContainerPatternId, L"ItemContainer"}, {UIA_VirtualizedItemPatternId, L"VirtualizedItem"}, {UIA_SynchronizedInputPatternId, L"SynchronizedInput"}, {UIA_ObjectModelPatternId, L"ObjectModel"}, {UIA_AnnotationPatternId, L"Annotation"}, {UIA_TextPattern2Id, L"Text2"}, {UIA_StylesPatternId, L"Styles"}, {UIA_SpreadsheetPatternId, L"Spreadsheet"}, {UIA_SpreadsheetItemPatternId, L"SpreadsheetItem"}, {UIA_TextChildPatternId, L"TextChild"}, {UIA_DragPatternId, L"Drag"}, {UIA_DropTargetPatternId, L"DropTarget"}, {UIA_TextEditPatternId, L"TextEdit"}, {UIA_CustomNavigationPatternId, L"CustomNavigation"} }; int supportedPatternCount = 0; for (size_t i = 0; i < sizeof(patterns) / sizeof(patterns[0]); i++) { IUnknown* patternObject = nullptr; HRESULT patternHr = propertyElement->GetCurrentPattern( patterns[i].id, &patternObject); if (SUCCEEDED(patternHr) && patternObject) { supportedPatternCount++; Wh_Log( L"Property Pattern: ID=%d Name=%s SUPPORTED", patterns[i].id, patterns[i].name); patternObject->Release(); } else { Wh_Log( L"Property Pattern: ID=%d Name=%s not supported (HRESULT=0x%08X)", patterns[i].id, patterns[i].name, patternHr); } } Wh_Log( L"Property SupportedPatterns: %d of %d tested", supportedPatternCount, (int)(sizeof(patterns) / sizeof(patterns[0]))); // Probe the UIA ValuePattern on read-only properties by writing // back exactly the value currently exposed by Explorer. This does // not request a different value; the purpose is only to determine // whether the provider accepts or rejects the ValuePattern write. BOOL isReadOnly = FALSE; IUIAutomationValuePattern* valuePattern = nullptr; HRESULT valuePatternHr = propertyElement->GetCurrentPattern( UIA_ValuePatternId, reinterpret_cast(&valuePattern)); if (SUCCEEDED(valuePatternHr) && valuePattern) { HRESULT readOnlyHr = valuePattern->get_CurrentIsReadOnly(&isReadOnly); if (SUCCEEDED(readOnlyHr)) { Wh_Log( L"Property ValuePattern write probe: IsReadOnly=%d", isReadOnly); if (isReadOnly) { BSTR currentValue = nullptr; HRESULT currentValueHr = valuePattern->get_CurrentValue(¤tValue); if (SUCCEEDED(currentValueHr) && currentValue) { Wh_Log( L"Property ValuePattern write probe: attempting SetValue(current value=\"%s\")", currentValue); HRESULT setValueHr = valuePattern->SetValue(currentValue); LogHresult( L"Property ValuePattern::SetValue(current value)", setValueHr); SysFreeString(currentValue); } else { LogHresult( L"Property ValuePattern::get_CurrentValue for write probe", currentValueHr); } } } else { LogHresult( L"Property ValuePattern::get_CurrentIsReadOnly for write probe", readOnlyHr); } valuePattern->Release(); } else { LogHresult( L"Property ValuePattern for write probe", valuePatternHr); } if (frameworkId) SysFreeString(frameworkId); if (providerDescription) SysFreeString(providerDescription); Wh_Log(L"----------------------------------------------"); } static void InspectUIAProperty( IUIAutomationElement* propertyElement) { if (!propertyElement) return; BSTR name = nullptr; BSTR automationId = nullptr; BSTR className = nullptr; BOOL isEnabled = FALSE; propertyElement->get_CurrentName(&name); propertyElement->get_CurrentAutomationId(&automationId); propertyElement->get_CurrentClassName(&className); propertyElement->get_CurrentIsEnabled(&isEnabled); Wh_Log( L"========== UIA PROPERTY INSPECTION: Name=\"%s\" AutomationId=\"%s\" ClassName=\"%s\" ==========", name ? name : L"", automationId ? automationId : L"", className ? className : L""); Wh_Log( L"Property state: IsEnabled=%d", isEnabled); IUIAutomationValuePattern* valuePattern = nullptr; HRESULT hr = propertyElement->GetCurrentPattern( UIA_ValuePatternId, reinterpret_cast(&valuePattern)); if (SUCCEEDED(hr) && valuePattern) { BSTR value = nullptr; BOOL isReadOnly = FALSE; HRESULT valueHr = valuePattern->get_CurrentValue(&value); HRESULT readOnlyHr = valuePattern->get_CurrentIsReadOnly(&isReadOnly); if (SUCCEEDED(valueHr)) { Wh_Log( L"Property ValuePattern: SUPPORTED, CurrentValue=\"%s\"", value ? value : L""); } else { LogHresult( L"Property ValuePattern::get_CurrentValue", valueHr); } if (SUCCEEDED(readOnlyHr)) { Wh_Log( L"Property ValuePattern: CurrentIsReadOnly=%d", isReadOnly); } else { LogHresult( L"Property ValuePattern::get_CurrentIsReadOnly", readOnlyHr); } if (value) SysFreeString(value); valuePattern->Release(); } else { Wh_Log( L"Property ValuePattern: NOT SUPPORTED (HRESULT=0x%08X)", (unsigned int)hr); } IUIAutomationLegacyIAccessiblePattern* legacyPattern = nullptr; hr = propertyElement->GetCurrentPattern( UIA_LegacyIAccessiblePatternId, reinterpret_cast(&legacyPattern)); if (SUCCEEDED(hr) && legacyPattern) { BSTR legacyName = nullptr; BSTR legacyValue = nullptr; BSTR legacyDefaultAction = nullptr; BSTR legacyKeyboardShortcut = nullptr; int legacyChildId = 0; DWORD legacyRole = 0; DWORD legacyState = 0; HRESULT nameHr = legacyPattern->get_CurrentName(&legacyName); HRESULT valueHr = legacyPattern->get_CurrentValue(&legacyValue); HRESULT childIdHr = legacyPattern->get_CurrentChildId(&legacyChildId); HRESULT roleHr = legacyPattern->get_CurrentRole(&legacyRole); HRESULT stateHr = legacyPattern->get_CurrentState(&legacyState); HRESULT actionHr = legacyPattern->get_CurrentDefaultAction( &legacyDefaultAction); HRESULT shortcutHr = legacyPattern->get_CurrentKeyboardShortcut( &legacyKeyboardShortcut); if (SUCCEEDED(nameHr)) { Wh_Log( L"Property LegacyIAccessible Name=\"%s\"", legacyName ? legacyName : L""); } else { LogHresult( L"Property LegacyIAccessible::get_CurrentName", nameHr); } if (SUCCEEDED(valueHr)) { Wh_Log( L"Property LegacyIAccessible Value=\"%s\"", legacyValue ? legacyValue : L""); } else { LogHresult( L"Property LegacyIAccessible::get_CurrentValue", valueHr); } if (SUCCEEDED(childIdHr)) { Wh_Log( L"Property LegacyIAccessible ChildId=%d", legacyChildId); } else { LogHresult( L"Property LegacyIAccessible::get_CurrentChildId", childIdHr); } if (SUCCEEDED(roleHr)) { Wh_Log( L"Property LegacyIAccessible Role=%lu", (unsigned long)legacyRole); } else { LogHresult( L"Property LegacyIAccessible::get_CurrentRole", roleHr); } if (SUCCEEDED(stateHr)) { Wh_Log( L"Property LegacyIAccessible State=0x%08lX", (unsigned long)legacyState); } else { LogHresult( L"Property LegacyIAccessible::get_CurrentState", stateHr); } if (SUCCEEDED(actionHr)) { Wh_Log( L"Property LegacyIAccessible DefaultAction=\"%s\"", legacyDefaultAction ? legacyDefaultAction : L""); } else { LogHresult( L"Property LegacyIAccessible::get_CurrentDefaultAction", actionHr); } if (SUCCEEDED(shortcutHr)) { Wh_Log( L"Property LegacyIAccessible KeyboardShortcut=\"%s\"", legacyKeyboardShortcut ? legacyKeyboardShortcut : L""); } else { LogHresult( L"Property LegacyIAccessible::get_CurrentKeyboardShortcut", shortcutHr); } if (legacyName) SysFreeString(legacyName); if (legacyValue) SysFreeString(legacyValue); if (legacyDefaultAction) SysFreeString(legacyDefaultAction); if (legacyKeyboardShortcut) SysFreeString(legacyKeyboardShortcut); legacyPattern->Release(); } else { Wh_Log( L"Property LegacyIAccessiblePattern: NOT SUPPORTED (HRESULT=0x%08X)", (unsigned int)hr); } IUIAutomationTextPattern* textPattern = nullptr; hr = propertyElement->GetCurrentPattern( UIA_TextPatternId, reinterpret_cast(&textPattern)); if (SUCCEEDED(hr) && textPattern) { Wh_Log(L"Property TextPattern: SUPPORTED"); IUIAutomationTextRange* documentRange = nullptr; HRESULT rangeHr = textPattern->get_DocumentRange(&documentRange); if (SUCCEEDED(rangeHr) && documentRange) { BSTR rangeText = nullptr; HRESULT textHr = documentRange->GetText(-1, &rangeText); if (SUCCEEDED(textHr)) { Wh_Log( L"Property TextPattern DocumentRange text=\"%s\"", rangeText ? rangeText : L""); } else { LogHresult( L"Property TextRange::GetText", textHr); } if (rangeText) SysFreeString(rangeText); documentRange->Release(); } else { LogHresult( L"Property TextPattern::get_DocumentRange", rangeHr); } textPattern->Release(); } else { Wh_Log( L"Property TextPattern: NOT SUPPORTED (HRESULT=0x%08X)", (unsigned int)hr); } if (name) SysFreeString(name); if (automationId) SysFreeString(automationId); if (className) SysFreeString(className); Wh_Log(L"--------------------------------------------------------------------------"); } [[maybe_unused]] static void InspectExplorerFrameStringReferences() { Wh_Log(L"========== EXPLORERFRAME STRING REFERENCE DIAGNOSTIC =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid DOS header"); Wh_Log(L"----------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast(base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid NT header"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* textBase = nullptr; DWORD textSize = 0; BYTE* rdataBase = nullptr; DWORD rdataSize = 0; BYTE* pdataBase = nullptr; DWORD pdataSize = 0; IMAGE_SECTION_HEADER* section = IMAGE_FIRST_SECTION(ntHeaders); for (WORD i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { char sectionName[9] = {}; memcpy(sectionName, section[i].Name, 8); if (strcmp(sectionName, ".text") == 0) { textBase = base + section[i].VirtualAddress; textSize = section[i].Misc.VirtualSize; } else if (strcmp(sectionName, ".rdata") == 0) { rdataBase = base + section[i].VirtualAddress; rdataSize = section[i].Misc.VirtualSize; } else if (strcmp(sectionName, ".pdata") == 0) { pdataBase = base + section[i].VirtualAddress; pdataSize = section[i].Misc.VirtualSize; } } if (!textBase || !textSize || !rdataBase || !rdataSize || !pdataBase || !pdataSize) { Wh_Log( L"Required sections not found: .text=%p/%lu .rdata=%p/%lu .pdata=%p/%lu", textBase, (unsigned long)textSize, rdataBase, (unsigned long)rdataSize, pdataBase, (unsigned long)pdataSize); Wh_Log(L"----------------------------------------------------"); return; } Wh_Log( L".text: base=%p size=0x%08lX .rdata: base=%p size=0x%08lX .pdata: base=%p size=0x%08lX", textBase, (unsigned long)textSize, rdataBase, (unsigned long)rdataSize, pdataBase, (unsigned long)pdataSize); const wchar_t* targets[] = { L"System.ItemNameDisplay", L"UIProperty", L"UIGroupHeader", L"UIGroupItem" }; for (int t = 0; t < (int)(sizeof(targets) / sizeof(targets[0])); t++) { const wchar_t* target = targets[t]; size_t targetBytes = (wcslen(target) + 1) * sizeof(wchar_t); int stringCount = 0; int referenceCount = 0; Wh_Log(L"Target string: \"%s\"", target); for (DWORD offset = 0; offset + targetBytes <= rdataSize; offset += sizeof(wchar_t)) { BYTE* candidate = rdataBase + offset; if (memcmp(candidate, target, targetBytes) != 0) continue; stringCount++; Wh_Log( L"String occurrence[%d]: RVA=0x%08lX Address=%p", stringCount, (unsigned long)(candidate - base), candidate); // Search for x64 RIP-relative references to this exact // string address. The displacement is a signed 32-bit value. // We test common ModRM positions (after 1..4 opcode bytes). int referencesForString = 0; for (DWORD textOffset = 0; textOffset + 8 < textSize; textOffset++) { BYTE* instruction = textBase + textOffset; for (int modrmOffset = 1; modrmOffset <= 4; modrmOffset++) { if (textOffset + modrmOffset + 5 > textSize) continue; BYTE modrm = instruction[modrmOffset]; // mod=00 and r/m=101 means RIP-relative addressing. if ((modrm & 0xC7) != 0x05) continue; INT32 displacement = 0; memcpy( &displacement, instruction + modrmOffset + 1, sizeof(displacement)); BYTE* referencedAddress = instruction + modrmOffset + 5 + displacement; if (referencedAddress != candidate) continue; referencesForString++; referenceCount++; // Locate the containing function directly through // the PE .pdata runtime-function table. This avoids // relying on the undocumented RtlLookupFunctionEntry // declaration, which is not available in Windhawk's // compiler environment. DWORD instructionRva = (DWORD)(instruction - base); DWORD functionBeginRva = 0; bool functionFound = false; struct RuntimeFunctionEntry { DWORD BeginAddress; DWORD EndAddress; DWORD UnwindInfoAddress; }; DWORD runtimeFunctionCount = pdataSize / sizeof(RuntimeFunctionEntry); RuntimeFunctionEntry* runtimeFunctions = reinterpret_cast( pdataBase); for (DWORD functionIndex = 0; functionIndex < runtimeFunctionCount; functionIndex++) { const RuntimeFunctionEntry& entry = runtimeFunctions[functionIndex]; if (instructionRva >= entry.BeginAddress && instructionRva < entry.EndAddress) { functionBeginRva = entry.BeginAddress; functionFound = true; break; } } if (functionFound) { BYTE* functionBegin = base + functionBeginRva; Wh_Log( L" RIP-relative reference[%d]: Instruction=%p RVA=0x%08lX FunctionBegin=%p FunctionRVA=0x%08lX ModRMOffset=%d", referencesForString, instruction, (unsigned long)instructionRva, functionBegin, (unsigned long)functionBeginRva, modrmOffset); } else { Wh_Log( L" RIP-relative reference[%d]: Instruction=%p RVA=0x%08lX FunctionBegin=UNKNOWN ModRMOffset=%d", referencesForString, instruction, (unsigned long)instructionRva, modrmOffset); } // Avoid flooding the log if the same string has many // compiler-generated references. if (referencesForString >= 32) break; } if (referencesForString >= 32) break; } if (referencesForString == 0) { Wh_Log(L" No RIP-relative references found"); } } if (stringCount == 0) { Wh_Log(L"No occurrences found in .rdata"); } else { Wh_Log( L"Target summary: strings=%d references=%d", stringCount, referenceCount); } } Wh_Log(L"----------------------------------------------------"); } static bool FindExplorerFrameFunction( BYTE* base, BYTE* pdataBase, DWORD pdataSize, DWORD functionRva, DWORD* functionEndRva) { if (!base || !pdataBase || !pdataSize) return false; struct RuntimeFunctionEntry { DWORD BeginAddress; DWORD EndAddress; DWORD UnwindInfoAddress; }; DWORD runtimeFunctionCount = pdataSize / sizeof(RuntimeFunctionEntry); RuntimeFunctionEntry* runtimeFunctions = reinterpret_cast(pdataBase); for (DWORD i = 0; i < runtimeFunctionCount; i++) { const RuntimeFunctionEntry& entry = runtimeFunctions[i]; if (functionRva >= entry.BeginAddress && functionRva < entry.EndAddress) { if (functionEndRva) *functionEndRva = entry.EndAddress; return true; } } return false; } static void InspectExplorerFrameCandidateFunction( BYTE* base, BYTE* textBase, DWORD textSize, BYTE* pdataBase, DWORD pdataSize, DWORD functionRva, const wchar_t* reason) { Wh_Log( L"========== EXPLORERFRAME CANDIDATE FUNCTION =========="); DWORD functionEndRva = 0; if (!FindExplorerFrameFunction( base, pdataBase, pdataSize, functionRva, &functionEndRva)) { Wh_Log( L"FunctionRVA=0x%08lX: NOT FOUND IN .pdata", (unsigned long)functionRva); Wh_Log(L"----------------------------------------------------"); return; } if (functionEndRva <= functionRva) { Wh_Log( L"FunctionRVA=0x%08lX has invalid end RVA=0x%08lX", (unsigned long)functionRva, (unsigned long)functionEndRva); Wh_Log(L"----------------------------------------------------"); return; } DWORD functionSize = functionEndRva - functionRva; Wh_Log( L"Reason=%s FunctionRVA=0x%08lX EndRVA=0x%08lX Size=0x%08lX (%lu bytes)", reason ? reason : L"", (unsigned long)functionRva, (unsigned long)functionEndRva, (unsigned long)functionSize, (unsigned long)functionSize); if (functionRva >= (DWORD)(textBase - base) && functionRva < (DWORD)(textBase - base) + textSize) { BYTE* functionBegin = base + functionRva; DWORD bytesToDump = functionSize < 96 ? functionSize : 96; Wh_Log( L"Function start address=%p Dumping first %lu bytes:", functionBegin, (unsigned long)bytesToDump); wchar_t byteLine[256] = {}; for (DWORD offset = 0; offset < bytesToDump; offset += 16) { DWORD lineBytes = bytesToDump - offset; if (lineBytes > 16) lineBytes = 16; wchar_t* p = byteLine; int written = swprintf( p, ARRAYSIZE(byteLine), L" +0x%04lX:", (unsigned long)offset); if (written < 0) continue; p += written; for (DWORD j = 0; j < lineBytes; j++) { written = swprintf( p, (size_t)(byteLine + ARRAYSIZE(byteLine) - p), L" %02X", functionBegin[offset + j]); if (written < 0) break; p += written; } Wh_Log(L"%s", byteLine); } int directCallCount = 0; int directJumpCount = 0; int ripReferenceCount = 0; // E8 rel32 = direct CALL. for (DWORD offset = 0; offset + 5 <= functionSize; offset++) { BYTE opcode = functionBegin[offset]; if (opcode == 0xE8) { INT32 displacement = 0; memcpy( &displacement, functionBegin + offset + 1, sizeof(displacement)); BYTE* targetAddress = functionBegin + offset + 5 + displacement; DWORD targetRva = (DWORD)(targetAddress - base); directCallCount++; Wh_Log( L" CALL[%d]: RVA=0x%08lX -> TargetRVA=0x%08lX Address=%p", directCallCount, (unsigned long)(functionRva + offset), (unsigned long)targetRva, targetAddress); if (directCallCount >= 32) break; } } // E9 rel32 = direct JMP. This is useful for detecting small // wrapper/thunk functions without attempting to disassemble them. for (DWORD offset = 0; offset + 5 <= functionSize; offset++) { if (functionBegin[offset] == 0xE9) { INT32 displacement = 0; memcpy( &displacement, functionBegin + offset + 1, sizeof(displacement)); BYTE* targetAddress = functionBegin + offset + 5 + displacement; DWORD targetRva = (DWORD)(targetAddress - base); directJumpCount++; Wh_Log( L" JMP[%d]: RVA=0x%08lX -> TargetRVA=0x%08lX Address=%p", directJumpCount, (unsigned long)(functionRva + offset), (unsigned long)targetRva, targetAddress); if (directJumpCount >= 16) break; } } // Search for RIP-relative references in this function. Only // references to the four strings already identified by v1.6 // are reported here, so the output stays focused. const wchar_t* targetNames[] = { L"System.ItemNameDisplay", L"UIProperty", L"UIGroupHeader", L"UIGroupItem" }; BYTE* targetAddresses[] = { nullptr, nullptr, nullptr, nullptr }; // Locate the target strings in .rdata once for this diagnostic. BYTE* rdataBase = nullptr; DWORD rdataSize = 0; IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(ntHeaders); for (WORD i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { char sectionName[9] = {}; memcpy(sectionName, sections[i].Name, 8); if (strcmp(sectionName, ".rdata") == 0) { rdataBase = base + sections[i].VirtualAddress; rdataSize = sections[i].Misc.VirtualSize; break; } } if (rdataBase && rdataSize) { for (int targetIndex = 0; targetIndex < 4; targetIndex++) { size_t targetBytes = (wcslen(targetNames[targetIndex]) + 1) * sizeof(wchar_t); for (DWORD offset = 0; offset + targetBytes <= rdataSize; offset += sizeof(wchar_t)) { BYTE* candidate = rdataBase + offset; if (memcmp( candidate, targetNames[targetIndex], targetBytes) == 0) { targetAddresses[targetIndex] = candidate; break; } } } } // The diagnostic intentionally scans possible ModRM positions // but deduplicates reports by instruction address. for (DWORD offset = 0; offset + 8 < functionSize; offset++) { BYTE* instruction = functionBegin + offset; bool alreadyReported = false; // Check the four common ModRM positions used by the v1.6 // reference scanner. Once a matching target is found at this // instruction, emit only one report. for (int modrmOffset = 1; modrmOffset <= 4 && !alreadyReported; modrmOffset++) { if (offset + modrmOffset + 5 > functionSize) continue; BYTE modrm = instruction[modrmOffset]; if ((modrm & 0xC7) != 0x05) continue; INT32 displacement = 0; memcpy( &displacement, instruction + modrmOffset + 1, sizeof(displacement)); BYTE* referencedAddress = instruction + modrmOffset + 5 + displacement; for (int targetIndex = 0; targetIndex < 4; targetIndex++) { if (referencedAddress == targetAddresses[targetIndex]) { ripReferenceCount++; Wh_Log( L" RIP-reference[%d]: InstructionRVA=0x%08lX Target=\"%s\" TargetRVA=0x%08lX ModRMOffset=%d", ripReferenceCount, (unsigned long)(functionRva + offset), targetNames[targetIndex], (unsigned long)( referencedAddress - base), modrmOffset); alreadyReported = true; break; } } } if (ripReferenceCount >= 32) break; } Wh_Log( L"Function summary: DirectCALL=%d DirectJMP=%d TargetRIPReferences=%d", directCallCount, directJumpCount, ripReferenceCount); } else { Wh_Log( L"FunctionRVA=0x%08lX is outside .text", (unsigned long)functionRva); } Wh_Log(L"----------------------------------------------------"); } [[maybe_unused]] static void InspectExplorerFrameDirectCallsToCandidates() { Wh_Log( L"========== EXPLORERFRAME DIRECT CALL TO CANDIDATE DIAGNOSTIC =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid DOS header"); Wh_Log(L"----------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid NT header"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* textBase = nullptr; DWORD textSize = 0; BYTE* pdataBase = nullptr; DWORD pdataSize = 0; IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(ntHeaders); for (WORD i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { char sectionName[9] = {}; memcpy(sectionName, sections[i].Name, 8); if (strcmp(sectionName, ".text") == 0) { textBase = base + sections[i].VirtualAddress; textSize = sections[i].Misc.VirtualSize; } else if (strcmp(sectionName, ".pdata") == 0) { pdataBase = base + sections[i].VirtualAddress; pdataSize = sections[i].Misc.VirtualSize; } } if (!textBase || !textSize || !pdataBase || !pdataSize) { Wh_Log( L"Required sections not found: .text=%p/%lu .pdata=%p/%lu", textBase, (unsigned long)textSize, pdataBase, (unsigned long)pdataSize); Wh_Log(L"----------------------------------------------------"); return; } struct Candidate { DWORD functionRva; const wchar_t* name; }; const Candidate candidates[] = { {0x000C8608, L"UIProperty[1]"}, {0x000C8820, L"UIProperty[2]"}, {0x00116138, L"UIGroupHeader[1]"}, {0x00116298, L"UIGroupHeader[2]"}, {0x000C7AB8, L"UIGroupItem[1]"}, {0x000C8B00, L"UIGroupItem[2]"} }; const int candidateCount = (int)(sizeof(candidates) / sizeof(candidates[0])); int totalMatches = 0; for (int candidateIndex = 0; candidateIndex < candidateCount; candidateIndex++) { int matches = 0; Wh_Log( L"Target candidate: %s FunctionRVA=0x%08lX", candidates[candidateIndex].name, (unsigned long)candidates[candidateIndex].functionRva); for (DWORD offset = 0; offset + 5 <= textSize; offset++) { BYTE* instruction = textBase + offset; if (instruction[0] != 0xE8) continue; INT32 displacement = 0; memcpy( &displacement, instruction + 1, sizeof(displacement)); BYTE* targetAddress = instruction + 5 + displacement; DWORD targetRva = (DWORD)(targetAddress - base); if (targetRva != candidates[candidateIndex].functionRva) continue; DWORD callerRva = (DWORD)(instruction - base); DWORD callerFunctionRva = 0; DWORD callerFunctionEndRva = 0; bool callerFound = false; struct RuntimeFunctionEntry { DWORD BeginAddress; DWORD EndAddress; DWORD UnwindInfoAddress; }; DWORD runtimeFunctionCount = pdataSize / sizeof(RuntimeFunctionEntry); RuntimeFunctionEntry* runtimeFunctions = reinterpret_cast(pdataBase); for (DWORD functionIndex = 0; functionIndex < runtimeFunctionCount; functionIndex++) { const RuntimeFunctionEntry& entry = runtimeFunctions[functionIndex]; if (callerRva >= entry.BeginAddress && callerRva < entry.EndAddress) { callerFunctionRva = entry.BeginAddress; callerFunctionEndRva = entry.EndAddress; callerFound = true; break; } } matches++; totalMatches++; if (callerFound) { Wh_Log( L" CALL match[%d]: CallRVA=0x%08lX CallerFunctionRVA=0x%08lX CallerEndRVA=0x%08lX -> TargetRVA=0x%08lX", matches, (unsigned long)callerRva, (unsigned long)callerFunctionRva, (unsigned long)callerFunctionEndRva, (unsigned long)targetRva); } else { Wh_Log( L" CALL match[%d]: CallRVA=0x%08lX CallerFunction=UNKNOWN -> TargetRVA=0x%08lX", matches, (unsigned long)callerRva, (unsigned long)targetRva); } } if (matches == 0) { Wh_Log(L" No direct E8 CALLs found to this candidate"); } } Wh_Log( L"Direct-call-to-candidate summary: TotalMatches=%d", totalMatches); Wh_Log(L"----------------------------------------------------"); } static void DumpExplorerFrameFocusedCandidateBytes( BYTE* base, DWORD functionRva, DWORD functionEndRva, DWORD focusRva, const wchar_t* label) { if (!base || functionEndRva <= functionRva || focusRva < functionRva || focusRva >= functionEndRva) { return; } const DWORD contextBefore = 32; const DWORD contextAfter = 48; DWORD startRva = focusRva > contextBefore ? focusRva - contextBefore : functionRva; if (startRva < functionRva) startRva = functionRva; DWORD endRva = focusRva + contextAfter; if (endRva > functionEndRva) endRva = functionEndRva; Wh_Log( L"Focused bytes: %s FocusRVA=0x%08lX Range=0x%08lX-0x%08lX", label ? label : L"", (unsigned long)focusRva, (unsigned long)startRva, (unsigned long)endRva); for (DWORD rva = startRva; rva < endRva; rva += 16) { DWORD lineBytes = endRva - rva; if (lineBytes > 16) lineBytes = 16; wchar_t byteLine[256] = {}; int written = swprintf( byteLine, ARRAYSIZE(byteLine), L" RVA=0x%08lX:", (unsigned long)rva); if (written < 0) continue; wchar_t* p = byteLine + written; for (DWORD j = 0; j < lineBytes; j++) { written = swprintf( p, (size_t)(byteLine + ARRAYSIZE(byteLine) - p), L" %02X", base[rva + j]); if (written < 0) break; p += written; } Wh_Log(L"%s", byteLine); } } static void DumpExplorerFrameCallSiteBytes( BYTE* base, DWORD callRva, const wchar_t* label) { if (!base) return; const DWORD contextBefore = 24; const DWORD contextAfter = 32; DWORD startRva = callRva > contextBefore ? callRva - contextBefore : 0; DWORD endRva = callRva + contextAfter; Wh_Log( L"Call-site bytes: %s CallRVA=0x%08lX Range=0x%08lX-0x%08lX", label ? label : L"", (unsigned long)callRva, (unsigned long)startRva, (unsigned long)endRva); for (DWORD rva = startRva; rva < endRva; rva += 16) { DWORD lineBytes = endRva - rva; if (lineBytes > 16) lineBytes = 16; wchar_t byteLine[256] = {}; int written = swprintf( byteLine, ARRAYSIZE(byteLine), L" RVA=0x%08lX:", (unsigned long)rva); if (written < 0) continue; wchar_t* p = byteLine + written; for (DWORD j = 0; j < lineBytes; j++) { written = swprintf( p, (size_t)(byteLine + ARRAYSIZE(byteLine) - p), L" %02X", base[rva + j]); if (written < 0) break; p += written; } Wh_Log(L"%s", byteLine); } } [[maybe_unused]] static void InspectExplorerFrameCandidateCallSites() { Wh_Log( L"========== EXPLORERFRAME CANDIDATE CALL-SITE CONTEXT =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid DOS header"); Wh_Log(L"----------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid NT header"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* textBase = nullptr; DWORD textSize = 0; BYTE* pdataBase = nullptr; DWORD pdataSize = 0; IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(ntHeaders); for (WORD i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { char sectionName[9] = {}; memcpy(sectionName, sections[i].Name, 8); if (strcmp(sectionName, ".text") == 0) { textBase = base + sections[i].VirtualAddress; textSize = sections[i].Misc.VirtualSize; } else if (strcmp(sectionName, ".pdata") == 0) { pdataBase = base + sections[i].VirtualAddress; pdataSize = sections[i].Misc.VirtualSize; } } if (!textBase || !textSize || !pdataBase || !pdataSize) { Wh_Log( L"Required sections not found: .text=%p/%lu .pdata=%p/%lu", textBase, (unsigned long)textSize, pdataBase, (unsigned long)pdataSize); Wh_Log(L"----------------------------------------------------"); return; } struct Candidate { DWORD functionRva; const wchar_t* name; }; const Candidate candidates[] = { {0x000C8608, L"UIProperty[1]"}, {0x000C8820, L"UIProperty[2]"}, {0x00116138, L"UIGroupHeader[1]"}, {0x00116298, L"UIGroupHeader[2]"}, {0x000C7AB8, L"UIGroupItem[1]"}, {0x000C8B00, L"UIGroupItem[2]"} }; struct RuntimeFunctionEntry { DWORD BeginAddress; DWORD EndAddress; DWORD UnwindInfoAddress; }; DWORD runtimeFunctionCount = pdataSize / sizeof(RuntimeFunctionEntry); RuntimeFunctionEntry* runtimeFunctions = reinterpret_cast(pdataBase); int totalCallSites = 0; for (int candidateIndex = 0; candidateIndex < (int)(sizeof(candidates) / sizeof(candidates[0])); candidateIndex++) { Wh_Log( L"Target=%s FunctionRVA=0x%08lX", candidates[candidateIndex].name, (unsigned long)candidates[candidateIndex].functionRva); int callSiteCount = 0; for (DWORD offset = 0; offset + 5 <= textSize; offset++) { BYTE* instruction = textBase + offset; // This is deliberately only a byte-pattern candidate. We do // not claim that every E8 byte found here is an instruction; // the surrounding bytes are dumped so the next stage can be // verified against a real disassembly. if (instruction[0] != 0xE8) continue; INT32 displacement = 0; memcpy( &displacement, instruction + 1, sizeof(displacement)); BYTE* targetAddress = instruction + 5 + displacement; DWORD targetRva = (DWORD)(targetAddress - base); if (targetRva != candidates[candidateIndex].functionRva) continue; DWORD callRva = (DWORD)(instruction - base); DWORD callerBeginRva = 0; DWORD callerEndRva = 0; bool callerFound = false; for (DWORD functionIndex = 0; functionIndex < runtimeFunctionCount; functionIndex++) { const RuntimeFunctionEntry& entry = runtimeFunctions[functionIndex]; if (callRva >= entry.BeginAddress && callRva < entry.EndAddress) { callerBeginRva = entry.BeginAddress; callerEndRva = entry.EndAddress; callerFound = true; break; } } callSiteCount++; totalCallSites++; if (callerFound) { Wh_Log( L" Call-site[%d]: CallRVA=0x%08lX CallerRVA=0x%08lX CallerEndRVA=0x%08lX TargetRVA=0x%08lX", callSiteCount, (unsigned long)callRva, (unsigned long)callerBeginRva, (unsigned long)callerEndRva, (unsigned long)targetRva); } else { Wh_Log( L" Call-site[%d]: CallRVA=0x%08lX Caller=UNKNOWN TargetRVA=0x%08lX", callSiteCount, (unsigned long)callRva, (unsigned long)targetRva); } DumpExplorerFrameCallSiteBytes( base, callRva, candidates[candidateIndex].name); if (callSiteCount >= 16) break; } if (callSiteCount == 0) { Wh_Log(L" No E8 byte-pattern call-sites found"); } } Wh_Log( L"Candidate call-site context summary: BytePatternMatches=%d", totalCallSites); Wh_Log(L"----------------------------------------------------"); } [[maybe_unused]] static void InspectExplorerFrameFocusedCandidates() { Wh_Log( L"========== EXPLORERFRAME FOCUSED CANDIDATE BYTES =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid DOS header"); Wh_Log(L"----------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid NT header"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* pdataBase = nullptr; DWORD pdataSize = 0; IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(ntHeaders); for (WORD i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { char sectionName[9] = {}; memcpy(sectionName, sections[i].Name, 8); if (strcmp(sectionName, ".pdata") == 0) { pdataBase = base + sections[i].VirtualAddress; pdataSize = sections[i].Misc.VirtualSize; break; } } if (!pdataBase || !pdataSize) { Wh_Log(L".pdata not found"); Wh_Log(L"----------------------------------------------------"); return; } const DWORD focusedRvas[] = { 0x000C8608, 0x000C8820, 0x00116138, 0x00116298, 0x000C7AB8, 0x000C8B00 }; const wchar_t* labels[] = { L"UIProperty[1] function start", L"UIProperty[2] function start", L"UIGroupHeader[1] function start", L"UIGroupHeader[2] function start", L"UIGroupItem[1] function start", L"UIGroupItem[2] function start" }; const DWORD focusOffsets[] = { 0x00000079, 0x00000049, 0x00000094, 0x00000049, 0x00000061, 0x00000049 }; const int count = (int)(sizeof(focusedRvas) / sizeof(focusedRvas[0])); for (int i = 0; i < count; i++) { DWORD endRva = 0; if (!FindExplorerFrameFunction( base, pdataBase, pdataSize, focusedRvas[i], &endRva)) { Wh_Log( L"Focused candidate 0x%08lX: NOT FOUND IN .pdata", (unsigned long)focusedRvas[i]); continue; } Wh_Log( L"Candidate %s FunctionRVA=0x%08lX EndRVA=0x%08lX", labels[i], (unsigned long)focusedRvas[i], (unsigned long)endRva); DumpExplorerFrameFocusedCandidateBytes( base, focusedRvas[i], endRva, focusedRvas[i] + focusOffsets[i], labels[i]); } Wh_Log(L"----------------------------------------------------"); } [[maybe_unused]] static void InspectExplorerFrameCandidateFunctions() { Wh_Log( L"========== EXPLORERFRAME CANDIDATE FUNCTION DIAGNOSTIC =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid DOS header"); Wh_Log(L"----------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid NT header"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* textBase = nullptr; DWORD textSize = 0; BYTE* pdataBase = nullptr; DWORD pdataSize = 0; IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(ntHeaders); for (WORD i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { char sectionName[9] = {}; memcpy(sectionName, sections[i].Name, 8); if (strcmp(sectionName, ".text") == 0) { textBase = base + sections[i].VirtualAddress; textSize = sections[i].Misc.VirtualSize; } else if (strcmp(sectionName, ".pdata") == 0) { pdataBase = base + sections[i].VirtualAddress; pdataSize = sections[i].Misc.VirtualSize; } } if (!textBase || !textSize || !pdataBase || !pdataSize) { Wh_Log( L"Required sections not found: .text=%p/%lu .pdata=%p/%lu", textBase, (unsigned long)textSize, pdataBase, (unsigned long)pdataSize); Wh_Log(L"----------------------------------------------------"); return; } struct Candidate { DWORD functionRva; const wchar_t* reason; }; const Candidate candidates[] = { {0x000524A0, L"System.ItemNameDisplay"}, {0x0005EA04, L"System.ItemNameDisplay"}, {0x000C8608, L"UIProperty"}, {0x000C8820, L"UIProperty"}, {0x00116138, L"UIGroupHeader"}, {0x00116298, L"UIGroupHeader"}, {0x000C7AB8, L"UIGroupItem"}, {0x000C8B00, L"UIGroupItem"} }; const int candidateCount = (int)(sizeof(candidates) / sizeof(candidates[0])); Wh_Log( L"Candidate function count=%d", candidateCount); for (int i = 0; i < candidateCount; i++) { Wh_Log( L"Candidate[%d]: FunctionRVA=0x%08lX Reason=%s", i + 1, (unsigned long)candidates[i].functionRva, candidates[i].reason); InspectExplorerFrameCandidateFunction( base, textBase, textSize, pdataBase, pdataSize, candidates[i].functionRva, candidates[i].reason); } Wh_Log(L"=============================================================="); } [[maybe_unused]] static void InspectExplorerFrameExports() { Wh_Log(L"========== EXPLORERFRAME EXPORT DIAGNOSTIC =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log( L"explorerframe.dll: NOT LOADED (GetModuleHandleW failed, error=%lu)", GetLastError()); Wh_Log(L"----------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid DOS header"); Wh_Log(L"----------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid NT header"); Wh_Log(L"----------------------------------------------------"); return; } IMAGE_DATA_DIRECTORY exportDirectory = ntHeaders->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT]; if (exportDirectory.VirtualAddress == 0 || exportDirectory.Size == 0) { Wh_Log(L"Export directory: NOT PRESENT"); Wh_Log(L"----------------------------------------------------"); return; } IMAGE_EXPORT_DIRECTORY* exports = reinterpret_cast( base + exportDirectory.VirtualAddress); Wh_Log( L"Export directory RVA=0x%08lX Size=0x%08lX", (unsigned long)exportDirectory.VirtualAddress, (unsigned long)exportDirectory.Size); Wh_Log( L"Exported functions=%lu Exported names=%lu", (unsigned long)exports->NumberOfFunctions, (unsigned long)exports->NumberOfNames); Wh_Log( L"Ordinal base=%lu", (unsigned long)exports->Base); DWORD* nameRVAs = reinterpret_cast( base + exports->AddressOfNames); WORD* nameOrdinals = reinterpret_cast( base + exports->AddressOfNameOrdinals); DWORD* functionRVAs = reinterpret_cast( base + exports->AddressOfFunctions); for (DWORD i = 0; i < exports->NumberOfNames; i++) { const char* exportName = reinterpret_cast( base + nameRVAs[i]); WORD ordinalIndex = nameOrdinals[i]; DWORD functionRVA = 0; if (ordinalIndex < exports->NumberOfFunctions) { functionRVA = functionRVAs[ordinalIndex]; } Wh_Log( L"Export[%lu]: Name=%hs Ordinal=%lu RVA=0x%08lX Address=%p", (unsigned long)i, exportName ? exportName : "", (unsigned long)(exports->Base + ordinalIndex), (unsigned long)functionRVA, functionRVA ? reinterpret_cast(base + functionRVA) : nullptr); } Wh_Log(L"----------------------------------------------------"); } [[maybe_unused]] static void InspectExplorerFrameModule() { Wh_Log(L"========== EXPLORERFRAME MODULE DIAGNOSTIC =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log( L"explorerframe.dll: NOT LOADED (GetModuleHandleW failed, error=%lu)", GetLastError()); Wh_Log(L"----------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid DOS header"); Wh_Log(L"----------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid NT header"); Wh_Log(L"----------------------------------------------------"); return; } Wh_Log( L"Module base=%p ImageSize=0x%08lX EntryPointRVA=0x%08lX", module, (unsigned long)ntHeaders->OptionalHeader.SizeOfImage, (unsigned long)ntHeaders->OptionalHeader.AddressOfEntryPoint); Wh_Log( L"ImageBase=0x%p NumberOfSections=%u", reinterpret_cast( (ULONG_PTR)ntHeaders->OptionalHeader.ImageBase), (unsigned int)ntHeaders->FileHeader.NumberOfSections); IMAGE_SECTION_HEADER* sectionHeaders = IMAGE_FIRST_SECTION(ntHeaders); for (unsigned int i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { char sectionName[9] = {}; memcpy( sectionName, sectionHeaders[i].Name, sizeof(sectionHeaders[i].Name)); Wh_Log( L"Section[%u]: Name=%hs RVA=0x%08lX VirtualSize=0x%08lX Characteristics=0x%08lX", i, sectionName, (unsigned long)sectionHeaders[i].VirtualAddress, (unsigned long)sectionHeaders[i].Misc.VirtualSize, (unsigned long)sectionHeaders[i].Characteristics); } Wh_Log(L"----------------------------------------------------"); } static void InspectUIAGroupStructure( IUIAutomation* automation, IUIAutomationElement* groupElement) { if (!automation || !groupElement) return; BSTR name = nullptr; BSTR automationId = nullptr; BSTR className = nullptr; groupElement->get_CurrentName(&name); groupElement->get_CurrentAutomationId(&automationId); groupElement->get_CurrentClassName(&className); Wh_Log( L"---------- UIA GROUP STRUCTURE: Name=\"%s\" AutomationId=\"%s\" ClassName=\"%s\" ----------", name ? name : L"", automationId ? automationId : L"", className ? className : L""); IUIAutomationCondition* trueCondition = nullptr; IUIAutomationElementArray* children = nullptr; IUIAutomationElementArray* descendants = nullptr; HRESULT hr = automation->CreateTrueCondition(&trueCondition); if (FAILED(hr) || !trueCondition) { LogHresult(L"CreateTrueCondition(group structure)", hr); goto cleanup; } hr = groupElement->FindAll( TreeScope_Children, trueCondition, &children); if (SUCCEEDED(hr) && children) { int childCount = 0; children->get_Length(&childCount); Wh_Log(L"UIA immediate children: %d", childCount); for (int i = 0; i < childCount && i < 32; i++) { IUIAutomationElement* child = nullptr; if (SUCCEEDED(children->GetElement(i, &child)) && child) { InspectUIAElement(child, i + 1); BSTR childClassName = nullptr; if (SUCCEEDED(child->get_CurrentClassName(&childClassName)) && childClassName) { if (wcscmp(childClassName, L"UIGroupHeader") == 0) { InspectUIAGroupHeader(child); } else if (wcscmp(childClassName, L"UIProperty") == 0) { BSTR childAutomationId = nullptr; if (SUCCEEDED( child->get_CurrentAutomationId( &childAutomationId)) && childAutomationId && wcscmp( childAutomationId, L"System.ItemNameDisplay") == 0) { InspectUIAProperty(child); InspectUIAPropertyInternals(child); } if (childAutomationId) SysFreeString(childAutomationId); } SysFreeString(childClassName); } child->Release(); } } children->Release(); children = nullptr; } else { LogHresult(L"IUIAutomationElement::FindAll(children)", hr); } hr = groupElement->FindAll( TreeScope_Descendants, trueCondition, &descendants); if (SUCCEEDED(hr) && descendants) { int descendantCount = 0; descendants->get_Length(&descendantCount); Wh_Log(L"UIA group descendants: %d", descendantCount); int listItemCount = 0; int groupHeaderCount = 0; int groupButtonCount = 0; for (int i = 0; i < descendantCount; i++) { IUIAutomationElement* descendant = nullptr; if (FAILED(descendants->GetElement(i, &descendant)) || !descendant) continue; int controlType = 0; BSTR descendantClassName = nullptr; BSTR descendantName = nullptr; BSTR descendantAutomationId = nullptr; descendant->get_CurrentControlType(&controlType); descendant->get_CurrentClassName(&descendantClassName); descendant->get_CurrentName(&descendantName); descendant->get_CurrentAutomationId(&descendantAutomationId); if (controlType == UIA_ListItemControlTypeId) { listItemCount++; } if (descendantClassName && wcscmp(descendantClassName, L"UIGroupHeader") == 0) { groupHeaderCount++; InspectUIAGroupHeader(descendant); } if (descendantClassName && wcscmp(descendantClassName, L"UIProperty") == 0 && descendantAutomationId && wcscmp( descendantAutomationId, L"System.ItemNameDisplay") == 0) { InspectUIAProperty(descendant); InspectUIAPropertyInternals(descendant); } if (descendantAutomationId && wcscmp(descendantAutomationId, L"UIGroupButton") == 0) { groupButtonCount++; } if (descendantClassName) SysFreeString(descendantClassName); if (descendantName) SysFreeString(descendantName); if (descendantAutomationId) SysFreeString(descendantAutomationId); descendant->Release(); } Wh_Log( L"UIA group structure counts: ListItem=%d, UIGroupHeader=%d, UIGroupButton=%d", listItemCount, groupHeaderCount, groupButtonCount); descendants->Release(); descendants = nullptr; } else { LogHresult(L"IUIAutomationElement::FindAll(descendants)", hr); } trueCondition->Release(); trueCondition = nullptr; cleanup: if (children) children->Release(); if (descendants) descendants->Release(); if (trueCondition) trueCondition->Release(); if (name) SysFreeString(name); if (automationId) SysFreeString(automationId); if (className) SysFreeString(className); Wh_Log(L"--------------------------------------------------------------------------"); } static void InspectUIAutomation(HWND directUIHwnd) { Wh_Log(L"========== UI AUTOMATION DIAGNOSTIC =========="); if (!directUIHwnd) { Wh_Log(L"DirectUIHWND not found"); Wh_Log(L"=============================================="); return; } Wh_Log(L"DirectUIHWND: 0x%p", directUIHwnd); IUIAutomation* automation = nullptr; HRESULT hr = CoCreateInstance( CLSID_CUIAutomation, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&automation)); if (FAILED(hr) || !automation) { LogHresult(L"CoCreateInstance(CLSID_CUIAutomation)", hr); Wh_Log(L"=============================================="); return; } IUIAutomationElement* root = nullptr; hr = automation->ElementFromHandle(directUIHwnd, &root); if (FAILED(hr) || !root) { LogHresult(L"IUIAutomation::ElementFromHandle", hr); automation->Release(); Wh_Log(L"=============================================="); return; } InspectUIAElement(root, 0); IUIAutomationCondition* trueCondition = nullptr; hr = automation->CreateTrueCondition(&trueCondition); if (FAILED(hr) || !trueCondition) { LogHresult(L"IUIAutomation::CreateTrueCondition", hr); root->Release(); automation->Release(); Wh_Log(L"=============================================="); return; } IUIAutomationElementArray* elements = nullptr; hr = root->FindAll(TreeScope_Descendants, trueCondition, &elements); trueCondition->Release(); if (FAILED(hr) || !elements) { LogHresult(L"IUIAutomationElement::FindAll", hr); root->Release(); automation->Release(); Wh_Log(L"=============================================="); return; } int length = 0; hr = elements->get_Length(&length); if (FAILED(hr)) { LogHresult(L"IUIAutomationElementArray::get_Length", hr); elements->Release(); root->Release(); automation->Release(); Wh_Log(L"=============================================="); return; } Wh_Log(L"UIA descendant count: %d", length); const int maxElements = 512; if (length > maxElements) { Wh_Log(L"UIA element limit: %d (actual=%d)", maxElements, length); length = maxElements; } for (int i = 0; i < length; i++) { IUIAutomationElement* element = nullptr; hr = elements->GetElement(i, &element); if (FAILED(hr) || !element) { Wh_Log(L"UIA[%d]: GetElement failed: 0x%08X", i + 1, (unsigned int)hr); continue; } InspectUIAElement(element, i + 1); BSTR elementClassName = nullptr; if (SUCCEEDED(element->get_CurrentClassName(&elementClassName)) && elementClassName) { if (wcscmp(elementClassName, L"UIGroupItem") == 0 || wcscmp(elementClassName, L"UIGroupHeader") == 0) { InspectUIAGroupStructure(automation, element); } SysFreeString(elementClassName); } element->Release(); } elements->Release(); root->Release(); automation->Release(); Wh_Log(L"=============================================="); } static const wchar_t* GetFocusedCallSiteName(DWORD callRva) { switch (callRva) { case 0x000C7BB1: return L"UIGroupItem[2] -> UIGroupItem[2] helper"; case 0x00116223: return L"UIGroupHeader[2] -> UIGroupHeader[2] helper"; default: return L"Unknown focused call site"; } } static void DumpExplorerFrameBytes( BYTE* base, DWORD startRva, DWORD endRva) { if (!base || startRva >= endRva) return; for (DWORD rva = startRva; rva < endRva; rva += 16) { DWORD count = endRva - rva; if (count > 16) count = 16; wchar_t bytes[16 * 3 + 1] = {}; wchar_t* out = bytes; for (DWORD i = 0; i < count; i++) { int written = swprintf( out, 4, L"%02X%s", base[rva + i], i + 1 == count ? L"" : L" "); if (written > 0) out += written; } Wh_Log( L" 0x%08lX: %s", (unsigned long)rva, bytes); } } struct FocusedArgumentState { bool rcxFound; bool rdxFound; bool r8Found; bool r9Found; bool stack20Found; bool stack24Found; bool stack28Found; bool stack30Found; bool stack38Found; bool stack40Found; bool stack60Found; bool stack68Found; bool complete; }; static void LogStackWriteInstruction( BYTE* base, DWORD instructionRva, BYTE opcode, BYTE displacement, const wchar_t* sourceRegister) { Wh_Log( L" FINAL [RSP+0x%02X]: 0x%08lX: MOV [RSP+0x%02X], %s (opcode=0x%02X)", displacement, (unsigned long)instructionRva, displacement, sourceRegister, opcode); } static void InspectFocusedHelperFunction( BYTE* base, DWORD helperRva, DWORD helperEndRva, const wchar_t* helperName) { if (!base || helperRva >= helperEndRva) return; Wh_Log(L" ---------- HELPER BODY %s ----------", helperName); Wh_Log( L" Helper RVA=0x%08lX EndRVA=0x%08lX Size=0x%lX", (unsigned long)helperRva, (unsigned long)helperEndRva, (unsigned long)(helperEndRva - helperRva)); DumpExplorerFrameBytes(base, helperRva, helperEndRva); for (DWORD rva = helperRva; rva + 5 <= helperEndRva; rva++) { if (base[rva] == 0xE8) { INT32 displacement = 0; memcpy( &displacement, base + rva + 1, sizeof(displacement)); DWORD targetRva = rva + 5 + displacement; Wh_Log( L" Helper direct CALL: 0x%08lX -> RVA 0x%08lX", (unsigned long)rva, (unsigned long)targetRva); } } Wh_Log(L" ------------------------------------"); } static bool LogBackwardImmediateRegister( BYTE* base, DWORD rva, const wchar_t* registerName, DWORD instructionLength, const wchar_t* mnemonic) { DWORD immediate = 0; if (instructionLength == 5) { memcpy(&immediate, base + rva + 1, sizeof(immediate)); } else { memcpy(&immediate, base + rva + 2, sizeof(immediate)); } Wh_Log( L" FINAL %s: 0x%08lX: %s %s, 0x%08lX", registerName, (unsigned long)rva, mnemonic, registerName, (unsigned long)immediate); return true; } static bool TryLogBackwardRIPRelative( BYTE* base, DWORD rva, DWORD instructionLength, const wchar_t* registerName, const wchar_t* mnemonic) { INT32 displacement = 0; memcpy( &displacement, base + rva + 3, sizeof(displacement)); DWORD targetRva = rva + instructionLength + displacement; Wh_Log( L" FINAL %s: 0x%08lX: %s %s, [RIP+0x%08lX] -> RVA 0x%08lX", registerName, (unsigned long)rva, mnemonic, registerName, (unsigned long)displacement, (unsigned long)targetRva); return true; } static void InspectFocusedCallArguments( BYTE* base, DWORD callRva) { if (!base) return; Wh_Log(L" Backward argument-state reconstruction v2.4:"); Wh_Log( L" Focused call site: 0x%08lX (%s)", (unsigned long)callRva, GetFocusedCallSiteName(callRva)); const DWORD lookback = 192; DWORD startRva = callRva >= lookback ? callRva - lookback : 0; FocusedArgumentState state = {}; // v2.3 tracked only [RSP+20h] and [RSP+28h]. Here we also track // the other nearby stack slots and the temporary locals observed // at [RSP+60h] and [RSP+68h]. for (DWORD rva = callRva; rva > startRva;) { DWORD current = rva - 1; BYTE* p = base + current; // 48 89 4C 24 xx : MOV [RSP+xx], RCX if (current >= startRva && current >= 4 && p[0] == 0x24 && p[-1] == 0x4C && p[-2] == 0x89 && p[-3] == 0x48) { BYTE offset = p[0]; if (offset == 0x20 || offset == 0x24 || offset == 0x28 || offset == 0x30 || offset == 0x38 || offset == 0x40 || offset == 0x60 || offset == 0x68) { bool* found = nullptr; if (offset == 0x20) found = &state.stack20Found; if (offset == 0x24) found = &state.stack24Found; if (offset == 0x28) found = &state.stack28Found; if (offset == 0x30) found = &state.stack30Found; if (offset == 0x38) found = &state.stack38Found; if (offset == 0x40) found = &state.stack40Found; if (offset == 0x60) found = &state.stack60Found; if (offset == 0x68) found = &state.stack68Found; if (found && !*found) { LogStackWriteInstruction( base, current - 3, 0x89, offset, L"RCX"); *found = true; rva = current - 3; continue; } } } // 48 89 54 24 xx : MOV [RSP+xx], RDX if (current >= startRva && current >= 4 && p[0] == 0x24 && p[-1] == 0x54 && p[-2] == 0x89 && p[-3] == 0x48) { BYTE offset = p[0]; if (offset == 0x20 || offset == 0x24 || offset == 0x28 || offset == 0x30 || offset == 0x38 || offset == 0x40 || offset == 0x60 || offset == 0x68) { bool* found = nullptr; if (offset == 0x20) found = &state.stack20Found; if (offset == 0x24) found = &state.stack24Found; if (offset == 0x28) found = &state.stack28Found; if (offset == 0x30) found = &state.stack30Found; if (offset == 0x38) found = &state.stack38Found; if (offset == 0x40) found = &state.stack40Found; if (offset == 0x60) found = &state.stack60Found; if (offset == 0x68) found = &state.stack68Found; if (found && !*found) { LogStackWriteInstruction( base, current - 3, 0x89, offset, L"RDX"); *found = true; rva = current - 3; continue; } } } // 4C 89 44 24 xx : MOV [RSP+xx], R8 if (current >= startRva && current >= 4 && p[0] == 0x24 && p[-1] == 0x44 && p[-2] == 0x89 && p[-3] == 0x4C) { BYTE offset = p[0]; if (offset == 0x20 || offset == 0x24 || offset == 0x28 || offset == 0x30 || offset == 0x38 || offset == 0x40 || offset == 0x60 || offset == 0x68) { bool* found = nullptr; if (offset == 0x20) found = &state.stack20Found; if (offset == 0x24) found = &state.stack24Found; if (offset == 0x28) found = &state.stack28Found; if (offset == 0x30) found = &state.stack30Found; if (offset == 0x38) found = &state.stack38Found; if (offset == 0x40) found = &state.stack40Found; if (offset == 0x60) found = &state.stack60Found; if (offset == 0x68) found = &state.stack68Found; if (found && !*found) { LogStackWriteInstruction( base, current - 3, 0x89, offset, L"R8"); *found = true; rva = current - 3; continue; } } } // 4C 89 4C 24 xx : MOV [RSP+xx], R9 if (current >= startRva && current >= 4 && p[0] == 0x24 && p[-1] == 0x4C && p[-2] == 0x89 && p[-3] == 0x4C) { BYTE offset = p[0]; if (offset == 0x20 || offset == 0x24 || offset == 0x28 || offset == 0x30 || offset == 0x38 || offset == 0x40 || offset == 0x60 || offset == 0x68) { bool* found = nullptr; if (offset == 0x20) found = &state.stack20Found; if (offset == 0x24) found = &state.stack24Found; if (offset == 0x28) found = &state.stack28Found; if (offset == 0x30) found = &state.stack30Found; if (offset == 0x38) found = &state.stack38Found; if (offset == 0x40) found = &state.stack40Found; if (offset == 0x60) found = &state.stack60Found; if (offset == 0x68) found = &state.stack68Found; if (found && !*found) { LogStackWriteInstruction( base, current - 3, 0x89, offset, L"R9"); *found = true; rva = current - 3; continue; } } } // C7 44 24 xx imm32 : MOV DWORD PTR [RSP+xx], imm32 if (current >= startRva && current >= 7 && p[0] == 0x24 && p[-1] == 0x44 && p[-2] == 0xC7) { BYTE offset = p[0]; if (offset == 0x20 || offset == 0x24 || offset == 0x28 || offset == 0x30 || offset == 0x38 || offset == 0x40 || offset == 0x60 || offset == 0x68) { DWORD instructionRva = current - 2; DWORD immediate = 0; memcpy( &immediate, base + instructionRva + 4, sizeof(immediate)); Wh_Log( L" STACK IMMEDIATE: 0x%08lX: MOV DWORD [RSP+0x%02X], 0x%08lX", (unsigned long)instructionRva, offset, (unsigned long)immediate); if (offset == 0x20) state.stack20Found = true; if (offset == 0x24) state.stack24Found = true; if (offset == 0x28) state.stack28Found = true; if (offset == 0x30) state.stack30Found = true; if (offset == 0x38) state.stack38Found = true; if (offset == 0x40) state.stack40Found = true; if (offset == 0x60) state.stack60Found = true; if (offset == 0x68) state.stack68Found = true; rva = instructionRva; continue; } } // 48 8D 0D disp32 : LEA RCX, [RIP+disp32] if (!state.rcxFound && current >= startRva && current >= 6 && p[0] == 0x0D && p[-1] == 0x8D && p[-2] == 0x48) { DWORD instructionRva = current - 2; TryLogBackwardRIPRelative( base, instructionRva, 7, L"RCX", L"LEA"); state.rcxFound = true; rva = instructionRva; continue; } // 48 8D 15 disp32 : LEA RDX, [RIP+disp32] if (!state.rdxFound && current >= startRva && current >= 6 && p[0] == 0x15 && p[-1] == 0x8D && p[-2] == 0x48) { DWORD instructionRva = current - 2; TryLogBackwardRIPRelative( base, instructionRva, 7, L"RDX", L"LEA"); state.rdxFound = true; rva = instructionRva; continue; } // 4C 8D 05 disp32 : LEA R8, [RIP+disp32] if (!state.r8Found && current >= startRva && current >= 6 && p[0] == 0x05 && p[-1] == 0x8D && p[-2] == 0x4C) { DWORD instructionRva = current - 2; TryLogBackwardRIPRelative( base, instructionRva, 7, L"R8", L"LEA"); state.r8Found = true; rva = instructionRva; continue; } // 4C 8D 0D disp32 : LEA R9, [RIP+disp32] if (!state.r9Found && current >= startRva && current >= 6 && p[0] == 0x0D && p[-1] == 0x8D && p[-2] == 0x4C) { DWORD instructionRva = current - 2; TryLogBackwardRIPRelative( base, instructionRva, 7, L"R9", L"LEA"); state.r9Found = true; rva = instructionRva; continue; } // 48 8B 0D disp32 : MOV RCX, [RIP+disp32] if (!state.rcxFound && current >= startRva && current >= 6 && p[0] == 0x0D && p[-1] == 0x8B && p[-2] == 0x48) { DWORD instructionRva = current - 2; TryLogBackwardRIPRelative( base, instructionRva, 7, L"RCX", L"MOV"); state.rcxFound = true; rva = instructionRva; continue; } // 48 8B 15 disp32 : MOV RDX, [RIP+disp32] if (!state.rdxFound && current >= startRva && current >= 6 && p[0] == 0x15 && p[-1] == 0x8B && p[-2] == 0x48) { DWORD instructionRva = current - 2; TryLogBackwardRIPRelative( base, instructionRva, 7, L"RDX", L"MOV"); state.rdxFound = true; rva = instructionRva; continue; } // 4C 8B 05 disp32 : MOV R8, [RIP+disp32] if (!state.r8Found && current >= startRva && current >= 6 && p[0] == 0x05 && p[-1] == 0x8B && p[-2] == 0x4C) { DWORD instructionRva = current - 2; TryLogBackwardRIPRelative( base, instructionRva, 7, L"R8", L"MOV"); state.r8Found = true; rva = instructionRva; continue; } // 4C 8B 0D disp32 : MOV R9, [RIP+disp32] if (!state.r9Found && current >= startRva && current >= 6 && p[0] == 0x0D && p[-1] == 0x8B && p[-2] == 0x4C) { DWORD instructionRva = current - 2; TryLogBackwardRIPRelative( base, instructionRva, 7, L"R9", L"MOV"); state.r9Found = true; rva = instructionRva; continue; } // B9 imm32 : MOV ECX, imm32 if (!state.rcxFound && current >= startRva && current >= 4 && p[0] == 0xB9) { DWORD instructionRva = current; LogBackwardImmediateRegister( base, instructionRva, L"RCX", 5, L"MOV"); state.rcxFound = true; rva = instructionRva; continue; } // BA imm32 : MOV EDX, imm32 if (!state.rdxFound && current >= startRva && current >= 4 && p[0] == 0xBA) { DWORD instructionRva = current; LogBackwardImmediateRegister( base, instructionRva, L"RDX", 5, L"MOV"); state.rdxFound = true; rva = instructionRva; continue; } // 41 B8 imm32 : MOV R8D, imm32 if (!state.r8Found && current >= startRva && current >= 5 && p[0] == 0xB8 && p[-1] == 0x41) { DWORD instructionRva = current - 1; LogBackwardImmediateRegister( base, instructionRva, L"R8D", 6, L"MOV"); state.r8Found = true; rva = instructionRva; continue; } // 41 B9 imm32 : MOV R9D, imm32 if (!state.r9Found && current >= startRva && current >= 5 && p[0] == 0xB9 && p[-1] == 0x41) { DWORD instructionRva = current - 1; LogBackwardImmediateRegister( base, instructionRva, L"R9D", 6, L"MOV"); state.r9Found = true; rva = instructionRva; continue; } rva = current; } state.complete = state.rcxFound && state.rdxFound && state.r8Found && state.r9Found && state.stack20Found && state.stack24Found && state.stack28Found; Wh_Log( L" Final argument/stack coverage: " L"RCX=%d RDX=%d R8=%d R9=%d " L"[RSP+20]=%d [RSP+24]=%d [RSP+28]=%d [RSP+30]=%d " L"[RSP+38]=%d [RSP+40]=%d [RSP+60]=%d [RSP+68]=%d", state.rcxFound, state.rdxFound, state.r8Found, state.r9Found, state.stack20Found, state.stack24Found, state.stack28Found, state.stack30Found, state.stack38Found, state.stack40Found, state.stack60Found, state.stack68Found); Wh_Log( L" Final argument-state reconstruction: %s", state.complete ? L"COMPLETE" : L"PARTIAL"); } static void InspectExplorerFrameIndirectReferences( BYTE* base, DWORD functionRva, DWORD functionSize) { if (!base || !functionSize) return; Wh_Log(L" ---------- INDIRECT CALL/JMP REFERENCES ----------"); int indirectCallCount = 0; int indirectJumpCount = 0; // x64 forms handled here: // FF 15 disp32 = CALL qword ptr [RIP+disp32] // FF 25 disp32 = JMP qword ptr [RIP+disp32] // These are common for import thunks and other RIP-relative // function-pointer slots. We log both the slot RVA and its current // 64-bit value when the slot is inside the loaded image. for (DWORD offset = 0; offset + 6 <= functionSize; offset++) { BYTE opcode = base[functionRva + offset]; BYTE modrm = base[functionRva + offset + 1]; if (opcode != 0xFF || (modrm != 0x15 && modrm != 0x25)) continue; INT32 displacement = 0; memcpy( &displacement, base + functionRva + offset + 2, sizeof(displacement)); DWORD slotRva = functionRva + offset + 6 + displacement; ULONGLONG slotValue = 0; bool slotInImage = false; IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic == IMAGE_DOS_SIGNATURE) { IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature == IMAGE_NT_SIGNATURE) { DWORD imageSize = ntHeaders->OptionalHeader.SizeOfImage; if (slotRva + sizeof(slotValue) <= imageSize) { memcpy( &slotValue, base + slotRva, sizeof(slotValue)); slotInImage = true; } } } bool isCall = (modrm == 0x15); int* count = isCall ? &indirectCallCount : &indirectJumpCount; (*count)++; if (slotInImage) { DWORD targetRva = (DWORD)(slotValue - (ULONGLONG)(base)); Wh_Log( L" INDIRECT %s[%d]: InstructionRVA=0x%08lX " L"SlotRVA=0x%08lX SlotValue=%p -> TargetRVA=0x%08lX", isCall ? L"CALL" : L"JMP", *count, (unsigned long)(functionRva + offset), (unsigned long)slotRva, reinterpret_cast(slotValue), (unsigned long)targetRva); } else { Wh_Log( L" INDIRECT %s[%d]: InstructionRVA=0x%08lX " L"SlotRVA=0x%08lX (slot outside loaded image)", isCall ? L"CALL" : L"JMP", *count, (unsigned long)(functionRva + offset), (unsigned long)slotRva); } } Wh_Log( L" Indirect CALL count=%d Indirect JMP count=%d", indirectCallCount, indirectJumpCount); Wh_Log(L" -----------------------------------------------"); } static bool GetExplorerFrameSectionRange( BYTE* base, IMAGE_NT_HEADERS* ntHeaders, const char* wantedName, DWORD* sectionRva, DWORD* sectionSize) { if (!base || !ntHeaders || !wantedName || !sectionRva || !sectionSize) return false; IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(ntHeaders); for (WORD i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { char sectionName[9] = {}; memcpy(sectionName, sections[i].Name, 8); if (strcmp(sectionName, wantedName) == 0) { *sectionRva = sections[i].VirtualAddress; *sectionSize = sections[i].Misc.VirtualSize; return true; } } return false; } static void LogAddressModule(ULONGLONG address) { HMODULE addressModule = nullptr; if (GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast( static_cast(address)), &addressModule) && addressModule) { wchar_t modulePath[MAX_PATH] = {}; DWORD length = GetModuleFileNameW( addressModule, modulePath, ARRAYSIZE(modulePath)); if (length) { Wh_Log( L" Address module: %s (base=%p)", modulePath, addressModule); } else { Wh_Log( L" Address module: base=%p (GetModuleFileNameW failed, error=%lu)", addressModule, GetLastError()); } } else { Wh_Log( L" Address module: NOT RESOLVED (error=%lu)", GetLastError()); } } static void ResolveExplorerFrameIndirectSlot( BYTE* base, DWORD imageSize, DWORD slotRva, const wchar_t* label) { if (!base || slotRva + sizeof(ULONGLONG) > imageSize) { Wh_Log( L" %s: slot RVA=0x%08lX is outside loaded image", label, (unsigned long)slotRva); return; } ULONGLONG slotValue = 0; memcpy(&slotValue, base + slotRva, sizeof(slotValue)); Wh_Log( L" %s: SlotRVA=0x%08lX SlotValue=%p", label, (unsigned long)slotRva, reinterpret_cast(slotValue)); if (slotValue) LogAddressModule(slotValue); } static void InspectExplorerFrameFocusedIndirectSlots() { HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) return; IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) return; DWORD imageSize = ntHeaders->OptionalHeader.SizeOfImage; Wh_Log(L"---------- RESOLVING FOCUSED INDIRECT SLOTS ----------"); ResolveExplorerFrameIndirectSlot( base, imageSize, 0x0029C060, L"Common CALL slot used by 0x0005E968 and 0x00035954"); ResolveExplorerFrameIndirectSlot( base, imageSize, 0x0029C048, L"JMP slot used by 0x0005E968"); ResolveExplorerFrameIndirectSlot( base, imageSize, 0x0029C050, L"JMP slot used by 0x00035954"); Wh_Log(L"------------------------------------------------------"); } static void InspectExplorerFrameFothkFocusedArea() { Wh_Log( L"========== EXPLORERFRAME FOTHK / 0x27C010 DIAGNOSTIC v2.7 =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid DOS header"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"explorerframe.dll: invalid NT header"); return; } DWORD fothkRva = 0; DWORD fothkSize = 0; if (!GetExplorerFrameSectionRange( base, ntHeaders, "fothk", &fothkRva, &fothkSize)) { Wh_Log(L"Section fothk: NOT FOUND"); Wh_Log(L"----------------------------------------------------"); return; } Wh_Log( L"fothk: RVA=0x%08lX VirtualSize=0x%08lX Address=%p", (unsigned long)fothkRva, (unsigned long)fothkSize, base + fothkRva); const DWORD focusRva = 0x0027C010; if (focusRva < fothkRva || focusRva >= fothkRva + fothkSize) { Wh_Log( L"0x0027C010 is outside fothk range; no byte dump performed"); Wh_Log(L"----------------------------------------------------"); return; } const DWORD radius = 0x100; DWORD startRva = focusRva > radius ? focusRva - radius : fothkRva; DWORD endRva = focusRva + radius; if (startRva < fothkRva) startRva = fothkRva; if (endRva > fothkRva + fothkSize) endRva = fothkRva + fothkSize; Wh_Log( L"Focused fothk range: RVA=0x%08lX..0x%08lX", (unsigned long)startRva, (unsigned long)endRva); for (DWORD rva = startRva; rva < endRva; rva += 16) { DWORD count = endRva - rva; if (count > 16) count = 16; wchar_t hex[16 * 3 + 1] = {}; wchar_t* out = hex; for (DWORD i = 0; i < count; i++) { swprintf( out, 4, L"%02X ", base[rva + i]); out += 3; } Wh_Log( L" 0x%08lX: %s", (unsigned long)rva, hex); } // The fothk region has no .pdata entry in the previous diagnostic, // so do not invent a function boundary here. Instead, inspect only // the x64 control-flow and RIP-relative patterns that can be decoded // unambiguously from the bytes in the focused window. Wh_Log(L"---------- FOCUSED INSTRUCTION PATTERNS ----------"); for (DWORD rva = startRva; rva + 6 <= endRva; rva++) { BYTE b0 = base[rva]; BYTE b1 = base[rva + 1]; if (b0 == 0xE8 || b0 == 0xE9) { INT32 displacement = 0; memcpy(&displacement, base + rva + 1, sizeof(displacement)); DWORD targetRva = rva + 5 + displacement; Wh_Log( L" %s: RVA=0x%08lX -> RVA=0x%08lX Address=%p", b0 == 0xE8 ? L"E8 CALL" : L"E9 JMP", (unsigned long)rva, (unsigned long)targetRva, base + targetRva); } else if (b0 == 0xFF && (b1 == 0x15 || b1 == 0x25)) { INT32 displacement = 0; memcpy(&displacement, base + rva + 2, sizeof(displacement)); DWORD slotRva = rva + 6 + displacement; ULONGLONG slotValue = 0; bool slotInImage = slotRva + sizeof(slotValue) <= ntHeaders->OptionalHeader.SizeOfImage; if (slotInImage) memcpy(&slotValue, base + slotRva, sizeof(slotValue)); Wh_Log( L" %s: InstructionRVA=0x%08lX SlotRVA=0x%08lX SlotValue=%p", b1 == 0x15 ? L"FF CALL" : L"FF JMP", (unsigned long)rva, (unsigned long)slotRva, slotInImage ? reinterpret_cast(slotValue) : nullptr); if (slotInImage && slotValue) LogAddressModule(slotValue); } else if ((b0 == 0x48 || b0 == 0x4C) && (b1 == 0x8B || b1 == 0x8D) && ((base[rva + 2] & 0xC7) == 0x05)) { INT32 displacement = 0; memcpy(&displacement, base + rva + 3, sizeof(displacement)); DWORD referenceRva = rva + 7 + displacement; Wh_Log( L" RIP %s: InstructionRVA=0x%08lX -> DataRVA=0x%08lX", b1 == 0x8B ? L"MOV" : L"LEA", (unsigned long)rva, (unsigned long)referenceRva); } } Wh_Log(L"----------------------------------------------------"); } static bool GetModuleImageInfo( HMODULE module, BYTE** baseOut, DWORD* imageSizeOut) { if (!module || !baseOut || !imageSizeOut) return false; BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) return false; IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast(base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) return false; *baseOut = base; *imageSizeOut = ntHeaders->OptionalHeader.SizeOfImage; return true; } static const char* FindExportNameAnsiByRva( HMODULE module, DWORD targetRva, char* buffer, size_t bufferSize) { if (!buffer || bufferSize == 0) return nullptr; buffer[0] = '\0'; BYTE* base = nullptr; DWORD imageSize = 0; if (!GetModuleImageInfo(module, &base, &imageSize)) return nullptr; IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast(base + dosHeader->e_lfanew); DWORD exportRva = ntHeaders->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; DWORD exportSize = ntHeaders->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT].Size; if (!exportRva || !exportSize || exportRva >= imageSize || exportRva + exportSize > imageSize) { return nullptr; } IMAGE_EXPORT_DIRECTORY* exports = reinterpret_cast(base + exportRva); DWORD* functions = reinterpret_cast( base + exports->AddressOfFunctions); DWORD* names = reinterpret_cast( base + exports->AddressOfNames); WORD* ordinals = reinterpret_cast( base + exports->AddressOfNameOrdinals); for (DWORD i = 0; i < exports->NumberOfNames; i++) { WORD ordinalIndex = ordinals[i]; if (ordinalIndex >= exports->NumberOfFunctions) continue; if (functions[ordinalIndex] == targetRva) { const char* name = reinterpret_cast(base + names[i]); lstrcpynA(buffer, name, (int)bufferSize); return buffer; } } return nullptr; } static void LogNearestExports( HMODULE module, DWORD targetRva) { BYTE* base = nullptr; DWORD imageSize = 0; if (!GetModuleImageInfo(module, &base, &imageSize)) return; IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast(base + dosHeader->e_lfanew); DWORD exportRva = ntHeaders->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; DWORD exportSize = ntHeaders->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT].Size; if (!exportRva || !exportSize || exportRva >= imageSize || exportRva + exportSize > imageSize) return; IMAGE_EXPORT_DIRECTORY* exports = reinterpret_cast(base + exportRva); DWORD* functions = reinterpret_cast( base + exports->AddressOfFunctions); DWORD* names = reinterpret_cast( base + exports->AddressOfNames); WORD* ordinals = reinterpret_cast( base + exports->AddressOfNameOrdinals); DWORD lowerRva = 0; DWORD upperRva = 0xFFFFFFFF; const char* lowerName = nullptr; const char* upperName = nullptr; for (DWORD i = 0; i < exports->NumberOfNames; i++) { WORD ordinalIndex = ordinals[i]; if (ordinalIndex >= exports->NumberOfFunctions) continue; DWORD functionRva = functions[ordinalIndex]; const char* name = reinterpret_cast(base + names[i]); if (functionRva <= targetRva && functionRva >= lowerRva) { lowerRva = functionRva; lowerName = name; } if (functionRva >= targetRva && functionRva <= upperRva) { upperRva = functionRva; upperName = name; } } if (lowerName) { Wh_Log( L" Nearest export below/equal: %hs RVA=0x%08lX (delta +0x%lX)", lowerName, (unsigned long)lowerRva, (unsigned long)(targetRva - lowerRva)); } if (upperName) { Wh_Log( L" Nearest export above/equal: %hs RVA=0x%08lX (delta 0x%lX)", upperName, (unsigned long)upperRva, (unsigned long)(upperRva - targetRva)); } } static void DumpAddressBytes( BYTE* address, SIZE_T count) { if (!address || !count) return; for (SIZE_T offset = 0; offset < count; offset += 16) { wchar_t hex[16 * 3 + 1] = {}; size_t pos = 0; SIZE_T lineCount = count - offset; if (lineCount > 16) lineCount = 16; for (SIZE_T i = 0; i < lineCount; i++) { pos += swprintf( hex + pos, ARRAYSIZE(hex) - pos, L"%02X ", address[offset + i]); } Wh_Log( L" %p +0x%02lX: %s", address, (unsigned long)offset, hex); } } static void InspectNtdllTargetFromFothk() { Wh_Log(L"========== v2.9 NTDLL TARGET / EXPORT DIAGNOSTIC =========="); HMODULE explorerFrame = GetModuleHandleW(L"explorerframe.dll"); if (!explorerFrame) { Wh_Log(L"explorerframe.dll: NOT LOADED"); return; } BYTE* explorerBase = nullptr; DWORD explorerImageSize = 0; if (!GetModuleImageInfo( explorerFrame, &explorerBase, &explorerImageSize)) { Wh_Log(L"explorerframe.dll: invalid PE image"); return; } const DWORD fothkJumpRva = 0x0027C010; if (fothkJumpRva + 5 > explorerImageSize) { Wh_Log(L"fothk jump RVA is outside explorerframe.dll"); return; } BYTE* jump = explorerBase + fothkJumpRva; Wh_Log( L"fothk 0x27C010 bytes: %02X %02X %02X %02X %02X", jump[0], jump[1], jump[2], jump[3], jump[4]); if (jump[0] != 0xE9) { Wh_Log(L"fothk 0x27C010: expected E9 JMP, not found"); return; } INT32 displacement = 0; memcpy(&displacement, jump + 1, sizeof(displacement)); BYTE* absoluteTarget = jump + 5 + displacement; Wh_Log( L"fothk JMP target: Address=%p", absoluteTarget); // Do not use GetModuleHandleExW(FROM_ADDRESS) here. // v2.8 showed that it can fail with ERROR_MOD_NOT_FOUND even // though the address is in the already loaded ntdll.dll. HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); if (!ntdll) { Wh_Log( L"ntdll.dll: NOT LOADED (error=%lu)", GetLastError()); return; } BYTE* ntdllBase = nullptr; DWORD ntdllImageSize = 0; if (!GetModuleImageInfo( ntdll, &ntdllBase, &ntdllImageSize)) { Wh_Log(L"ntdll.dll: invalid PE image"); return; } Wh_Log( L"ntdll.dll: base=%p SizeOfImage=0x%08lX", ntdllBase, (unsigned long)ntdllImageSize); ULONGLONG targetAddress = reinterpret_cast(absoluteTarget); ULONGLONG ntdllStart = reinterpret_cast(ntdllBase); ULONGLONG ntdllEnd = ntdllStart + ntdllImageSize; if (targetAddress < ntdllStart || targetAddress >= ntdllEnd) { Wh_Log( L"Target is NOT inside ntdll.dll: target=%p range=[%p, %p)", absoluteTarget, ntdllBase, reinterpret_cast(ntdllEnd)); return; } DWORD targetRva = (DWORD)(targetAddress - ntdllStart); Wh_Log( L"Target is inside ntdll.dll: RVA=0x%08lX", (unsigned long)targetRva); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(ntdllBase); IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( ntdllBase + dosHeader->e_lfanew); DWORD exportRva = ntHeaders->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; DWORD exportSize = ntHeaders->OptionalHeader.DataDirectory[ IMAGE_DIRECTORY_ENTRY_EXPORT].Size; Wh_Log( L"ntdll export directory: RVA=0x%08lX Size=0x%08lX", (unsigned long)exportRva, (unsigned long)exportSize); char exportName[256] = {}; const char* name = FindExportNameAnsiByRva( ntdll, targetRva, exportName, ARRAYSIZE(exportName)); if (name) { Wh_Log( L"ntdll exact export match: %hs", name); } else { Wh_Log(L"ntdll exact export match: NONE"); LogNearestExports(ntdll, targetRva); } SIZE_T dumpOffset = 0x20; BYTE* dumpStart = absoluteTarget >= ntdllBase + dumpOffset ? absoluteTarget - dumpOffset : ntdllBase; SIZE_T available = (SIZE_T)((ntdllBase + ntdllImageSize) - dumpStart); SIZE_T dumpSize = available > 0xA0 ? 0xA0 : available; Wh_Log( L"ntdll bytes around target (%lu bytes):", (unsigned long)dumpSize); DumpAddressBytes(dumpStart, dumpSize); Wh_Log( L"v2.9 conclusion: fothk 0x27C010 is a JMP into ntdll.dll; " L"the next step is to identify the exact ntdll target/export."); Wh_Log(L"------------------------------------------------------"); } static void InspectCommonIndirectCallTarget() { Wh_Log(L"========== v2.8 COMMON INDIRECT CALL TARGET =========="); HMODULE explorerFrame = GetModuleHandleW(L"explorerframe.dll"); if (!explorerFrame) { Wh_Log(L"explorerframe.dll: NOT LOADED"); return; } BYTE* base = nullptr; DWORD imageSize = 0; if (!GetModuleImageInfo(explorerFrame, &base, &imageSize)) return; const DWORD slotRva = 0x0029C060; if (slotRva + sizeof(ULONGLONG) > imageSize) { Wh_Log(L"Common CALL slot is outside explorerframe.dll"); return; } ULONGLONG slotValue = 0; memcpy(&slotValue, base + slotRva, sizeof(slotValue)); Wh_Log( L"Slot 0x%08lX value: %p", (unsigned long)slotRva, reinterpret_cast(slotValue)); if (!slotValue) { Wh_Log(L"Slot value is NULL"); return; } HMODULE targetModule = nullptr; if (!GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(static_cast(slotValue)), &targetModule) || !targetModule) { Wh_Log( L"Indirect target module: NOT RESOLVED (error=%lu)", GetLastError()); return; } wchar_t modulePath[MAX_PATH] = {}; DWORD pathLength = GetModuleFileNameW( targetModule, modulePath, ARRAYSIZE(modulePath)); if (pathLength) Wh_Log(L"Indirect target module: %s (base=%p)", modulePath, targetModule); else Wh_Log(L"Indirect target module: base=%p", targetModule); BYTE* targetBase = nullptr; DWORD targetImageSize = 0; if (!GetModuleImageInfo(targetModule, &targetBase, &targetImageSize)) return; DWORD targetRva = (DWORD)(slotValue - reinterpret_cast(targetBase)); Wh_Log( L"Indirect target RVA: 0x%08lX", (unsigned long)targetRva); char exportName[256] = {}; const char* name = FindExportNameAnsiByRva( targetModule, targetRva, exportName, ARRAYSIZE(exportName)); if (name) Wh_Log(L"Indirect target exact export: %hs", name); else { Wh_Log(L"Indirect target exact export: NONE"); LogNearestExports(targetModule, targetRva); } Wh_Log(L"------------------------------------------------------"); } static void InspectKnownIndirectSlotsV29() { Wh_Log(L"========== v2.9 ADDITIONAL INDIRECT SLOT DIAGNOSTIC =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) return; BYTE* base = nullptr; DWORD imageSize = 0; if (!GetModuleImageInfo(module, &base, &imageSize)) return; const DWORD slotRvas[] = { 0x0029C048, 0x0029C050 }; for (size_t i = 0; i < sizeof(slotRvas) / sizeof(slotRvas[0]); i++) { DWORD slotRva = slotRvas[i]; if (slotRva + sizeof(ULONGLONG) > imageSize) { Wh_Log( L"Slot 0x%08lX is outside explorerframe.dll", (unsigned long)slotRva); continue; } ULONGLONG slotValue = 0; memcpy(&slotValue, base + slotRva, sizeof(slotValue)); Wh_Log( L"Slot 0x%08lX value: %p", (unsigned long)slotRva, reinterpret_cast(slotValue)); if (!slotValue) continue; HMODULE ntdll = GetModuleHandleW(L"ntdll.dll"); if (ntdll) { BYTE* ntdllBase = nullptr; DWORD ntdllSize = 0; if (GetModuleImageInfo(ntdll, &ntdllBase, &ntdllSize)) { ULONGLONG start = reinterpret_cast(ntdllBase); ULONGLONG end = start + ntdllSize; if (slotValue >= start && slotValue < end) { DWORD targetRva = (DWORD)(slotValue - start); Wh_Log( L" Target is inside ntdll.dll: RVA=0x%08lX", (unsigned long)targetRva); char exportName[256] = {}; const char* name = FindExportNameAnsiByRva( ntdll, targetRva, exportName, ARRAYSIZE(exportName)); if (name) { Wh_Log( L" Exact ntdll export: %hs", name); } else { Wh_Log(L" Exact ntdll export: NONE"); } continue; } } } // Fall back to the generic in-process module resolver for // non-ntdll targets. LogAddressModule(slotValue); } Wh_Log(L"------------------------------------------------------"); } static void InspectC83C8VtableCall() { Wh_Log(L"========== v2.9 C83C8 VTABLE CALL DIAGNOSTIC =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) return; BYTE* base = nullptr; DWORD imageSize = 0; if (!GetModuleImageInfo(module, &base, &imageSize)) return; const DWORD rva = 0x000C83C8; const DWORD size = 0x27; if (rva + size > imageSize) return; Wh_Log( L"0x000C83C8 instruction sequence (size=0x%lX):", (unsigned long)size); DumpAddressBytes(base + rva, size); Wh_Log( L"Decoded key operation: MOV RAX,[RCX] -> " L"MOV RAX,[RAX+0x90] -> CALL RAX"); Wh_Log( L"vtable slot offset: +0x90 (decimal 144, slot index 18 on x64)"); Wh_Log( L"Meaning: C83C8 receives an object in RCX and invokes " L"the object's virtual method at vtable slot +0x90."); Wh_Log( L"Known caller chain: UIGroupItem/UIGroupHeader helper " L"obtains an object from 0x0005E968, moves that object into " L"RCX, then reaches 0x000C83C8."); Wh_Log( L"0x0005E968 and 0x00035954 both use the same indirect " L"CALL slot 0x0029C060, which v2.8 resolved to " L"KERNELBASE!GetProcessHeap."); Wh_Log( L"The actual object pointer and its vtable are runtime data; " L"this diagnostic intentionally does not dereference an " L"arbitrary Explorer object or modify Explorer."); Wh_Log(L"------------------------------------------------------"); } static void InspectResolvedDui70InitializeV214(ULONGLONG targetAddress) { Wh_Log(L"========== v2.14 DUI70 INITIALIZE TARGET DIAGNOSTIC =========="); if (!targetAddress) { Wh_Log(L"dui70 target address is zero"); Wh_Log(L"------------------------------------------------------"); return; } HMODULE module = nullptr; if (!GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(static_cast(targetAddress)), &module) || !module) { Wh_Log( L"dui70 target module: NOT RESOLVED (error=%lu)", GetLastError()); Wh_Log(L"------------------------------------------------------"); return; } BYTE* base = nullptr; DWORD imageSize = 0; if (!GetModuleImageInfo(module, &base, &imageSize)) { Wh_Log(L"dui70 target image info unavailable"); Wh_Log(L"------------------------------------------------------"); return; } DWORD targetRva = (DWORD)(targetAddress - reinterpret_cast(base)); wchar_t path[MAX_PATH] = {}; DWORD pathLength = GetModuleFileNameW( module, path, ARRAYSIZE(path)); Wh_Log( L"Target module: %s (RVA=0x%08lX)", pathLength ? path : L"", (unsigned long)targetRva); char exportName[256] = {}; const char* name = FindExportNameAnsiByRva( module, targetRva, exportName, ARRAYSIZE(exportName)); if (name) Wh_Log(L"Exact export: %hs", name); else Wh_Log(L"Exact export: NONE (target may be inside a non-exported thunk/function)"); Wh_Log(L"First 96 bytes at target:"); if (targetRva + 96 <= imageSize) DumpAddressBytes(base + targetRva, 96); else Wh_Log(L"Target byte range exceeds module image"); // Locate the containing function through this module's .pdata. IMAGE_DOS_HEADER* dos = reinterpret_cast(base); if (dos->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"Target module has invalid DOS header"); Wh_Log(L"------------------------------------------------------"); return; } IMAGE_NT_HEADERS* nt = reinterpret_cast( base + dos->e_lfanew); if (nt->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"Target module has invalid NT header"); Wh_Log(L"------------------------------------------------------"); return; } BYTE* pdataBase = nullptr; DWORD pdataSize = 0; IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(nt); for (WORD i = 0; i < nt->FileHeader.NumberOfSections; i++) { char sectionName[9] = {}; memcpy(sectionName, sections[i].Name, 8); if (strcmp(sectionName, ".pdata") == 0) { pdataBase = base + sections[i].VirtualAddress; pdataSize = sections[i].Misc.VirtualSize; break; } } if (!pdataBase || !pdataSize) { Wh_Log(L"Target module .pdata not found"); Wh_Log(L"------------------------------------------------------"); return; } struct RuntimeFunctionEntry { DWORD BeginAddress; DWORD EndAddress; DWORD UnwindInfoAddress; }; RuntimeFunctionEntry* entries = reinterpret_cast(pdataBase); DWORD entryCount = pdataSize / sizeof(RuntimeFunctionEntry); DWORD functionBegin = 0; DWORD functionEnd = 0; for (DWORD i = 0; i < entryCount; i++) { if (targetRva >= entries[i].BeginAddress && targetRva < entries[i].EndAddress) { functionBegin = entries[i].BeginAddress; functionEnd = entries[i].EndAddress; break; } } if (!functionBegin || functionEnd <= functionBegin) { Wh_Log(L"Containing function not found in .pdata"); Wh_Log(L"------------------------------------------------------"); return; } Wh_Log( L"Containing function: RVA=0x%08lX..0x%08lX Size=0x%lX", (unsigned long)functionBegin, (unsigned long)functionEnd, (unsigned long)(functionEnd - functionBegin)); DWORD dumpSize = functionEnd - functionBegin; if (dumpSize > 0x100) dumpSize = 0x100; Wh_Log(L"Containing function bytes (first 0x%lX bytes):", (unsigned long)dumpSize); DumpAddressBytes(base + functionBegin, dumpSize); Wh_Log(L"Direct/indirect calls inside containing function:"); int callCount = 0; for (DWORD rva = functionBegin; rva + 6 <= functionEnd; rva++) { BYTE* p = base + rva; if (p[0] == 0xE8) { INT32 displacement = 0; memcpy(&displacement, p + 1, sizeof(displacement)); DWORD callTarget = rva + 5 + displacement; Wh_Log( L" E8 CALL RVA=0x%08lX -> RVA=0x%08lX", (unsigned long)rva, (unsigned long)callTarget); callCount++; } else if (p[0] == 0xFF && p[1] == 0x15) { INT32 displacement = 0; memcpy(&displacement, p + 2, sizeof(displacement)); DWORD slotRva = rva + 6 + displacement; Wh_Log( L" FF 15 indirect CALL RVA=0x%08lX -> slot RVA=0x%08lX", (unsigned long)rva, (unsigned long)slotRva); if (slotRva + sizeof(ULONGLONG) <= imageSize) { ULONGLONG slotValue = 0; memcpy(&slotValue, base + slotRva, sizeof(slotValue)); Wh_Log( L" slot value = %016llX", (unsigned long long)slotValue); } callCount++; } } Wh_Log(L"Total calls in containing function: %d", callCount); Wh_Log(L"------------------------------------------------------"); } static void InspectC83C8ObjectFlowV29() { Wh_Log(L"========== v2.14 C83C8 CALLER-FUNCTION / OBJECT PREPARATION DIAGNOSTIC =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); return; } BYTE* base = nullptr; DWORD imageSize = 0; if (!GetModuleImageInfo(module, &base, &imageSize)) { Wh_Log(L"GetModuleImageInfo failed"); return; } IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) return; IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) return; BYTE* textBase = nullptr; DWORD textRva = 0; DWORD textSize = 0; BYTE* pdataBase = nullptr; DWORD pdataSize = 0; IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(ntHeaders); for (WORD i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { char name[9] = {}; memcpy(name, sections[i].Name, 8); if (strcmp(name, ".text") == 0) { textBase = base + sections[i].VirtualAddress; textRva = sections[i].VirtualAddress; textSize = sections[i].Misc.VirtualSize; } else if (strcmp(name, ".pdata") == 0) { pdataBase = base + sections[i].VirtualAddress; pdataSize = sections[i].Misc.VirtualSize; } } if (!textBase || !textSize || !pdataBase || !pdataSize) { Wh_Log(L"Required .text/.pdata sections not found"); return; } auto ResolveRip32 = [&](DWORD instructionRva, DWORD instructionLength, INT32 displacement, DWORD* targetRva) -> bool { if (!targetRva) return false; INT64 target = (INT64)instructionRva + (INT64)instructionLength + (INT64)displacement; if (target < 0 || target >= imageSize) return false; *targetRva = (DWORD)target; return true; }; auto LogRipTarget = [&](DWORD instructionRva, DWORD instructionLength, INT32 displacement, const wchar_t* operation) { DWORD targetRva = 0; if (ResolveRip32( instructionRva, instructionLength, displacement, &targetRva)) { Wh_Log( L" %s -> explorerframe RVA 0x%08lX", operation, (unsigned long)targetRva); } else { Wh_Log( L" %s -> RIP target outside image (disp=0x%08X)", operation, (unsigned int)displacement); } }; auto DumpFocusedBytes = [&](DWORD rva, DWORD before, DWORD after) { DWORD start = rva >= before ? rva - before : textRva; DWORD end = rva + after; DWORD textEnd = textRva + textSize; if (start < textRva) start = textRva; if (end > textEnd) end = textEnd; DumpAddressBytes(base + start, end - start); }; auto InspectCaller = [&](DWORD startRva, DWORD endRva, const wchar_t* label) { Wh_Log( L"========== %s RVA=0x%08lX..0x%08lX Size=0x%lX ==========" , label, (unsigned long)startRva, (unsigned long)endRva, (unsigned long)(endRva - startRva)); if (startRva < textRva || endRva > textRva + textSize) { Wh_Log(L"Caller range is outside .text; skipped"); return; } DumpAddressBytes(base + startRva, endRva - startRva); Wh_Log(L"---------- Immediate stack-parameter stores ----------"); int immediateStoreCount = 0; for (DWORD rva = startRva; rva + 8 <= endRva; rva++) { // C7 44 24 xx imm32 : MOV dword ptr [RSP+xx], imm32 if (base[rva] == 0xC7 && base[rva + 1] == 0x44 && base[rva + 2] == 0x24) { BYTE stackOffset = base[rva + 3]; DWORD immediate = 0; memcpy(&immediate, base + rva + 4, sizeof(immediate)); Wh_Log( L" MOV [RSP+0x%02X], 0x%08lX at RVA 0x%08lX (%lu)", stackOffset, (unsigned long)immediate, (unsigned long)rva, (unsigned long)immediate); if (stackOffset == 0x28 || stackOffset == 0x20 || stackOffset == 0x24) { Wh_Log( L" ** ABI argument-area value: [RSP+0x%02X] = 0x%08lX **", stackOffset, (unsigned long)immediate); } immediateStoreCount++; } } if (!immediateStoreCount) Wh_Log(L" No C7 immediate stack stores found"); Wh_Log(L"---------- RIP-relative argument/object preparation ----------"); int ripPreparationCount = 0; for (DWORD rva = startRva; rva + 7 <= endRva; rva++) { BYTE* p = base + rva; // 48 8D 0D disp32 : LEA RCX,[RIP+disp32] if (p[0] == 0x48 && p[1] == 0x8D && p[2] == 0x0D) { INT32 displacement = 0; memcpy(&displacement, p + 3, sizeof(displacement)); Wh_Log(L" RVA 0x%08lX: LEA RCX,[RIP+disp32]", (unsigned long)rva); LogRipTarget(rva, 7, displacement, L"LEA RCX"); ripPreparationCount++; } // 48 8D 15 disp32 : LEA RDX,[RIP+disp32] if (p[0] == 0x48 && p[1] == 0x8D && p[2] == 0x15) { INT32 displacement = 0; memcpy(&displacement, p + 3, sizeof(displacement)); Wh_Log(L" RVA 0x%08lX: LEA RDX,[RIP+disp32]", (unsigned long)rva); LogRipTarget(rva, 7, displacement, L"LEA RDX"); ripPreparationCount++; } // 4C 8D 05 disp32 : LEA R8,[RIP+disp32] if (p[0] == 0x4C && p[1] == 0x8D && p[2] == 0x05) { INT32 displacement = 0; memcpy(&displacement, p + 3, sizeof(displacement)); Wh_Log(L" RVA 0x%08lX: LEA R8,[RIP+disp32]", (unsigned long)rva); LogRipTarget(rva, 7, displacement, L"LEA R8"); ripPreparationCount++; } // 4C 8D 0D disp32 : LEA R9,[RIP+disp32] if (p[0] == 0x4C && p[1] == 0x8D && p[2] == 0x0D) { INT32 displacement = 0; memcpy(&displacement, p + 3, sizeof(displacement)); Wh_Log(L" RVA 0x%08lX: LEA R9,[RIP+disp32]", (unsigned long)rva); LogRipTarget(rva, 7, displacement, L"LEA R9"); ripPreparationCount++; } // 48 89 03 : MOV [RBX],RAX -- commonly the vtable/object header write. if (p[0] == 0x48 && p[1] == 0x89 && p[2] == 0x03) { Wh_Log( L" RVA 0x%08lX: MOV [RBX], RAX (object first-field/vtable write candidate)", (unsigned long)rva); ripPreparationCount++; } } if (!ripPreparationCount) Wh_Log(L" No recognized RIP-relative preparation instructions found"); Wh_Log(L"---------- Known RIP-relative data targets ----------"); const DWORD knownDataRvas[] = { 0x002AB658, 0x002AB608, 0x00297550 }; for (size_t i = 0; i < sizeof(knownDataRvas) / sizeof(knownDataRvas[0]); i++) { DWORD dataRva = knownDataRvas[i]; if (dataRva + 32 <= imageSize) { Wh_Log( L"Known data target RVA=0x%08lX (first 32 bytes):", (unsigned long)dataRva); DumpAddressBytes(base + dataRva, 32); } else { Wh_Log( L"Known data target RVA=0x%08lX is outside image", (unsigned long)dataRva); } } Wh_Log(L"---------- Direct/indirect calls in caller ----------"); int callCount = 0; for (DWORD rva = startRva; rva + 5 <= endRva; rva++) { BYTE* p = base + rva; if (p[0] == 0xE8) { INT32 displacement = 0; memcpy(&displacement, p + 1, sizeof(displacement)); DWORD targetRva = rva + 5 + displacement; Wh_Log( L" E8 CALL RVA=0x%08lX -> RVA=0x%08lX", (unsigned long)rva, (unsigned long)targetRva); callCount++; continue; } // FF 15 disp32 : CALL qword ptr [RIP+disp32] if (p[0] == 0xFF && p[1] == 0x15) { INT32 displacement = 0; memcpy(&displacement, p + 2, sizeof(displacement)); DWORD slotRva = 0; if (ResolveRip32(rva, 6, displacement, &slotRva)) { Wh_Log( L" FF 15 indirect CALL RVA=0x%08lX -> slot RVA=0x%08lX", (unsigned long)rva, (unsigned long)slotRva); if (slotRva < imageSize) { ULONGLONG slotValue = 0; memcpy(&slotValue, base + slotRva, sizeof(slotValue)); Wh_Log( L" slot value = %016llX", (unsigned long long)slotValue); } } else { Wh_Log( L" FF 15 indirect CALL RVA=0x%08lX -> slot outside image", (unsigned long)rva); } callCount++; } } Wh_Log(L"Total calls found in caller: %d", callCount); // The last call before C83C8 is especially important: C83C8 is // a wrapper around vtable slot +0x90, so this identifies the // call that prepares/validates the object immediately before it. DWORD c83c8CallRva = 0; for (DWORD rva = startRva; rva + 5 <= endRva; rva++) { if (base[rva] != 0xE8) continue; INT32 displacement = 0; memcpy(&displacement, base + rva + 1, sizeof(displacement)); DWORD targetRva = rva + 5 + displacement; if (targetRva == 0x000C83C8) { c83c8CallRva = rva; break; } } if (c83c8CallRva) { Wh_Log(L"---------- Immediate call preparation before C83C8 ----------"); Wh_Log(L"Search starts at RVA 0x%08lX (one byte before the C83C8 CALL)", (unsigned long)(c83c8CallRva - 1)); DWORD previousCallRva = 0; for (DWORD rva = c83c8CallRva - 1; rva > startRva; rva--) { if (base[rva] == 0xE8 || (base[rva] == 0xFF && rva + 1 < endRva && base[rva + 1] == 0x15)) { previousCallRva = rva; break; } } if (previousCallRva) { Wh_Log( L"Previous call before C83C8: RVA=0x%08lX", (unsigned long)previousCallRva); DumpFocusedBytes(previousCallRva, 0x30, 0x20); // The known callers use FF 15 indirect calls immediately // before C83C8. Resolve the slot and then resolve the // runtime target to a module/RVA/export when possible. if (base[previousCallRva] == 0xFF && previousCallRva + 6 <= endRva && base[previousCallRva + 1] == 0x15) { INT32 displacement = 0; memcpy( &displacement, base + previousCallRva + 2, sizeof(displacement)); DWORD slotRva = 0; if (ResolveRip32( previousCallRva, 6, displacement, &slotRva)) { Wh_Log( L"Pre-C83C8 indirect CALL slot RVA=0x%08lX", (unsigned long)slotRva); if (slotRva + sizeof(ULONGLONG) <= imageSize) { ULONGLONG slotValue = 0; memcpy( &slotValue, base + slotRva, sizeof(slotValue)); Wh_Log( L"Pre-C83C8 slot value=%p", reinterpret_cast(slotValue)); if (slotValue) { HMODULE targetModule = nullptr; if (GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast( static_cast(slotValue)), &targetModule) && targetModule) { BYTE* targetBase = nullptr; DWORD targetImageSize = 0; if (GetModuleImageInfo( targetModule, &targetBase, &targetImageSize)) { DWORD targetRva = (DWORD)(slotValue - reinterpret_cast(targetBase)); wchar_t targetPath[MAX_PATH] = {}; DWORD pathLength = GetModuleFileNameW( targetModule, targetPath, ARRAYSIZE(targetPath)); if (pathLength) { Wh_Log( L"Pre-C83C8 target module: %s (RVA=0x%08lX)", targetPath, (unsigned long)targetRva); } else { Wh_Log( L"Pre-C83C8 target module resolved, RVA=0x%08lX", (unsigned long)targetRva); } char exportName[256] = {}; const char* name = FindExportNameAnsiByRva( targetModule, targetRva, exportName, ARRAYSIZE(exportName)); if (name) { Wh_Log( L"Pre-C83C8 exact export: %hs", name); } else { Wh_Log(L"Pre-C83C8 exact export: NONE"); LogNearestExports( targetModule, targetRva); } InspectResolvedDui70InitializeV214(slotValue); } else { Wh_Log(L"Pre-C83C8 target image info unavailable"); } } else { Wh_Log( L"Pre-C83C8 target module: NOT RESOLVED (error=%lu)", GetLastError()); } } } else { Wh_Log(L"Pre-C83C8 slot is outside explorerframe.dll"); } } } else { Wh_Log( L"Pre-C83C8 call is not FF 15; no indirect slot to resolve"); } } else { Wh_Log(L"No previous direct/indirect call found before C83C8"); } } else { Wh_Log(L"C83C8 call not found in this caller range"); } Wh_Log(L"------------------------------------------------------"); }; Wh_Log( L"v2.14 focus: inspect the resolved dui70.dll ClassInfoBase::Initialize target and compare the two C83C8 caller functions, identify " L"the exact [RSP+0x28] constants (0x0A vs 0x08), resolve their " L"RIP-relative arguments, and inspect the call immediately before " L"C83C8. No Explorer state is changed and no live object is dereferenced."); InspectCaller( 0x000C8118, 0x000C81BC, L"C83C8 CALLER #1"); InspectCaller( 0x000C81C4, 0x000C8268, L"C83C8 CALLER #2"); Wh_Log( L"v2.14 interpretation target: determine whether the 0x0A/0x08 " L"values select different object/property types and identify the " L"pre-C83C8 call that supplies the object state. The diagnostic " L"does not assume that either constant is a group count."); Wh_Log(L"======================================================"); } struct RuntimeFunctionEntryV218 { DWORD BeginAddress; DWORD EndAddress; DWORD UnwindInfoAddress; }; static const char* GetSectionNameForRvaV218( IMAGE_NT_HEADERS* ntHeaders, DWORD rva) { IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(ntHeaders); for (WORD i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { DWORD sectionStart = sections[i].VirtualAddress; DWORD sectionSize = sections[i].Misc.VirtualSize; if (rva >= sectionStart && rva < sectionStart + sectionSize) { static char name[9]; memset(name, 0, sizeof(name)); memcpy(name, sections[i].Name, 8); return name; } } return ""; } static bool FindContainingFunctionV218( BYTE* base, IMAGE_NT_HEADERS* ntHeaders, DWORD targetRva, DWORD* beginRvaOut, DWORD* endRvaOut) { DWORD pdataRva = 0; DWORD pdataSize = 0; if (!GetExplorerFrameSectionRange( base, ntHeaders, ".pdata", &pdataRva, &pdataSize)) { return false; } if (pdataSize < sizeof(RuntimeFunctionEntryV218)) return false; RuntimeFunctionEntryV218* entries = reinterpret_cast( base + pdataRva); DWORD count = pdataSize / sizeof(RuntimeFunctionEntryV218); for (DWORD i = 0; i < count; i++) { const RuntimeFunctionEntryV218& entry = entries[i]; if (targetRva >= entry.BeginAddress && targetRva < entry.EndAddress) { if (beginRvaOut) *beginRvaOut = entry.BeginAddress; if (endRvaOut) *endRvaOut = entry.EndAddress; return true; } } return false; } static void InspectPropertyInfoCodeTargetV218( BYTE* base, IMAGE_NT_HEADERS* ntHeaders, DWORD targetRva) { DWORD beginRva = 0; DWORD endRva = 0; if (!FindContainingFunctionV218( base, ntHeaders, targetRva, &beginRva, &endRva)) { Wh_Log( L" .text target has no containing .pdata function"); return; } DWORD functionSize = endRva - beginRva; Wh_Log( L" Containing .pdata function: RVA=0x%08lX..0x%08lX Size=0x%lX", (unsigned long)beginRva, (unsigned long)endRva, (unsigned long)functionSize); DWORD dumpSize = functionSize < 0x80 ? functionSize : 0x80; Wh_Log( L" Function bytes (first 0x%lX):", (unsigned long)dumpSize); DumpAddressBytes(base + beginRva, dumpSize); Wh_Log(L" Calls / RIP-relative references in function prefix:"); DWORD scanEnd = beginRva + dumpSize; for (DWORD rva = beginRva; rva + 6 <= scanEnd; rva++) { BYTE b0 = base[rva]; BYTE b1 = base[rva + 1]; if (b0 == 0xE8 || b0 == 0xE9) { INT32 displacement = 0; memcpy( &displacement, base + rva + 1, sizeof(displacement)); DWORD target = rva + 5 + displacement; Wh_Log( L" %s RVA=0x%08lX -> RVA=0x%08lX", b0 == 0xE8 ? L"E8 CALL" : L"E9 JMP", (unsigned long)rva, (unsigned long)target); } else if (b0 == 0xFF && (b1 == 0x15 || b1 == 0x25)) { INT32 displacement = 0; memcpy( &displacement, base + rva + 2, sizeof(displacement)); DWORD slotRva = rva + 6 + displacement; Wh_Log( L" %s RVA=0x%08lX -> slot RVA=0x%08lX", b1 == 0x15 ? L"FF CALL" : L"FF JMP", (unsigned long)rva, (unsigned long)slotRva); DWORD imageSize = ntHeaders->OptionalHeader.SizeOfImage; if (slotRva + sizeof(ULONGLONG) <= imageSize) { ULONGLONG value = 0; memcpy( &value, base + slotRva, sizeof(value)); if (value) { Wh_Log( L" slot value=%p", reinterpret_cast(value)); LogAddressModule(value); } } } else if ((b0 == 0x48 || b0 == 0x4C) && (b1 == 0x8B || b1 == 0x8D) && ((base[rva + 2] & 0xC7) == 0x05)) { INT32 displacement = 0; memcpy( &displacement, base + rva + 3, sizeof(displacement)); DWORD referenceRva = rva + 7 + displacement; Wh_Log( L" RIP %s RVA=0x%08lX -> DataRVA=0x%08lX", b1 == 0x8B ? L"MOV" : L"LEA", (unsigned long)rva, (unsigned long)referenceRva); } } } static void InspectPairedPropertyInfoFunctionsV218( BYTE* base, IMAGE_NT_HEADERS* ntHeaders) { Wh_Log(L""); Wh_Log(L"========== v2.18 PAIRED TARGET ANALYSIS =========="); struct TargetPair { DWORD targetRva; const wchar_t* label; }; const TargetPair targets[] = { {0x000FD3F0, L"PropertyInfo[2] atomic +0x08"}, {0x0025EA00, L"PropertyInfo[3] paired +0x08"}, {0x000E95E0, L"PropertyInfo[7] atomic +0x28"}, {0x0025EA60, L"PropertyInfo[8] paired +0x28"}, }; DWORD imageSize = ntHeaders->OptionalHeader.SizeOfImage; for (size_t i = 0; i < ARRAYSIZE(targets); i++) { DWORD targetRva = targets[i].targetRva; Wh_Log(L""); Wh_Log( L"--- %s: RVA=0x%08lX ---", targets[i].label, (unsigned long)targetRva); if (targetRva >= imageSize) { Wh_Log(L"Target RVA outside image"); continue; } const char* section = GetSectionNameForRvaV218(ntHeaders, targetRva); Wh_Log( L"PE section: %hs", section); DWORD beginRva = 0; DWORD endRva = 0; if (!FindContainingFunctionV218( base, ntHeaders, targetRva, &beginRva, &endRva)) { Wh_Log(L"No containing .pdata function"); continue; } DWORD functionSize = endRva - beginRva; Wh_Log( L"Containing function: RVA=0x%08lX..0x%08lX Size=0x%lX", (unsigned long)beginRva, (unsigned long)endRva, (unsigned long)functionSize); Wh_Log( L"Target offset within function: +0x%lX", (unsigned long)(targetRva - beginRva)); DWORD dumpSize = functionSize; if (dumpSize > 0x200) dumpSize = 0x200; Wh_Log( L"Function bytes (first 0x%lX):", (unsigned long)dumpSize); DumpAddressBytes( base + beginRva, dumpSize); Wh_Log(L"Decoded references/calls:"); DWORD scanEnd = beginRva + dumpSize; for (DWORD rva = beginRva; rva + 6 <= scanEnd; rva++) { BYTE b0 = base[rva]; BYTE b1 = base[rva + 1]; if (b0 == 0xE8 || b0 == 0xE9) { INT32 displacement = 0; memcpy( &displacement, base + rva + 1, sizeof(displacement)); DWORD target = rva + 5 + displacement; Wh_Log( L" %s RVA=0x%08lX -> RVA=0x%08lX", b0 == 0xE8 ? L"E8 CALL" : L"E9 JMP", (unsigned long)rva, (unsigned long)target); } else if (b0 == 0xFF && (b1 == 0x15 || b1 == 0x25)) { INT32 displacement = 0; memcpy( &displacement, base + rva + 2, sizeof(displacement)); DWORD slotRva = rva + 6 + displacement; Wh_Log( L" %s RVA=0x%08lX -> slot RVA=0x%08lX", b1 == 0x15 ? L"FF CALL" : L"FF JMP", (unsigned long)rva, (unsigned long)slotRva); if (slotRva + sizeof(ULONGLONG) <= imageSize) { ULONGLONG value = 0; memcpy( &value, base + slotRva, sizeof(value)); if (value) { Wh_Log( L" slot value=%p", reinterpret_cast(value)); LogAddressModule(value); } } } else if ((b0 == 0x48 || b0 == 0x4C) && (b1 == 0x8B || b1 == 0x8D) && ((base[rva + 2] & 0xC7) == 0x05)) { INT32 displacement = 0; memcpy( &displacement, base + rva + 3, sizeof(displacement)); DWORD referenceRva = rva + 7 + displacement; Wh_Log( L" RIP %s RVA=0x%08lX -> RVA=0x%08lX", b1 == 0x8B ? L"MOV" : L"LEA", (unsigned long)rva, (unsigned long)referenceRva); if (referenceRva < imageSize) { const char* refSection = GetSectionNameForRvaV218( ntHeaders, referenceRva); Wh_Log( L" referenced PE section: %hs", refSection); } } } if (targetRva == 0x000FD3F0 || targetRva == 0x000E95E0) { Wh_Log( L"Atomic instruction focus: compare the object offset " L"used by F0 0F C1 ..."); } else { Wh_Log( L"Paired-function focus: inspect the matching atomic " L"offset and RIP-relative table references above."); } } Wh_Log(L""); Wh_Log( L"v2.18 pair map: [2]+[3] use object offset +0x08; " L"[7]+[8] use object offset +0x28."); Wh_Log( L"v2.18 intentionally does not assign PropertyInfo field " L"semantics or group-count meaning."); Wh_Log(L"=================================================="); } static void InspectFocusedTargetFunctionV219( BYTE* base, IMAGE_NT_HEADERS* ntHeaders, DWORD targetRva, const wchar_t* label) { Wh_Log(L""); Wh_Log( L"========== v2.19 FOCUSED TARGET: %s ==========", label); Wh_Log( L"Target RVA=0x%08lX Address=%p", (unsigned long)targetRva, base + targetRva); DWORD imageSize = ntHeaders->OptionalHeader.SizeOfImage; if (targetRva >= imageSize) { Wh_Log(L"Target RVA is outside explorerframe.dll image"); Wh_Log(L"--------------------------------------------------"); return; } DWORD beginRva = 0; DWORD endRva = 0; if (!FindContainingFunctionV218( base, ntHeaders, targetRva, &beginRva, &endRva)) { Wh_Log(L"Target has no containing .pdata function"); Wh_Log(L"--------------------------------------------------"); return; } DWORD functionSize = endRva - beginRva; Wh_Log( L"Containing .pdata function: RVA=0x%08lX..0x%08lX Size=0x%lX", (unsigned long)beginRva, (unsigned long)endRva, (unsigned long)functionSize); Wh_Log( L"Target offset within function: +0x%lX", (unsigned long)(targetRva - beginRva)); DWORD dumpSize = functionSize; if (dumpSize > 0x200) dumpSize = 0x200; Wh_Log( L"Function bytes (first 0x%lX):", (unsigned long)dumpSize); DumpAddressBytes(base + beginRva, dumpSize); Wh_Log(L"Decoded direct/indirect calls and RIP-relative references:"); DWORD scanEnd = beginRva + dumpSize; for (DWORD rva = beginRva; rva + 6 <= scanEnd; rva++) { BYTE b0 = base[rva]; BYTE b1 = base[rva + 1]; if (b0 == 0xE8 || b0 == 0xE9) { INT32 displacement = 0; memcpy( &displacement, base + rva + 1, sizeof(displacement)); DWORD target = rva + 5 + displacement; Wh_Log( L" %s RVA=0x%08lX -> RVA=0x%08lX", b0 == 0xE8 ? L"E8 CALL" : L"E9 JMP", (unsigned long)rva, (unsigned long)target); if (target == 0x000130BB4) { Wh_Log( L" *** CALLS COMMON TARGET 0x000130BB4 ***"); } } else if (b0 == 0xFF && (b1 == 0x15 || b1 == 0x25)) { INT32 displacement = 0; memcpy( &displacement, base + rva + 2, sizeof(displacement)); DWORD slotRva = rva + 6 + displacement; Wh_Log( L" %s RVA=0x%08lX -> slot RVA=0x%08lX", b1 == 0x15 ? L"FF CALL" : L"FF JMP", (unsigned long)rva, (unsigned long)slotRva); if (slotRva + sizeof(ULONGLONG) <= imageSize) { ULONGLONG value = 0; memcpy( &value, base + slotRva, sizeof(value)); if (value) { Wh_Log( L" slot value=%p", reinterpret_cast(value)); LogAddressModule(value); } } } else if ((b0 == 0x48 || b0 == 0x4C) && (b1 == 0x8B || b1 == 0x8D) && ((base[rva + 2] & 0xC7) == 0x05)) { INT32 displacement = 0; memcpy( &displacement, base + rva + 3, sizeof(displacement)); DWORD referenceRva = rva + 7 + displacement; Wh_Log( L" RIP %s RVA=0x%08lX -> DataRVA=0x%08lX", b1 == 0x8B ? L"MOV" : L"LEA", (unsigned long)rva, (unsigned long)referenceRva); } } Wh_Log(L"Focused object-offset byte patterns:"); for (DWORD rva = beginRva; rva + 8 <= scanEnd; rva++) { // Atomic XADD patterns seen in the paired PropertyInfo // functions. These are logged only when the exact instruction // bytes are present; no runtime object is dereferenced. if (base[rva] == 0xF0 && base[rva + 1] == 0x0F && base[rva + 2] == 0xC1 && base[rva + 3] == 0x79) { BYTE offset = base[rva + 4]; Wh_Log( L" XADD [RCX+0x%02X] at RVA=0x%08lX", (unsigned int)offset, (unsigned long)rva); } } Wh_Log( L"v2.19 note: this is static module-image analysis only. " L"Offsets +0x08/+0x28 are not assigned group-count semantics."); Wh_Log(L"--------------------------------------------------"); } static void InspectCommonTargetRawBytesV220() { const DWORD targetRva = 0x00130BB4; Wh_Log(L""); Wh_Log( L"========== v2.20 RAW COMMON-TARGET ANALYSIS: 0x00130BB4 =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"--------------------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (!dosHeader || dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"Invalid explorerframe.dll DOS header"); Wh_Log(L"--------------------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (!ntHeaders || ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"Invalid explorerframe.dll NT headers"); Wh_Log(L"--------------------------------------------------------------"); return; } DWORD imageSize = ntHeaders->OptionalHeader.SizeOfImage; if (targetRva >= imageSize) { Wh_Log(L"Target RVA is outside explorerframe.dll image"); Wh_Log(L"--------------------------------------------------------------"); return; } const char* targetSection = GetSectionNameForRvaV218( ntHeaders, targetRva); Wh_Log( L"Target RVA=0x%08lX Address=%p Section=%hs", (unsigned long)targetRva, base + targetRva, targetSection); /* * v2.19 could not associate 0x130BB4 with .pdata. * v2.20 therefore treats it only as an image address and examines * the surrounding bytes directly. No bytes are executed or changed. */ const DWORD beforeSize = 0x100; const DWORD afterSize = 0x100; DWORD beforeStart = targetRva > beforeSize ? targetRva - beforeSize : 0; DWORD afterEnd = targetRva + afterSize; if (afterEnd > imageSize) afterEnd = imageSize; Wh_Log( L"Raw bytes before target: RVA=0x%08lX..0x%08lX", (unsigned long)beforeStart, (unsigned long)targetRva); DumpAddressBytes( base + beforeStart, targetRva - beforeStart); Wh_Log( L"Raw bytes after target: RVA=0x%08lX..0x%08lX", (unsigned long)targetRva, (unsigned long)afterEnd); DumpAddressBytes( base + targetRva, afterEnd - targetRva); /* * Look for nearby padding. A run of CC bytes is useful for finding * likely code boundaries, although it is not treated as a proof of * a function boundary. */ Wh_Log(L"Nearby INT3 padding runs:"); DWORD scanStart = beforeStart; DWORD scanEnd = afterEnd; DWORD rva = scanStart; while (rva < scanEnd) { if (base[rva] != 0xCC) { rva++; continue; } DWORD runStart = rva; while (rva < scanEnd && base[rva] == 0xCC) rva++; DWORD runLength = rva - runStart; if (runLength >= 4) { Wh_Log( L" CC run RVA=0x%08lX..0x%08lX Length=0x%lX", (unsigned long)runStart, (unsigned long)rva, (unsigned long)runLength); } } /* * Decode only simple direct E8/E9 instructions in the local window. * This helps determine whether 0x130BB4 is entered from nearby code * or whether nearby code branches away from it. */ Wh_Log(L"Nearby direct CALL/JMP instructions:"); for (rva = scanStart; rva + 5 <= scanEnd; rva++) { BYTE opcode = base[rva]; if (opcode != 0xE8 && opcode != 0xE9) { continue; } INT32 displacement = 0; memcpy( &displacement, base + rva + 1, sizeof(displacement)); DWORD instructionEnd = rva + 5; INT64 target = (INT64)instructionEnd + displacement; if (target < 0 || (ULONGLONG)target >= imageSize) { continue; } Wh_Log( L" %s RVA=0x%08lX -> RVA=0x%08llX%s", opcode == 0xE8 ? L"E8 CALL" : L"E9 JMP", (unsigned long)rva, (unsigned long long)target, target == targetRva ? L" *** TARGET 0x130BB4 ***" : L""); } /* * Decode RIP-relative MOV/LEA instructions in the same window. * These are particularly useful if the target reads or obtains * an object/table pointer immediately around the call site. */ Wh_Log(L"Nearby RIP-relative MOV/LEA instructions:"); for (rva = scanStart; rva + 7 <= scanEnd; rva++) { BYTE b0 = base[rva]; BYTE b1 = base[rva + 1]; if ((b0 != 0x48 && b0 != 0x4C) || (b1 != 0x8B && b1 != 0x8D) || ((base[rva + 2] & 0xC7) != 0x05)) { continue; } INT32 displacement = 0; memcpy( &displacement, base + rva + 3, sizeof(displacement)); INT64 reference = (INT64)(rva + 7) + displacement; if (reference < 0 || (ULONGLONG)reference >= imageSize) { continue; } Wh_Log( L" RIP %s RVA=0x%08lX -> RVA=0x%08llX Section=%hs", b1 == 0x8B ? L"MOV" : L"LEA", (unsigned long)rva, (unsigned long long)reference, GetSectionNameForRvaV218( ntHeaders, (DWORD)reference)); } /* * Search the entire .text section for direct E8 calls whose target * is exactly 0x130BB4. This is the most useful test when the target * has no .pdata entry: it can reveal real callers even though the * target itself lacks unwind metadata. */ DWORD textRva = 0; DWORD textSize = 0; if (GetExplorerFrameSectionRange( base, ntHeaders, ".text", &textRva, &textSize)) { DWORD textEnd = textRva + textSize; if (textEnd > imageSize) textEnd = imageSize; Wh_Log(L"Direct callers of 0x00130BB4 in .text:"); int callerCount = 0; for (rva = textRva; rva + 5 <= textEnd; rva++) { if (base[rva] != 0xE8) continue; INT32 displacement = 0; memcpy( &displacement, base + rva + 1, sizeof(displacement)); DWORD callTarget = rva + 5 + displacement; if (callTarget == targetRva) { callerCount++; Wh_Log( L" CALL RVA=0x%08lX -> 0x00130BB4", (unsigned long)rva); Wh_Log(L" Caller bytes (-0x20..+0x20):"); DWORD callerStart = rva > 0x20 ? rva - 0x20 : 0; DWORD callerEnd = rva + 0x25; if (callerEnd > imageSize) callerEnd = imageSize; DumpAddressBytes( base + callerStart, callerEnd - callerStart); } } Wh_Log( L"Total direct CALL references to 0x00130BB4: %d", callerCount); } else { Wh_Log(L".text section: NOT FOUND"); } /* * If the address is in a gap between .pdata functions, report the * nearest pdata ranges around it. This distinguishes "no containing * pdata entry" from "no nearby functions at all". */ DWORD nearestBefore = 0; DWORD nearestBeforeEnd = 0; DWORD nearestAfter = imageSize; DWORD nearestAfterEnd = imageSize; DWORD exceptionRva = 0; DWORD exceptionSize = 0; if (GetExplorerFrameSectionRange( base, ntHeaders, ".pdata", &exceptionRva, &exceptionSize)) { DWORD entryCount = exceptionSize / sizeof(RuntimeFunctionEntry); RuntimeFunctionEntry* entries = reinterpret_cast( base + exceptionRva); for (DWORD i = 0; i < entryCount; i++) { DWORD begin = entries[i].BeginAddress; DWORD end = entries[i].EndAddress; if (begin == 0 && end == 0) { continue; } if (end <= targetRva && end > nearestBeforeEnd) { nearestBefore = begin; nearestBeforeEnd = end; } if (begin > targetRva && begin < nearestAfter) { nearestAfter = begin; nearestAfterEnd = end; } } if (nearestBeforeEnd) { Wh_Log( L"Nearest .pdata function before target: " L"0x%08lX..0x%08lX", (unsigned long)nearestBefore, (unsigned long)nearestBeforeEnd); } else { Wh_Log(L"No .pdata function before target"); } if (nearestAfter < imageSize) { Wh_Log( L"Nearest .pdata function after target: " L"0x%08lX..0x%08lX", (unsigned long)nearestAfter, (unsigned long)nearestAfterEnd); } else { Wh_Log(L"No .pdata function after target"); } } else { Wh_Log(L".pdata section: NOT FOUND"); } Wh_Log( L"v2.20 conclusion scope: this is still static image analysis only. " L"No Explorer mutation and no live-object dereference were performed."); Wh_Log(L"=============================================================="); } static void InspectRealCommonTargetV221() { const DWORD targetRva = 0x00074448; Wh_Log(L""); Wh_Log( L"========== v2.21 REAL COMMON TARGET ANALYSIS: 0x00074448 =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"--------------------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (!dosHeader || dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"Invalid explorerframe.dll DOS header"); Wh_Log(L"--------------------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (!ntHeaders || ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"Invalid explorerframe.dll NT headers"); Wh_Log(L"--------------------------------------------------------------"); return; } DWORD imageSize = ntHeaders->OptionalHeader.SizeOfImage; if (targetRva >= imageSize) { Wh_Log(L"Target RVA is outside explorerframe.dll image"); Wh_Log(L"--------------------------------------------------------------"); return; } Wh_Log( L"Real target RVA=0x%08lX Address=%p Section=%hs", (unsigned long)targetRva, base + targetRva, GetSectionNameForRvaV218(ntHeaders, targetRva)); DWORD functionBegin = 0; DWORD functionEnd = 0; if (FindContainingFunctionV218( base, ntHeaders, targetRva, &functionBegin, &functionEnd)) { Wh_Log( L"Containing .pdata function: 0x%08lX..0x%08lX Size=0x%08lX", (unsigned long)functionBegin, (unsigned long)functionEnd, (unsigned long)(functionEnd - functionBegin)); DWORD dumpEnd = functionBegin + 0x100; if (dumpEnd > functionEnd) dumpEnd = functionEnd; if (dumpEnd > imageSize) dumpEnd = imageSize; Wh_Log( L"Function bytes: RVA=0x%08lX..0x%08lX", (unsigned long)functionBegin, (unsigned long)dumpEnd); DumpAddressBytes( base + functionBegin, dumpEnd - functionBegin); } else { Wh_Log(L"Target has no containing .pdata function"); functionBegin = targetRva; functionEnd = targetRva + 0x100; if (functionEnd > imageSize) functionEnd = imageSize; Wh_Log( L"Fallback local byte window: RVA=0x%08lX..0x%08lX", (unsigned long)functionBegin, (unsigned long)functionEnd); DumpAddressBytes( base + functionBegin, functionEnd - functionBegin); } /* * Decode simple direct CALL/JMP instructions inside the actual * target function. The important result here is which helpers the * real target invokes after the 0x130BB4 thunk redirects here. */ Wh_Log(L"Direct CALL/JMP instructions in real target function:"); for (DWORD rva = functionBegin; rva + 5 <= functionEnd; rva++) { BYTE opcode = base[rva]; if (opcode != 0xE8 && opcode != 0xE9) continue; INT32 displacement = 0; memcpy( &displacement, base + rva + 1, sizeof(displacement)); INT64 target = (INT64)(rva + 5) + displacement; if (target < 0 || (ULONGLONG)target >= imageSize) { continue; } Wh_Log( L" %s RVA=0x%08lX -> RVA=0x%08llX Section=%hs", opcode == 0xE8 ? L"E8 CALL" : L"E9 JMP", (unsigned long)rva, (unsigned long long)target, GetSectionNameForRvaV218( ntHeaders, (DWORD)target)); } /* * Log RIP-relative MOV/LEA references. These often reveal global * tables, property metadata, or object pointers used by the function. */ Wh_Log(L"RIP-relative MOV/LEA references in real target function:"); for (DWORD rva = functionBegin; rva + 7 <= functionEnd; rva++) { BYTE b0 = base[rva]; BYTE b1 = base[rva + 1]; if ((b0 != 0x48 && b0 != 0x4C) || (b1 != 0x8B && b1 != 0x8D) || ((base[rva + 2] & 0xC7) != 0x05)) { continue; } INT32 displacement = 0; memcpy( &displacement, base + rva + 3, sizeof(displacement)); INT64 reference = (INT64)(rva + 7) + displacement; if (reference < 0 || (ULONGLONG)reference >= imageSize) { continue; } Wh_Log( L" RIP %s RVA=0x%08lX -> RVA=0x%08llX Section=%hs", b1 == 0x8B ? L"MOV" : L"LEA", (unsigned long)rva, (unsigned long long)reference, GetSectionNameForRvaV218( ntHeaders, (DWORD)reference)); } /* * Inspect common object-field operations. This is intentionally a * static byte-pattern scan; it does not dereference an Explorer * object. The offsets are reported as evidence only and are not * assigned group-count semantics. */ Wh_Log(L"Potential object-field accesses / counter operations:"); for (DWORD rva = functionBegin; rva + 4 <= functionEnd; rva++) { if (base[rva] == 0x48 && base[rva + 1] == 0x8B && (base[rva + 2] == 0x41 || base[rva + 2] == 0x49) ) { BYTE offset = base[rva + 3]; Wh_Log( L" MOV register,[RCX+0x%02X] at RVA=0x%08lX", (unsigned int)offset, (unsigned long)rva); } if (base[rva] == 0xF0 && base[rva + 1] == 0x0F && base[rva + 2] == 0xC1 && base[rva + 3] == 0x79) { BYTE offset = base[rva + 4]; Wh_Log( L" XADD [RCX+0x%02X],reg at RVA=0x%08lX", (unsigned int)offset, (unsigned long)rva); } if (base[rva] == 0xFF && (base[rva + 1] == 0x41 || base[rva + 1] == 0x49)) { BYTE offset = base[rva + 2]; Wh_Log( L" INC/DEC [RCX+0x%02X] pattern at RVA=0x%08lX", (unsigned int)offset, (unsigned long)rva); } if (base[rva] == 0x48 && base[rva + 1] == 0x83 && (base[rva + 2] == 0x41 || base[rva + 2] == 0x69)) { BYTE offset = base[rva + 3]; BYTE immediate = base[rva + 4]; Wh_Log( L" ADD/SUB [RCX+0x%02X],imm8=0x%02X pattern at RVA=0x%08lX", (unsigned int)offset, (unsigned int)immediate, (unsigned long)rva); } } /* * The two known callers are the PropertyInfo[3] and PropertyInfo[8] * functions. Dump their immediate pre-call bytes and resolve their * call targets. This lets the next step compare what each caller * places in the x64 argument registers before reaching 0x74448. */ const DWORD callers[] = { 0x0025EA00, 0x0025EA60 }; const wchar_t* callerLabels[] = { L"PropertyInfo[3] function", L"PropertyInfo[8] function" }; for (int i = 0; i < 2; i++) { DWORD callerRva = callers[i]; Wh_Log(L""); Wh_Log( L"---------- %s CALLER CONTEXT ----------", callerLabels[i]); if (callerRva >= imageSize) { Wh_Log(L"Caller RVA outside image"); continue; } Wh_Log( L"Caller RVA=0x%08lX Address=%p", (unsigned long)callerRva, base + callerRva); DWORD callerEnd = callerRva + 0x4B; if (callerEnd > imageSize) callerEnd = imageSize; DumpAddressBytes( base + callerRva, callerEnd - callerRva); Wh_Log(L"Caller direct CALL/JMP targets:"); for (DWORD rva = callerRva; rva + 5 <= callerEnd; rva++) { BYTE opcode = base[rva]; if (opcode != 0xE8 && opcode != 0xE9) continue; INT32 displacement = 0; memcpy( &displacement, base + rva + 1, sizeof(displacement)); INT64 target = (INT64)(rva + 5) + displacement; if (target < 0 || (ULONGLONG)target >= imageSize) { continue; } Wh_Log( L" %s RVA=0x%08lX -> RVA=0x%08llX%s", opcode == 0xE8 ? L"E8 CALL" : L"E9 JMP", (unsigned long)rva, (unsigned long long)target, target == targetRva ? L" *** REAL TARGET 0x74448 ***" : L""); } Wh_Log( L"Caller note: the bytes above are used only to identify the " L"values prepared for the call; no code is executed or changed."); } Wh_Log( L"v2.21 focus: 0x130BB4 is a JMP thunk to 0x74448. " L"This version analyzes the real target and the two known " L"PropertyInfo callers. No group-count meaning is assigned to " L"any field offset without further evidence."); Wh_Log(L"===================================================================="); } static void InspectFocusedTargetsV219() { Wh_Log(L""); Wh_Log( L"========== v2.19 COMMON TARGET / NEIGHBOR FUNCTION ANALYSIS =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"--------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (!dosHeader || dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"Invalid explorerframe.dll DOS header"); Wh_Log(L"--------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (!ntHeaders || ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"Invalid explorerframe.dll NT headers"); Wh_Log(L"--------------------------------------------------"); return; } struct FocusedTarget { DWORD rva; const wchar_t* label; }; const FocusedTarget targets[] = { { 0x000130BB4, L"COMMON TARGET called by PropertyInfo[3]/[8]" }, { 0x0004A33C, L"NEIGHBOR TARGET from PropertyInfo[3]" }, { 0x00047BE8, L"NEIGHBOR TARGET from PropertyInfo[8]" } }; for (size_t i = 0; i < ARRAYSIZE(targets); i++) { InspectFocusedTargetFunctionV219( base, ntHeaders, targets[i].rva, targets[i].label); } Wh_Log(L""); Wh_Log( L"v2.19 interpretation target: trace the common 0x130BB4 " L"function and compare the 0x4A33C/0x47BE8 branches for " L"references to the same internal fields or helper routines."); Wh_Log( L"No Explorer mutation and no arbitrary live-object " L"dereference was performed."); Wh_Log( L"=============================================================="); } static void InspectPropertyInfoArrayV218() { Wh_Log(L"========== v2.18 PROPERTYINFO TARGET / PAIRED-FUNCTION DIAGNOSTIC =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"------------------------------------------------------"); return; } BYTE* base = nullptr; DWORD imageSize = 0; if (!GetModuleImageInfo(module, &base, &imageSize)) { Wh_Log(L"GetModuleImageInfo failed"); Wh_Log(L"------------------------------------------------------"); return; } IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (!dosHeader || dosHeader->e_magic != IMAGE_DOS_SIGNATURE) { Wh_Log(L"Invalid explorerframe.dll DOS header"); Wh_Log(L"------------------------------------------------------"); return; } IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (!ntHeaders || ntHeaders->Signature != IMAGE_NT_SIGNATURE) { Wh_Log(L"Invalid explorerframe.dll NT headers"); Wh_Log(L"------------------------------------------------------"); return; } DWORD rdataRva = 0; DWORD rdataSize = 0; if (!GetExplorerFrameSectionRange( base, ntHeaders, ".rdata", &rdataRva, &rdataSize)) { Wh_Log(L"explorerframe.dll .rdata section: NOT FOUND"); Wh_Log(L"------------------------------------------------------"); return; } DWORD textRva = 0; DWORD textSize = 0; GetExplorerFrameSectionRange( base, ntHeaders, ".text", &textRva, &textSize); const DWORD arrayRva = 0x00297550; const DWORD maxEntries = 10; if (arrayRva + maxEntries * sizeof(ULONGLONG) > imageSize) { Wh_Log(L"PropertyInfo array range exceeds explorerframe.dll image"); Wh_Log(L"------------------------------------------------------"); return; } const wchar_t* knownStrings[] = { L"System.ItemNameDisplay", L"System.Size", L"System.DateModified", L"System.ItemTypeText", L"Name", L"Size", L"Date modified", L"Item type" }; Wh_Log( L"Candidate PropertyInfo array RVA=0x%08lX (maximum entries=%lu)", (unsigned long)arrayRva, (unsigned long)maxEntries); Wh_Log( L"UIItem uses 8 entries; LineScroller uses 10 entries."); Wh_Log( L"v2.18 does not assume a PropertyInfo structure layout; " L"it inspects only safe module-image memory."); Wh_Log(L""); Wh_Log(L"Known UTF-16 strings in explorerframe.dll .rdata:"); int knownStringTotal = 0; for (int k = 0; k < (int)(sizeof(knownStrings) / sizeof(knownStrings[0])); k++) { const wchar_t* wanted = knownStrings[k]; size_t wantedBytes = (wcslen(wanted) + 1) * sizeof(wchar_t); int matches = 0; for (DWORD offset = 0; offset + wantedBytes <= rdataSize; offset += sizeof(wchar_t)) { if (memcmp( base + rdataRva + offset, wanted, wantedBytes) == 0) { Wh_Log( L" \"%s\" -> .rdata RVA=0x%08lX", wanted, (unsigned long)(rdataRva + offset)); matches++; knownStringTotal++; } } if (!matches) { Wh_Log(L" \"%s\" -> NOT FOUND", wanted); } } Wh_Log( L"Known-string matches found=%d", knownStringTotal); Wh_Log(L""); Wh_Log(L"PropertyInfo pointer table:"); ULONGLONG explorerBase = reinterpret_cast(base); ULONGLONG explorerEnd = explorerBase + imageSize; for (DWORD i = 0; i < maxEntries; i++) { ULONGLONG pointerValue = 0; memcpy( &pointerValue, base + arrayRva + i * sizeof(ULONGLONG), sizeof(pointerValue)); Wh_Log( L"PropertyInfo[%lu] @ RVA=0x%08lX = %016llX", (unsigned long)i, (unsigned long)( arrayRva + i * sizeof(ULONGLONG)), (unsigned long long)pointerValue); if (!pointerValue) { Wh_Log(L" -> NULL"); continue; } if (pointerValue < explorerBase || pointerValue >= explorerEnd) { Wh_Log( L" -> outside explorerframe.dll " L"(candidate fields will not be dereferenced)"); continue; } DWORD targetRva = (DWORD)(pointerValue - explorerBase); Wh_Log( L" -> explorerframe.dll RVA=0x%08lX", (unsigned long)targetRva); const char* sectionName = GetSectionNameForRvaV218(ntHeaders, targetRva); Wh_Log( L" -> PE section: %hs", sectionName); if (strcmp(sectionName, ".text") == 0) { InspectPropertyInfoCodeTargetV218( base, ntHeaders, targetRva); } DWORD dumpSize = 0x40; if (targetRva + dumpSize > imageSize) dumpSize = imageSize - targetRva; Wh_Log( L" Target bytes (first 0x%lX):", (unsigned long)dumpSize); DumpAddressBytes(base + targetRva, dumpSize); char exportName[256] = {}; const char* name = FindExportNameAnsiByRva( module, targetRva, exportName, ARRAYSIZE(exportName)); if (name) Wh_Log(L" Exact export: %hs", name); Wh_Log( L" 8-byte aligned candidate fields:"); DWORD fieldCount = dumpSize / sizeof(ULONGLONG); for (DWORD field = 0; field < fieldCount; field++) { ULONGLONG candidate = 0; memcpy( &candidate, base + targetRva + field * sizeof(ULONGLONG), sizeof(candidate)); if (!candidate) continue; bool candidateInsideExplorer = candidate >= explorerBase && candidate < explorerEnd; if (!candidateInsideExplorer) { continue; } DWORD candidateRva = (DWORD)(candidate - explorerBase); Wh_Log( L" +0x%02lX: %016llX -> " L"explorerframe.dll RVA=0x%08lX", (unsigned long)( field * sizeof(ULONGLONG)), (unsigned long long)candidate, (unsigned long)candidateRva); if (candidateRva >= rdataRva && candidateRva < rdataRva + rdataSize) { const wchar_t* text = reinterpret_cast( base + candidateRva); size_t maxChars = 80; size_t availableBytes = (rdataRva + rdataSize) - candidateRva; size_t availableChars = availableBytes / sizeof(wchar_t); if (availableChars < maxChars) maxChars = availableChars; size_t length = 0; while (length < maxChars && text[length] != L'\0') { wchar_t ch = text[length]; if (ch < 0x20 || ch > 0x7E) { if (ch < 0x80) break; } length++; } if (length > 0 && length < maxChars) { Wh_Log( L" -> UTF-16 candidate string: \"%.*s\"", (int)length, text); for (int k = 0; k < (int)( sizeof(knownStrings) / sizeof(knownStrings[0])); k++) { if (wcscmp(text, knownStrings[k]) == 0) { Wh_Log( L" -> MATCHES known string \"%s\"", knownStrings[k]); } } } } } Wh_Log( L" Nearby known-string search " L"(target RVA +/- 0x100):"); DWORD nearbyStart = targetRva > 0x100 ? targetRva - 0x100 : 0; DWORD nearbyEnd = targetRva + 0x100 < imageSize ? targetRva + 0x100 : imageSize; if (nearbyStart < rdataRva) nearbyStart = rdataRva; DWORD rdataEnd = rdataRva + rdataSize; if (nearbyEnd > rdataEnd) nearbyEnd = rdataEnd; bool nearbyMatch = false; for (int k = 0; k < (int)( sizeof(knownStrings) / sizeof(knownStrings[0])); k++) { const wchar_t* wanted = knownStrings[k]; size_t wantedBytes = (wcslen(wanted) + 1) * sizeof(wchar_t); if (wantedBytes > (size_t)(nearbyEnd - nearbyStart)) { continue; } for (DWORD offset = nearbyStart; offset + wantedBytes <= nearbyEnd; offset += sizeof(wchar_t)) { if (memcmp( base + offset, wanted, wantedBytes) == 0) { Wh_Log( L" \"%s\" at RVA=0x%08lX", wanted, (unsigned long)offset); nearbyMatch = true; } } } if (!nearbyMatch) { Wh_Log(L" -> no known strings found in nearby .rdata"); } Wh_Log(L""); } InspectPairedPropertyInfoFunctionsV218( base, ntHeaders); Wh_Log( L"v2.18 interpretation: focus on the paired [2]/[3] and [7]/[8] " L"targets, their atomic object offsets, and their RIP-relative " L"references before assigning any PropertyInfo field meaning."); Wh_Log( L"No Explorer mutation and no arbitrary runtime-object " L"dereference was performed."); Wh_Log(L"------------------------------------------------------"); } static void InspectExplorerFrameFocusedV28() { Wh_Log(L"============================================================"); Wh_Log(L"EXPLORER GROUP COUNTERS FOCUSED DIAGNOSTIC v2.19"); InspectNtdllTargetFromFothk(); InspectCommonIndirectCallTarget(); InspectKnownIndirectSlotsV29(); InspectC83C8VtableCall(); Wh_Log(L"============================================================"); } [[maybe_unused]] static void InspectExplorerFrameDeepTargetFunctions() { Wh_Log( L"========== EXPLORERFRAME SHARED TARGET FUNCTION DIAGNOSTIC v2.7 =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); IMAGE_DOS_HEADER* dosHeader = reinterpret_cast(base); if (dosHeader->e_magic != IMAGE_DOS_SIGNATURE) return; IMAGE_NT_HEADERS* ntHeaders = reinterpret_cast( base + dosHeader->e_lfanew); if (ntHeaders->Signature != IMAGE_NT_SIGNATURE) return; BYTE* textBase = nullptr; DWORD textSize = 0; BYTE* pdataBase = nullptr; DWORD pdataSize = 0; IMAGE_SECTION_HEADER* sections = IMAGE_FIRST_SECTION(ntHeaders); for (WORD i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) { char sectionName[9] = {}; memcpy(sectionName, sections[i].Name, 8); if (strcmp(sectionName, ".text") == 0) { textBase = base + sections[i].VirtualAddress; textSize = sections[i].Misc.VirtualSize; } else if (strcmp(sectionName, ".pdata") == 0) { pdataBase = base + sections[i].VirtualAddress; pdataSize = sections[i].Misc.VirtualSize; } } if (!textBase || !textSize || !pdataBase || !pdataSize) { Wh_Log( L"Required PE sections not found: .text=%p .pdata=%p", textBase, pdataBase); return; } struct DeepTarget { DWORD rva; const wchar_t* name; }; const DeepTarget targets[] = { {0x0005E968, L"Shared target #1 (from UIGroupItem/UIGroupHeader)"}, {0x000C83C8, L"Shared target #2 (from UIGroupItem/UIGroupHeader)"}, {0x00035954, L"Tail-jump target from 0x000C83C8"} }; for (size_t i = 0; i < sizeof(targets) / sizeof(targets[0]); i++) { DWORD functionEndRva = 0; Wh_Log( L"---------- SHARED TARGET %s ----------", targets[i].name); Wh_Log( L"TargetRVA=0x%08lX Address=%p", (unsigned long)targets[i].rva, base + targets[i].rva); if (!FindExplorerFrameFunction( base, pdataBase, pdataSize, targets[i].rva, &functionEndRva)) { Wh_Log( L"TargetRVA=0x%08lX: NOT FOUND IN .pdata", (unsigned long)targets[i].rva); Wh_Log(L"----------------------------------------------"); continue; } DWORD functionSize = functionEndRva - targets[i].rva; Wh_Log( L"FunctionRVA=0x%08lX EndRVA=0x%08lX Size=0x%08lX (%lu bytes)", (unsigned long)targets[i].rva, (unsigned long)functionEndRva, (unsigned long)functionSize, (unsigned long)functionSize); if (targets[i].rva < (DWORD)(textBase - base) || targets[i].rva >= (DWORD)(textBase - base) + textSize || functionEndRva > (DWORD)(textBase - base) + textSize) { Wh_Log(L"Target function is outside .text"); Wh_Log(L"----------------------------------------------"); continue; } DumpExplorerFrameBytes( base, targets[i].rva, functionEndRva); InspectExplorerFrameIndirectReferences( base, targets[i].rva, functionSize); Wh_Log(L"----------------------------------------------"); } InspectExplorerFrameFocusedIndirectSlots(); InspectExplorerFrameFothkFocusedArea(); Wh_Log(L"============================================================"); } [[maybe_unused]] static void InspectExplorerFrameCallArguments() { Wh_Log( L"========== EXPLORERFRAME CALL ARGUMENT DIAGNOSTIC v2.6 =========="); HMODULE module = GetModuleHandleW(L"explorerframe.dll"); if (!module) { Wh_Log(L"explorerframe.dll: NOT LOADED"); Wh_Log(L"----------------------------------------------------"); return; } BYTE* base = reinterpret_cast(module); const DWORD focusedCallSites[] = { 0x000C7BB1, 0x00116223 }; const DWORD helperRvas[] = { 0x000C8B00, 0x00116298 }; const DWORD helperEndRvas[] = { 0x000C8BA4, 0x0011633C }; const wchar_t* helperNames[] = { L"UIGroupItem[2]", L"UIGroupHeader[2]" }; for (size_t i = 0; i < sizeof(focusedCallSites) / sizeof(focusedCallSites[0]); i++) { DWORD callRva = focusedCallSites[i]; Wh_Log( L"---------- FOCUSED CALL SITE %s ----------", GetFocusedCallSiteName(callRva)); DWORD beforeStart = callRva >= 32 ? callRva - 32 : 0; DWORD afterEnd = callRva + 12; Wh_Log( L" Bytes before CALL: 0x%08lX-0x%08lX", (unsigned long)beforeStart, (unsigned long)callRva); DumpExplorerFrameBytes( base, beforeStart, callRva); Wh_Log( L" Bytes after CALL: 0x%08lX-0x%08lX", (unsigned long)(callRva + 5), (unsigned long)afterEnd); DumpExplorerFrameBytes( base, callRva + 5, afterEnd); InspectFocusedCallArguments( base, callRva); InspectFocusedHelperFunction( base, helperRvas[i], helperEndRvas[i], helperNames[i]); Wh_Log( L" CALL instruction: E8 rel32 at RVA 0x%08lX", (unsigned long)callRva); } Wh_Log(L"============================================================"); } [[maybe_unused]] static void InspectExplorerWindows() { Wh_Log(L"========== COM diagnostic started =========="); HRESULT initHr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); bool uninitialize = SUCCEEDED(initHr); if (FAILED(initHr) && initHr != RPC_E_CHANGED_MODE) { LogHresult(L"CoInitializeEx failed", initHr); return; } IShellWindows* shellWindows = nullptr; HRESULT hr = CoCreateInstance( CLSID_ShellWindows, nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&shellWindows) ); if (FAILED(hr)) { LogHresult(L"CoCreateInstance(CLSID_ShellWindows)", hr); if (uninitialize) CoUninitialize(); return; } long count = 0; hr = shellWindows->get_Count(&count); if (FAILED(hr)) { LogHresult(L"IShellWindows::get_Count", hr); shellWindows->Release(); if (uninitialize) CoUninitialize(); return; } Wh_Log(L"ShellWindows count: %ld", count); for (long i = 0; i < count; i++) { VARIANT index; VariantInit(&index); index.vt = VT_I4; index.lVal = i; IDispatch* dispatch = nullptr; hr = shellWindows->Item(index, &dispatch); VariantClear(&index); if (FAILED(hr) || !dispatch) { LogHresult(L"IShellWindows::Item", hr); continue; } Wh_Log(L"---------- Explorer entry %ld ----------", i); IServiceProvider* serviceProvider = nullptr; hr = dispatch->QueryInterface( IID_PPV_ARGS(&serviceProvider) ); if (FAILED(hr)) { LogHresult(L"QueryInterface(IServiceProvider)", hr); dispatch->Release(); continue; } IShellBrowser* shellBrowser = nullptr; hr = serviceProvider->QueryService( SID_STopLevelBrowser, IID_PPV_ARGS(&shellBrowser) ); serviceProvider->Release(); if (FAILED(hr)) { LogHresult(L"QueryService(SID_STopLevelBrowser)", hr); dispatch->Release(); continue; } IShellView* shellView = nullptr; hr = shellBrowser->QueryActiveShellView(&shellView); shellBrowser->Release(); HWND shellViewHwnd = nullptr; if (SUCCEEDED(hr) && shellView) { HRESULT windowHr = shellView->GetWindow(&shellViewHwnd); if (SUCCEEDED(windowHr) && shellViewHwnd) { Wh_Log(L"ShellView HWND: 0x%p", shellViewHwnd); HWND directUIHwnd = FindDescendantWindowByClass( shellViewHwnd, L"DirectUIHWND"); if (directUIHwnd) { Wh_Log(L"DirectUIHWND found: 0x%p", directUIHwnd); InspectUIAutomation(directUIHwnd); } else { Wh_Log(L"DirectUIHWND not found under ShellView"); } } else { LogHresult(L"IShellView::GetWindow", windowHr); } } if (FAILED(hr)) { LogHresult(L"QueryActiveShellView", hr); dispatch->Release(); continue; } IFolderView2* folderView = nullptr; hr = shellView->QueryInterface( IID_PPV_ARGS(&folderView) ); shellView->Release(); dispatch->Release(); if (FAILED(hr)) { LogHresult(L"QueryInterface(IFolderView2)", hr); continue; } PROPERTYKEY groupKey = {}; BOOL ascending = FALSE; hr = folderView->GetGroupBy( &groupKey, &ascending ); bool groupingEnabled = false; if (hr == S_OK) { groupingEnabled = true; wchar_t guid[64] = {}; StringFromGUID2( groupKey.fmtid, guid, ARRAYSIZE(guid) ); Wh_Log(L"Grouping: ENABLED"); Wh_Log(L"Group property GUID: %s", guid); Wh_Log(L"Group property PID: %u", groupKey.pid); Wh_Log(L"Ascending: %d", ascending); // Query the Shell property schema for the grouping mode. InspectPropertyGroupingRange(groupKey); } else if (hr == S_FALSE) { Wh_Log(L"Grouping: DISABLED"); } else { LogHresult(L"IFolderView2::GetGroupBy", hr); } FOLDERVIEWMODE viewMode = FVM_AUTO; int imageSize = 0; hr = folderView->GetViewModeAndIconSize( &viewMode, &imageSize ); if (SUCCEEDED(hr)) { Wh_Log( L"View mode: %d, image size: %d", (int)viewMode, imageSize ); } else { LogHresult( L"GetViewModeAndIconSize", hr ); } int itemCount = 0; hr = folderView->ItemCount( SVGIO_ALLVIEW, &itemCount ); if (SUCCEEDED(hr)) { Wh_Log(L"Total items: %d", itemCount); } else { LogHresult(L"IFolderView::ItemCount", hr); } // Read the property used by Explorer for grouping. wchar_t groupNames[128][256] = {}; int groupCounts[128] = {}; int groupCount = 0; for (int j = 0; j < itemCount; j++) { IShellItem2* item = nullptr; HRESULT itemHr = folderView->GetItem( j, IID_PPV_ARGS(&item) ); if (FAILED(itemHr) || !item) { Wh_Log( L"Item %d: GetItem failed: 0x%08X", j, (unsigned int)itemHr ); continue; } PROPVARIANT value; PropVariantInit(&value); itemHr = item->GetProperty( groupKey, &value ); item->Release(); if (SUCCEEDED(itemHr)) { wchar_t valueText[256] = {}; switch (value.vt) { case VT_LPWSTR: if (value.pwszVal) { lstrcpynW( valueText, value.pwszVal, ARRAYSIZE(valueText) ); } break; case VT_BSTR: if (value.bstrVal) { lstrcpynW( valueText, value.bstrVal, ARRAYSIZE(valueText) ); } break; case VT_UI1: swprintf( valueText, ARRAYSIZE(valueText), L"%u", value.bVal ); break; case VT_UI2: swprintf( valueText, ARRAYSIZE(valueText), L"%u", value.uiVal ); break; case VT_UI4: swprintf( valueText, ARRAYSIZE(valueText), L"%u", value.ulVal ); break; case VT_UI8: swprintf( valueText, ARRAYSIZE(valueText), L"%llu", (unsigned long long)value.uhVal.QuadPart ); break; case VT_I1: swprintf( valueText, ARRAYSIZE(valueText), L"%d", value.cVal ); break; case VT_I2: swprintf( valueText, ARRAYSIZE(valueText), L"%d", value.iVal ); break; case VT_I4: swprintf( valueText, ARRAYSIZE(valueText), L"%d", value.lVal ); break; case VT_I8: swprintf( valueText, ARRAYSIZE(valueText), L"%lld", (long long)value.hVal.QuadPart ); break; case VT_LPSTR: if (value.pszVal) { MultiByteToWideChar( CP_ACP, 0, value.pszVal, -1, valueText, ARRAYSIZE(valueText) ); } break; case VT_FILETIME: { SYSTEMTIME st = {}; if (FileTimeToSystemTime( &value.filetime, &st)) { swprintf( valueText, ARRAYSIZE(valueText), L"%04u-%02u-%02u %02u:%02u:%02u", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond ); } break; } default: swprintf( valueText, ARRAYSIZE(valueText), L"", value.vt ); break; } if (valueText[0] != L'\0') { Wh_Log( L"Item %d: Group value = \"%s\" (VT=%u)", j, valueText, value.vt ); if (groupingEnabled) { InspectPropertyFormattedValue( groupKey, value, j ); } int k = 0; while ( k < groupCount && wcscmp(groupNames[k], valueText) != 0 ) { k++; } if (k == groupCount && groupCount < 128) { lstrcpynW( groupNames[groupCount], valueText, ARRAYSIZE(groupNames[groupCount]) ); groupCount++; } if (k < 128) { groupCounts[k]++; } } else { Wh_Log( L"Item %d: Unsupported/empty property (VT=%u)", j, value.vt ); } } else { Wh_Log( L"Item %d: GetProperty failed: 0x%08X", j, (unsigned int)itemHr ); } PropVariantClear(&value); } Wh_Log(L"========== GROUP VALUES =========="); for (int k = 0; k < groupCount; k++) { Wh_Log( L"Group value: \"%s\" - Count: %d", groupNames[k], groupCounts[k] ); } Wh_Log(L"=================================="); folderView->Release(); } shellWindows->Release(); Wh_Log(L"========== COM diagnostic finished =========="); if (uninitialize) CoUninitialize(); } BOOL Wh_ModInit() { Wh_Log(L"Explorer Group Counters diagnostic v2.21 started"); Wh_Log(L"Explorer PID: %lu", GetCurrentProcessId()); InspectExplorerFrameFocusedV28(); InspectPropertyInfoArrayV218(); InspectCommonTargetRawBytesV220(); InspectRealCommonTargetV221(); InspectFocusedTargetsV219(); InspectC83C8ObjectFlowV29(); return TRUE; } void Wh_ModUninit() { Wh_Log(L"Explorer Group Counters diagnostic stopped"); }