Skip to content

Commit

Permalink
Start: Functional Windows 10 Start menu
Browse files Browse the repository at this point in the history
  • Loading branch information
valinet committed Feb 24, 2022
1 parent 43adf91 commit fbd6ab5
Show file tree
Hide file tree
Showing 14 changed files with 1,118 additions and 19 deletions.
11 changes: 10 additions & 1 deletion ExplorerPatcher.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
VisualStudioVersion = 17.0.32126.317
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExplorerPatcher", "ExplorerPatcher\ExplorerPatcher.vcxproj", "{DB3E4319-2969-42B6-B7E8-BB57AA8C9FA9}"
ProjectSection(ProjectDependencies) = postProject
Expand All @@ -18,6 +18,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ep_setup", "ep_setup\ep_set
{DB3E4319-2969-42B6-B7E8-BB57AA8C9FA9} = {DB3E4319-2969-42B6-B7E8-BB57AA8C9FA9}
{1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87} = {1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87}
{314A50C1-F0A0-4D0C-89E1-AD8F3951043E} = {314A50C1-F0A0-4D0C-89E1-AD8F3951043E}
{6BF03EEA-200A-4698-9555-057DD52B0C78} = {6BF03EEA-200A-4698-9555-057DD52B0C78}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ep_setup_patch", "ep_setup_patch\ep_setup_patch.vcxproj", "{0C13E5F3-106B-4836-A7C2-8E5808A6ED78}"
Expand All @@ -34,6 +35,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ep_weather_host", "ep_weath
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ep_weather_host_stub", "ep_weather_host_stub\ep_weather_host_stub.vcxproj", "{AF02ABAC-EAEB-471C-9957-73D430B8B4DE}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ep_startmenu", "ep_startmenu\ep_startmenu.vcxproj", "{6BF03EEA-200A-4698-9555-057DD52B0C78}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|amd64 = Debug|amd64
Expand Down Expand Up @@ -92,6 +95,12 @@ Global
{AF02ABAC-EAEB-471C-9957-73D430B8B4DE}.Release|amd64.ActiveCfg = Release|x64
{AF02ABAC-EAEB-471C-9957-73D430B8B4DE}.Release|amd64.Build.0 = Release|x64
{AF02ABAC-EAEB-471C-9957-73D430B8B4DE}.Release|IA-32.ActiveCfg = Release|Win32
{6BF03EEA-200A-4698-9555-057DD52B0C78}.Debug|amd64.ActiveCfg = Debug|x64
{6BF03EEA-200A-4698-9555-057DD52B0C78}.Debug|amd64.Build.0 = Debug|x64
{6BF03EEA-200A-4698-9555-057DD52B0C78}.Debug|IA-32.ActiveCfg = Debug|Win32
{6BF03EEA-200A-4698-9555-057DD52B0C78}.Release|amd64.ActiveCfg = Release|x64
{6BF03EEA-200A-4698-9555-057DD52B0C78}.Release|amd64.Build.0 = Release|x64
{6BF03EEA-200A-4698-9555-057DD52B0C78}.Release|IA-32.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
202 changes: 187 additions & 15 deletions ExplorerPatcher/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -8863,6 +8863,7 @@ char VisibilityChangedEventArguments_GetVisible(__int64 a1)
return v3[0];
}

DWORD StartMenu_ShowClassicMode = 0;
DWORD StartMenu_maximumFreqApps = 6;
DWORD StartMenu_ShowAllApps = 0;

Expand Down Expand Up @@ -8933,6 +8934,41 @@ void StartMenu_LoadSettings(BOOL bRestartIfChanged)
StartMenu_maximumFreqApps = dwVal;
RegCloseKey(hKey);
}

RegCreateKeyExW(
HKEY_CURRENT_USER,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_READ,
NULL,
&hKey,
NULL
);
if (hKey == NULL || hKey == INVALID_HANDLE_VALUE)
{
hKey = NULL;
}
if (hKey)
{
dwSize = sizeof(DWORD);
dwVal = 0;
RegQueryValueExW(
hKey,
TEXT("Start_ShowClassicMode"),
0,
NULL,
&dwVal,
&dwSize
);
if (bRestartIfChanged && dwVal != StartMenu_ShowClassicMode)
{
exit(0);
}
StartMenu_ShowClassicMode = dwVal;
RegCloseKey(hKey);
}
}

static INT64(*StartDocked_LauncherFrame_OnVisibilityChangedFunc)(void*, INT64, void*) = NULL;
Expand Down Expand Up @@ -8966,6 +9002,13 @@ INT64 StartDocked_SystemListPolicyProvider_GetMaximumFrequentAppsHook(void* _thi
return StartMenu_maximumFreqApps;
}

INT64(*StartUI_SystemListPolicyProvider_GetMaximumFrequentAppsFunc)(void*) = NULL;

INT64 StartUI_SystemListPolicyProvider_GetMaximumFrequentAppsHook(void* _this)
{
return StartMenu_maximumFreqApps;
}

INT64(*StartDocked_StartSizingFrame_StartSizingFrameFunc)(void* _this) = NULL;

INT64 StartDocked_StartSizingFrame_StartSizingFrameHook(void* _this)
Expand Down Expand Up @@ -8993,6 +9036,110 @@ INT64 StartDocked_StartSizingFrame_StartSizingFrameHook(void* _this)
return rv;
}

HANDLE start_CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
WCHAR path[MAX_PATH];
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemResources\\Windows.UI.ShellCommon\\Windows.UI.ShellCommon.pri");
if (!_wcsicmp(path, lpFileName))
{
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\Windows.UI.ShellCommon.pri");
return CreateFileW(path, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemResources\\Windows.UI.ShellCommon\\pris");
int len = wcslen(path);
if (!_wcsnicmp(path, lpFileName, len))
{
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\pris2");
wcscat_s(path, MAX_PATH, lpFileName + len);
return CreateFileW(path, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}
return CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}

BOOL start_GetFileAttributesExW(LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId, LPVOID lpFileInformation)
{
WCHAR path[MAX_PATH];
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemResources\\Windows.UI.ShellCommon\\Windows.UI.ShellCommon.pri");
if (!_wcsicmp(path, lpFileName))
{
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\Windows.UI.ShellCommon.pri");
return GetFileAttributesExW(path, fInfoLevelId, lpFileInformation);
}
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemResources\\Windows.UI.ShellCommon\\pris");
int len = wcslen(path);
if (!_wcsnicmp(path, lpFileName, len))
{
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\pris2");
wcscat_s(path, MAX_PATH, lpFileName + len);
return GetFileAttributesExW(path, fInfoLevelId, lpFileInformation);
}
return GetFileAttributesExW(lpFileName, fInfoLevelId, lpFileInformation);
}

HANDLE start_FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData)
{
WCHAR path[MAX_PATH];
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemResources\\Windows.UI.ShellCommon\\Windows.UI.ShellCommon.pri");
if (!_wcsicmp(path, lpFileName))
{
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\Windows.UI.ShellCommon.pri");
return FindFirstFileW(path, lpFindFileData);
}
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemResources\\Windows.UI.ShellCommon\\pris");
int len = wcslen(path);
if (!_wcsnicmp(path, lpFileName, len))
{
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\pris2");
wcscat_s(path, MAX_PATH, lpFileName + len);
return FindFirstFileW(path, lpFindFileData);
}
return FindFirstFileW(lpFileName, lpFindFileData);
}

LSTATUS start_RegGetValueW(HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue, DWORD dwFlags, LPDWORD pdwType, PVOID pvData, LPDWORD pcbData)
{
if (hkey == HKEY_LOCAL_MACHINE && !_wcsicmp(lpSubKey, L"Software\\Microsoft\\Windows\\CurrentVersion\\Mrt\\_Merged") && !_wcsicmp(lpValue, L"ShouldMergeInProc"))
{
*(DWORD*)pvData = 1;
return ERROR_SUCCESS;
}
return RegGetValueW(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData);
}

int start_SetWindowRgn(HWND hWnd, HRGN hRgn, BOOL bRedraw)
{
DWORD dwThisPID = GetCurrentProcessId(), dwForeignPID = 0;
GetWindowThreadProcessId(GetForegroundWindow(), &dwForeignPID);
ShowWindow(hWnd, (!hRgn && dwThisPID != dwForeignPID) ? SW_HIDE : SW_SHOW);
return SetWindowRgn(hWnd, hRgn, bRedraw);
}

HMODULE start_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
{
WCHAR path[MAX_PATH];
GetSystemDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\StartTileData.dll");
if (!_wcsicmp(path, lpLibFileName))
{
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\StartTileDataLegacy.dll");
return LoadLibraryExW(path, hFile, dwFlags);
}
return LoadLibraryExW(lpLibFileName, hFile, dwFlags);
}

int WINAPI SetupMessage(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
return 0;
Expand Down Expand Up @@ -9407,9 +9554,33 @@ void InjectStartMenu()
#ifdef _WIN64
funchook = funchook_create();

LoadLibraryW(L"StartDocked.dll");
HANDLE hStartDocked = GetModuleHandleW(L"StartDocked.dll");
LoadLibraryW(L"StartUI.dll");
HANDLE hStartUI = GetModuleHandleW(L"StartUI.dll");

StartMenu_LoadSettings(FALSE);

Setting* settings = calloc(3, sizeof(Setting));
if (StartMenu_ShowClassicMode)
{
// Fixes hang when Start menu closes
VnPatchDelayIAT(hStartUI, "ext-ms-win-ntuser-draw-l1-1-0.dll", "SetWindowRgn", start_SetWindowRgn);

// Redirects to StartTileData from 22000.51 which works with the legacy menu
LoadLibraryW(L"combase.dll");
HANDLE hCombase = GetModuleHandleW(L"combase.dll");
VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", start_LoadLibraryExW);

// Redirects to pri files from 22000.51 which work with the legacy menu
LoadLibraryW(L"MrmCoreR.dll");
HANDLE hMrmCoreR = GetModuleHandleW(L"MrmCoreR.dll");
VnPatchIAT(hMrmCoreR, "api-ms-win-core-file-l1-1-0.dll", "CreateFileW", start_CreateFileW);
VnPatchIAT(hMrmCoreR, "api-ms-win-core-file-l1-1-0.dll", "GetFileAttributesExW", start_GetFileAttributesExW);
VnPatchIAT(hMrmCoreR, "api-ms-win-core-file-l1-1-0.dll", "FindFirstFileW", start_FindFirstFileW);
VnPatchIAT(hMrmCoreR, "api-ms-win-core-registry-l1-1-0.dll", "RegGetValueW", start_RegGetValueW);
}

Setting* settings = calloc(4, sizeof(Setting));
settings[0].callback = NULL;
settings[0].data = NULL;
settings[0].hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
Expand All @@ -9428,10 +9599,16 @@ void InjectStartMenu()
settings[2].hKey = NULL;
wcscpy_s(settings[2].name, MAX_PATH, TEXT(REGPATH_STARTMENU));
settings[2].origin = HKEY_CURRENT_USER;
settings[3].callback = StartMenu_LoadSettings;
settings[3].data = TRUE;
settings[3].hEvent = NULL;
settings[3].hKey = NULL;
wcscpy_s(settings[3].name, MAX_PATH, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced");
settings[3].origin = HKEY_CURRENT_USER;

SettingsChangeParameters* params = calloc(1, sizeof(SettingsChangeParameters));
params->settings = settings;
params->size = 3;
params->size = 4;
CreateThread(
0,
0,
Expand All @@ -9442,8 +9619,7 @@ void InjectStartMenu()
);

int rv;

DWORD dwVal0 = 0x62254, dwVal1 = 0x188EBC, dwVal2 = 0x187120, dwVal3 = 0x3C10, dwVal4 = 0x160AEC;
DWORD dwVal0 = 0x62254, dwVal1 = 0x188EBC, dwVal2 = 0x187120, dwVal3 = 0x3C10, dwVal4 = 0;

HMODULE hModule = LoadLibraryW(L"Shlwapi.dll");
if (hModule)
Expand All @@ -9453,7 +9629,6 @@ void InjectStartMenu()

if (SHRegGetValueFromHKCUHKLMFunc)
{

dwSize = sizeof(DWORD);
SHRegGetValueFromHKCUHKLMFunc(
TEXT(REGPATH_STARTMENU) TEXT("\\") TEXT(STARTDOCKED_SB_NAME),
Expand Down Expand Up @@ -9488,20 +9663,17 @@ void InjectStartMenu()
(LPDWORD)(&dwSize)
);
SHRegGetValueFromHKCUHKLMFunc(
TEXT(REGPATH_STARTMENU) TEXT("\\") TEXT(STARTDOCKED_SB_NAME),
TEXT(STARTDOCKED_SB_4),
TEXT(REGPATH_STARTMENU) TEXT("\\") TEXT(STARTUI_SB_NAME),
TEXT(STARTUI_SB_0),
SRRF_RT_REG_DWORD,
NULL,
&dwVal4,
(LPDWORD)(&dwSize)
);

}
FreeLibrary(hModule);
}

LoadLibraryW(L"StartDocked.dll");
HANDLE hStartDocked = GetModuleHandle(L"StartDocked.dll");
if (dwVal1 && dwVal1 != 0xFFFFFFFF)
{
StartDocked_LauncherFrame_ShowAllAppsFunc = (INT64(*)(void*))
Expand Down Expand Up @@ -9539,18 +9711,18 @@ void InjectStartMenu()
}
if (dwVal4 && dwVal4 != 0xFFFFFFFF)
{
/*StartDocked_StartSizingFrame_StartSizingFrameFunc = (INT64(*)(void*, INT64, void*))
((uintptr_t)hStartDocked + dwVal4);
StartUI_SystemListPolicyProvider_GetMaximumFrequentAppsFunc = (INT64(*)(void*, INT64, void*))
((uintptr_t)hStartUI + dwVal4);
rv = funchook_prepare(
funchook,
(void**)&StartDocked_StartSizingFrame_StartSizingFrameFunc,
StartDocked_StartSizingFrame_StartSizingFrameHook
(void**)&StartUI_SystemListPolicyProvider_GetMaximumFrequentAppsFunc,
StartUI_SystemListPolicyProvider_GetMaximumFrequentAppsHook
);
if (rv != 0)
{
FreeLibraryAndExitThread(hModule, rv);
return rv;
}*/
}
}

rv = funchook_install(funchook, 0);
Expand Down
Loading

0 comments on commit fbd6ab5

Please sign in to comment.