From 655e62c364e3b16c8a4b53e42e0b56a18a644d85 Mon Sep 17 00:00:00 2001 From: Amrsatrio Date: Sun, 22 Oct 2023 00:03:31 +0700 Subject: [PATCH] Start10: Fixed a bug where certain localizable texts stayed in English I've employed a different method to fix the context menus. Even so, I'm keeping the old method as a fallback. --- ExplorerPatcher/ExplorerPatcher.rc | Bin 35990 -> 36132 bytes ExplorerPatcher/dllmain.c | 108 +++++++++++++++++++++++++++-- ExplorerPatcher/resource.h | 1 + 3 files changed, 102 insertions(+), 7 deletions(-) diff --git a/ExplorerPatcher/ExplorerPatcher.rc b/ExplorerPatcher/ExplorerPatcher.rc index 1e1f3a87867f6e916a5cd38530b9c59e6967742b..3e006d955d5f02d833343a84d4169c9c6cc2a245 100644 GIT binary patch delta 100 zcmbO>lWEB;rVS2)llKVlD7rBOF}N}WGk5?=7a$$N5Xs;J7KvwwU~pn^o17_Nsvg9U r%8m_buffer = LockResource(hgRscr); + pBuffer->m_count = SizeofResource(hModule, hRscr); + pBuffer->m_bufferType = XBT_Binary; + return TRUE; +} + +Parser_XamlBuffer g_EmptyRefreshedStylesXbfBuffer; + +HRESULT(*CCoreServices_TryLoadXamlResourceHelperFunc)(void* _this, void* pUri, bool* pfHasBinaryFile, void** ppMemory, Parser_XamlBuffer* pBuffer, void** ppPhysicalUri); +HRESULT CCoreServices_TryLoadXamlResourceHelperHook(void* _this, void* pUri, bool* pfHasBinaryFile, void** ppMemory, Parser_XamlBuffer* pBuffer, void** ppPhysicalUri) +{ + HRESULT(*Clone)(void* _this, void** ppUri); // index 3 + HRESULT(*GetPath)(void* _this, unsigned int* pBufferLength, wchar_t* pszBuffer); // index 12 + void** vtable = *(void***)pUri; + Clone = vtable[3]; + GetPath = vtable[12]; + wchar_t thePath[MAX_PATH]; + unsigned int len = MAX_PATH; + GetPath(pUri, &len, thePath); + // OutputDebugStringW(thePath); OutputDebugStringW(L"<<<<<\n"); + + if (!wcscmp(thePath, L"/JumpViewUI/RefreshedStyles.xaml")) + { + *pfHasBinaryFile = true; + *pBuffer = g_EmptyRefreshedStylesXbfBuffer; + if (ppPhysicalUri) + Clone(pUri, ppPhysicalUri); + return pBuffer->m_buffer ? S_OK : E_FAIL; + } + + return CCoreServices_TryLoadXamlResourceHelperFunc(_this, pUri, pfHasBinaryFile, ppMemory, pBuffer, ppPhysicalUri); +} + +static BOOL StartMenu_FixContextMenuXbfHijackMethod() +{ + LoadLibraryW(L"Windows.UI.Xaml.dll"); + HANDLE hWindowsUIXaml = GetModuleHandleW(L"Windows.UI.Xaml.dll"); + MODULEINFO mi; + GetModuleInformation(GetCurrentProcess(), hWindowsUIXaml, &mi, sizeof(mi)); + + if (!StartMenu_FillParserBuffer(&g_EmptyRefreshedStylesXbfBuffer, IDR_REFRESHEDSTYLES_XBF)) + return FALSE; + + // 49 89 43 C8 E8 ?? ?? ?? ?? 85 C0 + // ^^^^^^^^^^^ + // Ref: CCoreServices::LoadXamlResource() + PBYTE match = FindPattern( + mi.lpBaseOfDll, + mi.SizeOfImage, + "\x49\x89\x43\xC8\xE8\x00\x00\x00\x00\x85\xC0", + "xxxxx????xx" + ); + if (!match) + return FALSE; + + match += 4; + match += 5 + *(int*)(match + 1); + CCoreServices_TryLoadXamlResourceHelperFunc = match; + funchook_prepare( + funchook, + (void**)&CCoreServices_TryLoadXamlResourceHelperFunc, + CCoreServices_TryLoadXamlResourceHelperHook + ); + return TRUE; +} + LSTATUS StartUI_RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult) { if (wcsstr(lpSubKey, L"$start.tilegrid$windows.data.curatedtilecollection.tilecollection\\Current")) @@ -13189,13 +13279,17 @@ DWORD InjectStartMenu() PatchAppResolver(); PatchStartTileData(); - // 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", StartUI_CreateFileW); - VnPatchIAT(hMrmCoreR, "api-ms-win-core-file-l1-1-0.dll", "GetFileAttributesExW", StartUI_GetFileAttributesExW); - VnPatchIAT(hMrmCoreR, "api-ms-win-core-file-l1-1-0.dll", "FindFirstFileW", StartUI_FindFirstFileW); - VnPatchIAT(hMrmCoreR, "api-ms-win-core-registry-l1-1-0.dll", "RegGetValueW", StartUI_RegGetValueW); + // Fixes context menu crashes + if (!StartMenu_FixContextMenuXbfHijackMethod()) { + // Fallback to the old method, but we'll have broken localization + // 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", StartUI_CreateFileW); + VnPatchIAT(hMrmCoreR, "api-ms-win-core-file-l1-1-0.dll", "GetFileAttributesExW", StartUI_GetFileAttributesExW); + VnPatchIAT(hMrmCoreR, "api-ms-win-core-file-l1-1-0.dll", "FindFirstFileW", StartUI_FindFirstFileW); + VnPatchIAT(hMrmCoreR, "api-ms-win-core-registry-l1-1-0.dll", "RegGetValueW", StartUI_RegGetValueW); + } // Enables "Show more tiles" setting LoadLibraryW(L"Windows.CloudStore.dll"); diff --git a/ExplorerPatcher/resource.h b/ExplorerPatcher/resource.h index 57986c4..2e86782 100644 --- a/ExplorerPatcher/resource.h +++ b/ExplorerPatcher/resource.h @@ -16,6 +16,7 @@ #define IDS_UNINSTALL_ERROR_TEXT 112 #define IDS_OPERATION_NONE 113 #define IDR_REGISTRY2 114 +#define IDR_REFRESHEDSTYLES_XBF 115 #define IDS_DRIVECATEGORY_HARDDISKDRIVES 40000 #define IDS_DRIVECATEGORY_REMOVABLESTORAGE 40001 #define IDS_DRIVECATEGORY_OTHER 40002