Skip to content

Commit

Permalink
Merge branch 'valinet:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
deep-soft authored Oct 23, 2023
2 parents 1b4a9ac + a77aff4 commit d2da7ec
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 60 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

This document includes the same release notes as in the [Releases](https://github.com/valinet/ExplorerPatcher/releases) section on GitHub.

## 22621.2428.59

Tested on OS builds 22000.2416, 22621.2428, 23555.1000, and 23560.1000.

#### Details

##### 1

Note: After updating to this version, the symbols will be re-downloaded even if they have been downloaded before.

* Taskbar10: Fixed Control Center and Toast Center positioning on build 25951 (Canary). (dca0b3a)
* Taskbar10: Fixed start menu position when the taskbar is at the left or right side on Moment 4 builds. (a57471f)
* Taskbar10: Fixed the Windows 10 taskbar background patch to not crash anymore on build 25951 (Canary). (b52bd79)
* Taskbar10: Made taskbar fonts (when using classic theme mitigations) more accurate (thanks @aubymori). (8fc53a1)
* Start10: Fixed a bug where certain texts in the Windows 10 Start menu stayed in English. (c6a7d3f, ed251e9)
* Start10: Properly fixed start menu showing/hiding along with its original animations on builds 22000.65+. (7e2f768)
* GUI: Fixed a bug where "Remember last used section" doesn't remember the current page after being enabled. (dcf72bb)
* Symbols: Reworked how symbols are managed so that symbols don't need to be successfully downloaded in succession. (8412bd6)

## 22621.2361.58

Tested on OS builds 22000.2416, 22621.1, 22621.2134, 22621.2361, 22631.2338, and 23545.1000.
Expand Down
Binary file modified ExplorerPatcher/ExplorerPatcher.rc
Binary file not shown.
4 changes: 2 additions & 2 deletions ExplorerPatcher/ExplorerPatcher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;WINRT_NO_SOURCE_LOCATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)libs\funchook\include;$(SolutionDir)libs\libvalinet;$(SolutionDir)libs\funchook\distorm\include;$(SolutionDir)libs\Detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand Down Expand Up @@ -126,7 +126,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;WINRT_NO_SOURCE_LOCATION;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>$(SolutionDir)libs\funchook\include;$(SolutionDir)libs\libvalinet;$(SolutionDir)libs\funchook\distorm\include;$(SolutionDir)libs\Detours\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
Expand Down
2 changes: 1 addition & 1 deletion ExplorerPatcher/GUI.c
Original file line number Diff line number Diff line change
Expand Up @@ -1619,7 +1619,7 @@ static BOOL GUI_Build(HDC hDC, HWND hwnd, POINT pt)
}
else
{
BeginExplorerRestart();
BeginExplorerRestart(NULL);
}
}
Sleep(100);
Expand Down
Binary file added ExplorerPatcher/RefreshedStyles.xbf
Binary file not shown.
8 changes: 4 additions & 4 deletions ExplorerPatcher/StartMenuSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static std::vector<winrt::guid> GlobalStartData_GetPlacesFromRegistry()
std::vector<winrt::guid> places;

DWORD dwSize;
HRESULT hr = RegGetValueW(
LSTATUS lRes = RegGetValueW(
HKEY_CURRENT_USER,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Start",
L"VisiblePlaces",
Expand All @@ -35,11 +35,11 @@ static std::vector<winrt::guid> GlobalStartData_GetPlacesFromRegistry()
nullptr,
&dwSize
);
if (FAILED(hr) || dwSize == 0)
if (lRes != ERROR_SUCCESS || dwSize == 0)
return places;

places.resize(dwSize / sizeof(winrt::guid));
hr = RegGetValueW(
lRes = RegGetValueW(
HKEY_CURRENT_USER,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Start",
L"VisiblePlaces",
Expand All @@ -48,7 +48,7 @@ static std::vector<winrt::guid> GlobalStartData_GetPlacesFromRegistry()
places.data(),
&dwSize
);
if (FAILED(hr))
if (lRes != ERROR_SUCCESS)
places.clear();

return places;
Expand Down
4 changes: 2 additions & 2 deletions ExplorerPatcher/def.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _H_DEF_H_
#define _H_DEF_H_
#define APPID L"Microsoft.Windows.Explorer"
#define REGPATH "SOFTWARE\\ExplorerPatcher"
#define REGPATH_OLD "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ExplorerPatcher"
#define REGPATH "Software\\ExplorerPatcher"
#define REGPATH_OLD "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ExplorerPatcher"
#define REGPATH_STARTMENU REGPATH_OLD
#define SPECIAL_FOLDER CSIDL_PROGRAM_FILES
#define SPECIAL_FOLDER_LEGACY CSIDL_APPDATA
Expand Down
168 changes: 137 additions & 31 deletions ExplorerPatcher/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -4296,6 +4296,7 @@ INT64 winrt_Windows_Internal_Shell_implementation_MeetAndChatManager_OnMessageHo

#pragma region "Enable old taskbar"
#ifdef _WIN64
HRESULT(*explorer_RoGetActivationFactoryFunc)(HSTRING activatableClassId, GUID* iid, void** factory);
HRESULT explorer_RoGetActivationFactoryHook(HSTRING activatableClassId, GUID* iid, void** factory)
{
PCWSTR StringRawBuffer = WindowsGetStringRawBuffer(activatableClassId, 0);
Expand All @@ -4312,7 +4313,7 @@ HRESULT explorer_RoGetActivationFactoryHook(HSTRING activatableClassId, GUID* ii
return S_OK;
}
}
return RoGetActivationFactory(activatableClassId, iid, factory);
return explorer_RoGetActivationFactoryFunc(activatableClassId, iid, factory);
}

FARPROC explorer_GetProcAddressHook(HMODULE hModule, const CHAR* lpProcName)
Expand Down Expand Up @@ -8062,27 +8063,15 @@ HRESULT explorer_DrawThemeTextEx(
SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICSW), &ncm, 0);

HFONT hFont = NULL;
if (bIsActiveUnhovered)
if (bIsActiveUnhovered || bIsActiveHovered)
{
hFont = CreateFontIndirectW(&(ncm.lfCaptionFont));
}
else if (bIsInactiveUnhovered)
{
hFont = CreateFontIndirectW(&(ncm.lfMenuFont));
}
else if (bIsActiveHovered)
{
hFont = CreateFontIndirectW(&(ncm.lfCaptionFont));
}
else if (bIsInactiveHovered)
{
hFont = CreateFontIndirectW(&(ncm.lfMenuFont));
ncm.lfCaptionFont.lfWeight = FW_BOLD;
}
else
{
hFont = CreateFontIndirectW(&(ncm.lfMenuFont));
//wprintf(L"DrawThemeTextEx %d %d %s\n", iPartId, iStateId, pszText);
ncm.lfCaptionFont.lfWeight = FW_NORMAL;
}
hFont = CreateFontIndirectW(&(ncm.lfCaptionFont));

if (iPartId == 5 && iStateId == 0) // clock
{
Expand Down Expand Up @@ -11001,16 +10990,16 @@ BOOL FixStartMenuAnimation(LPMODULEINFO mi)
}

DWORD dwOldProtect = 0;
if (VirtualProtect(match7a + 11, 3, PAGE_EXECUTE_READWRITE, &dwOldProtect))
if (VirtualProtect(match7a + 11, 1, PAGE_EXECUTE_READWRITE, &dwOldProtect))
{
match7a[0] = 0xEB;
VirtualProtect(match7a + 11, 3, dwOldProtect, &dwOldProtect);
VirtualProtect(match7a + 11, 1, dwOldProtect, &dwOldProtect);

dwOldProtect = 0;
if (VirtualProtect(match7b + 11, 3, PAGE_EXECUTE_READWRITE, &dwOldProtect))
if (VirtualProtect(match7b + 11, 1, PAGE_EXECUTE_READWRITE, &dwOldProtect))
{
match7b[0] = 0xEB;
VirtualProtect(match7b + 11, 3, dwOldProtect, &dwOldProtect);
VirtualProtect(match7b + 11, 1, dwOldProtect, &dwOldProtect);
}
}

Expand Down Expand Up @@ -11396,6 +11385,9 @@ DWORD Inject(BOOL bIsExplorer)
{
VnPatchIAT(hExplorer, "user32.dll", (LPCSTR)2005, explorer_SetChildWindowNoActivateHook);
VnPatchDelayIAT(hExplorer, "ext-ms-win-rtcore-ntuser-window-ext-l1-1-0.dll", "SendMessageW", explorer_SendMessageW);
// A certain configuration update in 23560.1000 broke this method, this didn't get called with
// "RoGetActivationFactory" anymore. ~~We're now hooking RoGetActivationFactory directly.~~ Pulled back for now.
explorer_RoGetActivationFactoryFunc = RoGetActivationFactory;
VnPatchIAT(hExplorer, "api-ms-win-core-libraryloader-l1-2-0.dll", "GetProcAddress", explorer_GetProcAddressHook);
VnPatchIAT(hExplorer, "shell32.dll", "ShellExecuteW", explorer_ShellExecuteW);
VnPatchIAT(hExplorer, "shell32.dll", "ShellExecuteExW", explorer_ShellExecuteExW);
Expand Down Expand Up @@ -11724,11 +11716,31 @@ DWORD Inject(BOOL bIsExplorer)
printf("Setup twinui.pcshell functions done\n");


if (IsWindows11Version22H2OrHigher())
if (IsWindows11())
{
HANDLE hCombase = LoadLibraryW(L"combase.dll");
// Fixed a bug that crashed Explorer when a folder window was opened after a first one was closed on OS builds 22621+
VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", Windows11v22H2_combase_LoadLibraryExW);
/*if (bOldTaskbar) // TODO Pulled back for now, crashes on 22621.2428
{
// Hook RoGetActivationFactory() for old taskbar
explorer_RoGetActivationFactoryFunc = GetProcAddress(hCombase, "RoGetActivationFactory");
if (explorer_RoGetActivationFactoryFunc)
{
rv = funchook_prepare(
funchook,
(void**)&explorer_RoGetActivationFactoryFunc,
explorer_RoGetActivationFactoryHook
);
}
if (rv != 0)
{
printf("Failed to hook RoGetActivationFactory(). rv = %d\n", rv);
}
}*/
if (IsWindows11Version22H2OrHigher())
{
// Fixed a bug that crashed Explorer when a folder window was opened after a first one was closed on OS builds 22621+
VnPatchIAT(hCombase, "api-ms-win-core-libraryloader-l1-2-0.dll", "LoadLibraryExW", Windows11v22H2_combase_LoadLibraryExW);
}
printf("Setup combase functions done\n");
}

Expand Down Expand Up @@ -12569,6 +12581,96 @@ LSTATUS StartUI_RegGetValueW(HKEY hkey, LPCWSTR lpSubKey, LPCWSTR lpValue, DWORD
return RegGetValueW(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData);
}

typedef enum Parser_XamlBufferType
{
XBT_Text,
XBT_Binary,
XBT_MemoryMappedResource
} Parser_XamlBufferType;

typedef struct Parser_XamlBuffer
{
unsigned int m_count;
Parser_XamlBufferType m_bufferType;
const unsigned __int8* m_buffer;
} Parser_XamlBuffer;

static BOOL StartMenu_FillParserBuffer(Parser_XamlBuffer* pBuffer, int resourceId)
{
HRSRC hRscr = FindResource(hModule, MAKEINTRESOURCE(resourceId), RT_RCDATA);
if (!hRscr)
return FALSE;

HGLOBAL hgRscr = LoadResource(hModule, hRscr);
if (!hgRscr)
return FALSE;

pBuffer->m_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"))
Expand Down Expand Up @@ -13201,13 +13303,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");
Expand Down
10 changes: 10 additions & 0 deletions ExplorerPatcher/fmemopen.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,15 @@
#include <fcntl.h>
#include <windows.h>
#include <sys/stat.h>

#ifdef __cplusplus
extern "C" {
#endif

FILE* fmemopen(void* buf, size_t len, const char* type);

#ifdef __cplusplus
}
#endif

#endif
8 changes: 8 additions & 0 deletions ExplorerPatcher/getline.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;

#ifdef __cplusplus
extern "C" {
#endif

ssize_t getdelim(char** buf, size_t* bufsiz, int delimiter, FILE* fp);

ssize_t getline(char** buf, size_t* bufsiz, FILE* fp);

#ifdef __cplusplus
}
#endif

#endif
9 changes: 9 additions & 0 deletions ExplorerPatcher/osutility.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#endif
#define DWMWA_MICA_EFFFECT 1029

#ifdef __cplusplus
extern "C" {
#endif

extern RTL_OSVERSIONINFOW global_rovi;
extern DWORD32 global_ubr;

Expand Down Expand Up @@ -94,4 +98,9 @@ inline BOOL IsWindows11Version22H2Build2361OrHigher()
if (global_rovi.dwBuildNumber > 22621) return TRUE;
return global_rovi.dwBuildNumber == 22621 && global_ubr >= 2361;
}

#ifdef __cplusplus
}
#endif

#endif
1 change: 1 addition & 0 deletions ExplorerPatcher/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit d2da7ec

Please sign in to comment.