Skip to content

Commit 6f70250

Browse files
committed
Add /SUBSYSTEM:WINDOWS build config ReleaseW
1 parent 5101ff1 commit 6f70250

3 files changed

Lines changed: 55 additions & 5 deletions

File tree

Shell32Patcher.sln

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ Global
99
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1010
Debug|x64 = Debug|x64
1111
Release|x64 = Release|x64
12+
ReleaseW|x64 = ReleaseW|x64
1213
EndGlobalSection
1314
GlobalSection(ProjectConfigurationPlatforms) = postSolution
1415
{72A07A64-5D50-4561-A3A1-0BF42710A1BB}.Debug|x64.ActiveCfg = Debug|x64
1516
{72A07A64-5D50-4561-A3A1-0BF42710A1BB}.Debug|x64.Build.0 = Debug|x64
1617
{72A07A64-5D50-4561-A3A1-0BF42710A1BB}.Release|x64.ActiveCfg = Release|x64
1718
{72A07A64-5D50-4561-A3A1-0BF42710A1BB}.Release|x64.Build.0 = Release|x64
19+
{72A07A64-5D50-4561-A3A1-0BF42710A1BB}.ReleaseW|x64.ActiveCfg = ReleaseW|x64
20+
{72A07A64-5D50-4561-A3A1-0BF42710A1BB}.ReleaseW|x64.Build.0 = ReleaseW|x64
1821
EndGlobalSection
1922
GlobalSection(SolutionProperties) = preSolution
2023
HideSolutionNode = FALSE

Shell32Patcher/Shell32Patcher.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
#include <wtsapi32.h>
55
#include <psapi.h>
66

7+
#ifndef _CONSOLE
8+
#define printf(...) {}
9+
#endif
10+
711
int main()
812
{
913
HANDLE hProcess = GetCurrentProcess();
@@ -33,20 +37,24 @@ int main()
3337
HANDLE hExplorer = OpenProcess(PROCESS_VM_READ | PROCESS_VM_OPERATION | PROCESS_VM_WRITE, TRUE, processList[i].ProcessId);
3438
if (!hExplorer) continue;
3539

36-
DWORD Needed;
37-
HMODULE hMods[255];
40+
DWORD cb, cbNeeded;
3841
WCHAR szModName[MAX_PATH];
39-
EnumProcessModulesEx(hExplorer, hMods, sizeof(hMods), &Needed, LIST_MODULES_64BIT);
42+
EnumProcessModulesEx(hExplorer, NULL, 0, &cb, LIST_MODULES_64BIT);
43+
auto hMods = (HMODULE *)LocalAlloc(NONZEROLPTR, cb);
44+
if (!hMods) continue;
45+
EnumProcessModulesEx(hExplorer, hMods, cb, &cbNeeded, LIST_MODULES_64BIT);
46+
if (cbNeeded < cb) cb = cbNeeded;
4047

4148
HANDLE hModShell32 = INVALID_HANDLE_VALUE;
42-
for (DWORD i = 0; i < Needed / sizeof(HMODULE); i++) {
49+
for (DWORD i = 0; i < cb / sizeof(HMODULE); i++) {
4350
if (!GetModuleFileNameExW(hExplorer, hMods[i], szModName, sizeof(szModName) / sizeof(WCHAR))) continue;
4451
if (!lstrcmpiW(szModName, szShell32)) {
4552
hModShell32 = hMods[i];
4653
break;
4754
}
4855
}
49-
if (!hModShell32) continue;
56+
LocalFree(hMods);
57+
if (hModShell32 == INVALID_HANDLE_VALUE) continue;
5058

5159
// and qword ptr [rdx], 0
5260
// and rax, 0

Shell32Patcher/Shell32Patcher.vcxproj

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
<Configuration>Debug</Configuration>
66
<Platform>x64</Platform>
77
</ProjectConfiguration>
8+
<ProjectConfiguration Include="ReleaseW|x64">
9+
<Configuration>ReleaseW</Configuration>
10+
<Platform>x64</Platform>
11+
</ProjectConfiguration>
812
<ProjectConfiguration Include="Release|x64">
913
<Configuration>Release</Configuration>
1014
<Platform>x64</Platform>
@@ -32,6 +36,13 @@
3236
<WholeProgramOptimization>true</WholeProgramOptimization>
3337
<CharacterSet>Unicode</CharacterSet>
3438
</PropertyGroup>
39+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseW|x64'" Label="Configuration">
40+
<ConfigurationType>Application</ConfigurationType>
41+
<UseDebugLibraries>false</UseDebugLibraries>
42+
<PlatformToolset>v142</PlatformToolset>
43+
<WholeProgramOptimization>true</WholeProgramOptimization>
44+
<CharacterSet>Unicode</CharacterSet>
45+
</PropertyGroup>
3546
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
3647
<ImportGroup Label="ExtensionSettings">
3748
</ImportGroup>
@@ -43,6 +54,9 @@
4354
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
4455
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
4556
</ImportGroup>
57+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseW|x64'" Label="PropertySheets">
58+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
59+
</ImportGroup>
4660
<PropertyGroup Label="UserMacros" />
4761
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
4862
<LinkIncremental>true</LinkIncremental>
@@ -51,6 +65,10 @@
5165
<LinkIncremental>false</LinkIncremental>
5266
<GenerateManifest>false</GenerateManifest>
5367
</PropertyGroup>
68+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseW|x64'">
69+
<LinkIncremental>false</LinkIncremental>
70+
<GenerateManifest>false</GenerateManifest>
71+
</PropertyGroup>
5472
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
5573
<ClCompile>
5674
<WarningLevel>Level3</WarningLevel>
@@ -80,6 +98,27 @@
8098
<OptimizeReferences>true</OptimizeReferences>
8199
<GenerateDebugInformation>false</GenerateDebugInformation>
82100
<AdditionalDependencies>Dbghelp.lib;Wtsapi32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
101+
<EntryPointSymbol>
102+
</EntryPointSymbol>
103+
</Link>
104+
</ItemDefinitionGroup>
105+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseW|x64'">
106+
<ClCompile>
107+
<WarningLevel>Level3</WarningLevel>
108+
<FunctionLevelLinking>true</FunctionLevelLinking>
109+
<IntrinsicFunctions>true</IntrinsicFunctions>
110+
<SDLCheck>false</SDLCheck>
111+
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
112+
<ConformanceMode>true</ConformanceMode>
113+
<DebugInformationFormat>None</DebugInformationFormat>
114+
</ClCompile>
115+
<Link>
116+
<SubSystem>Windows</SubSystem>
117+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
118+
<OptimizeReferences>true</OptimizeReferences>
119+
<GenerateDebugInformation>false</GenerateDebugInformation>
120+
<AdditionalDependencies>Dbghelp.lib;Wtsapi32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
121+
<EntryPointSymbol>main</EntryPointSymbol>
83122
</Link>
84123
</ItemDefinitionGroup>
85124
<ItemGroup>

0 commit comments

Comments
 (0)