Skip to content

Commit 57fe40b

Browse files
committed
Improve startup, Fix delayload version check, Update delayload imports, Remove legacy imports
1 parent af60418 commit 57fe40b

File tree

9 files changed

+94
-121
lines changed

9 files changed

+94
-121
lines changed

ProcessHacker/ProcessHacker.vcxproj

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,14 @@
106106
<StringPooling>true</StringPooling>
107107
</ClCompile>
108108
<Link>
109-
<AdditionalDependencies>aclui.lib;comctl32.lib;iphlpapi.lib;noarg.obj;noenv.obj;ntdll.lib;phlib.lib;userenv.lib;uxtheme.lib;version.lib;wbemuuid.lib;windowscodecs.lib;winsta.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
109+
<AdditionalDependencies>aclui.lib;comctl32.lib;iphlpapi.lib;noarg.obj;noenv.obj;ntdll.lib;phlib.lib;shlwapi.lib;userenv.lib;uxtheme.lib;version.lib;wbemuuid.lib;windowscodecs.lib;winsta.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
110110
<GenerateDebugInformation>true</GenerateDebugInformation>
111111
<SubSystem>Windows</SubSystem>
112112
<TargetMachine>MachineX86</TargetMachine>
113113
<MinimumRequiredVersion>6.01</MinimumRequiredVersion>
114114
<AdditionalLibraryDirectories>$(SolutionDir)phlib\bin\$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
115115
<ModuleDefinitionFile>ProcessHacker.def</ModuleDefinitionFile>
116-
<DelayLoadDLLs>advapi32.dll;aclui.dll;comdlg32.dll;comctl32.dll;gdi32.dll;iphlpapi.dll;oleaut32.dll;ole32.dll;shell32.dll;userenv.dll;user32.dll;uxtheme.dll;version.dll;winsta.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
116+
<DelayLoadDLLs>advapi32.dll;aclui.dll;comdlg32.dll;comctl32.dll;gdi32.dll;iphlpapi.dll;oleaut32.dll;ole32.dll;shell32.dll;shlwapi.dll;userenv.dll;user32.dll;uxtheme.dll;version.dll;winsta.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
117117
</Link>
118118
<ResourceCompile>
119119
<PreprocessorDefinitions>_UNICODE;UNICODE;%(PreprocessorDefinitions);$(ExternalCompilerOptions)</PreprocessorDefinitions>
@@ -138,14 +138,14 @@
138138
<StringPooling>true</StringPooling>
139139
</ClCompile>
140140
<Link>
141-
<AdditionalDependencies>aclui.lib;comctl32.lib;iphlpapi.lib;noarg.obj;noenv.obj;ntdll.lib;phlib.lib;userenv.lib;uxtheme.lib;version.lib;wbemuuid.lib;windowscodecs.lib;winsta.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
141+
<AdditionalDependencies>aclui.lib;comctl32.lib;iphlpapi.lib;noarg.obj;noenv.obj;ntdll.lib;phlib.lib;shlwapi.lib;userenv.lib;uxtheme.lib;version.lib;wbemuuid.lib;windowscodecs.lib;winsta.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
142142
<GenerateDebugInformation>true</GenerateDebugInformation>
143143
<SubSystem>Windows</SubSystem>
144144
<TargetMachine>MachineX64</TargetMachine>
145145
<MinimumRequiredVersion>6.01</MinimumRequiredVersion>
146146
<AdditionalLibraryDirectories>$(SolutionDir)phlib\bin\$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
147147
<ModuleDefinitionFile>ProcessHacker.def</ModuleDefinitionFile>
148-
<DelayLoadDLLs>advapi32.dll;aclui.dll;comdlg32.dll;comctl32.dll;gdi32.dll;iphlpapi.dll;oleaut32.dll;ole32.dll;shell32.dll;userenv.dll;user32.dll;uxtheme.dll;version.dll;winsta.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
148+
<DelayLoadDLLs>advapi32.dll;aclui.dll;comdlg32.dll;comctl32.dll;gdi32.dll;iphlpapi.dll;oleaut32.dll;ole32.dll;shell32.dll;shlwapi.dll;userenv.dll;user32.dll;uxtheme.dll;version.dll;winsta.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
149149
</Link>
150150
<ResourceCompile>
151151
<PreprocessorDefinitions>_UNICODE;UNICODE;%(PreprocessorDefinitions);$(ExternalCompilerOptions)</PreprocessorDefinitions>
@@ -175,7 +175,7 @@
175175
<ControlFlowGuard>Guard</ControlFlowGuard>
176176
</ClCompile>
177177
<Link>
178-
<AdditionalDependencies>aclui.lib;comctl32.lib;iphlpapi.lib;noarg.obj;noenv.obj;ntdll.lib;phlib.lib;userenv.lib;uxtheme.lib;version.lib;wbemuuid.lib;windowscodecs.lib;winsta.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
178+
<AdditionalDependencies>aclui.lib;comctl32.lib;iphlpapi.lib;noarg.obj;noenv.obj;ntdll.lib;phlib.lib;shlwapi.lib;userenv.lib;uxtheme.lib;version.lib;wbemuuid.lib;windowscodecs.lib;winsta.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
179179
<SubSystem>Windows</SubSystem>
180180
<OptimizeReferences>true</OptimizeReferences>
181181
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -184,7 +184,7 @@
184184
<MinimumRequiredVersion>6.01</MinimumRequiredVersion>
185185
<AdditionalLibraryDirectories>$(SolutionDir)phlib\bin\$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
186186
<ModuleDefinitionFile>ProcessHacker.def</ModuleDefinitionFile>
187-
<DelayLoadDLLs>advapi32.dll;aclui.dll;comdlg32.dll;comctl32.dll;gdi32.dll;iphlpapi.dll;oleaut32.dll;ole32.dll;shell32.dll;userenv.dll;user32.dll;uxtheme.dll;version.dll;winsta.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
187+
<DelayLoadDLLs>advapi32.dll;aclui.dll;comdlg32.dll;comctl32.dll;gdi32.dll;iphlpapi.dll;oleaut32.dll;ole32.dll;shell32.dll;shlwapi.dll;userenv.dll;user32.dll;uxtheme.dll;version.dll;winsta.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
188188
<GenerateDebugInformation>true</GenerateDebugInformation>
189189
</Link>
190190
<ResourceCompile>
@@ -213,7 +213,7 @@
213213
<ControlFlowGuard>Guard</ControlFlowGuard>
214214
</ClCompile>
215215
<Link>
216-
<AdditionalDependencies>aclui.lib;comctl32.lib;iphlpapi.lib;noarg.obj;noenv.obj;ntdll.lib;phlib.lib;userenv.lib;uxtheme.lib;version.lib;wbemuuid.lib;windowscodecs.lib;winsta.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
216+
<AdditionalDependencies>aclui.lib;comctl32.lib;iphlpapi.lib;noarg.obj;noenv.obj;ntdll.lib;phlib.lib;shlwapi.lib;userenv.lib;uxtheme.lib;version.lib;wbemuuid.lib;windowscodecs.lib;winsta.lib;ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
217217
<SubSystem>Windows</SubSystem>
218218
<OptimizeReferences>true</OptimizeReferences>
219219
<EnableCOMDATFolding>true</EnableCOMDATFolding>
@@ -222,7 +222,7 @@
222222
<MinimumRequiredVersion>6.01</MinimumRequiredVersion>
223223
<AdditionalLibraryDirectories>$(SolutionDir)phlib\bin\$(Configuration)$(PlatformArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
224224
<ModuleDefinitionFile>ProcessHacker.def</ModuleDefinitionFile>
225-
<DelayLoadDLLs>advapi32.dll;aclui.dll;comdlg32.dll;comctl32.dll;gdi32.dll;iphlpapi.dll;oleaut32.dll;ole32.dll;shell32.dll;userenv.dll;user32.dll;uxtheme.dll;version.dll;winsta.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
225+
<DelayLoadDLLs>advapi32.dll;aclui.dll;comdlg32.dll;comctl32.dll;gdi32.dll;iphlpapi.dll;oleaut32.dll;ole32.dll;shell32.dll;shlwapi.dll;userenv.dll;user32.dll;uxtheme.dll;version.dll;winsta.dll;ws2_32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
226226
<GenerateDebugInformation>true</GenerateDebugInformation>
227227
</Link>
228228
<ResourceCompile>

ProcessHacker/mainwnd.c

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -606,43 +606,34 @@ VOID PhMwpOnCommand(
606606
break;
607607
case ID_HACKER_RUN:
608608
{
609-
if (RunFileDlg)
610-
{
611-
SelectedRunAsMode = 0;
612-
RunFileDlg(PhMainWndHandle, NULL, NULL, NULL, NULL, RFF_OPTRUNAS);
613-
}
609+
SelectedRunAsMode = 0;
610+
PhShowRunFileDialog(PhMainWndHandle, NULL, NULL, NULL, NULL, RFF_OPTRUNAS);
614611
}
615612
break;
616613
case ID_HACKER_RUNASADMINISTRATOR:
617614
{
618-
if (RunFileDlg)
619-
{
620-
SelectedRunAsMode = RUNAS_MODE_ADMIN;
621-
RunFileDlg(
622-
PhMainWndHandle,
623-
NULL,
624-
NULL,
625-
NULL,
626-
L"Type the name of a program that will be opened under alternate credentials.",
627-
0
628-
);
629-
}
615+
SelectedRunAsMode = RUNAS_MODE_ADMIN;
616+
PhShowRunFileDialog(
617+
PhMainWndHandle,
618+
NULL,
619+
NULL,
620+
NULL,
621+
L"Type the name of a program that will be opened under alternate credentials.",
622+
0
623+
);
630624
}
631625
break;
632626
case ID_HACKER_RUNASLIMITEDUSER:
633627
{
634-
if (RunFileDlg)
635-
{
636-
SelectedRunAsMode = RUNAS_MODE_LIMITED;
637-
RunFileDlg(
638-
PhMainWndHandle,
639-
NULL,
640-
NULL,
641-
NULL,
642-
L"Type the name of a program that will be opened under standard user privileges.",
643-
0
644-
);
645-
}
628+
SelectedRunAsMode = RUNAS_MODE_LIMITED;
629+
PhShowRunFileDialog(
630+
PhMainWndHandle,
631+
NULL,
632+
NULL,
633+
NULL,
634+
L"Type the name of a program that will be opened under standard user privileges.",
635+
0
636+
);
646637
}
647638
break;
648639
case ID_HACKER_RUNAS:

ProcessHacker/procprv.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,9 +864,9 @@ VOID PhpProcessQueryStage1(
864864
}
865865

866866
// Immersive
867-
if (processHandleLimited && IsImmersiveProcess_I && !processItem->IsSubsystemProcess)
867+
if (processHandleLimited && WINDOWS_HAS_IMMERSIVE && IsImmersiveProcess && !processItem->IsSubsystemProcess)
868868
{
869-
Data->IsImmersive = !!IsImmersiveProcess_I(processHandleLimited);
869+
Data->IsImmersive = !!IsImmersiveProcess(processHandleLimited);
870870
}
871871

872872
// Package full name
@@ -2350,11 +2350,11 @@ VOID PhProcessProviderUpdate(
23502350
}
23512351

23522352
// Immersive
2353-
if (processItem->QueryHandle && IsImmersiveProcess_I)
2353+
if (processItem->QueryHandle && WINDOWS_HAS_IMMERSIVE && IsImmersiveProcess)
23542354
{
23552355
BOOLEAN isImmersive;
23562356

2357-
isImmersive = !!IsImmersiveProcess_I(processItem->QueryHandle);
2357+
isImmersive = !!IsImmersiveProcess(processItem->QueryHandle);
23582358

23592359
if (processItem->IsImmersive != isImmersive)
23602360
{

ProcessHacker/runas.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,8 @@ INT_PTR CALLBACK PhpRunAsDlgProc(
855855

856856
if (SendMessage(context->ProgramComboBoxWindowHandle, CB_GETCOMBOBOXINFO, 0, (LPARAM)&info))
857857
{
858-
if (SHAutoComplete_I)
859-
SHAutoComplete_I(info.hwndItem, SHACF_DEFAULT);
858+
if (SHAutoComplete)
859+
SHAutoComplete(info.hwndItem, SHACF_DEFAULT);
860860
}
861861
}
862862

phlib/apiimport.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,3 @@ PH_DEFINE_IMPORT(L"ntdll.dll", NtQueryInformationEnlistment);
6262
PH_DEFINE_IMPORT(L"ntdll.dll", NtQueryInformationResourceManager);
6363
PH_DEFINE_IMPORT(L"ntdll.dll", NtQueryInformationTransaction);
6464
PH_DEFINE_IMPORT(L"ntdll.dll", NtQueryInformationTransactionManager);
65-
PH_DEFINE_IMPORT(L"shell32.dll", SHCreateShellItem);
66-
PH_DEFINE_IMPORT(L"shell32.dll", SHOpenFolderAndSelectItems);
67-
PH_DEFINE_IMPORT(L"shell32.dll", SHParseDisplayName);

phlib/guisup.c

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ typedef struct _PH_WINDOW_PROPERTY_CONTEXT
5353
PVOID Context;
5454
} PH_WINDOW_PROPERTY_CONTEXT, *PPH_WINDOW_PROPERTY_CONTEXT;
5555

56-
_IsImmersiveProcess IsImmersiveProcess_I = NULL;
57-
_RunFileDlg RunFileDlg = NULL;
58-
_SHAutoComplete SHAutoComplete_I = NULL;
59-
6056
HFONT PhApplicationFont = NULL;
6157
HFONT PhTreeWindowFont = NULL;
6258
PH_INTEGER_PAIR PhSmallIconSize = { 16, 16 };
@@ -76,8 +72,6 @@ VOID PhGuiSupportInitialization(
7672
)
7773
{
7874
HDC hdc;
79-
PVOID shell32Handle;
80-
PVOID shlwapiHandle;
8175

8276
WindowCallbackHashTable = PhCreateHashtable(
8377
sizeof(PH_PLUGIN_WINDOW_CALLBACK_REGISTRATION),
@@ -102,14 +96,6 @@ VOID PhGuiSupportInitialization(
10296
PhGlobalDpi = GetDeviceCaps(hdc, LOGPIXELSY);
10397
ReleaseDC(NULL, hdc);
10498
}
105-
106-
shell32Handle = LoadLibrary(L"shell32.dll");
107-
shlwapiHandle = LoadLibrary(L"shlwapi.dll");
108-
109-
if (WINDOWS_HAS_IMMERSIVE)
110-
IsImmersiveProcess_I = PhGetDllProcedureAddress(L"user32.dll", "IsImmersiveProcess", 0);
111-
RunFileDlg = PhGetDllBaseProcedureAddress(shell32Handle, NULL, 61);
112-
SHAutoComplete_I = PhGetDllBaseProcedureAddress(shlwapiHandle, "SHAutoComplete", 0);
11399
}
114100

115101
VOID PhSetControlTheme(
@@ -1497,8 +1483,8 @@ HWND PhGetProcessMainWindowEx(
14971483
else
14981484
PhOpenProcess(&processHandle, PROCESS_QUERY_LIMITED_INFORMATION, ProcessId);
14991485

1500-
if (processHandle && IsImmersiveProcess_I)
1501-
context.IsImmersive = IsImmersiveProcess_I(processHandle);
1486+
if (processHandle && WINDOWS_HAS_IMMERSIVE && IsImmersiveProcess)
1487+
context.IsImmersive = IsImmersiveProcess(processHandle);
15021488

15031489
PhEnumChildWindows(NULL, 0x800, PhpGetProcessMainWindowEnumWindowsProc, &context);
15041490

@@ -1676,3 +1662,43 @@ VOID PhWindowNotifyTopMostEvent(
16761662

16771663
PhReleaseQueuedLockExclusive(&WindowCallbackListLock);
16781664
}
1665+
1666+
BOOLEAN PhShowRunFileDialog(
1667+
_In_ HWND WindowHandle,
1668+
_In_opt_ HICON WindowIcon,
1669+
_In_opt_ PWSTR WorkingDirectory,
1670+
_In_opt_ PWSTR WindowTitle,
1671+
_In_opt_ PWSTR WindowDescription,
1672+
_In_ ULONG Flags
1673+
)
1674+
{
1675+
BOOL (WINAPI *RunFileDlg_I)(
1676+
_In_ HWND hwndOwner,
1677+
_In_opt_ HICON hIcon,
1678+
_In_opt_ LPCWSTR lpszDirectory,
1679+
_In_opt_ LPCWSTR lpszTitle,
1680+
_In_opt_ LPCWSTR lpszDescription,
1681+
_In_ ULONG uFlags
1682+
);
1683+
BOOLEAN result = FALSE;
1684+
PVOID shell32Handle;
1685+
1686+
if (shell32Handle = LoadLibrary(L"shell32.dll"))
1687+
{
1688+
if (RunFileDlg_I = PhGetDllBaseProcedureAddress(shell32Handle, NULL, 61))
1689+
{
1690+
result = !!RunFileDlg_I(
1691+
WindowHandle,
1692+
WindowIcon,
1693+
WorkingDirectory,
1694+
WindowTitle,
1695+
WindowDescription,
1696+
Flags
1697+
);
1698+
}
1699+
1700+
FreeLibrary(shell32Handle);
1701+
}
1702+
1703+
return result;
1704+
}

phlib/include/apiimport.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,42 +35,11 @@ typedef NTSTATUS (NTAPI *_NtQueryInformationTransactionManager)(
3535
_Out_opt_ PULONG ReturnLength
3636
);
3737

38-
// shell32
39-
40-
#if defined(_M_IX86)
41-
#define __unaligned
42-
#endif
43-
44-
typedef HRESULT (WINAPI *_SHCreateShellItem)(
45-
_In_opt_ const struct _ITEMIDLIST __unaligned *pidlParent,
46-
_In_opt_ struct IShellFolder *psfParent,
47-
_In_ const struct _ITEMIDLIST __unaligned *pidl,
48-
_Out_ struct IShellItem **ppsi
49-
);
50-
51-
typedef HRESULT (WINAPI *_SHOpenFolderAndSelectItems)(
52-
_In_ const struct _ITEMIDLIST __unaligned *pidlFolder,
53-
_In_ UINT cidl,
54-
_In_reads_opt_(cidl) const struct _ITEMIDLIST __unaligned **apidl,
55-
_In_ ULONG dwFlags
56-
);
57-
58-
typedef HRESULT (WINAPI *_SHParseDisplayName)(
59-
_In_ LPCWSTR pszName,
60-
_In_opt_ struct IBindCtx *pbc,
61-
_Out_ const struct _ITEMIDLIST __unaligned **ppidl,
62-
_In_ ULONG sfgaoIn,
63-
_Out_ ULONG *psfgaoOut
64-
);
65-
6638
#define PH_DECLARE_IMPORT(Name) _##Name Name##_Import(VOID)
6739

6840
PH_DECLARE_IMPORT(NtQueryInformationEnlistment);
6941
PH_DECLARE_IMPORT(NtQueryInformationResourceManager);
7042
PH_DECLARE_IMPORT(NtQueryInformationTransaction);
7143
PH_DECLARE_IMPORT(NtQueryInformationTransactionManager);
72-
PH_DECLARE_IMPORT(SHCreateShellItem);
73-
PH_DECLARE_IMPORT(SHOpenFolderAndSelectItems);
74-
PH_DECLARE_IMPORT(SHParseDisplayName);
7544

7645
#endif

phlib/include/guisup.h

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ extern "C" {
1111

1212
// guisup
1313

14-
typedef BOOL (WINAPI *_IsImmersiveProcess)(
15-
_In_ HANDLE hProcess
16-
);
17-
1814
#define RFF_NOBROWSE 0x0001
1915
#define RFF_NODEFAULT 0x0002
2016
#define RFF_CALCDIRECTORY 0x0004
@@ -43,24 +39,6 @@ typedef LPNMRUNFILEDLGW LPNMRUNFILEDLG;
4339

4440
typedef HANDLE HTHEME;
4541

46-
typedef BOOL (WINAPI *_RunFileDlg)(
47-
_In_ HWND hwndOwner,
48-
_In_opt_ HICON hIcon,
49-
_In_opt_ LPCWSTR lpszDirectory,
50-
_In_opt_ LPCWSTR lpszTitle,
51-
_In_opt_ LPCWSTR lpszDescription,
52-
_In_ ULONG uFlags
53-
);
54-
55-
typedef HRESULT (WINAPI *_SHAutoComplete)(
56-
_In_ HWND hwndEdit,
57-
_In_ ULONG dwFlags
58-
);
59-
60-
extern _IsImmersiveProcess IsImmersiveProcess_I;
61-
extern _RunFileDlg RunFileDlg;
62-
extern _SHAutoComplete SHAutoComplete_I;
63-
6442
extern PH_INTEGER_PAIR PhSmallIconSize;
6543
extern PH_INTEGER_PAIR PhLargeIconSize;
6644

@@ -905,6 +883,18 @@ PhWindowNotifyTopMostEvent(
905883
_In_ BOOLEAN TopMost
906884
);
907885

886+
PHLIBAPI
887+
BOOLEAN
888+
NTAPI
889+
PhShowRunFileDialog(
890+
_In_ HWND WindowHandle,
891+
_In_opt_ HICON WindowIcon,
892+
_In_opt_ PWSTR WorkingDirectory,
893+
_In_opt_ PWSTR WindowTitle,
894+
_In_opt_ PWSTR WindowDescription,
895+
_In_ ULONG Flags
896+
);
897+
908898
// theme support (theme.c)
909899

910900
PHLIBAPI extern HFONT PhApplicationFont; // phapppub

0 commit comments

Comments
 (0)