1
0
mirror of https://github.com/valinet/ExplorerPatcher.git synced 2024-11-23 23:21:08 +01:00

Start10: Updated method for using the old start menu

This commit is contained in:
Amrsatrio 2024-07-31 19:05:41 +07:00
parent e60c5ff596
commit 755f101285
6 changed files with 157 additions and 16 deletions

View File

@ -12295,8 +12295,9 @@ DWORD InjectStartMenu()
if (dwStartShowClassicMode || !IsWindows11()) if (dwStartShowClassicMode || !IsWindows11())
{ {
LoadLibraryW(L"StartUI.dll"); hStartUI = LoadLibraryW(L"StartUI.dll");
hStartUI = GetModuleHandleW(L"StartUI.dll"); if (!hStartUI)
hStartUI = LoadLibraryW(L"StartUI_.dll");
// Fixes hang when Start menu closes // Fixes hang when Start menu closes
VnPatchDelayIAT(hStartUI, "ext-ms-win-ntuser-draw-l1-1-0.dll", "SetWindowRgn", Start_SetWindowRgn); VnPatchDelayIAT(hStartUI, "ext-ms-win-ntuser-draw-l1-1-0.dll", "SetWindowRgn", Start_SetWindowRgn);

View File

@ -1330,8 +1330,7 @@ BOOL DownloadFile(LPCWSTR wszURL, DWORD dwSize, LPCWSTR wszPath)
exe_buffer = calloc(dwSize, sizeof(char)); exe_buffer = calloc(dwSize, sizeof(char));
if (exe_buffer) if (exe_buffer)
{ {
BOOL bRet = FALSE; if (InternetReadFile(
if (bRet = InternetReadFile(
hConnect, hConnect,
exe_buffer, exe_buffer,
dwSize - 1, dwSize - 1,
@ -1342,7 +1341,7 @@ BOOL DownloadFile(LPCWSTR wszURL, DWORD dwSize, LPCWSTR wszPath)
_wfopen_s(&f, wszPath, L"wb"); _wfopen_s(&f, wszPath, L"wb");
if (f) if (f)
{ {
fwrite(exe_buffer, 1, dwRead, f); bOK = fwrite(exe_buffer, 1, dwRead, f) == dwRead;
fclose(f); fclose(f);
} }
} }

View File

@ -921,7 +921,15 @@ inline BOOL DoesWindows10StartMenuExist()
wchar_t szPath[MAX_PATH]; wchar_t szPath[MAX_PATH];
GetWindowsDirectoryW(szPath, MAX_PATH); GetWindowsDirectoryW(szPath, MAX_PATH);
wcscat_s(szPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\StartUI.dll"); wcscat_s(szPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\StartUI.dll");
return FileExistsW(szPath); if (FileExistsW(szPath))
return TRUE;
GetWindowsDirectoryW(szPath, MAX_PATH);
wcscat_s(szPath, MAX_PATH, L"\\SystemApps\\Microsoft.Windows.StartMenuExperienceHost_cw5n1h2txyewy\\StartUI_.dll");
if (FileExistsW(szPath))
return TRUE;
return FALSE;
} }
inline BOOL IsStockWindows10TaskbarAvailable() inline BOOL IsStockWindows10TaskbarAvailable()

View File

@ -1,6 +1,6 @@
#include <Windows.h> #include <Windows.h>
#include <initguid.h> #include <initguid.h>
#include <valinet/hooking/iatpatch.h> // #include <valinet/hooking/iatpatch.h>
#include <valinet/utility/memmem.h> #include <valinet/utility/memmem.h>
#include "../ExplorerPatcher/utility.h" #include "../ExplorerPatcher/utility.h"
#include "ep_sm_forwards.h" #include "ep_sm_forwards.h"
@ -22,6 +22,33 @@ DEFINE_GUID(IID_StartUI_XamlMetaDataProvider, 0xF2777C41, 0xD2CC, 0x34B6, 0xA7,
return TRUE; return TRUE;
}*/ }*/
BOOL GetStartUIName(WCHAR* out, int cch)
{
if (out && cch)
out[0] = 0;
WCHAR szPath[MAX_PATH];
wcscpy_s(szPath, MAX_PATH, L"StartUI.dll");
if (FileExistsW(szPath))
{
if (out && cch)
wcscpy_s(out, cch, szPath);
return TRUE;
}
wcscpy_s(szPath, MAX_PATH, L"StartUI_.dll");
if (FileExistsW(szPath))
{
if (out && cch)
wcscpy_s(out, cch, szPath);
return TRUE;
}
return FALSE;
}
WCHAR g_szStartUIName[MAX_PATH];
BOOL GetStartShowClassicMode() BOOL GetStartShowClassicMode()
{ {
DWORD dwStartShowClassicMode = 0; DWORD dwStartShowClassicMode = 0;
@ -30,7 +57,7 @@ BOOL GetStartShowClassicMode()
if (dwStartShowClassicMode == 0) if (dwStartShowClassicMode == 0)
return FALSE; return FALSE;
if (!FileExistsW(L"StartUI.dll")) if (!GetStartUIName(g_szStartUIName, ARRAYSIZE(g_szStartUIName)))
return FALSE; return FALSE;
return TRUE; return TRUE;
@ -55,9 +82,10 @@ void PatchXamlMetaDataProviderGuid()
PIMAGE_NT_HEADERS64 ntHeader = (PIMAGE_NT_HEADERS64)((u_char*)dosHeader + dosHeader->e_lfanew); PIMAGE_NT_HEADERS64 ntHeader = (PIMAGE_NT_HEADERS64)((u_char*)dosHeader + dosHeader->e_lfanew);
if (ntHeader->Signature == IMAGE_NT_SIGNATURE) if (ntHeader->Signature == IMAGE_NT_SIGNATURE)
{ {
PIMAGE_SECTION_HEADER firstSection = IMAGE_FIRST_SECTION(ntHeader);
for (unsigned int i = 0; i < ntHeader->FileHeader.NumberOfSections; ++i) for (unsigned int i = 0; i < ntHeader->FileHeader.NumberOfSections; ++i)
{ {
PIMAGE_SECTION_HEADER section = IMAGE_FIRST_SECTION(ntHeader) + i; PIMAGE_SECTION_HEADER section = firstSection + i;
if (!strncmp(section->Name, ".rdata", 6)) if (!strncmp(section->Name, ".rdata", 6))
{ {
beginRData = (PBYTE)dosHeader + section->VirtualAddress; beginRData = (PBYTE)dosHeader + section->VirtualAddress;
@ -72,7 +100,7 @@ void PatchXamlMetaDataProviderGuid()
return; return;
} }
GUID* pguidTarget = memmem(beginRData, sizeRData, &IID_StartDocked_XamlMetaDataProvider, sizeof(GUID)); GUID* pguidTarget = memmem(beginRData, sizeRData, (void*)&IID_StartDocked_XamlMetaDataProvider, sizeof(GUID));
if (!pguidTarget) if (!pguidTarget)
{ {
return; return;
@ -122,14 +150,17 @@ wchar_t* GetCmdArguments(int* a1)
return pGetCmdArguments(a1); return pGetCmdArguments(a1);
} }
extern HRESULT LoadOurShellCommonPri();
extern HRESULT GetActivationFactoryByPCWSTR_InStartUI(PCWSTR activatableClassId, REFIID riid, void** ppv);
#pragma comment(linker, "/export:?GetActivationFactoryByPCWSTR@@YAJPEAXAEAVGuid@Platform@@PEAPEAX@Z=GetActivationFactoryByPCWSTR,@129") #pragma comment(linker, "/export:?GetActivationFactoryByPCWSTR@@YAJPEAXAEAVGuid@Platform@@PEAPEAX@Z=GetActivationFactoryByPCWSTR,@129")
HRESULT GetActivationFactoryByPCWSTR(PCWSTR activatableClassId, const GUID* iid, void** ppv) HRESULT GetActivationFactoryByPCWSTR(PCWSTR activatableClassId, REFIID riid, void** ppv)
{ {
if (!hOrig) if (!hOrig)
{ {
hOrig = LoadLibraryW(L"wincorlib_orig.dll"); hOrig = LoadLibraryW(L"wincorlib_orig.dll");
} }
static HRESULT (*pGetActivationFactoryByPCWSTR)(PCWSTR, const GUID*, void**) = NULL; static HRESULT (*pGetActivationFactoryByPCWSTR)(PCWSTR, REFIID, void**) = NULL;
if (!pGetActivationFactoryByPCWSTR && hOrig) if (!pGetActivationFactoryByPCWSTR && hOrig)
{ {
pGetActivationFactoryByPCWSTR = GetProcAddress(hOrig, "?GetActivationFactoryByPCWSTR@@YAJPEAXAEAVGuid@Platform@@PEAPEAX@Z"); pGetActivationFactoryByPCWSTR = GetProcAddress(hOrig, "?GetActivationFactoryByPCWSTR@@YAJPEAXAEAVGuid@Platform@@PEAPEAX@Z");
@ -139,22 +170,28 @@ HRESULT GetActivationFactoryByPCWSTR(PCWSTR activatableClassId, const GUID* iid,
return E_FAIL; return E_FAIL;
} }
if (!wcscmp(activatableClassId, L"StartDocked.App") && IsEqualGUID(iid, &IID_StartDocked_App)) if (!wcscmp(activatableClassId, L"StartDocked.App") && IsEqualGUID(riid, &IID_StartDocked_App))
{ {
if (GetStartShowClassicMode()) if (GetStartShowClassicMode())
{ {
return pGetActivationFactoryByPCWSTR(L"StartUI.App", &IID_StartUI_App, ppv); LoadOurShellCommonPri();
return GetActivationFactoryByPCWSTR_InStartUI(L"StartUI.App", &IID_StartUI_App, ppv);
} }
} }
else if (!wcscmp(activatableClassId, L"StartDocked.startdocked_XamlTypeInfo.XamlMetaDataProvider")) else if (!wcscmp(activatableClassId, L"StartDocked.startdocked_XamlTypeInfo.XamlMetaDataProvider"))
{ {
if (GetStartShowClassicMode()) if (GetStartShowClassicMode())
{ {
return pGetActivationFactoryByPCWSTR(L"StartUI.startui_XamlTypeInfo.XamlMetaDataProvider", iid, ppv); return GetActivationFactoryByPCWSTR_InStartUI(L"StartUI.startui_XamlTypeInfo.XamlMetaDataProvider", riid, ppv);
} }
} }
return pGetActivationFactoryByPCWSTR(activatableClassId, iid, ppv); if (wcsncmp(activatableClassId, L"StartUI.", 8) == 0)
{
return GetActivationFactoryByPCWSTR_InStartUI(activatableClassId, riid, ppv);
}
return pGetActivationFactoryByPCWSTR(activatableClassId, riid, ppv);
} }
BOOL WINAPI DllMain( BOOL WINAPI DllMain(

View File

@ -0,0 +1,89 @@
#include <Windows.h>
#include <windows.foundation.h>
#include <windows.applicationmodel.resources.core.h>
#include <wrl/client.h>
#include <wrl/wrappers/corewrappers.h>
namespace ABI::Windows::ApplicationModel::Resources::Core::Internal
{
MIDL_INTERFACE("4a8eac58-b652-459d-8de1-239471e8b22b")
IResourceManagerStaticInternal : IInspectable
{
virtual HRESULT STDMETHODCALLTYPE GetResourceManagerForSystemProfile(IResourceManager** result) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentResourceManagerForSystemProfile(IResourceManager** result) = 0;
virtual HRESULT STDMETHODCALLTYPE GetCurrentResourceManagerState(DWORD* result) = 0;
};
MIDL_INTERFACE("c408a1f1-3ede-41e9-9a38-c203678c2df7")
ISystemResourceManagerExtensions : IInspectable
{
virtual HRESULT STDMETHODCALLTYPE GetDefaultResourceContextForCurrentThread(IResourceContext**) = 0;
virtual HRESULT STDMETHODCALLTYPE GetMrtResourceManagerForResourceManager(IInspectable**) = 0;
};
MIDL_INTERFACE("8c25e859-1042-4da0-9232-bf2aa8ff3726")
ISystemResourceManagerExtensions2 : IInspectable
{
virtual HRESULT STDMETHODCALLTYPE LoadPriFileForSystemUse(const WCHAR* path) = 0;
};
}
using namespace Microsoft::WRL;
extern "C" HRESULT LoadOurShellCommonPri()
{
using namespace ABI::Windows::Foundation;
ComPtr<IInspectable> pInspectable;
HRESULT hr = Windows::Foundation::GetActivationFactory(
Wrappers::HStringReference(L"Windows.ApplicationModel.Resources.Core.ResourceManager").Get(),
pInspectable.GetAddressOf()
);
if (FAILED(hr))
return hr;
ComPtr<ABI::Windows::ApplicationModel::Resources::Core::Internal::IResourceManagerStaticInternal> pResourceManagerStaticInternal;
hr = pInspectable.As(&pResourceManagerStaticInternal);
if (FAILED(hr))
return hr;
ComPtr<ABI::Windows::ApplicationModel::Resources::Core::IResourceManager> pResourceManager;
hr = pResourceManagerStaticInternal->GetCurrentResourceManagerForSystemProfile(&pResourceManager);
if (FAILED(hr))
return hr;
ComPtr<ABI::Windows::ApplicationModel::Resources::Core::Internal::ISystemResourceManagerExtensions2> pSystemResourceManagerExtensions2;
pResourceManager.As(&pSystemResourceManagerExtensions2);
WCHAR wszPath[MAX_PATH] = {};
wcscat_s(wszPath, MAX_PATH, L"C:\\Program Files\\ExplorerPatcher\\Windows.UI.ShellCommon.pri");
hr = pSystemResourceManagerExtensions2->LoadPriFileForSystemUse(wszPath);
return hr;
}
extern "C" WCHAR g_szStartUIName[MAX_PATH];
extern "C" HRESULT GetActivationFactoryByPCWSTR_InStartUI(PCWSTR activatableClassId, REFIID riid, void** ppv)
{
typedef HRESULT (WINAPI* DllGetActivationFactory_t)(HSTRING, IActivationFactory**);
static DllGetActivationFactory_t pfnGetActivationFactory;
if (!pfnGetActivationFactory)
{
HMODULE hModule = GetModuleHandleW(g_szStartUIName);
if (hModule)
{
pfnGetActivationFactory = (DllGetActivationFactory_t)GetProcAddress(hModule, "DllGetActivationFactory");
}
}
if (!pfnGetActivationFactory)
return E_FAIL;
ComPtr<IActivationFactory> activationFactory;
HRESULT hr = pfnGetActivationFactory(Wrappers::HStringReference(activatableClassId).Get(), &activationFactory);
if (FAILED(hr))
return hr;
return activationFactory.CopyTo(riid, ppv);
}

View File

@ -133,6 +133,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
@ -149,6 +150,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
@ -165,6 +167,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
@ -181,6 +184,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
@ -197,6 +201,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
@ -213,6 +218,7 @@
<SDLCheck>true</SDLCheck> <SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode> <ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary> <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)libs\libvalinet;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
@ -228,6 +234,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="ep_sm_main.c" /> <ClCompile Include="ep_sm_main.c" />
<ClCompile Include="ep_sm_main_cpp.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="..\ExplorerPatcher\ExplorerPatcher.rc" /> <ResourceCompile Include="..\ExplorerPatcher\ExplorerPatcher.rc" />