From 583440d48947f80c41d26a46e0116504ddd4cc42 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Mon, 30 Aug 2021 20:45:37 +0300 Subject: [PATCH] Implements #6 (option to revert to classic context menu) --- CHANGELOG.md | 9 ++ ExplorerPatcher/ExplorerPatcher.rc | 8 +- .../ExplorerPatcherLibrary.rc | 8 +- ExplorerPatcherLibrary/dllmain.c | 125 ++++++++++++++++++ 4 files changed, 142 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66a6128f7..1fcc47833 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ This document includes the same release notes as in the [Releases](https://github.com/valinet/ExplorerPatcher/releases) section on GitHub. +## 22000.168.0.9 + +Implements [#6](https://github.com/valinet/ExplorerPatcher/issues/6) (option to revert to classic context menu). To disable this feature, add this to the settings.ini file: + +``` +[General] +AllowImmersiveContextMenus=1 +``` + ## 22000.168.0.8 The popup menu for "Safe to Remove Hardware" is now skinned in the same style as the Win+X menu and the taskbar context menus, in order to improve UI consistency. diff --git a/ExplorerPatcher/ExplorerPatcher.rc b/ExplorerPatcher/ExplorerPatcher.rc index 53ea7ee1d..6787ccf47 100644 --- a/ExplorerPatcher/ExplorerPatcher.rc +++ b/ExplorerPatcher/ExplorerPatcher.rc @@ -51,8 +51,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 22000,168,0,8 - PRODUCTVERSION 22000,168,0,8 + FILEVERSION 22000,168,0,9 + PRODUCTVERSION 22000,168,0,9 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -69,12 +69,12 @@ BEGIN BEGIN VALUE "CompanyName", "VALINET Solutions SRL" VALUE "FileDescription", "ExplorerPatcher Daemon" - VALUE "FileVersion", "22000.168.0.8" + VALUE "FileVersion", "22000.168.0.9" VALUE "InternalName", "ExplorerPatcher.exe" VALUE "LegalCopyright", "Copyright (C) 2006-2021 VALINET Solutions SRL. All rights reserved." VALUE "OriginalFilename", "ExplorerPatcher.exe" VALUE "ProductName", "ExplorerPatcher" - VALUE "ProductVersion", "22000.168.0.8" + VALUE "ProductVersion", "22000.168.0.9" END END BLOCK "VarFileInfo" diff --git a/ExplorerPatcherLibrary/ExplorerPatcherLibrary.rc b/ExplorerPatcherLibrary/ExplorerPatcherLibrary.rc index 85b7e366c..972724a86 100644 --- a/ExplorerPatcherLibrary/ExplorerPatcherLibrary.rc +++ b/ExplorerPatcherLibrary/ExplorerPatcherLibrary.rc @@ -51,8 +51,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 22000,168,0,8 - PRODUCTVERSION 22000,168,0,8 + FILEVERSION 22000,168,0,9 + PRODUCTVERSION 22000,168,0,9 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -69,12 +69,12 @@ BEGIN BEGIN VALUE "CompanyName", "VALINET Solutions SRL" VALUE "FileDescription", "ExplorerPatcher Library" - VALUE "FileVersion", "22000.168.0.8" + VALUE "FileVersion", "22000.168.0.9" VALUE "InternalName", "ExplorerPatcherLibrary.dll" VALUE "LegalCopyright", "Copyright (C) 2006-2021 VALINET Solutions SRL. All rights reserved." VALUE "OriginalFilename", "ExplorerPatcherLibrary.dll" VALUE "ProductName", "WinOverview" - VALUE "ProductVersion", "22000.168.0.8" + VALUE "ProductVersion", "22000.168.0.9" END END BLOCK "VarFileInfo" diff --git a/ExplorerPatcherLibrary/dllmain.c b/ExplorerPatcherLibrary/dllmain.c index ac6fe6b30..3b5f1b4f6 100644 --- a/ExplorerPatcherLibrary/dllmain.c +++ b/ExplorerPatcherLibrary/dllmain.c @@ -64,6 +64,9 @@ DEFINE_GUID(__uuidof_IAuthUILogonSound, #define STOBJECT_SB_0 "SysTrayWndProc" #define STOBJECT_SB_1 "HotPlugButtonClick" #define STOBJECT_SB_CNT 2 +#define WINDOWSUIFILEEXPLORER_SB_NAME "Windows.UI.FileExplorer" +#define WINDOWSUIFILEEXPLORER_SB_0 "ContextMenuPresenter::DoContextMenu" +#define WINDOWSUIFILEEXPLORER_SB_CNT 1 const char* explorer_SN[EXPLORER_SB_CNT] = { EXPLORER_SB_0, EXPLORER_SB_1, @@ -87,6 +90,9 @@ const char* stobject_SN[STOBJECT_SB_CNT] = { STOBJECT_SB_0, STOBJECT_SB_1 }; +const char* windowsuifileexplorer_SN[WINDOWSUIFILEEXPLORER_SB_CNT] = { + WINDOWSUIFILEEXPLORER_SB_0 +}; #pragma pack(push, 1) typedef struct symbols_addr { @@ -94,6 +100,7 @@ typedef struct symbols_addr DWORD twinui_pcshell_PTRS[TWINUI_PCSHELL_SB_CNT]; DWORD twinui_PTRS[TWINUI_SB_CNT]; DWORD stobject_PTRS[STOBJECT_SB_CNT]; + DWORD windowsuifileexplorer_PTRS[WINDOWSUIFILEEXPLORER_SB_CNT]; } symbols_addr; #pragma pack(pop) @@ -289,6 +296,31 @@ static BOOL(*TrackPopupMenuFunc)( +static char(*ContextMenuPresenter_DoContextMenuFunc)( + char* _this, + INT64 a2, + INT a3, + void* a4 + ); + +char ContextMenuPresenter_DoContextMenuHook( + char* _this, + INT64 a2, + INT a3, + void* a4 +) +{ + *(((char*)_this + 156)) = 0; + ContextMenuPresenter_DoContextMenuFunc( + _this, + a2, + a3, + a4 + ); + return 1; +} + + DEFINE_GUID(CLSID_ImmersiveShell, 0xc2f03a33, @@ -1562,6 +1594,13 @@ __declspec(dllexport) DWORD WINAPI main( wszSettingsPath ); + symbols_PTRS.windowsuifileexplorer_PTRS[0] = VnGetUInt( + TEXT(WINDOWSUIFILEEXPLORER_SB_NAME), + TEXT(WINDOWSUIFILEEXPLORER_SB_0), + 0, + wszSettingsPath + ); + BOOL bNeedToDownload = FALSE; for (UINT i = 0; i < sizeof(symbols_addr) / sizeof(DWORD); ++i) { @@ -1978,6 +2017,65 @@ __declspec(dllexport) DWORD WINAPI main( wszSettingsPath ); + char windowsuifileexplorer_sb_dll[MAX_PATH]; + ZeroMemory( + windowsuifileexplorer_sb_dll, + (MAX_PATH) * sizeof(char) + ); + GetSystemDirectoryA( + windowsuifileexplorer_sb_dll, + MAX_PATH + ); + strcat_s( + windowsuifileexplorer_sb_dll, + MAX_PATH, + "\\" + ); + strcat_s( + windowsuifileexplorer_sb_dll, + MAX_PATH, + WINDOWSUIFILEEXPLORER_SB_NAME + ); + strcat_s( + windowsuifileexplorer_sb_dll, + MAX_PATH, + ".dll" + ); + printf("Downloading symbols for %s.\n", windowsuifileexplorer_sb_dll); + if (VnDownloadSymbols( + NULL, + windowsuifileexplorer_sb_dll, + szSettingsPath, + MAX_PATH + )) + { + FreeLibraryAndExitThread( + hModule, + 6 + ); + return 6; + } + printf("Reading symbols.\n"); + if (VnGetSymbols( + szSettingsPath, + symbols_PTRS.windowsuifileexplorer_PTRS, + windowsuifileexplorer_SN, + WINDOWSUIFILEEXPLORER_SB_CNT + )) + { + FreeLibraryAndExitThread( + hModule, + 7 + ); + return 7; + } + VnWriteUInt( + TEXT(WINDOWSUIFILEEXPLORER_SB_NAME), + TEXT(WINDOWSUIFILEEXPLORER_SB_0), + symbols_PTRS.windowsuifileexplorer_PTRS[0], + wszSettingsPath + ); + VnWriteString( TEXT("OS"), TEXT("Build"), @@ -2131,6 +2229,33 @@ __declspec(dllexport) DWORD WINAPI main( } + + LoadLibrary(L"Windows.UI.FileExplorer.dll"); + HANDLE hWindowsUIFileExplorer = GetModuleHandle(L"Windows.UI.FileExplorer.dll"); + ContextMenuPresenter_DoContextMenuFunc = (char(*)(void*)) + ((uintptr_t)hWindowsUIFileExplorer + symbols_PTRS.windowsuifileexplorer_PTRS[0]); + UINT archive_plugin = VnGetUInt( + L"ArchiveMenu", + L"Enabled", + 0, + wszSettingsPath + ); + if (archive_plugin) + { + rv = funchook_prepare( + funchook, + (void**)&ContextMenuPresenter_DoContextMenuFunc, + ContextMenuPresenter_DoContextMenuHook + ); + if (rv != 0) + { + FreeLibraryAndExitThread(hModule, rv); + return rv; + } + } + + + rv = funchook_install(funchook, 0); if (rv != 0) {