Update to latest phlib

This commit is contained in:
dmex
2018-07-01 23:38:17 +10:00
parent 4b714a5b5f
commit e6b81a7ac9
24 changed files with 276 additions and 191 deletions
+8 -2
View File
@@ -354,12 +354,16 @@ BOOLEAN PhpStartPhSvcProcess(
};
ULONG i;
PPH_STRING applicationDirectory;
for (i = 0; i < sizeof(relativeFileNames) / sizeof(PWSTR); i++)
if (!(applicationDirectory = PhGetApplicationDirectory()))
return FALSE;
for (i = 0; i < RTL_NUMBER_OF(relativeFileNames); i++)
{
PPH_STRING fileName;
fileName = PhConcatStrings2(PhApplicationDirectory->Buffer, relativeFileNames[i]);
fileName = PhConcatStrings2(applicationDirectory->Buffer, relativeFileNames[i]);
PhMoveReference(&fileName, PhGetFullPath(fileName->Buffer, NULL));
if (fileName && RtlDoesFileExists_U(fileName->Buffer))
@@ -376,11 +380,13 @@ BOOLEAN PhpStartPhSvcProcess(
))
{
PhDereferenceObject(fileName);
PhDereferenceObject(applicationDirectory);
return TRUE;
}
}
PhClearReference(&fileName);
PhClearReference(&applicationDirectory);
}
}
break;
+18 -4
View File
@@ -738,12 +738,19 @@ VOID PhShellExecuteUserString(
)
{
static PH_STRINGREF replacementToken = PH_STRINGREF_INIT(L"%s");
PPH_STRING applicationDirectory;
PPH_STRING executeString;
PH_STRINGREF stringBefore;
PH_STRINGREF stringAfter;
PPH_STRING ntMessage;
if (!(applicationDirectory = PhGetApplicationDirectory()))
{
PhShowStatus(hWnd, L"Unable to locate the application directory.", STATUS_NOT_FOUND, 0);
return;
}
// Get the execute command.
executeString = PhGetStringSetting(Setting);
// Expand environment strings.
@@ -764,7 +771,7 @@ VOID PhShellExecuteUserString(
// Make sure the string is absolute and escape the filename.
if (RtlDetermineDosPathNameType_U(fileName->Buffer) == RtlPathTypeRelative)
PhMoveReference(&fileName, PhConcatStrings(4, L"\"", PhApplicationDirectory->Buffer, fileName->Buffer, L"\""));
PhMoveReference(&fileName, PhConcatStrings(4, L"\"", applicationDirectory->Buffer, fileName->Buffer, L"\""));
else
PhMoveReference(&fileName, PhConcatStrings(3, L"\"", fileName->Buffer, L"\""));
@@ -781,7 +788,7 @@ VOID PhShellExecuteUserString(
else
{
if (RtlDetermineDosPathNameType_U(executeString->Buffer) == RtlPathTypeRelative)
PhMoveReference(&executeString, PhConcatStrings(4, L"\"", PhApplicationDirectory->Buffer, executeString->Buffer, L"\""));
PhMoveReference(&executeString, PhConcatStrings(4, L"\"", applicationDirectory->Buffer, executeString->Buffer, L"\""));
else
PhMoveReference(&executeString, PhConcatStrings(3, L"\"", executeString->Buffer, L"\""));
}
@@ -832,6 +839,7 @@ VOID PhShellExecuteUserString(
}
PhDereferenceObject(executeString);
PhDereferenceObject(applicationDirectory);
}
VOID PhLoadSymbolProviderOptions(
@@ -1134,9 +1142,13 @@ BOOLEAN PhShellProcessHackerEx(
)
{
BOOLEAN result;
PPH_STRING applicationFileName;
PH_STRING_BUILDER sb;
PWSTR parameters;
if (!(applicationFileName = PhGetApplicationFileName()))
return FALSE;
if (AppFlags & PH_SHELL_APP_PROPAGATE_PARAMETERS)
{
PhInitializeStringBuilder(&sb, 128);
@@ -1243,7 +1255,7 @@ BOOLEAN PhShellProcessHackerEx(
result = PhShellExecuteEx(
hWnd,
FileName ? FileName : PhApplicationFileName->Buffer,
FileName ? FileName : PhGetString(applicationFileName),
parameters,
ShowWindowType,
Flags,
@@ -1254,6 +1266,8 @@ BOOLEAN PhShellProcessHackerEx(
if (AppFlags & PH_SHELL_APP_PROPAGATE_PARAMETERS)
PhDeleteStringBuilder(&sb);
PhDereferenceObject(applicationFileName);
return result;
}
+2 -2
View File
@@ -130,8 +130,8 @@ static VOID PhpRefreshProcessList(
NtClose(processHandle);
}
if (process->UniqueProcessId == SYSTEM_IDLE_PROCESS_ID && !userName && PhLocalSystemName)
PhSetReference(&userName, PhLocalSystemName);
if (process->UniqueProcessId == SYSTEM_IDLE_PROCESS_ID && !userName)
PhSetReference(&userName, PhCreateString(L"NT AUTHORITY\\SYSTEM"));
if (process->UniqueProcessId == SYSTEM_PROCESS_ID)
fileName = PhGetKernelFileName();
-4
View File
@@ -72,11 +72,7 @@ typedef struct _PH_STARTUP_PARAMETERS
PPH_STRING SysInfo;
} PH_STARTUP_PARAMETERS, *PPH_STARTUP_PARAMETERS;
extern PPH_STRING PhApplicationDirectory;
extern PPH_STRING PhApplicationFileName;
PHAPPAPI extern HFONT PhApplicationFont; // phapppub
extern PPH_STRING PhCurrentUserName;
extern PPH_STRING PhLocalSystemName;
extern BOOLEAN PhPluginsEnabled;
extern PPH_STRING PhSettingsFileName;
extern PH_INTEGER_PAIR PhSmallIconSize;
+1 -2
View File
@@ -15,8 +15,7 @@ typedef struct _PHSVC_STOP
} PHSVC_STOP, *PPHSVC_STOP;
NTSTATUS PhSvcMain(
_In_opt_ PUNICODE_STRING PortName,
_In_opt_ PLARGE_INTEGER Timeout,
_In_opt_ PPH_STRING PortName,
_Inout_opt_ PPHSVC_STOP Stop
);
+62 -65
View File
@@ -84,11 +84,8 @@ BOOLEAN PhInitializeMitigationPolicy(
VOID
);
PPH_STRING PhApplicationDirectory = NULL;
PPH_STRING PhApplicationFileName = NULL;
PHAPPAPI HFONT PhApplicationFont = NULL;
PPH_STRING PhCurrentUserName = NULL;
PPH_STRING PhLocalSystemName = NULL;
BOOLEAN PhPluginsEnabled = FALSE;
PPH_STRING PhSettingsFileName = NULL;
PH_INTEGER_PAIR PhSmallIconSize = { 16, 16 };
@@ -116,7 +113,7 @@ INT WINAPI wWinMain(
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (!NT_SUCCESS(PhInitializePhLibEx(ULONG_MAX, Instance, 0, 0)))
if (!NT_SUCCESS(PhInitializePhLibEx(L"Process Hacker", ULONG_MAX, Instance, 0, 0)))
return 1;
if (!PhInitializeExceptionPolicy())
return 1;
@@ -124,22 +121,8 @@ INT WINAPI wWinMain(
return 1;
if (!PhInitializeRestartPolicy())
return 1;
if (!PhInitializeAppSystem())
return 1;
PhInitializeCommonControls();
if (!(PhApplicationFileName = PhGetApplicationFileName()))
PhApplicationFileName = PhCreateString(L"ProcessHacker.exe");
if (!(PhApplicationDirectory = PhGetApplicationDirectory()))
PhApplicationDirectory = PhReferenceEmptyString();
if (!(PhLocalSystemName = PhGetSidFullName(&PhSeLocalSystemSid, TRUE, NULL)))
PhLocalSystemName = PhCreateString(L"NT AUTHORITY\\SYSTEM");
if (!(PhCurrentUserName = PhGetTokenUserString(PhGetOwnTokenAttributes().TokenHandle, TRUE)))
PhCurrentUserName = PhReferenceEmptyString();
PhpProcessStartupParameters();
PhSettingsInitialization();
PhpEnablePrivileges();
if (PhStartupParameters.RunAsServiceMode)
@@ -147,9 +130,16 @@ INT WINAPI wWinMain(
RtlExitUserProcess(PhRunAsServiceStart(PhStartupParameters.RunAsServiceMode));
}
if (PhStartupParameters.CommandMode &&
PhStartupParameters.CommandType &&
PhStartupParameters.CommandAction)
{
RtlExitUserProcess(PhCommandModeStart());
}
PhSettingsInitialization();
PhpInitializeSettings();
// Activate a previous instance if required.
if (PhGetIntegerSetting(L"AllowOnlyOneInstance") &&
!PhStartupParameters.NewInstance &&
!PhStartupParameters.ShowOptions &&
@@ -159,21 +149,13 @@ INT WINAPI wWinMain(
PhActivatePreviousInstance();
}
if (PhGetIntegerSetting(L"EnableKph") && !PhStartupParameters.NoKph && !PhStartupParameters.CommandMode && !PhIsExecutingInWow64())
PhInitializeKph();
if (PhStartupParameters.CommandMode && PhStartupParameters.CommandType && PhStartupParameters.CommandAction)
if (PhGetIntegerSetting(L"EnableKph") &&
!PhStartupParameters.NoKph &&
!PhStartupParameters.CommandMode &&
!PhIsExecutingInWow64()
)
{
NTSTATUS status;
status = PhCommandModeStart();
if (!NT_SUCCESS(status) && !PhStartupParameters.Silent)
{
PhShowStatus(NULL, L"Unable to execute the command.", status, 0);
}
RtlExitUserProcess(status);
PhInitializeKph();
}
#ifdef DEBUG
@@ -186,6 +168,9 @@ INT WINAPI wWinMain(
PhInitializeAutoPool(&BaseAutoPool);
PhInitializeAppSystem();
PhInitializeCommonControls();
PhEmInitialization();
PhGuiSupportInitialization();
PhTreeNewInitialization();
@@ -205,22 +190,7 @@ INT WINAPI wWinMain(
RtlExitUserProcess(STATUS_SUCCESS);
}
#ifndef DEBUG
if (PhIsExecutingInWow64() && !PhStartupParameters.PhSvc)
{
PhShowWarning(
NULL,
L"You are attempting to run the 32-bit version of Process Hacker on 64-bit Windows. "
L"Most features will not work correctly.\n\n"
L"Please run the 64-bit version of Process Hacker instead."
);
RtlExitUserProcess(STATUS_IMAGE_SUBSYSTEM_NOT_PRESENT);
}
#endif
PhPluginsEnabled = PhGetIntegerSetting(L"EnablePlugins") && !PhStartupParameters.NoPlugins;
if (PhPluginsEnabled)
if (PhPluginsEnabled = PhGetIntegerSetting(L"EnablePlugins") && !PhStartupParameters.NoPlugins)
{
PhPluginsInitialization();
PhLoadPlugins();
@@ -249,9 +219,22 @@ INT WINAPI wWinMain(
PostMessage(NULL, WM_NULL, 0, 0);
GetMessage(&message, NULL, 0, 0);
RtlExitUserProcess(PhSvcMain(NULL, NULL, NULL));
RtlExitUserProcess(PhSvcMain(NULL, NULL));
}
#ifndef DEBUG
if (PhIsExecutingInWow64())
{
PhShowWarning(
NULL,
L"You are attempting to run the 32-bit version of Process Hacker on 64-bit Windows. "
L"Most features will not work correctly.\n\n"
L"Please run the 64-bit version of Process Hacker instead."
);
RtlExitUserProcess(STATUS_IMAGE_SUBSYSTEM_NOT_PRESENT);
}
#endif
// Create a mutant for the installer.
{
HANDLE mutantHandle;
@@ -789,15 +772,18 @@ VOID PhInitializeKph(
VOID
)
{
static PH_STRINGREF kprocesshacker = PH_STRINGREF_INIT(L"kprocesshacker.sys");
static PH_STRINGREF processhackerSig = PH_STRINGREF_INIT(L"ProcessHacker.sig");
NTSTATUS status;
PPH_STRING applicationDirectory;
PPH_STRING kprocesshackerFileName;
PPH_STRING processhackerSigFileName;
KPH_PARAMETERS parameters;
kprocesshackerFileName = PhConcatStringRef2(&PhApplicationDirectory->sr, &kprocesshacker);
processhackerSigFileName = PhConcatStringRef2(&PhApplicationDirectory->sr, &processhackerSig);
if (!(applicationDirectory = PhGetApplicationDirectory()))
return;
kprocesshackerFileName = PhConcatStringRefZ(&applicationDirectory->sr, L"kprocesshacker.sys");
processhackerSigFileName = PhConcatStringRefZ(&applicationDirectory->sr, L"ProcessHacker.sig");
PhDereferenceObject(applicationDirectory);
if (!RtlDoesFileExists_U(kprocesshackerFileName->Buffer))
{
@@ -856,8 +842,6 @@ BOOLEAN PhInitializeAppSystem(
VOID
)
{
PhApplicationName = L"Process Hacker";
if (!PhProcessProviderInitialization())
return FALSE;
if (!PhServiceProviderInitialization())
@@ -886,6 +870,7 @@ VOID PhpInitializeSettings(
if (!PhStartupParameters.NoSettings)
{
static PH_STRINGREF settingsPath = PH_STRINGREF_INIT(L"%APPDATA%\\Process Hacker\\settings.xml");
static PH_STRINGREF settingsSuffix = PH_STRINGREF_INIT(L".settings.xml");
PPH_STRING settingsFileName;
@@ -905,22 +890,29 @@ VOID PhpInitializeSettings(
// 2. File in program directory
if (!PhSettingsFileName)
{
settingsFileName = PhConcatStringRef2(&PhApplicationFileName->sr, &settingsSuffix);
PPH_STRING applicationFileName;
if (RtlDoesFileExists_U(settingsFileName->Buffer))
if (applicationFileName = PhGetApplicationFileName())
{
PhSettingsFileName = settingsFileName;
}
else
{
PhDereferenceObject(settingsFileName);
settingsFileName = PhConcatStringRef2(&applicationFileName->sr, &settingsSuffix);
if (RtlDoesFileExists_U(settingsFileName->Buffer))
{
PhSettingsFileName = settingsFileName;
}
else
{
PhDereferenceObject(settingsFileName);
}
PhDereferenceObject(applicationFileName);
}
}
// 3. Default location
if (!PhSettingsFileName)
{
PhSettingsFileName = PhGetKnownLocation(CSIDL_APPDATA, L"\\Process Hacker\\settings.xml");
PhSettingsFileName = PhExpandEnvironmentStrings(&settingsPath);
}
if (PhSettingsFileName)
@@ -1245,10 +1237,15 @@ VOID PhpProcessStartupParameters(
if (PhStartupParameters.InstallKph)
{
NTSTATUS status;
PPH_STRING applicationDirectory;
PPH_STRING kprocesshackerFileName;
KPH_PARAMETERS parameters;
kprocesshackerFileName = PhConcatStrings2(PhApplicationDirectory->Buffer, L"\\kprocesshacker.sys");
if (!(applicationDirectory = PhGetApplicationDirectory()))
return;
kprocesshackerFileName = PhConcatStringRefZ(&applicationDirectory->sr, L"\\kprocesshacker.sys");
PhDereferenceObject(applicationDirectory);
parameters.SecurityLevel = KphSecuritySignatureCheck;
parameters.CreateDynamicConfiguration = TRUE;
+7 -4
View File
@@ -31,6 +31,7 @@
#include <cpysave.h>
#include <emenu.h>
#include <kphuser.h>
#include <lsasup.h>
#include <svcsup.h>
#include <verify.h>
#include <workqueue.h>
@@ -122,14 +123,17 @@ BOOLEAN PhMainWndInitialization(
if (PhGetIntegerSetting(L"EnableWindowText"))
{
PPH_STRING currentUserName;
PhAppendStringBuilder2(&stringBuilder, L"Process Hacker");
if (PhCurrentUserName)
if (currentUserName = PhGetTokenUserString(PhGetOwnTokenAttributes().TokenHandle, TRUE))
{
PhAppendStringBuilder2(&stringBuilder, L" [");
PhAppendStringBuilder(&stringBuilder, &PhCurrentUserName->sr);
PhAppendStringBuilder(&stringBuilder, &currentUserName->sr);
PhAppendCharStringBuilder(&stringBuilder, ']');
if (KphIsConnected()) PhAppendCharStringBuilder(&stringBuilder, '+');
PhDereferenceObject(currentUserName);
}
if (PhGetOwnTokenAttributes().ElevationType == TokenElevationTypeFull)
@@ -2984,8 +2988,7 @@ VOID PhMwpAddIconProcesses(
if (
processItem->CpuUsage == 0 ||
!processItem->UserName ||
(PhCurrentUserName && !PhEqualString(processItem->UserName, PhCurrentUserName, TRUE))
processItem->SessionId != NtCurrentPeb()->SessionId
)
{
PhRemoveItemList(processList, i);
+64 -25
View File
@@ -716,6 +716,7 @@ static VOID ReadCurrentUserRun(
PH_STRINGREF fileName;
PH_STRINGREF arguments;
PPH_STRING fullFileName;
PPH_STRING applicationFileName;
PH_AUTO(value);
@@ -723,10 +724,15 @@ static VOID ReadCurrentUserRun(
{
PH_AUTO(fullFileName);
if (fullFileName && PhEqualString(fullFileName, PhApplicationFileName, TRUE))
if (applicationFileName = PhGetApplicationFileName())
{
CurrentUserRunPresent = TRUE;
CurrentUserRunStartHidden = PhEqualStringRef2(&arguments, L"-hide", FALSE);
if (fullFileName && PhEqualString(fullFileName, applicationFileName, TRUE))
{
CurrentUserRunPresent = TRUE;
CurrentUserRunStartHidden = PhEqualStringRef2(&arguments, L"-hide", FALSE);
}
PhDereferenceObject(applicationFileName);
}
}
}
@@ -760,13 +766,26 @@ static VOID WriteCurrentUserRun(
if (Present)
{
PPH_STRING value;
PPH_STRING fileName;
value = PH_AUTO(PhConcatStrings(3, L"\"", PhApplicationFileName->Buffer, L"\""));
if (fileName = PhGetApplicationFileName())
{
value = PH_AUTO(PhConcatStrings(3, L"\"", PhGetStringOrEmpty(fileName), L"\""));
if (StartHidden)
value = PhaConcatStrings2(value->Buffer, L" -hide");
if (StartHidden)
value = PhaConcatStrings2(value->Buffer, L" -hide");
NtSetValueKey(keyHandle, &valueName, 0, REG_SZ, value->Buffer, (ULONG)value->Length + 2);
NtSetValueKey(
keyHandle,
&valueName,
0,
REG_SZ,
value->Buffer,
(ULONG)value->Length + sizeof(WCHAR)
);
PhDereferenceObject(fileName);
}
}
else
{
@@ -782,25 +801,31 @@ static BOOLEAN PathMatchesPh(
)
{
BOOLEAN match = FALSE;
PPH_STRING fileName;
if (PhEqualString(OldTaskMgrDebugger, PhApplicationFileName, TRUE))
if (fileName = PhGetApplicationFileName())
{
match = TRUE;
}
// Allow for a quoted value.
else if (
OldTaskMgrDebugger->Length == PhApplicationFileName->Length + sizeof(WCHAR) * sizeof(WCHAR) &&
OldTaskMgrDebugger->Buffer[0] == '"' &&
OldTaskMgrDebugger->Buffer[OldTaskMgrDebugger->Length / sizeof(WCHAR) - 1] == '"'
)
{
PH_STRINGREF partInside;
partInside.Buffer = &OldTaskMgrDebugger->Buffer[1];
partInside.Length = OldTaskMgrDebugger->Length - sizeof(WCHAR) * sizeof(WCHAR);
if (PhEqualStringRef(&partInside, &PhApplicationFileName->sr, TRUE))
if (PhEqualString(OldTaskMgrDebugger, fileName, TRUE))
{
match = TRUE;
}
// Allow for a quoted value.
else if (
OldTaskMgrDebugger->Length == fileName->Length + sizeof(WCHAR) * sizeof(WCHAR) &&
OldTaskMgrDebugger->Buffer[0] == '"' &&
OldTaskMgrDebugger->Buffer[OldTaskMgrDebugger->Length / sizeof(WCHAR) - 1] == '"'
)
{
PH_STRINGREF partInside;
partInside.Buffer = &OldTaskMgrDebugger->Buffer[1];
partInside.Length = OldTaskMgrDebugger->Length - sizeof(WCHAR) * sizeof(WCHAR);
if (PhEqualStringRef(&partInside, &fileName->sr, TRUE))
match = TRUE;
}
PhDereferenceObject(fileName);
}
return match;
@@ -878,9 +903,23 @@ VOID PhpSetDefaultTaskManager(
else
{
PPH_STRING quotedFileName;
PPH_STRING applicationFileName;
quotedFileName = PH_AUTO(PhConcatStrings(3, L"\"", PhApplicationFileName->Buffer, L"\""));
status = NtSetValueKey(taskmgrKeyHandle, &valueName, 0, REG_SZ, quotedFileName->Buffer, (ULONG)quotedFileName->Length + 2);
if (applicationFileName = PhGetApplicationFileName())
{
quotedFileName = PH_AUTO(PhConcatStrings(3, L"\"", PhGetStringOrEmpty(applicationFileName), L"\""));
status = NtSetValueKey(
taskmgrKeyHandle,
&valueName,
0,
REG_SZ,
quotedFileName->Buffer,
(ULONG)quotedFileName->Length + sizeof(WCHAR)
);
PhDereferenceObject(applicationFileName);
}
}
NtClose(taskmgrKeyHandle);
+9 -13
View File
@@ -3,6 +3,7 @@
* server
*
* Copyright (C) 2011 wj32
* Copyright (C) 2018 dmex
*
* This file is part of Process Hacker.
*
@@ -27,8 +28,7 @@ HANDLE PhSvcTimeoutStandbyEventHandle;
HANDLE PhSvcTimeoutCancelEventHandle;
NTSTATUS PhSvcMain(
_In_opt_ PUNICODE_STRING PortName,
_In_opt_ PLARGE_INTEGER Timeout,
_In_opt_ PPH_STRING PortName,
_Inout_opt_ PPHSVC_STOP Stop
)
{
@@ -36,27 +36,23 @@ NTSTATUS PhSvcMain(
UNICODE_STRING portName;
LARGE_INTEGER timeout;
if (!PortName)
if (PortName)
{
PhStringRefToUnicodeString(&PortName->sr, &portName);
}
else
{
if (PhIsExecutingInWow64())
RtlInitUnicodeString(&portName, PHSVC_WOW64_PORT_NAME);
else
RtlInitUnicodeString(&portName, PHSVC_PORT_NAME);
PortName = &portName;
}
if (!Timeout)
{
timeout.QuadPart = -(LONGLONG)UInt32x32To64(15, PH_TIMEOUT_SEC);
Timeout = &timeout;
}
if (!NT_SUCCESS(status = PhSvcClientInitialization()))
return status;
if (!NT_SUCCESS(status = PhSvcApiInitialization()))
return status;
if (!NT_SUCCESS(status = PhSvcApiPortInitialization(PortName)))
if (!NT_SUCCESS(status = PhSvcApiPortInitialization(&portName)))
return status;
if (!NT_SUCCESS(status = NtCreateEvent(&PhSvcTimeoutStandbyEventHandle, EVENT_ALL_ACCESS, NULL, SynchronizationEvent, TRUE)))
@@ -85,7 +81,7 @@ NTSTATUS PhSvcMain(
if (Stop && Stop->Stop)
break;
status = NtWaitForSingleObject(PhSvcTimeoutCancelEventHandle, FALSE, Timeout);
status = NtWaitForSingleObject(PhSvcTimeoutCancelEventHandle, FALSE, PhTimeoutFromMilliseconds(&timeout, 10 * 1000));
if (Stop && Stop->Stop)
break;
+18 -6
View File
@@ -250,18 +250,30 @@ VOID PhLoadPlugins(
if (RtlDetermineDosPathNameType_U(pluginsDirectory->Buffer) == RtlPathTypeRelative)
{
// Not absolute. Make sure it is.
PluginsDirectory = PhConcatStrings(4, PhApplicationDirectory->Buffer, L"\\", pluginsDirectory->Buffer, L"\\");
PhDereferenceObject(pluginsDirectory);
PPH_STRING applicationDirectory;
if (applicationDirectory = PhGetApplicationDirectory())
{
PhMoveReference(&PluginsDirectory, PhConcatStrings( // Not absolute. Make sure it is.
4,
applicationDirectory->Buffer,
L"\\",
pluginsDirectory->Buffer,
L"\\"
));
PhDereferenceObject(pluginsDirectory);
}
}
else
if (PhIsNullOrEmptyString(PluginsDirectory))
{
PluginsDirectory = pluginsDirectory;
PhMoveReference(&PluginsDirectory, pluginsDirectory);
}
if (NT_SUCCESS(PhCreateFileWin32(
&pluginsDirectoryHandle,
PluginsDirectory->Buffer,
PhGetString(PluginsDirectory),
FILE_GENERIC_READ,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ,
+1 -1
View File
@@ -1226,7 +1226,7 @@ VOID PhpFillProcessItem(
ProcessItem->ProcessId == SYSTEM_PROCESS_ID // System token can't be opened on XP
)
{
PhSetReference(&ProcessItem->UserName, PhLocalSystemName);
PhSetReference(&ProcessItem->UserName, PhCreateString(L"NT AUTHORITY\\SYSTEM"));
}
}
+11 -9
View File
@@ -1221,6 +1221,7 @@ NTSTATUS PhExecuteRunAsCommand(
{
NTSTATUS status;
ULONG win32Result;
PPH_STRING applicationFileName;
PPH_STRING commandLine;
SC_HANDLE scManagerHandle;
SC_HANDLE serviceHandle;
@@ -1231,7 +1232,10 @@ NTSTATUS PhExecuteRunAsCommand(
if (!(scManagerHandle = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE)))
return PhGetLastWin32ErrorAsNtStatus();
commandLine = PhFormatString(L"\"%s\" -ras \"%s\"", PhApplicationFileName->Buffer, Parameters->ServiceName);
if (!(applicationFileName = PhGetApplicationFileName()))
return STATUS_FAIL_CHECK;
commandLine = PhFormatString(L"\"%s\" -ras \"%s\"", applicationFileName->Buffer, Parameters->ServiceName);
serviceHandle = CreateService(
scManagerHandle,
@@ -1251,6 +1255,7 @@ NTSTATUS PhExecuteRunAsCommand(
win32Result = GetLastError();
PhDereferenceObject(commandLine);
PhDereferenceObject(applicationFileName);
CloseServiceHandle(scManagerHandle);
@@ -1489,21 +1494,18 @@ static VOID WINAPI RunAsServiceMain(
)
{
PPH_STRING portName;
UNICODE_STRING portNameUs;
LARGE_INTEGER timeout;
memset(&RunAsServiceStop, 0, sizeof(PHSVC_STOP));
RunAsServiceStatusHandle = RegisterServiceCtrlHandlerEx(RunAsServiceName->Buffer, RunAsServiceHandlerEx, NULL);
SetRunAsServiceStatus(SERVICE_RUNNING);
portName = PhConcatStrings2(L"\\BaseNamedObjects\\", RunAsServiceName->Buffer);
PhStringRefToUnicodeString(&portName->sr, &portNameUs);
portName = PhConcatStrings2(
L"\\BaseNamedObjects\\",
RunAsServiceName->Buffer
);
// Use a shorter timeout value to reduce the time spent running as SYSTEM.
timeout.QuadPart = -(LONGLONG)UInt32x32To64(5, PH_TIMEOUT_SEC);
PhSvcMain(&portNameUs, &timeout, &RunAsServiceStop);
PhSvcMain(portName, &RunAsServiceStop);
SetRunAsServiceStatus(SERVICE_STOPPED);
}
+5 -3
View File
@@ -21,7 +21,7 @@
*/
#include <phapp.h>
#include <lsasup.h>
#include <windowsx.h>
#include <winsta.h>
@@ -69,6 +69,7 @@ INT_PTR CALLBACK PhpSessionSendMessageDlgProc(
case WM_INITDIALOG:
{
HWND iconComboBox;
PPH_STRING currentUserName;
PhSetWindowContext(hwndDlg, PH_WINDOW_CONTEXT_DEFAULT, UlongToPtr((ULONG)lParam));
@@ -83,13 +84,14 @@ INT_PTR CALLBACK PhpSessionSendMessageDlgProc(
ComboBox_AddString(iconComboBox, L"Question");
PhSelectComboBoxString(iconComboBox, L"None", FALSE);
if (PhCurrentUserName)
if (currentUserName = PhGetTokenUserString(PhGetOwnTokenAttributes().TokenHandle, TRUE))
{
PhSetDialogItemText(
hwndDlg,
IDC_TITLE,
PhaFormatString(L"Message from %s", PhCurrentUserName->Buffer)->Buffer
PhaFormatString(L"Message from %s", currentUserName->Buffer)->Buffer
);
PhDereferenceObject(currentUserName);
}
PhSetDialogFocus(hwndDlg, GetDlgItem(hwndDlg, IDC_TEXT));
+5 -2
View File
@@ -40,7 +40,7 @@ VOID PhInitializeWindowsVersion(
);
PHLIBAPI PVOID PhInstanceHandle;
PHLIBAPI PWSTR PhApplicationName = L"Application";
PHLIBAPI PWSTR PhApplicationName;
PHLIBAPI ULONG PhGlobalDpi = 96;
PHLIBAPI PVOID PhHeapHandle;
PHLIBAPI RTL_OSVERSIONINFOEXW PhOsVersion;
@@ -63,7 +63,8 @@ NTSTATUS PhInitializePhLib(
)
{
return PhInitializePhLibEx(
0xffffffff, // all possible features
L"Application",
ULONG_MAX, // all possible features
NtCurrentPeb()->ImageBaseAddress,
0,
0
@@ -71,12 +72,14 @@ NTSTATUS PhInitializePhLib(
}
NTSTATUS PhInitializePhLibEx(
_In_ PWSTR ApplicationName,
_In_ ULONG Flags,
_In_ PVOID ImageBaseAddress,
_In_opt_ SIZE_T HeapReserveSize,
_In_opt_ SIZE_T HeapCommitSize
)
{
PhApplicationName = ApplicationName;
PhInstanceHandle = ImageBaseAddress;
PhHeapHandle = RtlCreateHeap(
HEAP_GROWABLE | HEAP_CLASS_1,
+1 -1
View File
@@ -178,7 +178,7 @@ PhDelayExecution(
{
LARGE_INTEGER interval;
interval.QuadPart = Interval * -PH_TIMEOUT_MS;
interval.QuadPart = -(LONGLONG)UInt32x32To64(Interval, PH_TIMEOUT_MS);
return NtDelayExecution(FALSE, &interval);
}
+1
View File
@@ -75,6 +75,7 @@ PHLIBAPI
NTSTATUS
NTAPI
PhInitializePhLibEx(
_In_ PWSTR Name,
_In_ ULONG Flags,
_In_ PVOID ImageBaseAddress,
_In_opt_ SIZE_T HeapReserveSize,
+1 -1
View File
@@ -497,4 +497,4 @@ PPH_STRING PhGetTokenUserString(
}
return tokenUserString;
}
}
+30 -16
View File
@@ -247,21 +247,37 @@ VOID PhpSymbolProviderCompleteInitialization(
{
static struct
{
ULONG Folder;
PWSTR AppendPath;
PH_STRINGREF AppendPath;
} locations[] =
{
#ifdef _WIN64
{ CSIDL_PROGRAM_FILESX86, L"\\Windows Kits\\10\\Debuggers\\x64\\dbghelp.dll" },
{ CSIDL_PROGRAM_FILES, L"\\Windows Kits\\10\\Debuggers\\x64\\dbghelp.dll" },
{ CSIDL_PROGRAM_FILESX86, L"\\Windows Kits\\8.1\\Debuggers\\x64\\dbghelp.dll" },
{ CSIDL_PROGRAM_FILESX86, L"\\Windows Kits\\8.0\\Debuggers\\x64\\dbghelp.dll" },
{ CSIDL_PROGRAM_FILES, L"\\Debugging Tools for Windows (x64)\\dbghelp.dll" }
PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\10\\Debuggers\\x64\\dbghelp.dll"),
PH_STRINGREF_INIT(L"%ProgramFiles%\\Windows Kits\\10\\Debuggers\\x64\\dbghelp.dll"),
PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\8.1\\Debuggers\\x64\\dbghelp.dll"),
PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\8.0\\Debuggers\\x64\\dbghelp.dll"),
PH_STRINGREF_INIT(L"%ProgramFiles%\\Debugging Tools for Windows (x64)\\dbghelp.dll")
#else
{ CSIDL_PROGRAM_FILES, L"\\Windows Kits\\10\\Debuggers\\x86\\dbghelp.dll" },
{ CSIDL_PROGRAM_FILES, L"\\Windows Kits\\8.1\\Debuggers\\x86\\dbghelp.dll" },
{ CSIDL_PROGRAM_FILES, L"\\Windows Kits\\8.0\\Debuggers\\x86\\dbghelp.dll" },
{ CSIDL_PROGRAM_FILES, L"\\Debugging Tools for Windows (x86)\\dbghelp.dll" }
PH_STRINGREF_INIT(L"%ProgramFiles%\\Windows Kits\\10\\Debuggers\\x86\\dbghelp.dll"),
PH_STRINGREF_INIT(L"%ProgramFiles%\\Windows Kits\\8.1\\Debuggers\\x86\\dbghelp.dll"),
PH_STRINGREF_INIT(L"%ProgramFiles%\\Windows Kits\\8.0\\Debuggers\\x86\\dbghelp.dll"),
PH_STRINGREF_INIT(L"%ProgramFiles%\\Debugging Tools for Windows (x86)\\dbghelp.dll")
#endif
};
static struct
{
PH_STRINGREF AppendPath;
} symsrvlocation[] =
{
#ifdef _WIN64
{ PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\10\\Debuggers\\x64\\symsrv.dll") },
{ PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\8.1\\Debuggers\\x64\\symsrv.dll") },
{ PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\8.0\\Debuggers\\x64\\symsrv.dll") },
{ PH_STRINGREF_INIT(L"%ProgramFiles%\\Debugging Tools for Windows (x64)\\symsrv.dll") }
#else
{ CSIDL_PROGRAM_FILES, L"%ProgramFiles%\\Windows Kits\\10\\Debuggers\\x86\\symsrv.dll" },
{ CSIDL_PROGRAM_FILES, L"%ProgramFiles%\\Windows Kits\\8.1\\Debuggers\\x86\\symsrv.dll" },
{ CSIDL_PROGRAM_FILES, L"%ProgramFiles%\\Windows Kits\\8.0\\Debuggers\\x86\\symsrv.dll" },
{ CSIDL_PROGRAM_FILES, L"%ProgramFiles%\\Debugging Tools for Windows (x86)\\symsrv.dll" }
#endif
};
@@ -275,9 +291,9 @@ VOID PhpSymbolProviderCompleteInitialization(
if (dbghelpHandle && symsrvHandle)
return;
for (ULONG i = 0; i < ARRAYSIZE(locations); i++)
for (ULONG i = 0; i < RTL_NUMBER_OF(locations); i++)
{
if (dbghelpPath = PhGetKnownLocation(locations[i].Folder, locations[i].AppendPath))
if (dbghelpPath = PhExpandEnvironmentStrings(&locations[i].AppendPath))
{
if (RtlDoesFileExists_U(dbghelpPath->Buffer))
break;
@@ -299,12 +315,10 @@ VOID PhpSymbolProviderCompleteInitialization(
{
if (indexOfFileName != 0)
{
static PH_STRINGREF symsrvString = PH_STRINGREF_INIT(L"\\symsrv.dll");
dbghelpFolder.Buffer = fullDbghelpPath->Buffer;
dbghelpFolder.Length = indexOfFileName * sizeof(WCHAR);
symsrvPath = PhConcatStringRef2(&dbghelpFolder, &symsrvString);
symsrvPath = PhConcatStringRefZ(&dbghelpFolder, L"\\symsrv.dll");
symsrvHandle = LoadLibrary(symsrvPath->Buffer);
PhDereferenceObject(symsrvPath);
}
+4 -1
View File
@@ -38,7 +38,10 @@ VOID LoadGeoLiteDb(
dbpath = PhGetExpandStringSetting(SETTING_NAME_DB_LOCATION);
if (PhIsNullOrEmptyString(dbpath))
PhMoveReference(&dbpath, PhGetKnownLocation(CSIDL_APPDATA, L"\\Process Hacker\\GeoLite2-Country.mmdb"));
{
PH_STRINGREF defaultDbPathSr = PH_STRINGREF_INIT(L"%APPDATA%\\Process Hacker\\GeoLite2-Country.mmdb");
PhMoveReference(&dbpath, PhExpandEnvironmentStrings(&defaultDbPathSr));
}
if (MMDB_open(PhGetString(dbpath), MMDB_MODE_MMAP, &GeoDb) == MMDB_SUCCESS)
{
+5 -1
View File
@@ -375,7 +375,11 @@ NTSTATUS GeoIPUpdateThread(
dbpath = PhGetExpandStringSetting(SETTING_NAME_DB_LOCATION);
if (PhIsNullOrEmptyString(dbpath))
PhMoveReference(&dbpath, PhGetKnownLocation(CSIDL_APPDATA, L"\\Process Hacker\\GeoLite2-Country.mmdb"));
{
PH_STRINGREF defaultDbPathSr = PH_STRINGREF_INIT(L"%APPDATA%\\Process Hacker\\GeoLite2-Country.mmdb");
PhMoveReference(&dbpath, PhExpandEnvironmentStrings(&defaultDbPathSr));
}
if (RtlDoesFileExists_U(PhGetString(dbpath)))
{
+1 -3
View File
@@ -52,7 +52,7 @@ INT WINAPI wWinMain(
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (!NT_SUCCESS(PhInitializePhLib()))
if (!NT_SUCCESS(PhInitializePhLibEx(L"PE Viewer", ULONG_MAX, hInstance, 0, 0)))
return 1;
// Create a mutant for the installer.
@@ -93,8 +93,6 @@ INT WINAPI wWinMain(
PvPropInitialization();
PhTreeNewInitialization();
PhApplicationName = L"PE Viewer";
if (!NT_SUCCESS(PhGetProcessCommandLine(NtCurrentProcess(), &commandLine)))
return 1;
+18 -21
View File
@@ -2274,28 +2274,27 @@ PPH_STRING PvFindDbghelpPath(
static struct
{
BOOLEAN Type;
ULONG Folder;
PWSTR AppendPath;
PH_STRINGREF AppendPath;
} locations[] =
{
#ifdef _WIN64
{ FALSE, CSIDL_PROGRAM_FILESX86, L"\\Windows Kits\\10\\Debuggers\\x64\\dbghelp.dll" },
{ FALSE, CSIDL_PROGRAM_FILESX86, L"\\Windows Kits\\8.1\\Debuggers\\x64\\dbghelp.dll" },
{ FALSE, CSIDL_PROGRAM_FILESX86, L"\\Windows Kits\\8.0\\Debuggers\\x64\\dbghelp.dll" },
{ FALSE, CSIDL_PROGRAM_FILES, L"\\Debugging Tools for Windows (x64)\\dbghelp.dll" },
{ TRUE, CSIDL_PROGRAM_FILESX86, L"\\Windows Kits\\10\\Debuggers\\x64\\symsrv.dll" },
{ TRUE, CSIDL_PROGRAM_FILESX86, L"\\Windows Kits\\8.1\\Debuggers\\x64\\symsrv.dll" },
{ TRUE, CSIDL_PROGRAM_FILESX86, L"\\Windows Kits\\8.0\\Debuggers\\x64\\symsrv.dll" },
{ TRUE, CSIDL_PROGRAM_FILES, L"\\Debugging Tools for Windows (x64)\\symsrv.dll" }
{ FALSE, PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\10\\Debuggers\\x64\\dbghelp.dll") },
{ FALSE, PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\8.1\\Debuggers\\x64\\dbghelp.dll") },
{ FALSE, PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\8.0\\Debuggers\\x64\\dbghelp.dll") },
{ FALSE, PH_STRINGREF_INIT(L"%ProgramFiles%\\Debugging Tools for Windows (x64)\\dbghelp.dll") },
{ TRUE, PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\10\\Debuggers\\x64\\symsrv.dll") },
{ TRUE, PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\8.1\\Debuggers\\x64\\symsrv.dll") },
{ TRUE, PH_STRINGREF_INIT(L"%ProgramFiles(x86)%\\Windows Kits\\8.0\\Debuggers\\x64\\symsrv.dll") },
{ TRUE, PH_STRINGREF_INIT(L"%ProgramFiles%\\Debugging Tools for Windows (x64)\\symsrv.dll") }
#else
{ FALSE, CSIDL_PROGRAM_FILES, L"\\Windows Kits\\10\\Debuggers\\x86\\dbghelp.dll" },
{ FALSE, CSIDL_PROGRAM_FILES, L"\\Windows Kits\\8.1\\Debuggers\\x86\\dbghelp.dll" },
{ FALSE, CSIDL_PROGRAM_FILES, L"\\Windows Kits\\8.0\\Debuggers\\x86\\dbghelp.dll" },
{ FALSE, CSIDL_PROGRAM_FILES, L"\\Debugging Tools for Windows (x86)\\dbghelp.dll" },
{ TRUE, CSIDL_PROGRAM_FILES, L"\\Windows Kits\\10\\Debuggers\\x86\\symsrv.dll" },
{ TRUE, CSIDL_PROGRAM_FILES, L"\\Windows Kits\\8.1\\Debuggers\\x86\\symsrv.dll" },
{ TRUE, CSIDL_PROGRAM_FILES, L"\\Windows Kits\\8.0\\Debuggers\\x86\\symsrv.dll" },
{ TRUE, CSIDL_PROGRAM_FILES, L"\\Debugging Tools for Windows (x86)\\symsrv.dll" }
{ FALSE, PH_STRINGREF_INIT(L"%ProgramFiles%\\Windows Kits\\10\\Debuggers\\x86\\dbghelp.dll") },
{ FALSE, PH_STRINGREF_INIT(L"%ProgramFiles%\\Windows Kits\\8.1\\Debuggers\\x86\\dbghelp.dll") },
{ FALSE, PH_STRINGREF_INIT(L"%ProgramFiles%\\Windows Kits\\8.0\\Debuggers\\x86\\dbghelp.dll") },
{ FALSE, PH_STRINGREF_INIT(L"%ProgramFiles%\\Debugging Tools for Windows (x86)\\dbghelp.dll") },
{ TRUE, PH_STRINGREF_INIT(L"%ProgramFiles%\\Windows Kits\\10\\Debuggers\\x86\\symsrv.dll") },
{ TRUE, PH_STRINGREF_INIT(L"%ProgramFiles%\\Windows Kits\\8.1\\Debuggers\\x86\\symsrv.dll") },
{ TRUE, PH_STRINGREF_INIT(L"%ProgramFiles%\\Windows Kits\\8.0\\Debuggers\\x86\\symsrv.dll") },
{ TRUE, PH_STRINGREF_INIT(L"%ProgramFiles%\\Debugging Tools for Windows (x86)\\symsrv.dll") }
#endif
};
@@ -2307,9 +2306,7 @@ PPH_STRING PvFindDbghelpPath(
if (locations[i].Type != Type)
continue;
path = PhGetKnownLocation(locations[i].Folder, locations[i].AppendPath);
if (path)
if (path = PhExpandEnvironmentStrings(&locations[i].AppendPath))
{
if (RtlDoesFileExists_U(path->Buffer))
return path;
+2 -4
View File
@@ -218,7 +218,7 @@ VERIFY_RESULT PvpVerifyFileWithAdditionalCatalog(
)
{
static PH_STRINGREF codeIntegrityFileName = PH_STRINGREF_INIT(L"\\AppxMetadata\\CodeIntegrity.cat");
static PH_STRINGREF windowsAppsPathSr = PH_STRINGREF_INIT(L"%ProgramFiles%\\WindowsApps\\");
VERIFY_RESULT result;
PH_VERIFY_FILE_INFO info;
PPH_STRING windowsAppsPath;
@@ -231,9 +231,7 @@ VERIFY_RESULT PvpVerifyFileWithAdditionalCatalog(
info.Flags = Flags;
info.hWnd = hWnd;
windowsAppsPath = PhGetKnownLocation(CSIDL_PROGRAM_FILES, L"\\WindowsApps\\");
if (windowsAppsPath)
if (windowsAppsPath = PhExpandEnvironmentStrings(&windowsAppsPathSr))
{
if (PhStartsWithStringRef(&FileName->sr, &windowsAppsPath->sr, TRUE))
{
+2 -1
View File
@@ -60,6 +60,7 @@ VOID PeInitializeSettings(
VOID
)
{
static PH_STRINGREF settingsPath = PH_STRINGREF_INIT(L"%APPDATA%\\Process Hacker\\peview.xml");
static PH_STRINGREF settingsSuffix = PH_STRINGREF_INIT(L".peview.xml");
NTSTATUS status;
PPH_STRING appFileName;
@@ -88,7 +89,7 @@ VOID PeInitializeSettings(
// 2. Default location
if (!PeSettingsFileName)
{
PeSettingsFileName = PhGetKnownLocation(CSIDL_APPDATA, L"\\Process Hacker\\peview.xml");
PeSettingsFileName = PhExpandEnvironmentStrings(&settingsPath);
}
if (PeSettingsFileName)