Skip to content

Commit

Permalink
Start10: Fix start menu folders, show recently added, and show freque…
Browse files Browse the repository at this point in the history
…ntly used apps settings not being applied on 22621.2134+
  • Loading branch information
Amrsatrio committed Oct 1, 2023
1 parent 4ece80c commit e28940d
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 5 deletions.
8 changes: 8 additions & 0 deletions ExplorerPatcher/ExplorerPatcher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<AdditionalIncludeDirectories>$(SolutionDir)libs\funchook\include;$(SolutionDir)libs\libvalinet;$(SolutionDir)libs\funchook\distorm\include;$(SolutionDir)libs\Detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<CallingConvention>Cdecl</CallingConvention>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -130,6 +131,7 @@
<AdditionalIncludeDirectories>$(SolutionDir)libs\funchook\include;$(SolutionDir)libs\libvalinet;$(SolutionDir)libs\funchook\distorm\include;$(SolutionDir)libs\Detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<CallingConvention>StdCall</CallingConvention>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -158,6 +160,7 @@
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<CallingConvention>Cdecl</CallingConvention>
<ForcedIncludeFiles>$(SolutionDir)debug.h</ForcedIncludeFiles>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -184,6 +187,7 @@
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<CallingConvention>StdCall</CallingConvention>
<ForcedIncludeFiles>$(SolutionDir)debug.h</ForcedIncludeFiles>
<LanguageStandard>stdcpp20</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -268,6 +272,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="StartMenuSettings.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="StartupSound.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
Expand Down
5 changes: 4 additions & 1 deletion ExplorerPatcher/ExplorerPatcher.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
<ClCompile Include="StartMenu.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="StartMenuSettings.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="symbols.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -223,4 +226,4 @@
<Filter>Settings</Filter>
</None>
</ItemGroup>
</Project>
</Project>
139 changes: 139 additions & 0 deletions ExplorerPatcher/StartMenuSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#include <windows.h>
#include <windows.system.h>
#include <winrt/windows.foundation.collections.h>
#include <winrt/windows.system.h>
#include <roapi.h>

static std::vector<winrt::guid> GlobalStartData_GetPlacesFromRegistry()
{
std::vector<winrt::guid> places;

DWORD dwSize;
HRESULT hr = RegGetValueW(
HKEY_CURRENT_USER,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Start",
L"VisiblePlaces",
RRF_RT_REG_BINARY,
nullptr,
nullptr,
&dwSize
);
if (FAILED(hr) || dwSize == 0)
return places;

places.resize(dwSize / sizeof(winrt::guid));
hr = RegGetValueW(
HKEY_CURRENT_USER,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Start",
L"VisiblePlaces",
RRF_RT_REG_BINARY,
nullptr,
places.data(),
&dwSize
);
if (FAILED(hr))
places.clear();

return places;
}

namespace ABI::WindowsInternal::Shell::CDSProperties
{
interface IStartGlobalProperties;

MIDL_INTERFACE("2c670963-f8a9-4bbb-9adf-683a3a89537e")
IStartGlobalPropertiesFactory : public IInspectable
{
virtual HRESULT STDMETHODCALLTYPE Create(Windows::System::IUser* user, IStartGlobalProperties** result) = 0;
};

MIDL_INTERFACE("ee807266-a2db-4c9a-a1b4-970d33f99c91")
IStartGlobalProperties : public IInspectable
{
virtual HRESULT STDMETHODCALLTYPE get_FullScreenMode(unsigned char*) = 0;
virtual HRESULT STDMETHODCALLTYPE put_FullScreenMode(unsigned char) = 0;
virtual HRESULT STDMETHODCALLTYPE get_HideAppList(unsigned char*) = 0;
virtual HRESULT STDMETHODCALLTYPE put_HideAppList(unsigned char) = 0;
virtual HRESULT STDMETHODCALLTYPE get_HideRecentList(unsigned char*) = 0;
virtual HRESULT STDMETHODCALLTYPE put_HideRecentList(unsigned char) = 0;
virtual HRESULT STDMETHODCALLTYPE get_HideFrequentList(unsigned char*) = 0;
virtual HRESULT STDMETHODCALLTYPE put_HideFrequentList(unsigned char) = 0;
virtual HRESULT STDMETHODCALLTYPE get_StartMenuRelativeHeightPixels(unsigned int*) = 0;
virtual HRESULT STDMETHODCALLTYPE put_StartMenuRelativeHeightPixels(unsigned int) = 0;
virtual HRESULT STDMETHODCALLTYPE get_PlacesInitialized(unsigned char*) = 0;
virtual HRESULT STDMETHODCALLTYPE put_PlacesInitialized(unsigned char) = 0;
virtual HRESULT STDMETHODCALLTYPE get_PlacesInitializedVersion(unsigned int*) = 0;
virtual HRESULT STDMETHODCALLTYPE put_PlacesInitializedVersion(unsigned int) = 0;
virtual HRESULT STDMETHODCALLTYPE GetVisiblePlaces(Windows::Foundation::Collections::IVectorView<GUID>**) = 0;
virtual HRESULT STDMETHODCALLTYPE SetVisiblePlaces(Windows::Foundation::Collections::IVectorView<GUID>*) = 0;
virtual HRESULT STDMETHODCALLTYPE get_StartViewRestoring(unsigned char*) = 0;
virtual HRESULT STDMETHODCALLTYPE put_StartViewRestoring(unsigned char) = 0;
virtual HRESULT STDMETHODCALLTYPE add_PropertiesChanged(
/*Windows::Foundation::ITypedEventHandler<
StartGlobalProperties*,
StartGlobalPropertiesChangedArgs*
>*,
EventRegistrationToken**/
) = 0;
virtual HRESULT STDMETHODCALLTYPE remove_PropertiesChanged(EventRegistrationToken) = 0;
};
}

extern "C" BOOL NeedsRo_SyncSettingsFromRegToCDS()
{
winrt::com_ptr<ABI::WindowsInternal::Shell::CDSProperties::IStartGlobalPropertiesFactory> global_properties_factory;
winrt::param::hstring hstr = L"WindowsInternal.Shell.CDSProperties.StartGlobalProperties";
HRESULT hr = RoGetActivationFactory(
*(HSTRING*)&hstr,
__uuidof(ABI::WindowsInternal::Shell::CDSProperties::IStartGlobalPropertiesFactory),
global_properties_factory.put_void()
);
if (FAILED(hr))
{
return FALSE;
}

winrt::Windows::System::User user = winrt::Windows::System::User::FindAllAsync().get().GetAt(0);
winrt::com_ptr<ABI::WindowsInternal::Shell::CDSProperties::IStartGlobalProperties> start_global_properties;
hr = global_properties_factory->Create(user.as<ABI::Windows::System::IUser>().get(), start_global_properties.put());
if (FAILED(hr))
{
return FALSE;
}

DWORD dwValue, dwSize;

// ShowFrequentList
dwValue = 0; // Default off
dwSize = sizeof(DWORD);
RegGetValueW(
HKEY_CURRENT_USER,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Start",
L"ShowFrequentList",
RRF_RT_REG_DWORD,
nullptr,
&dwValue,
&dwSize
);
start_global_properties->put_HideFrequentList(!dwValue);

// ShowRecentList
dwValue = 1; // Default on
dwSize = sizeof(DWORD);
RegGetValueW(
HKEY_CURRENT_USER,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Start",
L"ShowRecentList",
RRF_RT_REG_DWORD,
nullptr,
&dwValue,
&dwSize
);
start_global_properties->put_HideRecentList(!dwValue);

// VisiblePlaces
auto places_view = single_threaded_vector<winrt::guid>(GlobalStartData_GetPlacesFromRegistry()).GetView();
start_global_properties->SetVisiblePlaces(places_view.as<ABI::Windows::Foundation::Collections::IVectorView<GUID>>().get());

return TRUE;
}
13 changes: 9 additions & 4 deletions ExplorerPatcher/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,7 @@ void EnsureXAML()
hr = IXamlApplicationStatics_get_Current(pXamlApplicationStatics, &pXamlApplication);
if (FAILED(hr))
{
printf("[EnsureXAML] IXamlApplicationStatics::get_Current() failed.\n");
printf("[EnsureXAML] IXamlApplicationStatics::get_Current() failed. 0x%lX\n", hr);
goto cleanup1;
}
pXamlApplication->lpVtbl->Release(pXamlApplication);
Expand Down Expand Up @@ -1996,7 +1996,7 @@ void EnsureXAML()
hr = pCoreWindow5->lpVtbl->get_DispatcherQueue(pCoreWindow5, &pDispatcherQueue);
if (FAILED(hr))
{
printf("[EnsureXAML] ICoreWindow5::get_DispatcherQueue() failed.\n");
printf("[EnsureXAML] ICoreWindow5::get_DispatcherQueue() failed. 0x%lX\n", hr);
goto cleanup3;
}
// Keep pDispatcherQueue referenced in memory
Expand Down Expand Up @@ -11180,7 +11180,7 @@ DWORD Inject(BOOL bIsExplorer)
twinui_pcshell_CMultitaskingViewManager__CreateXamlMTVHostHook
);
}
else
else if (IsWindows11())
{
twinui_pcshell_IsUndockedAssetAvailableFunc = (INT64(*)(void*, POINT*))
((uintptr_t)hTwinuiPcshell + symbols_PTRS.twinui_pcshell_PTRS[7]);
Expand All @@ -11195,7 +11195,7 @@ DWORD Inject(BOOL bIsExplorer)
{
if (IsWindows11Version22H2OrHigher())
printf("Failed to hook twinui_pcshell_CMultitaskingViewManager__CreateXamlMTVHost(). rv = %d\n", rv);
else
else if (IsWindows11())
printf("Failed to hook twinui_pcshell_IsUndockedAssetAvailable(). rv = %d\n", rv);
}

Expand Down Expand Up @@ -12337,6 +12337,11 @@ int Start_SetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw)
SetWindowPos(hWnd, NULL, mi.rcWork.left, mi.rcWork.top, 0, 0, SWP_NOSIZE | SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS);
}
}
if (bIsWindowVisible && IsWindows11Version22H2Build2134OrHigher())
{
extern void NeedsRo_SyncSettingsFromRegToCDS();
NeedsRo_SyncSettingsFromRegToCDS();
}
}
return SetWindowRgn(hWnd, hRgn, bRedraw);
}
Expand Down

2 comments on commit e28940d

@valinet
Copy link
Owner

@valinet valinet commented on e28940d Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Amrsatrio How did you figure this interface out, I am genuinely curious. An excellent contribution, so basically one can obtain this interface from winrt which lets you get/set Start menu’s properties as you wish? Did you disassemble older versions of SystemSettings.exe or older DLLs? You looked through the registry for factories with “Start” in their name? Would you mine explaining the whole process a little bit out? Thank you very much.

@Amrsatrio
Copy link
Collaborator Author

@Amrsatrio Amrsatrio commented on e28940d Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Found hints about what MS calls them as using https://github.com/m417z/UWPSpy. Found out that they're called VisiblePlaces
  2. Cracked open both StartUI.dll and StartDocked.dll, found a function named BuildVisiblePlacesList or something
  3. Found that they call IStartGlobalProperties functions. I forgot how I found that StartGlobalProperties is constructed by StartGlobalPropertiesFactory, but I searched for StartGlobalPropertiesFactory::StartGlobalPropertiesFactory in the process
    The consumer call in StartDocked.dll has the updated code that retrieves the data from registry if a certain feature flag is enabled (instead of calling the interface), while StartUI.dll doesn't have
  4. Found that it retrieves the activation factory for that interface (we got the Interface GUID), then through the registry I cracked open StartTileData.dll which has the implementation for that interfece
  5. Copied the mangled vtable names, demangled them, and turned them into a usable interface in the C++ code

There's nothing in SystemSettings.dll that deals with these start menu settings, I've checked. Ironically, those are in StartTileData.dll which has the same feature flag and loading/saving from registry as well.

I disassembled both 22621.1992 and 22621.2361 (2134 is also fine) DLLs in order to see the differences.

Please sign in to comment.