1
0
mirror of https://github.com/valinet/ExplorerPatcher.git synced 2024-09-24 11:38:28 +02:00

Start10: Implemented proper fix for Pin to Start/Unpin from Start

This commit is contained in:
Amrsatrio 2023-10-06 06:33:58 +07:00
parent a4f5bd0ceb
commit 15c07a0530
5 changed files with 88 additions and 239 deletions

View File

@ -2239,126 +2239,6 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
}
}
}
else if (!strncmp(line + 1, "pin_tiles", 9))
{
BOOL bFirst = TRUE;
DWORD dwPermitOldStartTileData = TRUE;
DWORD dwSize = sizeof(DWORD);
RegSetKeyValueW(HKEY_CURRENT_USER, L"Software\\ExplorerPatcher", L"PermitOldStartTileDataOneShot", REG_DWORD, &dwPermitOldStartTileData, dwSize);
/*
LPCWSTR csPath = L"::{26EE0668-A00A-44D7-9371-BEB064C98683}";
SFGAOF stSFGAOFIn = 0;
SFGAOF stSFGAOFOut = 0;
SHParseDisplayName(csPath, NULL, &pidl, stSFGAOFIn, &stSFGAOFOut);
*/
WCHAR wszOrigPath[MAX_PATH], wszCurPath[MAX_PATH];
IShellFolder* psfDesktop = NULL;
hr = SHGetDesktopFolder(&psfDesktop);
if (psfDesktop)
{
LPITEMIDLIST pidl;
hr = SHGetFolderLocation(NULL, CSIDL_CONTROLS, (HANDLE)-1, 0, &pidl);
if (pidl)
{
STRRET strret;
hr = psfDesktop->lpVtbl->GetDisplayNameOf(psfDesktop, pidl, SHGDN_FORPARSING, &strret);
StrRetToBufW(&strret, pidl, wszOrigPath, MAX_PATH);
SHOpenFolderAndSelectItems(pidl, 0, NULL, 0);
VARIANT vt;
HRESULT hr = E_FAIL;
IShellWindows* pShellWindows = NULL;
hr = CoCreateInstance(&CLSID_ShellWindows, NULL, CLSCTX_ALL, &IID_IShellWindows, &pShellWindows);
if (pShellWindows)
{
long k = 0;
pShellWindows->lpVtbl->get_Count(pShellWindows, &k);
for (int i = 0; i < k; ++i)
{
vt.vt = VT_I4;
vt.intVal = i;
IDispatch* pDispatch = NULL;
hr = pShellWindows->lpVtbl->Item(pShellWindows, vt, &pDispatch);
if (pDispatch)
{
IWebBrowserApp* pWebBrowserApp = NULL;
hr = pDispatch->lpVtbl->QueryInterface(pDispatch, &IID_IWebBrowserApp, &pWebBrowserApp);
if (pWebBrowserApp)
{
IServiceProvider* pServiceProvider = NULL;
hr = pWebBrowserApp->lpVtbl->QueryInterface(pWebBrowserApp, &IID_IServiceProvider, &pServiceProvider);
if (pServiceProvider)
{
IShellBrowser* pShellBrowser = NULL;
hr = pServiceProvider->lpVtbl->QueryService(pServiceProvider, &SID_STopLevelBrowser, &IID_IShellBrowser, &pShellBrowser);
if (pShellBrowser)
{
IShellView* pShellView = NULL;
hr = pShellBrowser->lpVtbl->QueryActiveShellView(pShellBrowser, &pShellView);
if (pShellView)
{
IFolderView* pFolderView = NULL;
hr = pShellView->lpVtbl->QueryInterface(pShellView, &IID_IFolderView, &pFolderView);
if (pFolderView)
{
IPersistFolder2* pPersistFolder2 = NULL;
hr = pFolderView->lpVtbl->GetFolder(pFolderView, &IID_IPersistFolder2, &pPersistFolder2);
if (pPersistFolder2)
{
LPITEMIDLIST pCur = NULL;
hr = pPersistFolder2->lpVtbl->GetCurFolder(pPersistFolder2, &pCur);
if (pCur)
{
hr = psfDesktop->lpVtbl->GetDisplayNameOf(psfDesktop, pCur, SHGDN_FORPARSING, &strret);
StrRetToBufW(&strret, pidl, wszCurPath, MAX_PATH);
if (!_wcsnicmp(wszOrigPath, wszCurPath, 40) && wcslen(wszCurPath) == 40 && bFirst)
{
LPITEMIDLIST pNew = NULL;
hr = SHGetFolderLocation(NULL, CSIDL_DRIVES, (HANDLE)-1, 0, &pNew);
if (pNew)
{
hr = pShellBrowser->lpVtbl->BrowseObject(pShellBrowser, pNew, SBSP_SAMEBROWSER);
if (SUCCEEDED(hr))
{
HWND hWndExp = NULL;
pWebBrowserApp->lpVtbl->get_HWND(pWebBrowserApp, &hWndExp);
if (hWndExp)
{
INPUT input;
ZeroMemory(&input, sizeof(INPUT));
input.type = INPUT_KEYBOARD;
input.ki.wVk = VK_F5;
SetForegroundWindow(hWndExp);
SendInput(1, &input, sizeof(INPUT));
bFirst = FALSE;
}
}
CoTaskMemFree(pNew);
}
}
CoTaskMemFree(pCur);
}
pPersistFolder2->lpVtbl->Release(pPersistFolder2);
}
pFolderView->lpVtbl->Release(pFolderView);
}
pShellView->lpVtbl->Release(pShellView);
}
pShellBrowser->lpVtbl->Release(pShellBrowser);
}
pServiceProvider->lpVtbl->Release(pServiceProvider);
}
pWebBrowserApp->lpVtbl->Release(pWebBrowserApp);
}
pDispatch->lpVtbl->Release(pDispatch);
}
}
pShellWindows->lpVtbl->Release(pShellWindows);
}
CoTaskMemFree(pidl);
}
psfDesktop->lpVtbl->Release(psfDesktop);
}
}
else if (!strncmp(line + 1, "spotlight_menu", 14))
{
POINT p;

View File

@ -26,8 +26,6 @@ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#include "utility.h"
#include "../ep_weather_host/ep_weather.h"
#include "../ep_weather_host/ep_weather_host_h.h"
#include <ExDisp.h>
#include <ShlGuid.h>
#define MAX_LINE_LENGTH 2000
extern HMODULE hModule;

View File

@ -9301,34 +9301,6 @@ BOOL twinui_RegisterHotkeyHook(HWND hWnd, int id, UINT fsModifiers, UINT vk)
#pragma endregion
#pragma region "Redirect certain library loads to other versions"
HMODULE patched_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
{
if (IsWindows11Version22H2OrHigher())
return LoadLibraryExW(lpLibFileName, hFile, dwFlags);
WCHAR path[MAX_PATH];
GetSystemDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\AppResolver.dll");
if (!_wcsicmp(path, lpLibFileName))
{
GetWindowsDirectoryW(path, MAX_PATH);
wcscat_s(path, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\AppResolverLegacy.dll");
return LoadLibraryExW(path, hFile, dwFlags);
}
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);
}
#pragma endregion
#pragma region "Fix taskbar thumbnails and acrylic in newer OS builds (22572+)"
#ifdef _WIN64
unsigned int (*GetTaskbarColor)(INT64 u1, INT64 u2) = NULL;
@ -9862,53 +9834,6 @@ DWORD InjectBasicFunctions(BOOL bIsExplorer, BOOL bInstall)
}
}
DWORD dwPermitOldStartTileData = FALSE;
DWORD dwSize = sizeof(DWORD);
if (bInstall)
{
dwSize = sizeof(DWORD);
RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", L"Start_ShowClassicMode", RRF_RT_DWORD, NULL, &dwStartShowClassicMode, &dwSize);
dwSize = sizeof(DWORD);
RegGetValueW(HKEY_CURRENT_USER, L"Software\\ExplorerPatcher", L"PermitOldStartTileDataOneShot", RRF_RT_DWORD, NULL, &dwPermitOldStartTileData, &dwSize);
}
if (dwStartShowClassicMode && dwPermitOldStartTileData)
{
HANDLE hCombase = LoadLibraryW(L"combase.dll");
if (hCombase)
{
if (bInstall)
{
WCHAR wszPath[MAX_PATH], wszExpectedPath[MAX_PATH];
ZeroMemory(wszPath, MAX_PATH);
ZeroMemory(wszExpectedPath, MAX_PATH);
DWORD dwLength = MAX_PATH;
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
if (hProcess)
{
QueryFullProcessImageNameW(hProcess, 0, wszPath, &dwLength);
CloseHandle(hProcess);
}
if (GetWindowsDirectoryW(wszExpectedPath, MAX_PATH))
{
wcscat_s(wszExpectedPath, MAX_PATH, L"\\explorer.exe");
if (!_wcsicmp(wszPath, wszExpectedPath))
{
dwPermitOldStartTileData = FALSE;
dwSize = sizeof(DWORD);
RegDeleteKeyValueW(HKEY_CURRENT_USER, L"Software\\ExplorerPatcher", L"PermitOldStartTileDataOneShot");
VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", patched_LoadLibraryExW);
}
}
else
{
VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", LoadLibraryExW);
FreeLibrary(hCombase);
FreeLibrary(hCombase);
}
}
}
}
#ifdef _WIN64
// As of writing this function is never invoked with bInstall=TRUE, so we don't handle the case if it's false for now
RtlQueryFeatureConfigurationFunc = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlQueryFeatureConfiguration");
@ -10672,7 +10597,8 @@ cleanup:
#pragma region "Fix Pin to Start from Explorer not working when using Windows 10 start menu"
#ifdef _WIN64
HRESULT(*AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc)(void** out);
HRESULT AppResolver_StartDocked_GetStartScreenManagerExtensionStatics(void** out)
HRESULT(*StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc)(void** out);
HRESULT StartDocked_GetStartScreenManagerExtensionStaticsHook(void** out)
{
if (dwStartShowClassicMode)
{
@ -10686,53 +10612,54 @@ typedef struct CCacheShortcut CCacheShortcut;
extern HRESULT(*AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc)(const CCacheShortcut* a2, const void* a3);
extern HRESULT AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStart(const CCacheShortcut* a2, const void* a3);
void PatchAppResolver()
static void FindGetStartScreenManagerExtensionStatics(const MODULEINFO* pModuleInfo, HRESULT(**ppfnOut)(void**))
{
// StartDocked::GetStartScreenManagerExtensionStatics
// 48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 37 ?? 8B F1 48 83 21 00
PBYTE match = FindPattern(
pModuleInfo->lpBaseOfDll,
pModuleInfo->SizeOfImage,
"\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x55\x57\x41\x56\x48\x8D\x6C\x24\x00\x48\x81\xEC\x00\x00\x00\x00\x48\x8B\x05\x00\x00\x00\x00\x48\x33\xC4\x48\x89\x45\x37\x00\x8B\xF1\x48\x83\x21\x00",
"xxxx?xxxx?xxxxxxxx?xxx????xxx????xxxxxxx?xxxxxx"
);
if (match)
{
*ppfnOut = match;
}
}
static void PatchAppResolver()
{
HANDLE hAppResolver = LoadLibraryW(L"AppResolver.dll");
MODULEINFO miAppResolver;
GetModuleInformation(GetCurrentProcess(), hAppResolver, &miAppResolver, sizeof(MODULEINFO));
// StartDocked::GetStartScreenManagerExtensionStatics
// 48 89 5C 24 ? 48 89 74 24 ? 55 57 41 56 48 8D 6C 24 ? 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 48 33 C4 48 89 45 37 ?? 8B F1 48 83 21 00
PBYTE match = FindPattern(
hAppResolver,
miAppResolver.SizeOfImage,
"\x48\x89\x5C\x24\x00\x48\x89\x74\x24\x00\x55\x57\x41\x56\x48\x8D\x6C\x24\x00\x48\x81\xEC\x00\x00\x00\x00\x48\x8B\x05\x00\x00\x00\x00\x48\x33\xC4\x48\x89\x45\x37\x00\x8B\xF1\x48\x83\x21\x00",
"xxxx?xxxx?xxxxxxxx?xxx????xxx????xxxxxxx?xxxxxx"
);
int rv = -1;
if (match)
FindGetStartScreenManagerExtensionStatics(&miAppResolver, &AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc);
if (AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc)
{
AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc = match;
printf("StartDocked::GetStartScreenManagerExtensionStatics() = %llX\n", match - (PBYTE)hAppResolver);
rv = funchook_prepare(
funchook,
(void**)&AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc,
AppResolver_StartDocked_GetStartScreenManagerExtensionStatics
);
}
if (rv != 0)
{
printf("Failed to hook StartDocked::GetStartScreenManagerExtensionStatics(). rv = %d\n", rv);
printf("AppResolver.dll!StartDocked::GetStartScreenManagerExtensionStatics() = %llX\n", (PBYTE)AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc - (PBYTE)hAppResolver);
}
// CAppResolverCacheBuilder::_AddUserPinnedShortcutToStart()
// 8B ? 48 8B D3 E8 ? ? ? ? 48 8B 8D
// ^^^^^^^
match = FindPattern(
PBYTE match = FindPattern(
hAppResolver,
miAppResolver.SizeOfImage,
"\x8B\x00\x48\x8B\xD3\xE8\x00\x00\x00\x00\x48\x8B\x8D",
"x?xxxx????xxx"
);
rv = -1;
if (match)
{
match += 5;
match = match + 5 + *(int*)(match + 1);
AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc = match;
printf("CAppResolverCacheBuilder::_AddUserPinnedShortcutToStart() = %llX\n", match - (PBYTE)hAppResolver);
extern HRESULT AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStart(const void* a2, const void* a3);
}
int rv = -1;
if (AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc)
{
rv = funchook_prepare(
funchook,
(void**)&AppResolver_CAppResolverCacheBuilder__AddUserPinnedShortcutToStartFunc,
@ -10742,6 +10669,48 @@ void PatchAppResolver()
if (rv != 0)
{
printf("Failed to hook CAppResolverCacheBuilder::_AddUserPinnedShortcutToStart(). rv = %d\n", rv);
return; // Must be hooked properly otherwise our GetStartScreenManagerExtensionStatics hook will make it crash
}
rv = -1;
if (AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc)
{
rv = funchook_prepare(
funchook,
(void**)&AppResolver_StartDocked_GetStartScreenManagerExtensionStaticsFunc,
StartDocked_GetStartScreenManagerExtensionStaticsHook
);
}
if (rv != 0)
{
printf("Failed to hook AppResolver.dll!StartDocked::GetStartScreenManagerExtensionStatics(). rv = %d\n", rv);
}
}
static void PatchStartTileData()
{
HANDLE hStartTileData = LoadLibraryW(L"StartTileData.dll");
MODULEINFO miStartTileData;
GetModuleInformation(GetCurrentProcess(), hStartTileData, &miStartTileData, sizeof(MODULEINFO));
FindGetStartScreenManagerExtensionStatics(&miStartTileData, &StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc);
if (StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc)
{
printf("StartTileData.dll!StartDocked::GetStartScreenManagerExtensionStatics() = %llX\n", (PBYTE)StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc - (PBYTE)hStartTileData);
}
int rv = -1;
if (StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc)
{
rv = funchook_prepare(
funchook,
(void**)&StartTileData_StartDocked_GetStartScreenManagerExtensionStaticsFunc,
StartDocked_GetStartScreenManagerExtensionStaticsHook
);
}
if (rv != 0)
{
printf("Failed to hook StartTileData.dll!StartDocked::GetStartScreenManagerExtensionStatics(). rv = %d\n", rv);
}
}
#endif
@ -11099,6 +11068,7 @@ DWORD Inject(BOOL bIsExplorer)
// Fix Pin to Start/Unpin from Start
PatchAppResolver();
PatchStartTileData();
}
//VnPatchIAT(hExplorer, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadStringW", explorer_LoadStringWHook);
if (bClassicThemeMitigations)
@ -12855,10 +12825,9 @@ void InjectStartMenu()
if (IsWindows11())
{
// 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", patched_LoadLibraryExW);
// Fixes Pin to Start/Unpin from Start
PatchAppResolver();
PatchStartTileData();
// Redirects to pri files from 22000.51 which work with the legacy menu
LoadLibraryW(L"MrmCoreR.dll");

View File

@ -326,8 +326,6 @@
;x 3 Hide
;x 1 Disable
;"Virtualized_{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}_NoStartMenuMorePrograms"=dword:00000000
;u Pin tiles to Windows 10 Start menu from File Explorer
;pin_tiles
;y IMPORTANT, MUST READ: Notice regarding this feature (online)
;https://github.com/valinet/ExplorerPatcher/discussions/1679
;g StartMenu_Windows10

View File

@ -951,18 +951,18 @@ int WINAPI wWinMain(
{
GetWindowsDirectoryW(wszPath, MAX_PATH);
wcscat_s(wszPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\AppResolverLegacy.dll");
if (ShouldDownloadOrDelete(bInstall, hInstance, wszPath, "BAD744C69B92BBD508D3950B41822683") && IsConnectedToInternet() == TRUE)
if (FileExistsW(wszPath))
{
DownloadFile(L"https://github.com/valinet/ExplorerPatcher/files/8148997/AppResolverLegacy.dll.txt", 10 * 1024 * 1024, wszPath);
bOk = DeleteFileW(wszPath);
}
}
if (bOk && IsWindows11())
{
GetWindowsDirectoryW(wszPath, MAX_PATH);
wcscat_s(wszPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\StartTileDataLegacy.dll");
if (ShouldDownloadOrDelete(bInstall, hInstance, wszPath, "aa36a082e3b33297b6930eea6e98f8cf") && IsConnectedToInternet() == TRUE)
if (FileExistsW(wszPath))
{
DownloadFile(L"https://github.com/valinet/ExplorerPatcher/files/8136435/StartTileDataLegacy.pri.txt", 10 * 1024 * 1024, wszPath);
bOk = DeleteFileW(wszPath);
}
}
if (bOk && IsWindows11())
@ -977,12 +977,16 @@ int WINAPI wWinMain(
if (bOk && IsWindows11())
{
GetWindowsDirectoryW(wszPath, MAX_PATH);
wcscat_s(wszPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\en-US");
CreateDirectoryW(wszPath, NULL);
wcscat_s(wszPath, MAX_PATH, L"\\StartTileDataLegacy.dll.mui");
if (ShouldDownloadOrDelete(bInstall, hInstance, wszPath, "0ed61f384c39116f424eb2fa6b3b9ef8") && IsConnectedToInternet() == TRUE)
wcscat_s(wszPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\en-US\\StartTileDataLegacy.dll.mui");
if (FileExistsW(wszPath))
{
DownloadFile(L"https://github.com/valinet/ExplorerPatcher/files/8136433/StartTileDataLegacy.dll.mui.txt", 10 * 1024 * 1024, wszPath);
bOk = DeleteFileW(wszPath);
if (bOk)
{
GetWindowsDirectoryW(wszPath, MAX_PATH);
wcscat_s(wszPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\en-US");
bOk = RemoveDirectoryW(wszPath);
}
}
}
if (bOk && IsWindows11())
@ -1244,4 +1248,4 @@ int WINAPI wWinMain(
}
return GetLastError();
}
}