Skip to content

Commit

Permalink
Moved ep_dwm as separate executable
Browse files Browse the repository at this point in the history
  • Loading branch information
valinet committed Jan 24, 2022
1 parent aa4803c commit e5c4e8b
Show file tree
Hide file tree
Showing 15 changed files with 218 additions and 142 deletions.
9 changes: 9 additions & 0 deletions ExplorerPatcher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ep_setup", "ep_setup\ep_setup.vcxproj", "{2FD40B09-F224-4E9A-B2FE-A22B50B2DEBF}"
ProjectSection(ProjectDependencies) = postProject
{DB3E4319-2969-42B6-B7E8-BB57AA8C9FA9} = {DB3E4319-2969-42B6-B7E8-BB57AA8C9FA9}
{1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87} = {1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ep_setup_patch", "ep_setup_patch\ep_setup_patch.vcxproj", "{0C13E5F3-106B-4836-A7C2-8E5808A6ED78}"
ProjectSection(ProjectDependencies) = postProject
{2FD40B09-F224-4E9A-B2FE-A22B50B2DEBF} = {2FD40B09-F224-4E9A-B2FE-A22B50B2DEBF}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ep_dwm", "ep_dwm\ep_dwm\ep_dwm.vcxproj", "{1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|amd64 = Debug|amd64
Expand Down Expand Up @@ -59,6 +62,12 @@ Global
{0C13E5F3-106B-4836-A7C2-8E5808A6ED78}.Release|amd64.ActiveCfg = Release|x64
{0C13E5F3-106B-4836-A7C2-8E5808A6ED78}.Release|amd64.Build.0 = Release|x64
{0C13E5F3-106B-4836-A7C2-8E5808A6ED78}.Release|IA-32.ActiveCfg = Release|Win32
{1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87}.Debug|amd64.ActiveCfg = Debug|x64
{1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87}.Debug|amd64.Build.0 = Debug|x64
{1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87}.Debug|IA-32.ActiveCfg = Debug|x64
{1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87}.Release|amd64.ActiveCfg = Release|x64
{1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87}.Release|amd64.Build.0 = Release|x64
{1ECCAB38-61B6-4C85-BBB5-2E2232DA3A87}.Release|IA-32.ActiveCfg = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
10 changes: 1 addition & 9 deletions ExplorerPatcher/ExplorerPatcher.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,6 @@
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\ep_dwm\ep_dwm\ep_dwm.c">
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">EP_DWM_NO_DLLMAIN;EP_DWM_NO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">EP_DWM_NO_DLLMAIN;EP_DWM_NO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">EP_DWM_NO_DLLMAIN;EP_DWM_NO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">EP_DWM_NO_DLLMAIN;EP_DWM_NO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\libs\sws\SimpleWindowSwitcher\sws_error.c">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
Expand Down Expand Up @@ -300,7 +292,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\ep_dwm\ep_dwm\ep_dwm.h" />
<ClInclude Include="..\libs\sws\SimpleWindowSwitcher\sws_def.h" />
<ClInclude Include="..\libs\sws\SimpleWindowSwitcher\sws_error.h" />
<ClInclude Include="..\libs\sws\SimpleWindowSwitcher\sws_IconPainter.h" />
Expand All @@ -315,6 +306,7 @@
<ClInclude Include="..\libs\sws\SimpleWindowSwitcher\sws_WindowSwitcherLayoutWindow.h" />
<ClInclude Include="..\version.h" />
<ClInclude Include="ArchiveMenu.h" />
<ClInclude Include="def.h" />
<ClInclude Include="dxgi_imp.h" />
<ClInclude Include="fmemopen.h" />
<ClInclude Include="getline.h" />
Expand Down
13 changes: 2 additions & 11 deletions ExplorerPatcher/ExplorerPatcher.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
<Filter Include="Settings">
<UniqueIdentifier>{190d08ad-4a1d-4b58-81a1-6403eeb3cd2a}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\ep_dwm">
<UniqueIdentifier>{50a6ac61-12c4-460e-a9d1-cdaf9bf7e7b1}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\ep_dwm">
<UniqueIdentifier>{fd25654b-7123-401a-86c7-90413d703f30}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h">
Expand Down Expand Up @@ -129,8 +123,8 @@
<ClInclude Include="..\libs\sws\SimpleWindowSwitcher\sws_IconPainter.h">
<Filter>Header Files\sws</Filter>
</ClInclude>
<ClInclude Include="..\ep_dwm\ep_dwm\ep_dwm.h">
<Filter>Header Files\ep_dwm</Filter>
<ClInclude Include="def.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -211,9 +205,6 @@
<ClCompile Include="..\libs\sws\SimpleWindowSwitcher\sws_tshwnd.c">
<Filter>Source Files\sws</Filter>
</ClCompile>
<ClCompile Include="..\ep_dwm\ep_dwm\ep_dwm.c">
<Filter>Source Files\ep_dwm</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="settings.reg">
Expand Down
98 changes: 2 additions & 96 deletions ExplorerPatcher/GUI.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,101 +327,7 @@ LSTATUS GUI_Internal_RegSetValueExW(
}
else if (!wcscmp(lpValueName, L"Virtualized_" _T(EP_CLSID) L"_DisableRoundedCorners"))
{
WCHAR wszPath[MAX_PATH];
GetSystemDirectoryW(wszPath, MAX_PATH);
wcscat_s(wszPath, MAX_PATH, L"\\cmd.exe");

WCHAR wszSCPath[MAX_PATH];
GetSystemDirectoryW(wszSCPath, MAX_PATH);
wcscat_s(wszSCPath, MAX_PATH, L"\\sc.exe");

WCHAR wszRundll32[MAX_PATH];
GetSystemDirectoryW(wszRundll32, MAX_PATH);
wcscat_s(wszRundll32, MAX_PATH, L"\\rundll32.exe");

WCHAR wszEP[MAX_PATH];
GetWindowsDirectoryW(wszEP, MAX_PATH);
wcscat_s(wszEP, MAX_PATH, L"\\dxgi.dll");

WCHAR wszTaskkill[MAX_PATH];
GetSystemDirectoryW(wszTaskkill, MAX_PATH);
wcscat_s(wszTaskkill, MAX_PATH, L"\\taskkill.exe");

WCHAR wszArgumentsRegister[MAX_PATH * 10];
swprintf_s(
wszArgumentsRegister,
MAX_PATH * 10,
L"/c \""
L"\"%s\" create ep_dwm_" _T(EP_CLSID_LITE) L" binPath= \"\\\"%s\\\" \\\"%s\\\",ZZDWM\" DisplayName= \"ExplorerPatcher Desktop Window Manager Service\" start= auto & "
L"\"%s\" description ep_dwm_" _T(EP_CLSID_LITE) L" \"Implements functionality to disable rounded corners for windows\" & "
L"\"%s\" start ep_dwm_" _T(EP_CLSID_LITE)
L"\"",
wszSCPath,
wszRundll32,
wszEP,
wszSCPath,
wszSCPath
);
WCHAR wszArgumentsUnRegister[MAX_PATH * 10];
swprintf_s(
wszArgumentsUnRegister,
MAX_PATH * 10,
L"/c \""
L"\"%s\" stop ep_dwm_" _T(EP_CLSID_LITE) L" & "
L"\"%s\" delete ep_dwm_" _T(EP_CLSID_LITE) L" & "
L"\"",
wszSCPath,
wszSCPath
);
wprintf(L"%s\n", wszArgumentsRegister);

BOOL bAreRoundedCornersDisabled = FALSE;
HANDLE h_exists = CreateEventW(NULL, FALSE, FALSE, L"Global\\ep_dwm_" _T(EP_CLSID));
if (h_exists)
{
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
bAreRoundedCornersDisabled = TRUE;
}
else
{
bAreRoundedCornersDisabled = FALSE;
}
CloseHandle(h_exists);
}
else
{
if (GetLastError() == ERROR_ACCESS_DENIED)
{
bAreRoundedCornersDisabled = TRUE;
}
else
{
bAreRoundedCornersDisabled = FALSE;
}
}
if ((bAreRoundedCornersDisabled && *(DWORD*)lpData) || (!bAreRoundedCornersDisabled && !*(DWORD*)lpData))
{
return ERROR_SUCCESS;
}
SHELLEXECUTEINFO ShExecInfo = { 0 };
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"runas";
ShExecInfo.lpFile = wszPath;
ShExecInfo.lpParameters = !bAreRoundedCornersDisabled ? wszArgumentsRegister : wszArgumentsUnRegister;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
if (ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess)
{
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
DWORD dwExitCode = 0;
GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode);
CloseHandle(ShExecInfo.hProcess);
}
return ERROR_SUCCESS;
return RegisterDWMService(*(DWORD*)lpData, 0);
}
else if (!wcscmp(lpValueName, L"Virtualized_" _T(EP_CLSID) L"_RegisterAsShellExtension"))
{
Expand Down Expand Up @@ -612,7 +518,7 @@ LSTATUS GUI_Internal_RegQueryValueExW(
}
else if (!wcscmp(lpValueName, L"Virtualized_" _T(EP_CLSID) L"_DisableRoundedCorners"))
{
HANDLE h_exists = CreateEventW(NULL, FALSE, FALSE, L"Global\\ep_dwm_" _T(EP_CLSID));
HANDLE h_exists = CreateEventW(NULL, FALSE, FALSE, _T(EP_DWM_EVENTNAME));
if (h_exists)
{
if (GetLastError() == ERROR_ALREADY_EXISTS)
Expand Down
21 changes: 21 additions & 0 deletions ExplorerPatcher/def.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#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_STARTMENU REGPATH_OLD
#define SPECIAL_FOLDER CSIDL_PROGRAM_FILES
#define SPECIAL_FOLDER_LEGACY CSIDL_APPDATA
#define PRODUCT_NAME "ExplorerPatcher"
#define PRODUCT_PUBLISHER "VALINET Solutions SRL"
#define APP_RELATIVE_PATH "\\" PRODUCT_NAME
#define EP_CLSID_LITE "D17F1E1A-5919-4427-8F89-A1A8503CA3EB"
#define EP_CLSID "{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}"
#define DOSMODE_OFFSET 78
#define SETUP_UTILITY_NAME "ep_setup.exe"
#define TOAST_BUFSIZ 1024
#define SEH_REGPATH "Control Panel\\Quick Actions\\Control Center\\QuickActionsStateCapture\\ExplorerPatcher"
#define EP_SETUP_HELPER_SWITCH "/CreateExplorerShellUnelevatedAfterServicing"
#define EP_DWM_SERVICENAME "ep_dwm_" EP_CLSID_LITE
#define EP_DWM_EVENTNAME "Global\\ep_dwm_2_" EP_CLSID_LITE
#endif
7 changes: 0 additions & 7 deletions ExplorerPatcher/dllmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ HRESULT WINAPI _DllGetClassObject(
REFIID riid,
LPVOID* ppv
);
#ifdef _WIN64
BOOL ep_dwm_StartService(LPWSTR wszServiceName, LPWSTR wszEventName);
__declspec(dllexport) int ZZDWM(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int nCmdShow)
{
ep_dwm_StartService(L"ep_dwm_Service_" _T(EP_CLSID), L"Global\\ep_dwm_" _T(EP_CLSID));
}
#endif

#pragma region "Updates"
#ifdef _WIN64
Expand Down
108 changes: 108 additions & 0 deletions ExplorerPatcher/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,111 @@ void ToggleTaskbarAutohide()
SHAppBarMessage(ABM_SETSTATE, &abd);
}
}

LSTATUS RegisterDWMService(DWORD dwDesiredState, DWORD dwOverride)
{
WCHAR wszPath[MAX_PATH];
GetSystemDirectoryW(wszPath, MAX_PATH);
wcscat_s(wszPath, MAX_PATH, L"\\cmd.exe");

WCHAR wszSCPath[MAX_PATH];
GetSystemDirectoryW(wszSCPath, MAX_PATH);
wcscat_s(wszSCPath, MAX_PATH, L"\\sc.exe");

WCHAR wszRundll32[MAX_PATH];
SHGetFolderPathW(NULL, SPECIAL_FOLDER, NULL, SHGFP_TYPE_CURRENT, wszRundll32);
wcscat_s(wszRundll32, MAX_PATH, _T(APP_RELATIVE_PATH));
wcscat_s(wszRundll32, MAX_PATH, L"\\ep_dwm.exe");

WCHAR wszEP[MAX_PATH];
GetWindowsDirectoryW(wszEP, MAX_PATH);
wcscat_s(wszEP, MAX_PATH, L"\\dxgi.dll");

WCHAR wszTaskkill[MAX_PATH];
GetSystemDirectoryW(wszTaskkill, MAX_PATH);
wcscat_s(wszTaskkill, MAX_PATH, L"\\taskkill.exe");

WCHAR wszArgumentsRegister[MAX_PATH * 10];
swprintf_s(
wszArgumentsRegister,
MAX_PATH * 10,
L"/c \""
L"\"%s\" create " _T(EP_DWM_SERVICENAME) L" binPath= \"\\\"%s\\\" %s\" DisplayName= \"ExplorerPatcher Desktop Window Manager Service\" start= auto & "
L"\"%s\" description " _T(EP_DWM_SERVICENAME) L" \"Service for managing aspects related to the Desktop Window Manager.\" & "
L"\"%s\" %s " _T(EP_DWM_SERVICENAME)
L"\"",
wszSCPath,
wszRundll32,
_T(EP_DWM_SERVICENAME) L" " _T(EP_DWM_EVENTNAME),
wszSCPath,
wszSCPath,
(!dwOverride || dwOverride == 3) ? L"start" : L"query"
);
WCHAR wszArgumentsUnRegister[MAX_PATH * 10];
swprintf_s(
wszArgumentsUnRegister,
MAX_PATH * 10,
L"/c \""
L"\"%s\" stop " _T(EP_DWM_SERVICENAME) L" & "
L"\"%s\" delete " _T(EP_DWM_SERVICENAME) L" & "
L"\"",
wszSCPath,
wszSCPath
);
wprintf(L"%s\n", wszArgumentsRegister);

BOOL bAreRoundedCornersDisabled = FALSE;
if (dwOverride)
{
bAreRoundedCornersDisabled = !(dwOverride - 1);
}
else
{
HANDLE h_exists = CreateEventW(NULL, FALSE, FALSE, _T(EP_DWM_EVENTNAME));
if (h_exists)
{
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
bAreRoundedCornersDisabled = TRUE;
}
else
{
bAreRoundedCornersDisabled = FALSE;
}
CloseHandle(h_exists);
}
else
{
if (GetLastError() == ERROR_ACCESS_DENIED)
{
bAreRoundedCornersDisabled = TRUE;
}
else
{
bAreRoundedCornersDisabled = FALSE;
}
}
if ((bAreRoundedCornersDisabled && dwDesiredState) || (!bAreRoundedCornersDisabled && !dwDesiredState))
{
return FALSE;
}
}
SHELLEXECUTEINFO ShExecInfo = { 0 };
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = L"runas";
ShExecInfo.lpFile = wszPath;
ShExecInfo.lpParameters = !bAreRoundedCornersDisabled ? wszArgumentsRegister : wszArgumentsUnRegister;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_HIDE;
ShExecInfo.hInstApp = NULL;
if (ShellExecuteExW(&ShExecInfo) && ShExecInfo.hProcess)
{
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
DWORD dwExitCode = 0;
GetExitCodeProcess(ShExecInfo.hProcess, &dwExitCode);
CloseHandle(ShExecInfo.hProcess);
}
return TRUE;
}
19 changes: 3 additions & 16 deletions ExplorerPatcher/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,7 @@
#include "queryversion.h"
#pragma comment(lib, "Psapi.lib")

#define APPID L"Microsoft.Windows.Explorer"
#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
#define PRODUCT_NAME "ExplorerPatcher"
#define PRODUCT_PUBLISHER "VALINET Solutions SRL"
#define APP_RELATIVE_PATH "\\" PRODUCT_NAME
#define EP_CLSID_LITE "D17F1E1A-5919-4427-8F89-A1A8503CA3EB"
#define EP_CLSID "{D17F1E1A-5919-4427-8F89-A1A8503CA3EB}"
#define DOSMODE_OFFSET 78
#define SETUP_UTILITY_NAME "ep_setup.exe"
#define TOAST_BUFSIZ 1024
#define SEH_REGPATH "Control Panel\\Quick Actions\\Control Center\\QuickActionsStateCapture\\ExplorerPatcher"
#define EP_SETUP_HELPER_SWITCH "/CreateExplorerShellUnelevatedAfterServicing"
#include "def.h"

#define WM_MSG_GUI_SECTION WM_USER + 1
#define WM_MSG_GUI_SECTION_GET 1
Expand Down Expand Up @@ -249,6 +234,8 @@ void LaunchPropertiesGUI(HMODULE hModule);

BOOL SystemShutdown(BOOL reboot);

LSTATUS RegisterDWMService(DWORD dwDesiredState, DWORD dwOverride);

inline long long milliseconds_now() {
LARGE_INTEGER s_frequency;
BOOL s_use_qpc = QueryPerformanceFrequency(&s_frequency);
Expand Down
2 changes: 1 addition & 1 deletion ep_dwm
Loading

0 comments on commit e5c4e8b

Please sign in to comment.