re-organized phlib
This commit is contained in:
@@ -6138,7 +6138,7 @@ BOOLEAN PhUiUnloadModule(
|
||||
ProcessId
|
||||
)))
|
||||
{
|
||||
status = NtUnmapViewOfSection(processHandle, Module->BaseAddress);
|
||||
status = PhUnmapViewOfSection(processHandle, Module->BaseAddress);
|
||||
NtClose(processHandle);
|
||||
}
|
||||
|
||||
@@ -6241,7 +6241,7 @@ BOOLEAN PhUiFreeMemory(
|
||||
}
|
||||
else
|
||||
{
|
||||
status = NtUnmapViewOfSection(processHandle, baseAddress);
|
||||
status = PhUnmapViewOfSection(processHandle, baseAddress);
|
||||
}
|
||||
|
||||
NtClose(processHandle);
|
||||
@@ -6411,7 +6411,7 @@ BOOLEAN PhUiCloseHandles(
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(PhGetProcessMitigationPolicyInformation(
|
||||
if (NT_SUCCESS(PhGetProcessMitigationPolicy(
|
||||
processHandle,
|
||||
ProcessStrictHandleCheckPolicy,
|
||||
&policyInfo
|
||||
|
||||
@@ -816,7 +816,7 @@ VOID PhShellExecuteUserString(
|
||||
// here because the string may be a URL. (dmex)
|
||||
if (PhFindCharInString(executeString, 0, L':') == SIZE_MAX)
|
||||
{
|
||||
static CONST PH_STRINGREF seperator = PH_STRINGREF_INIT(L"\"");
|
||||
static CONST PH_STRINGREF separator = PH_STRINGREF_INIT(L"\"");
|
||||
static CONST PH_STRINGREF space = PH_STRINGREF_INIT(L" ");
|
||||
PPH_LIST stringArgList;
|
||||
PPH_STRING fileName = NULL;
|
||||
@@ -842,16 +842,16 @@ VOID PhShellExecuteUserString(
|
||||
// Make sure the string is absolute and escape the filename.
|
||||
if (PhDetermineDosPathNameType(&fileName->sr) == RtlPathTypeRelative)
|
||||
{
|
||||
PhMoveReference(&fileName, PhConcatStringRef3(&seperator, &applicationDirectory->sr, &fileName->sr));
|
||||
PhMoveReference(&fileName, PhConcatStringRef2(&fileName->sr, &seperator));
|
||||
PhMoveReference(&fileName, PhConcatStringRef3(&separator, &applicationDirectory->sr, &fileName->sr));
|
||||
PhMoveReference(&fileName, PhConcatStringRef2(&fileName->sr, &separator));
|
||||
}
|
||||
else
|
||||
{
|
||||
PhMoveReference(&fileName, PhConcatStringRef3(&seperator, &fileName->sr, &seperator));
|
||||
PhMoveReference(&fileName, PhConcatStringRef3(&separator, &fileName->sr, &separator));
|
||||
}
|
||||
|
||||
// Escape the parameters.
|
||||
PhMoveReference(&fileArgs, PhConcatStringRef3(&seperator, &fileArgs->sr, &seperator));
|
||||
PhMoveReference(&fileArgs, PhConcatStringRef3(&separator, &fileArgs->sr, &separator));
|
||||
|
||||
// Create the escaped execute string.
|
||||
PhMoveReference(&executeString, PhConcatStringRef3(&fileName->sr, &space, &fileArgs->sr));
|
||||
@@ -860,12 +860,12 @@ VOID PhShellExecuteUserString(
|
||||
{
|
||||
if (PhDetermineDosPathNameType(&executeString->sr) == RtlPathTypeRelative)
|
||||
{
|
||||
PhMoveReference(&executeString, PhConcatStringRef3(&seperator, &applicationDirectory->sr, &executeString->sr));
|
||||
PhMoveReference(&executeString, PhConcatStringRef2(&executeString->sr, &seperator));
|
||||
PhMoveReference(&executeString, PhConcatStringRef3(&separator, &applicationDirectory->sr, &executeString->sr));
|
||||
PhMoveReference(&executeString, PhConcatStringRef2(&executeString->sr, &separator));
|
||||
}
|
||||
else
|
||||
{
|
||||
PhMoveReference(&executeString, PhConcatStringRef3(&seperator, &executeString->sr, &seperator));
|
||||
PhMoveReference(&executeString, PhConcatStringRef3(&separator, &executeString->sr, &separator));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -269,14 +269,13 @@ VOID PhShowHandleObjectProperties1(
|
||||
else
|
||||
tooBig = TRUE;
|
||||
|
||||
status = NtMapViewOfSection(
|
||||
status = PhMapViewOfSection(
|
||||
handle,
|
||||
NtCurrentProcess(),
|
||||
&viewBase,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&viewSize,
|
||||
viewSize,
|
||||
ViewUnmap,
|
||||
0,
|
||||
readOnly ? PAGE_READONLY : PAGE_READWRITE
|
||||
@@ -284,14 +283,13 @@ VOID PhShowHandleObjectProperties1(
|
||||
|
||||
if (status == STATUS_SECTION_PROTECTION && !readOnly)
|
||||
{
|
||||
status = NtMapViewOfSection(
|
||||
status = PhMapViewOfSection(
|
||||
handle,
|
||||
NtCurrentProcess(),
|
||||
&viewBase,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&viewSize,
|
||||
viewSize,
|
||||
ViewUnmap,
|
||||
0,
|
||||
PAGE_READONLY
|
||||
|
||||
@@ -108,6 +108,64 @@ VOID PhMwpInvokeUpdateWindowFontMonospace(
|
||||
_In_opt_ PVOID Parameter
|
||||
);
|
||||
|
||||
// main
|
||||
|
||||
LONG PhMainMessageLoop(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhActivatePreviousInstance(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhInitializeCommonControls(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhInitializeSuperclassControls( // delayhook.c
|
||||
VOID
|
||||
);
|
||||
|
||||
BOOLEAN PhInitializeAppSystem(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhpInitializeSettings(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhpProcessStartupParameters(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhpEnablePrivileges(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhEnableTerminationPolicy(
|
||||
_In_ BOOLEAN Enabled
|
||||
);
|
||||
|
||||
NTSTATUS PhInitializeDirectoryPolicy(
|
||||
VOID
|
||||
);
|
||||
|
||||
NTSTATUS PhInitializeExceptionPolicy(
|
||||
VOID
|
||||
);
|
||||
|
||||
NTSTATUS PhInitializeMitigationPolicy(
|
||||
VOID
|
||||
);
|
||||
|
||||
NTSTATUS PhInitializeComPolicy(
|
||||
VOID
|
||||
);
|
||||
|
||||
NTSTATUS PhInitializeTimerPolicy(
|
||||
VOID
|
||||
);
|
||||
|
||||
// Event handlers
|
||||
|
||||
VOID PhMwpOnDestroy(
|
||||
|
||||
@@ -116,9 +116,11 @@ VOID PhGetSelectedNetworkItems(
|
||||
_Out_ PULONG NumberOfNetworkItems
|
||||
);
|
||||
|
||||
// begin_phapppub
|
||||
VOID PhDeselectAllNetworkNodes(
|
||||
VOID
|
||||
);
|
||||
// end_phapppub
|
||||
|
||||
VOID PhSelectAndEnsureVisibleNetworkNode(
|
||||
_In_ PPH_NETWORK_NODE NetworkNode
|
||||
|
||||
@@ -37,7 +37,7 @@ typedef struct _PH_PROCESS_MITIGATION_POLICY_ALL_INFORMATION
|
||||
PROCESS_MITIGATION_SEHOP_POLICY SEHOPPolicy; // ProcessSEHOPPolicy
|
||||
} PH_PROCESS_MITIGATION_POLICY_ALL_INFORMATION, *PPH_PROCESS_MITIGATION_POLICY_ALL_INFORMATION;
|
||||
|
||||
NTSTATUS PhGetProcessMitigationPolicy(
|
||||
NTSTATUS PhGetProcessMitigationPolicyAllInformation(
|
||||
_In_ HANDLE ProcessHandle,
|
||||
_Out_ PPH_PROCESS_MITIGATION_POLICY_ALL_INFORMATION Information
|
||||
);
|
||||
|
||||
+13
-12
@@ -171,10 +171,10 @@ PPH_STRING PhGetProcessTooltipText(
|
||||
{
|
||||
PH_IMAGE_VERSION_INFO versionInfo;
|
||||
|
||||
if (PhInitializeImageVersionInfo(
|
||||
if (NT_SUCCESS(PhInitializeImageVersionInfo(
|
||||
&versionInfo,
|
||||
knownCommandLine.RunDllAsApp.FileName->Buffer
|
||||
))
|
||||
)))
|
||||
{
|
||||
tempString = PhFormatImageVersionInfo(
|
||||
knownCommandLine.RunDllAsApp.FileName,
|
||||
@@ -219,10 +219,10 @@ PPH_STRING PhGetProcessTooltipText(
|
||||
PhAppendCharStringBuilder(&stringBuilder, L'\n');
|
||||
}
|
||||
|
||||
if (knownCommandLine.ComSurrogate.FileName && PhInitializeImageVersionInfo(
|
||||
if (knownCommandLine.ComSurrogate.FileName && NT_SUCCESS(PhInitializeImageVersionInfo(
|
||||
&versionInfo,
|
||||
knownCommandLine.ComSurrogate.FileName->Buffer
|
||||
))
|
||||
)))
|
||||
{
|
||||
tempString = PhFormatImageVersionInfo(
|
||||
knownCommandLine.ComSurrogate.FileName,
|
||||
@@ -505,9 +505,7 @@ VOID PhpFillUmdfDrivers(
|
||||
{
|
||||
static CONST PH_STRINGREF activeDevices = PH_STRINGREF_INIT(L"ACTIVE_DEVICES");
|
||||
static CONST PH_STRINGREF currentControlSetEnum = PH_STRINGREF_INIT(L"System\\CurrentControlSet\\Enum\\");
|
||||
|
||||
HANDLE processHandle;
|
||||
ULONG flags = 0;
|
||||
PVOID environment;
|
||||
ULONG environmentLength;
|
||||
ULONG enumerationKey;
|
||||
@@ -529,7 +527,12 @@ VOID PhpFillUmdfDrivers(
|
||||
{
|
||||
enumerationKey = 0;
|
||||
|
||||
while (PhEnumProcessEnvironmentVariables(environment, environmentLength, &enumerationKey, &variable))
|
||||
while (NT_SUCCESS(PhEnumProcessEnvironmentVariables(
|
||||
environment,
|
||||
environmentLength,
|
||||
&enumerationKey,
|
||||
&variable
|
||||
)))
|
||||
{
|
||||
PH_STRINGREF part;
|
||||
PH_STRINGREF remainingPart;
|
||||
@@ -577,12 +580,10 @@ VOID PhpFillUmdfDrivers(
|
||||
PhInitializeStringRef(&deviceName, L"Unknown Device");
|
||||
}
|
||||
|
||||
hardwareId = PhQueryRegistryStringZ(driverKeyHandle, L"HardwareID");
|
||||
|
||||
PhAppendStringBuilder(Drivers, &StandardIndent);
|
||||
PhAppendStringBuilder(Drivers, &deviceName);
|
||||
|
||||
if (hardwareId)
|
||||
if (hardwareId = PhQueryRegistryStringZ(driverKeyHandle, L"HardwareID"))
|
||||
{
|
||||
PhTrimToNullTerminatorString(hardwareId);
|
||||
|
||||
@@ -790,10 +791,10 @@ PPH_STRING PhGetServiceTooltipText(
|
||||
PH_IMAGE_VERSION_INFO versionInfo;
|
||||
PPH_STRING versionInfoText;
|
||||
|
||||
if (PhInitializeImageVersionInfo(
|
||||
if (NT_SUCCESS(PhInitializeImageVersionInfo(
|
||||
&versionInfo,
|
||||
fileName->Buffer
|
||||
))
|
||||
)))
|
||||
{
|
||||
versionInfoText = PhFormatImageVersionInfo(
|
||||
fileName,
|
||||
|
||||
+18
-13
@@ -159,7 +159,7 @@ PPH_STRING KsiGetKernelVersionString(
|
||||
|
||||
if (fileName = KsiGetKernelFileName())
|
||||
{
|
||||
if (PhInitializeImageVersionInfoEx(&versionInfo, &fileName->sr, FALSE))
|
||||
if (NT_SUCCESS(PhInitializeImageVersionInfoEx(&versionInfo, &fileName->sr, FALSE)))
|
||||
{
|
||||
KsiKernelVersion = versionInfo.FileVersion;
|
||||
|
||||
@@ -698,7 +698,7 @@ BOOLEAN KsiCommsCallback(
|
||||
}
|
||||
|
||||
NTSTATUS KsiReadConfiguration(
|
||||
_In_ PCWSTR FileName,
|
||||
_In_ PCPH_STRINGREF FileName,
|
||||
_Out_ PBYTE* Data,
|
||||
_Out_ PULONG Length
|
||||
)
|
||||
@@ -710,12 +710,9 @@ NTSTATUS KsiReadConfiguration(
|
||||
*Data = NULL;
|
||||
*Length = 0;
|
||||
|
||||
status = STATUS_NO_SUCH_FILE;
|
||||
|
||||
fileName = PhGetApplicationDirectoryFileNameZ(FileName, TRUE);
|
||||
if (fileName)
|
||||
if (fileName = PhGetApplicationDirectoryFileName(FileName, TRUE))
|
||||
{
|
||||
if (NT_SUCCESS(status = PhCreateFile(
|
||||
status = PhCreateFile(
|
||||
&fileHandle,
|
||||
&fileName->sr,
|
||||
FILE_GENERIC_READ,
|
||||
@@ -723,15 +720,20 @@ NTSTATUS KsiReadConfiguration(
|
||||
FILE_SHARE_READ,
|
||||
FILE_OPEN,
|
||||
FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT
|
||||
)))
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
status = PhGetFileData(fileHandle, Data, Length);
|
||||
|
||||
NtClose(fileHandle);
|
||||
}
|
||||
|
||||
PhDereferenceObject(fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = STATUS_NO_SUCH_FILE;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -745,8 +747,6 @@ NTSTATUS KsiValidateDynamicConfiguration(
|
||||
PPH_STRING fileName;
|
||||
KSI_SUPPORT_DATA supportData;
|
||||
|
||||
status = STATUS_NO_SUCH_FILE;
|
||||
|
||||
if (fileName = KsiGetKernelFileName())
|
||||
{
|
||||
KsiGetKernelSupportData(&supportData);
|
||||
@@ -764,6 +764,10 @@ NTSTATUS KsiValidateDynamicConfiguration(
|
||||
|
||||
PhDereferenceObject(fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = STATUS_NO_SUCH_FILE;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -775,6 +779,7 @@ NTSTATUS KsiGetDynData(
|
||||
_Out_ PULONG SignatureLength
|
||||
)
|
||||
{
|
||||
static CONST PH_STRINGREF fileName = PH_STRINGREF_INIT(L"ksidyn.bin");
|
||||
NTSTATUS status;
|
||||
PBYTE data = NULL;
|
||||
ULONG dataLength;
|
||||
@@ -788,7 +793,7 @@ NTSTATUS KsiGetDynData(
|
||||
*Signature = NULL;
|
||||
*SignatureLength = 0;
|
||||
|
||||
status = KsiReadConfiguration(L"ksidyn.bin", &data, &dataLength);
|
||||
status = KsiReadConfiguration(&fileName, &data, &dataLength);
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
@@ -796,7 +801,7 @@ NTSTATUS KsiGetDynData(
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
status = KsiReadConfiguration(L"ksidyn.sig", &sig, &sigLength);
|
||||
status = KsiReadConfiguration(&fileName, &sig, &sigLength);
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
|
||||
+23
-79
@@ -18,8 +18,8 @@
|
||||
|
||||
#include <extmgri.h>
|
||||
#include <mainwnd.h>
|
||||
#include <mainwndp.h>
|
||||
#include <netprv.h>
|
||||
#include <phconsole.h>
|
||||
#include <phsettings.h>
|
||||
#include <phsvc.h>
|
||||
#include <procprv.h>
|
||||
@@ -30,71 +30,13 @@
|
||||
#include <settings.h>
|
||||
#include <srvprv.h>
|
||||
|
||||
LONG PhMainMessageLoop(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhActivatePreviousInstance(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhInitializeCommonControls(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhInitializeSuperclassControls( // delayhook.c
|
||||
VOID
|
||||
);
|
||||
|
||||
BOOLEAN PhInitializeAppSystem(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhpInitializeSettings(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhpProcessStartupParameters(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhpEnablePrivileges(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhEnableTerminationPolicy(
|
||||
_In_ BOOLEAN Enabled
|
||||
);
|
||||
|
||||
BOOLEAN PhInitializeDirectoryPolicy(
|
||||
VOID
|
||||
);
|
||||
|
||||
BOOLEAN PhInitializeExceptionPolicy(
|
||||
VOID
|
||||
);
|
||||
|
||||
BOOLEAN PhInitializeMitigationPolicy(
|
||||
VOID
|
||||
);
|
||||
|
||||
BOOLEAN PhInitializeComPolicy(
|
||||
VOID
|
||||
);
|
||||
|
||||
BOOLEAN PhInitializeTimerPolicy(
|
||||
VOID
|
||||
);
|
||||
|
||||
BOOLEAN PhPluginsEnabled = FALSE;
|
||||
BOOLEAN PhPortableEnabled = FALSE;
|
||||
PPH_STRING PhSettingsFileName = NULL;
|
||||
PH_STARTUP_PARAMETERS PhStartupParameters = { .UpdateChannel = PhInvalidChannel };
|
||||
|
||||
PH_PROVIDER_THREAD PhPrimaryProviderThread;
|
||||
PH_PROVIDER_THREAD PhSecondaryProviderThread;
|
||||
PH_PROVIDER_THREAD PhTertiaryProviderThread;
|
||||
|
||||
static PPH_LIST DialogList = NULL;
|
||||
static PPH_LIST FilterList = NULL;
|
||||
static PH_AUTO_POOL BaseAutoPool;
|
||||
@@ -111,13 +53,13 @@ INT WINAPI wWinMain(
|
||||
PHP_BASE_THREAD_DBG dbg;
|
||||
#endif
|
||||
|
||||
if (!NT_SUCCESS(PhInitializePhLib(L"System Informer", Instance)))
|
||||
if (!NT_SUCCESS(PhInitializePhLib(L"System Informer")))
|
||||
return 1;
|
||||
if (!PhInitializeDirectoryPolicy())
|
||||
if (!NT_SUCCESS(PhInitializeDirectoryPolicy()))
|
||||
return 1;
|
||||
if (!PhInitializeExceptionPolicy())
|
||||
if (!NT_SUCCESS(PhInitializeExceptionPolicy()))
|
||||
return 1;
|
||||
if (!PhInitializeComPolicy())
|
||||
if (!NT_SUCCESS(PhInitializeComPolicy()))
|
||||
return 1;
|
||||
|
||||
PhpProcessStartupParameters();
|
||||
@@ -207,7 +149,7 @@ INT WINAPI wWinMain(
|
||||
}
|
||||
|
||||
// N.B. Must be called after loading plugins since we set Microsoft signed only.
|
||||
if (!PhInitializeMitigationPolicy())
|
||||
if (!NT_SUCCESS(PhInitializeMitigationPolicy()))
|
||||
return 1;
|
||||
|
||||
if (PhStartupParameters.PhSvc)
|
||||
@@ -283,6 +225,7 @@ INT WINAPI wWinMain(
|
||||
}
|
||||
|
||||
PhExitApplication(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
LONG PhMainMessageLoop(
|
||||
@@ -374,7 +317,7 @@ VOID PhUnregisterDialog(
|
||||
|
||||
indexOfDialog = PhFindItemList(DialogList, (PVOID)DialogWindowHandle);
|
||||
|
||||
if (indexOfDialog != -1)
|
||||
if (indexOfDialog != ULONG_MAX)
|
||||
PhRemoveItemList(DialogList, indexOfDialog);
|
||||
}
|
||||
|
||||
@@ -419,7 +362,7 @@ typedef struct _PHP_PREVIOUS_MAIN_WINDOW_CONTEXT
|
||||
PPH_STRING WindowName;
|
||||
} PHP_PREVIOUS_MAIN_WINDOW_CONTEXT, *PPHP_PREVIOUS_MAIN_WINDOW_CONTEXT;
|
||||
|
||||
static BOOL CALLBACK PhPreviousInstanceWindowEnumProc(
|
||||
static BOOLEAN CALLBACK PhPreviousInstanceWindowEnumProc(
|
||||
_In_ HWND WindowHandle,
|
||||
_In_ PVOID Context
|
||||
)
|
||||
@@ -588,7 +531,7 @@ VOID PhInitializeCommonControls(
|
||||
InitCommonControlsEx(&icex);
|
||||
}
|
||||
|
||||
BOOLEAN PhInitializeDirectoryPolicy(
|
||||
NTSTATUS PhInitializeDirectoryPolicy(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
@@ -597,26 +540,26 @@ BOOLEAN PhInitializeDirectoryPolicy(
|
||||
PH_STRINGREF currentDirectory;
|
||||
|
||||
if (!(applicationDirectory = PhGetApplicationDirectoryWin32()))
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
|
||||
PhUnicodeStringToStringRef(&NtCurrentPeb()->ProcessParameters->CurrentDirectory.DosPath, ¤tDirectory);
|
||||
|
||||
if (PhEqualStringRef(&applicationDirectory->sr, ¤tDirectory, TRUE))
|
||||
{
|
||||
PhDereferenceObject(applicationDirectory);
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (!PhStringRefToUnicodeString(&applicationDirectory->sr, &applicationDirectoryUs))
|
||||
{
|
||||
PhDereferenceObject(applicationDirectory);
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(RtlSetCurrentDirectory_U(&applicationDirectoryUs)))
|
||||
{
|
||||
PhDereferenceObject(applicationDirectory);
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
PhDereferenceObject(applicationDirectory);
|
||||
@@ -874,7 +817,7 @@ ULONG CALLBACK PhpUnhandledExceptionCallback(
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
BOOLEAN PhInitializeExceptionPolicy(
|
||||
NTSTATUS PhInitializeExceptionPolicy(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
@@ -891,10 +834,10 @@ BOOLEAN PhInitializeExceptionPolicy(
|
||||
#endif
|
||||
SetUnhandledExceptionFilter(PhpUnhandledExceptionCallback);
|
||||
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
BOOLEAN PhInitializeMitigationPolicy(
|
||||
NTSTATUS PhInitializeMitigationPolicy(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
@@ -924,10 +867,10 @@ BOOLEAN PhInitializeMitigationPolicy(
|
||||
//NtSetInformationProcess(NtCurrentProcess(), ProcessMitigationPolicy, &policyInfo, sizeof(PROCESS_MITIGATION_POLICY_INFORMATION));
|
||||
}
|
||||
#endif
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
BOOLEAN PhInitializeComPolicy(
|
||||
NTSTATUS PhInitializeComPolicy(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
@@ -992,6 +935,7 @@ BOOLEAN PhInitializeComPolicy(
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
assert(RtlValidSecurityDescriptor(securityDescriptor));
|
||||
assert(securityDescriptorAllocationLength < sizeof(securityDescriptorBuffer));
|
||||
assert(RtlLengthSecurityDescriptor(securityDescriptor) < sizeof(securityDescriptorBuffer));
|
||||
#endif
|
||||
@@ -1001,7 +945,7 @@ BOOLEAN PhInitializeComPolicy(
|
||||
if (!SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)))
|
||||
NOTHING;
|
||||
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1030,7 +974,7 @@ VOID PhEnableTerminationPolicy(
|
||||
}
|
||||
}
|
||||
|
||||
BOOLEAN PhInitializeTimerPolicy(
|
||||
NTSTATUS PhInitializeTimerPolicy(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
@@ -1038,7 +982,7 @@ BOOLEAN PhInitializeTimerPolicy(
|
||||
|
||||
SetUserObjectInformation(NtCurrentProcess(), UOI_TIMERPROC_EXCEPTION_SUPPRESSION, &timerSuppression, sizeof(BOOL));
|
||||
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
BOOLEAN PhInitializeAppSystem(
|
||||
|
||||
@@ -266,7 +266,7 @@ RTL_ATOM PhMwpInitializeWindowClass(
|
||||
memset(&wcex, 0, sizeof(WNDCLASSEX));
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.lpfnWndProc = PhMainWndProc;
|
||||
wcex.hInstance = PhInstanceHandle;
|
||||
wcex.hInstance = NtCurrentImageBase();
|
||||
className = PhaGetStringSetting(L"MainWindowClassName");
|
||||
wcex.lpszClassName = PhGetStringOrDefault(className, L"MainWindowClassName");
|
||||
wcex.hCursor = PhLoadCursor(NULL, IDC_ARROW);
|
||||
@@ -475,7 +475,7 @@ VOID PhMwpInitializeControls(
|
||||
0,
|
||||
WindowHandle,
|
||||
NULL,
|
||||
PhInstanceHandle,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
@@ -489,7 +489,7 @@ VOID PhMwpInitializeControls(
|
||||
0,
|
||||
WindowHandle,
|
||||
NULL,
|
||||
PhInstanceHandle,
|
||||
NULL,
|
||||
&treelistCreateParams
|
||||
);
|
||||
|
||||
@@ -503,7 +503,7 @@ VOID PhMwpInitializeControls(
|
||||
0,
|
||||
WindowHandle,
|
||||
NULL,
|
||||
PhInstanceHandle,
|
||||
NULL,
|
||||
&treelistCreateParams
|
||||
);
|
||||
|
||||
@@ -517,7 +517,7 @@ VOID PhMwpInitializeControls(
|
||||
0,
|
||||
WindowHandle,
|
||||
NULL,
|
||||
PhInstanceHandle,
|
||||
NULL,
|
||||
&treelistCreateParams
|
||||
);
|
||||
|
||||
@@ -4738,7 +4738,7 @@ PVOID PhPluginInvokeWindowCallback(
|
||||
break;
|
||||
case PH_MAINWINDOW_CALLBACK_TYPE_WINDOW_BASE:
|
||||
{
|
||||
return (PVOID)PhInstanceHandle;
|
||||
return (PVOID)NtCurrentImageBase();
|
||||
}
|
||||
break;
|
||||
case PH_MAINWINDOW_CALLBACK_TYPE_GETWINDOW_PROCEDURE:
|
||||
|
||||
@@ -180,7 +180,7 @@ VOID PhShowMemoryEditorDialog(
|
||||
|
||||
// Just in case.
|
||||
if ((Flags & PH_MEMORY_EDITOR_UNMAP_VIEW_OF_SECTION) && ProcessId == NtCurrentProcessId())
|
||||
NtUnmapViewOfSection(NtCurrentProcess(), BaseAddress);
|
||||
PhUnmapViewOfSection(NtCurrentProcess(), BaseAddress);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ INT_PTR CALLBACK PhpMemoryEditorDlgProc(
|
||||
PhClearReference(&context->Title);
|
||||
|
||||
if ((context->Flags & PH_MEMORY_EDITOR_UNMAP_VIEW_OF_SECTION) && context->ProcessId == NtCurrentProcessId())
|
||||
NtUnmapViewOfSection(NtCurrentProcess(), context->BaseAddress);
|
||||
PhUnmapViewOfSection(NtCurrentProcess(), context->BaseAddress);
|
||||
|
||||
PhFree(context);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ VOID PhShowProcessMitigationPolicyDialog(
|
||||
context.SystemDllInitBlock = dllInitBlock;
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(PhGetProcessMitigationPolicy(processHandle, &information)))
|
||||
if (NT_SUCCESS(PhGetProcessMitigationPolicyAllInformation(processHandle, &information)))
|
||||
{
|
||||
for (policy = 0; policy < MaxProcessMitigationPolicy; policy++)
|
||||
{
|
||||
|
||||
@@ -879,7 +879,7 @@ static VOID WriteCurrentUserRun(
|
||||
)))
|
||||
{
|
||||
static CONST PH_STRINGREF valueName = PH_STRINGREF_INIT(L"System Informer");
|
||||
static CONST PH_STRINGREF seperator = PH_STRINGREF_INIT(L"\"");
|
||||
static CONST PH_STRINGREF separator = PH_STRINGREF_INIT(L"\"");
|
||||
|
||||
if (Present)
|
||||
{
|
||||
@@ -888,7 +888,7 @@ static VOID WriteCurrentUserRun(
|
||||
|
||||
if (fileName = PhGetApplicationFileNameWin32())
|
||||
{
|
||||
value = PH_AUTO(PhConcatStringRef3(&seperator, &fileName->sr, &seperator));
|
||||
value = PH_AUTO(PhConcatStringRef3(&separator, &fileName->sr, &separator));
|
||||
|
||||
if (StartHidden)
|
||||
value = PH_AUTO(PhConcatStringRefZ(&value->sr, L" -hide"));
|
||||
@@ -1021,7 +1021,7 @@ VOID PhpSetDefaultTaskManager(
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
static CONST PH_STRINGREF valueName = PH_STRINGREF_INIT(L"Debugger");
|
||||
static CONST PH_STRINGREF seperator = PH_STRINGREF_INIT(L"\"");
|
||||
static CONST PH_STRINGREF separator = PH_STRINGREF_INIT(L"\"");
|
||||
|
||||
if (PhpIsDefaultTaskManager())
|
||||
{
|
||||
@@ -1034,7 +1034,7 @@ VOID PhpSetDefaultTaskManager(
|
||||
|
||||
if (applicationFileName = PhGetApplicationFileNameWin32())
|
||||
{
|
||||
quotedFileName = PH_AUTO(PhConcatStringRef3(&seperator, &applicationFileName->sr, &seperator));
|
||||
quotedFileName = PH_AUTO(PhConcatStringRef3(&separator, &applicationFileName->sr, &separator));
|
||||
|
||||
status = PhSetValueKey(
|
||||
taskmgrKeyHandle,
|
||||
@@ -2071,7 +2071,7 @@ INT_PTR CALLBACK PhpOptionsGeneralDlgProc(
|
||||
|
||||
if (applicationFileName = PhGetApplicationFileNameWin32())
|
||||
{
|
||||
static PH_STRINGREF seperator = PH_STRINGREF_INIT(L"\"");
|
||||
static const PH_STRINGREF separator = PH_STRINGREF_INIT(L"\"");
|
||||
HRESULT status;
|
||||
PPH_STRING quotedFileName;
|
||||
|
||||
@@ -2082,9 +2082,9 @@ INT_PTR CALLBACK PhpOptionsGeneralDlgProc(
|
||||
}
|
||||
|
||||
quotedFileName = PH_AUTO(PhConcatStringRef3(
|
||||
&seperator,
|
||||
&separator,
|
||||
&applicationFileName->sr,
|
||||
&seperator
|
||||
&separator
|
||||
));
|
||||
|
||||
status = PhCreateAdminTask(
|
||||
|
||||
@@ -24,7 +24,6 @@ NTSTATUS PhSvcConnectToServer(
|
||||
{
|
||||
NTSTATUS status;
|
||||
HANDLE sectionHandle;
|
||||
OBJECT_ATTRIBUTES objectAttributes;
|
||||
LARGE_INTEGER sectionSize;
|
||||
PORT_VIEW clientView;
|
||||
REMOTE_PORT_VIEW serverView;
|
||||
@@ -39,21 +38,13 @@ NTSTATUS PhSvcConnectToServer(
|
||||
if (PortSectionSize == 0)
|
||||
PortSectionSize = UInt32x32To64(8, 1024 * 1024); // 8 MB
|
||||
|
||||
InitializeObjectAttributes(
|
||||
&objectAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
sectionSize.QuadPart = PortSectionSize;
|
||||
|
||||
// Create the port section and connect to the port.
|
||||
|
||||
sectionSize.QuadPart = PortSectionSize;
|
||||
status = NtCreateSection(
|
||||
status = PhCreateSection(
|
||||
§ionHandle,
|
||||
SECTION_ALL_ACCESS,
|
||||
&objectAttributes,
|
||||
§ionSize,
|
||||
PAGE_READWRITE,
|
||||
SEC_COMMIT,
|
||||
@@ -720,6 +711,7 @@ VOID PhSvcpPackBuffer(
|
||||
|
||||
va_start(argptr, NumberOfPointersToRebase);
|
||||
PhSvcpPackBuffer_V(BytesBuilder, PointerInBytesBuilder, Length, Alignment, NumberOfPointersToRebase, argptr);
|
||||
va_end(argptr);
|
||||
}
|
||||
|
||||
SIZE_T PhSvcpBufferLengthStringZ(
|
||||
|
||||
@@ -57,6 +57,7 @@ NTSTATUS PhSvcApiPortInitialization(
|
||||
PhAddAccessAllowedAce(dacl, ACL_REVISION, PORT_ALL_ACCESS, administratorsSid);
|
||||
PhAddAccessAllowedAce(dacl, ACL_REVISION, PORT_CONNECT, (PSID)&PhSeEveryoneSid);
|
||||
PhSetDaclSecurityDescriptor(securityDescriptor, TRUE, dacl, FALSE);
|
||||
assert(RtlValidSecurityDescriptor(securityDescriptor));
|
||||
|
||||
InitializeObjectAttributes(
|
||||
&objectAttributes,
|
||||
@@ -82,6 +83,9 @@ NTSTATUS PhSvcApiPortInitialization(
|
||||
|
||||
PhSvcApiThreadContextTlsIndex = PhTlsAlloc();
|
||||
|
||||
if (PhSvcApiThreadContextTlsIndex == TLS_OUT_OF_INDEXES)
|
||||
return STATUS_NO_MEMORY;
|
||||
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
PhCreateThread2(PhSvcApiRequestThreadStart, NULL);
|
||||
|
||||
@@ -190,7 +190,7 @@ PPH_PLUGIN_TREE_ROOT_NODE AddPluginsNode(
|
||||
|
||||
if (fileName = PhGetPluginFileName(Plugin))
|
||||
{
|
||||
if (PhInitializeImageVersionInfoEx(&versionInfo, &fileName->sr, FALSE))
|
||||
if (NT_SUCCESS(PhInitializeImageVersionInfoEx(&versionInfo, &fileName->sr, FALSE)))
|
||||
{
|
||||
pluginNode->Version = PhReferenceObject(versionInfo.FileVersion);
|
||||
PhDeleteImageVersionInfo(&versionInfo);
|
||||
@@ -911,7 +911,7 @@ VOID PhpRefreshPluginDetails(
|
||||
PhSetDialogItemText(hwndDlg, IDC_DESCRIPTION, SelectedPlugin->Information.Description);
|
||||
PhSetDialogItemText(hwndDlg, IDC_URL, SelectedPlugin->Information.Url);
|
||||
|
||||
if (fileName && PhInitializeImageVersionInfoEx(&versionInfo, &fileName->sr, FALSE))
|
||||
if (fileName && NT_SUCCESS(PhInitializeImageVersionInfoEx(&versionInfo, &fileName->sr, FALSE)))
|
||||
{
|
||||
PhSetDialogItemText(hwndDlg, IDC_VERSION, PhGetStringOrDefault(versionInfo.FileVersion, L"Unknown"));
|
||||
PhDeleteImageVersionInfo(&versionInfo);
|
||||
|
||||
@@ -47,7 +47,7 @@ NTSTATUS PhpCopyProcessMitigationPolicy(
|
||||
return status;
|
||||
}
|
||||
|
||||
NTSTATUS PhGetProcessMitigationPolicy(
|
||||
NTSTATUS PhGetProcessMitigationPolicyAllInformation(
|
||||
_In_ HANDLE ProcessHandle,
|
||||
_Out_ PPH_PROCESS_MITIGATION_POLICY_ALL_INFORMATION Information
|
||||
)
|
||||
|
||||
@@ -158,8 +158,10 @@ INT_PTR CALLBACK PhpProcessRecordDlgProc(
|
||||
NULL
|
||||
);
|
||||
|
||||
if (PhInitializeImageVersionInfo(&versionInfo, context->Record->FileName->Buffer))
|
||||
if (NT_SUCCESS(PhInitializeImageVersionInfo(&versionInfo, context->Record->FileName->Buffer)))
|
||||
{
|
||||
versionInfoInitialized = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (context->FileIcon)
|
||||
|
||||
+49
-44
@@ -1286,6 +1286,7 @@ static VOID PhpUpdateProcessNodeImage(
|
||||
// }
|
||||
//}
|
||||
|
||||
SetFlag(ProcessNode->ValidMask, PHPN_IMAGE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1742,52 +1743,28 @@ static VOID PhpUpdateProcessNodeMitigationPolicies(
|
||||
{
|
||||
if (!FlagOn(ProcessNode->ValidMask, PHPN_MITIGATIONPOLICIES))
|
||||
{
|
||||
NTSTATUS status;
|
||||
PH_PROCESS_MITIGATION_POLICY_ALL_INFORMATION information;
|
||||
|
||||
PhClearReference(&ProcessNode->MitigationPoliciesText);
|
||||
|
||||
if (ProcessNode->ProcessItem->QueryHandle &&
|
||||
NT_SUCCESS(status = PhGetProcessMitigationPolicy(ProcessNode->ProcessItem->QueryHandle, &information)))
|
||||
if (ProcessNode->ProcessItem->QueryHandle && !ProcessNode->ProcessItem->IsSubsystemProcess)
|
||||
{
|
||||
PH_STRING_BUILDER sb;
|
||||
PROCESS_MITIGATION_POLICY policy;
|
||||
PPH_STRING shortDescription;
|
||||
NTSTATUS status;
|
||||
PH_PROCESS_MITIGATION_POLICY_ALL_INFORMATION information;
|
||||
|
||||
PhInitializeStringBuilder(&sb, 100);
|
||||
status = PhGetProcessMitigationPolicyAllInformation(ProcessNode->ProcessItem->QueryHandle, &information);
|
||||
|
||||
for (policy = 0; policy < MaxProcessMitigationPolicy; policy++)
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
if (information.Pointers[policy] && PhDescribeProcessMitigationPolicy(
|
||||
policy,
|
||||
information.Pointers[policy],
|
||||
&shortDescription,
|
||||
NULL
|
||||
))
|
||||
PH_STRING_BUILDER sb;
|
||||
PROCESS_MITIGATION_POLICY policy;
|
||||
PPH_STRING shortDescription;
|
||||
|
||||
PhInitializeStringBuilder(&sb, 100);
|
||||
|
||||
for (policy = 0; policy < MaxProcessMitigationPolicy; policy++)
|
||||
{
|
||||
PhAppendStringBuilder(&sb, &shortDescription->sr);
|
||||
PhAppendStringBuilder2(&sb, L"; ");
|
||||
PhDereferenceObject(shortDescription);
|
||||
}
|
||||
}
|
||||
|
||||
// HACK: Show System process CET mitigation (dmex)
|
||||
if (ProcessNode->ProcessItem->ProcessId == SYSTEM_PROCESS_ID)
|
||||
{
|
||||
SYSTEM_SHADOW_STACK_INFORMATION shadowStackInformation;
|
||||
|
||||
if (NT_SUCCESS(PhGetSystemShadowStackInformation(&shadowStackInformation)))
|
||||
{
|
||||
PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY policyData;
|
||||
|
||||
memset(&policyData, 0, sizeof(PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY));
|
||||
policyData.EnableUserShadowStack = shadowStackInformation.KernelCetEnabled;
|
||||
policyData.EnableUserShadowStackStrictMode = shadowStackInformation.KernelCetEnabled;
|
||||
policyData.AuditUserShadowStack = shadowStackInformation.KernelCetAuditModeEnabled;
|
||||
|
||||
if (PhDescribeProcessMitigationPolicy(
|
||||
ProcessUserShadowStackPolicy,
|
||||
&policyData,
|
||||
if (information.Pointers[policy] && PhDescribeProcessMitigationPolicy(
|
||||
policy,
|
||||
information.Pointers[policy],
|
||||
&shortDescription,
|
||||
NULL
|
||||
))
|
||||
@@ -1797,12 +1774,40 @@ static VOID PhpUpdateProcessNodeMitigationPolicies(
|
||||
PhDereferenceObject(shortDescription);
|
||||
}
|
||||
}
|
||||
|
||||
// HACK: Show System process CET mitigation (dmex)
|
||||
if (ProcessNode->ProcessItem->ProcessId == SYSTEM_PROCESS_ID)
|
||||
{
|
||||
SYSTEM_SHADOW_STACK_INFORMATION shadowStackInformation;
|
||||
|
||||
if (NT_SUCCESS(PhGetSystemShadowStackInformation(&shadowStackInformation)))
|
||||
{
|
||||
PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY policyData;
|
||||
|
||||
memset(&policyData, 0, sizeof(PROCESS_MITIGATION_USER_SHADOW_STACK_POLICY));
|
||||
policyData.EnableUserShadowStack = shadowStackInformation.KernelCetEnabled;
|
||||
policyData.EnableUserShadowStackStrictMode = shadowStackInformation.KernelCetEnabled;
|
||||
policyData.AuditUserShadowStack = shadowStackInformation.KernelCetAuditModeEnabled;
|
||||
|
||||
if (PhDescribeProcessMitigationPolicy(
|
||||
ProcessUserShadowStackPolicy,
|
||||
&policyData,
|
||||
&shortDescription,
|
||||
NULL
|
||||
))
|
||||
{
|
||||
PhAppendStringBuilder(&sb, &shortDescription->sr);
|
||||
PhAppendStringBuilder2(&sb, L"; ");
|
||||
PhDereferenceObject(shortDescription);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (sb.String->Length != 0)
|
||||
PhRemoveEndStringBuilder(&sb, 2);
|
||||
|
||||
ProcessNode->MitigationPoliciesText = PhFinalStringBuilderString(&sb);
|
||||
}
|
||||
|
||||
if (sb.String->Length != 0)
|
||||
PhRemoveEndStringBuilder(&sb, 2);
|
||||
|
||||
ProcessNode->MitigationPoliciesText = PhFinalStringBuilderString(&sb);
|
||||
}
|
||||
|
||||
SetFlag(ProcessNode->ValidMask, PHPN_MITIGATIONPOLICIES);
|
||||
|
||||
@@ -242,7 +242,12 @@ VOID PhpRefreshEnvironmentList(
|
||||
|
||||
enumerationKey = 0;
|
||||
|
||||
while (PhEnumProcessEnvironmentVariables(systemDefaultEnvironment, (ULONG)variableLength * sizeof(WCHAR), &enumerationKey, &variable))
|
||||
while (NT_SUCCESS(PhEnumProcessEnvironmentVariables(
|
||||
systemDefaultEnvironment,
|
||||
(ULONG)variableLength * sizeof(WCHAR),
|
||||
&enumerationKey,
|
||||
&variable
|
||||
)))
|
||||
{
|
||||
PH_ENVIRONMENT_ITEM entry;
|
||||
|
||||
@@ -330,7 +335,12 @@ VOID PhpRefreshEnvironmentList(
|
||||
{
|
||||
enumerationKey = 0;
|
||||
|
||||
while (PhEnumProcessEnvironmentVariables(environment, environmentLength, &enumerationKey, &variable))
|
||||
while (NT_SUCCESS(PhEnumProcessEnvironmentVariables(
|
||||
environment,
|
||||
environmentLength,
|
||||
&enumerationKey,
|
||||
&variable
|
||||
)))
|
||||
{
|
||||
PH_ENVIRONMENT_ITEM entry;
|
||||
|
||||
@@ -470,7 +480,11 @@ VOID PhpRefreshWslEnvironmentList(
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PhWslQueryDistroProcessEnvironment(&ProcessItem->FileName->sr, ProcessItem->LxssProcessId, &environment))
|
||||
if (!NT_SUCCESS(PhWslQueryDistroProcessEnvironment(
|
||||
&ProcessItem->FileName->sr,
|
||||
ProcessItem->LxssProcessId,
|
||||
&environment
|
||||
)))
|
||||
{
|
||||
PhpSetEnvironmentListStatusMessage(Context, STATUS_PARTIAL_COPY);
|
||||
TreeNew_NodesStructured(Context->TreeNewHandle);
|
||||
@@ -479,7 +493,12 @@ VOID PhpRefreshWslEnvironmentList(
|
||||
|
||||
enumerationKey = 0;
|
||||
|
||||
while (PhEnumProcessEnvironmentVariables(PhGetString(environment), (ULONG)environment->Length, &enumerationKey, &variable))
|
||||
while (NT_SUCCESS(PhEnumProcessEnvironmentVariables(
|
||||
PhGetString(environment),
|
||||
(ULONG)environment->Length,
|
||||
&enumerationKey,
|
||||
&variable
|
||||
)))
|
||||
{
|
||||
PH_ENVIRONMENT_ITEM entry;
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ VOID PhpUpdateProcessMitigationPolicies(
|
||||
ProcessItem->ProcessId
|
||||
)))
|
||||
{
|
||||
if (NT_SUCCESS(status = PhGetProcessMitigationPolicy(processHandle, &information)))
|
||||
if (NT_SUCCESS(status = PhGetProcessMitigationPolicyAllInformation(processHandle, &information)))
|
||||
{
|
||||
PH_STRING_BUILDER sb;
|
||||
PROCESS_MITIGATION_POLICY policy;
|
||||
|
||||
+8
-10
@@ -89,7 +89,7 @@ HWND PhCreateServiceListControl(
|
||||
}
|
||||
|
||||
_Function_class_(PH_CALLBACK_FUNCTION)
|
||||
VOID NTAPI ServiceModifiedHandler(
|
||||
VOID NTAPI PhServiceListModifiedHandler(
|
||||
_In_ PVOID Parameter,
|
||||
_In_ PVOID Context
|
||||
)
|
||||
@@ -210,20 +210,11 @@ INT_PTR CALLBACK PhpServicesPageProc(
|
||||
context->WindowHandle = hwndDlg;
|
||||
context->ListViewHandle = GetDlgItem(hwndDlg, IDC_LIST);
|
||||
|
||||
PhRegisterCallback(
|
||||
PhGetGeneralCallback(GeneralCallbackServiceProviderModifiedEvent),
|
||||
ServiceModifiedHandler,
|
||||
context,
|
||||
&context->ModifiedEventRegistration
|
||||
);
|
||||
|
||||
// Initialize the list.
|
||||
PhSetListViewStyle(context->ListViewHandle, TRUE, TRUE);
|
||||
PhSetControlTheme(context->ListViewHandle, L"explorer");
|
||||
PhAddListViewColumn(context->ListViewHandle, 0, 0, 0, LVCFMT_LEFT, 120, L"Name");
|
||||
PhAddListViewColumn(context->ListViewHandle, 1, 1, 1, LVCFMT_LEFT, 220, L"Display name");
|
||||
PhAddListViewColumn(context->ListViewHandle, 2, 2, 2, LVCFMT_LEFT, 220, L"File name");
|
||||
|
||||
PhSetExtendedListView(context->ListViewHandle);
|
||||
|
||||
for (ULONG i = 0; i < context->NumberOfServices; i++)
|
||||
@@ -271,6 +262,13 @@ INT_PTR CALLBACK PhpServicesPageProc(
|
||||
PhAddLayoutItem(&context->LayoutManager, GetDlgItem(hwndDlg, IDC_PAUSE), NULL, PH_ANCHOR_RIGHT | PH_ANCHOR_BOTTOM);
|
||||
|
||||
PhInitializeWindowTheme(hwndDlg, PhEnableThemeSupport);
|
||||
|
||||
PhRegisterCallback(
|
||||
PhGetGeneralCallback(GeneralCallbackServiceProviderModifiedEvent),
|
||||
PhServiceListModifiedHandler,
|
||||
context,
|
||||
&context->ModifiedEventRegistration
|
||||
);
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
|
||||
@@ -475,12 +475,12 @@ VOID PhServiceQueryStage1(
|
||||
|
||||
if (nativeFilename = PhDosPathNameToNtPathName(&fileName->sr))
|
||||
{
|
||||
if (PhInitializeImageVersionInfoCached(
|
||||
if (NT_SUCCESS(PhInitializeImageVersionInfoCached(
|
||||
&versionInfo, // Data->VersionInfo
|
||||
nativeFilename,
|
||||
FALSE,
|
||||
!!PhCsEnableVersionSupport
|
||||
))
|
||||
)))
|
||||
{
|
||||
// Note: This is how msconfig determines default services. (dmex)
|
||||
if (versionInfo.CompanyName && PhStartsWithStringRef2(&versionInfo.CompanyName->sr, L"Microsoft", TRUE))
|
||||
|
||||
@@ -1585,12 +1585,12 @@ INT_PTR CALLBACK PhpTokenPageProc(
|
||||
break;
|
||||
}
|
||||
|
||||
if (PhSetTokenPrivilege(
|
||||
if (NT_SUCCESS(PhSetTokenPrivilege(
|
||||
tokenHandle,
|
||||
NULL,
|
||||
&listViewItems[i]->TokenPrivilege->Luid,
|
||||
newAttributes
|
||||
))
|
||||
)))
|
||||
{
|
||||
LONG itemIndex;
|
||||
|
||||
|
||||
+179
-143
@@ -135,7 +135,7 @@ static CONST ULONG PhpPrimeNumbers[] =
|
||||
/**
|
||||
* Initializes the base support module.
|
||||
*/
|
||||
BOOLEAN PhBaseInitialization(
|
||||
NTSTATUS PhBaseInitialization(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
@@ -159,9 +159,12 @@ BOOLEAN PhBaseInitialization(
|
||||
|
||||
#ifdef DEBUG
|
||||
PhDbgThreadDbgTlsIndex = PhTlsAlloc();
|
||||
|
||||
if (PhDbgThreadDbgTlsIndex == TLS_OUT_OF_INDEXES)
|
||||
return STATUS_NO_MEMORY;
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
_Function_class_(USER_THREAD_START_ROUTINE)
|
||||
@@ -192,6 +195,8 @@ NTSTATUS PhpBaseThreadStart(
|
||||
PhTlsSetValue(PhDbgThreadDbgTlsIndex, &dbg);
|
||||
#endif
|
||||
|
||||
GdiSetBatchLimit(1);
|
||||
|
||||
// Initialization code
|
||||
|
||||
result = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
@@ -1399,15 +1404,12 @@ PWSTR PhDuplicateStringZ(
|
||||
* \param ReturnCount A variable which receives the number of characters required to contain the
|
||||
* input string, including the null terminator. If the function returns TRUE, this variable contains
|
||||
* the number of characters written to the output buffer.
|
||||
*
|
||||
* \return TRUE if the input string was copied to the output string, otherwise FALSE.
|
||||
*
|
||||
* \remarks The function stops copying when it encounters the first null character in the input
|
||||
* string. It will also stop copying when it reaches the character count specified in \a InputCount,
|
||||
* if \a InputCount is not -1.
|
||||
*/
|
||||
_Success_(return)
|
||||
BOOLEAN PhCopyBytesZ(
|
||||
NTSTATUS PhCopyBytesZ(
|
||||
_In_ PCSTR InputBuffer,
|
||||
_In_ SIZE_T InputCount,
|
||||
_Out_writes_opt_z_(OutputCount) PSTR OutputBuffer,
|
||||
@@ -1415,8 +1417,8 @@ BOOLEAN PhCopyBytesZ(
|
||||
_Out_opt_ PSIZE_T ReturnCount
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
SIZE_T i;
|
||||
BOOLEAN copied;
|
||||
|
||||
// Determine the length of the input string.
|
||||
|
||||
@@ -1438,17 +1440,19 @@ BOOLEAN PhCopyBytesZ(
|
||||
{
|
||||
memcpy(OutputBuffer, InputBuffer, i);
|
||||
OutputBuffer[i] = ANSI_NULL;
|
||||
copied = TRUE;
|
||||
status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
copied = FALSE;
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (ReturnCount)
|
||||
{
|
||||
*ReturnCount = i + sizeof(ANSI_NULL);
|
||||
}
|
||||
|
||||
return copied;
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1462,15 +1466,12 @@ BOOLEAN PhCopyBytesZ(
|
||||
* \param ReturnCount A variable which receives the number of characters required to contain the
|
||||
* input string, including the null terminator. If the function returns TRUE, this variable contains
|
||||
* the number of characters written to the output buffer.
|
||||
*
|
||||
* \return TRUE if the input string was copied to the output string, otherwise FALSE.
|
||||
*
|
||||
* \remarks The function stops copying when it encounters the first null character in the input
|
||||
* string. It will also stop copying when it reaches the character count specified in \a InputCount,
|
||||
* if \a InputCount is not -1.
|
||||
*/
|
||||
_Success_(return)
|
||||
BOOLEAN PhCopyStringZ(
|
||||
NTSTATUS PhCopyStringZ(
|
||||
_In_ PCWSTR InputBuffer,
|
||||
_In_ SIZE_T InputCount,
|
||||
_Out_writes_opt_z_(OutputCount) PWSTR OutputBuffer,
|
||||
@@ -1478,8 +1479,8 @@ BOOLEAN PhCopyStringZ(
|
||||
_Out_opt_ PSIZE_T ReturnCount
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
SIZE_T i;
|
||||
BOOLEAN copied;
|
||||
|
||||
// Determine the length of the input string.
|
||||
|
||||
@@ -1501,17 +1502,19 @@ BOOLEAN PhCopyStringZ(
|
||||
{
|
||||
memcpy(OutputBuffer, InputBuffer, i * sizeof(WCHAR));
|
||||
OutputBuffer[i] = UNICODE_NULL;
|
||||
copied = TRUE;
|
||||
status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
copied = FALSE;
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (ReturnCount)
|
||||
{
|
||||
*ReturnCount = i + sizeof(UNICODE_NULL);
|
||||
}
|
||||
|
||||
return copied;
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1525,15 +1528,12 @@ BOOLEAN PhCopyStringZ(
|
||||
* \param ReturnCount A variable which receives the number of characters required to contain the
|
||||
* input string, including the null terminator. If the function returns TRUE, this variable contains
|
||||
* the number of characters written to the output buffer.
|
||||
*
|
||||
* \return TRUE if the input string was copied to the output string, otherwise FALSE.
|
||||
*
|
||||
* \remarks The function stops copying when it encounters the first null character in the input
|
||||
* string. It will also stop copying when it reaches the character count specified in \a InputCount,
|
||||
* if \a InputCount is not -1.
|
||||
*/
|
||||
_Success_(return)
|
||||
BOOLEAN PhCopyStringZFromBytes(
|
||||
NTSTATUS PhCopyStringZFromBytes(
|
||||
_In_ PCSTR InputBuffer,
|
||||
_In_ SIZE_T InputCount,
|
||||
_Out_writes_opt_z_(OutputCount) PWSTR OutputBuffer,
|
||||
@@ -1541,8 +1541,8 @@ BOOLEAN PhCopyStringZFromBytes(
|
||||
_Out_opt_ PSIZE_T ReturnCount
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
SIZE_T i;
|
||||
BOOLEAN copied;
|
||||
|
||||
// Determine the length of the input string.
|
||||
|
||||
@@ -1564,17 +1564,19 @@ BOOLEAN PhCopyStringZFromBytes(
|
||||
{
|
||||
PhZeroExtendToUtf16Buffer(InputBuffer, i, OutputBuffer);
|
||||
OutputBuffer[i] = UNICODE_NULL;
|
||||
copied = TRUE;
|
||||
status = STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
copied = FALSE;
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (ReturnCount)
|
||||
{
|
||||
*ReturnCount = i + sizeof(ANSI_NULL);
|
||||
}
|
||||
|
||||
return copied;
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1588,15 +1590,12 @@ BOOLEAN PhCopyStringZFromBytes(
|
||||
* \param ReturnCount A variable which receives the number of characters required to contain the
|
||||
* input string, including the null terminator. If the function returns TRUE, this variable contains
|
||||
* the number of characters written to the output buffer.
|
||||
*
|
||||
* \return TRUE if the input string was copied to the output string, otherwise FALSE.
|
||||
*
|
||||
* \remarks The function stops copying when it encounters the first null character in the input
|
||||
* string. It will also stop copying when it reaches the character count specified in \a InputCount,
|
||||
* if \a InputCount is not -1.
|
||||
*/
|
||||
_Success_(return)
|
||||
BOOLEAN PhCopyStringZFromMultiByte(
|
||||
NTSTATUS PhCopyStringZFromMultiByte(
|
||||
_In_ PCSTR InputBuffer,
|
||||
_In_ SIZE_T InputCount,
|
||||
_Out_writes_opt_z_(OutputCount) PWSTR OutputBuffer,
|
||||
@@ -1608,7 +1607,6 @@ BOOLEAN PhCopyStringZFromMultiByte(
|
||||
SIZE_T i;
|
||||
ULONG inputBytes;
|
||||
ULONG unicodeBytes;
|
||||
BOOLEAN copied;
|
||||
|
||||
// Determine the length of the input string.
|
||||
|
||||
@@ -1631,7 +1629,7 @@ BOOLEAN PhCopyStringZFromMultiByte(
|
||||
if (ReturnCount)
|
||||
*ReturnCount = SIZE_MAX;
|
||||
|
||||
return FALSE;
|
||||
return status;
|
||||
}
|
||||
|
||||
// Determine the length of the output string.
|
||||
@@ -1647,7 +1645,7 @@ BOOLEAN PhCopyStringZFromMultiByte(
|
||||
if (ReturnCount)
|
||||
*ReturnCount = SIZE_MAX;
|
||||
|
||||
return FALSE;
|
||||
return status;
|
||||
}
|
||||
|
||||
// Convert the string to Unicode if there is enough room.
|
||||
@@ -1666,26 +1664,22 @@ BOOLEAN PhCopyStringZFromMultiByte(
|
||||
{
|
||||
// RtlMultiByteToUnicodeN doesn't null terminate the string.
|
||||
*(PWCHAR)PTR_ADD_OFFSET(OutputBuffer, unicodeBytes) = UNICODE_NULL;
|
||||
copied = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
copied = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
copied = FALSE;
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (ReturnCount)
|
||||
{
|
||||
*ReturnCount = (unicodeBytes + sizeof(UNICODE_NULL)) / sizeof(WCHAR);
|
||||
}
|
||||
|
||||
return copied;
|
||||
return status;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhCopyStringZFromUtf8(
|
||||
NTSTATUS PhCopyStringZFromUtf8(
|
||||
_In_ PCSTR InputBuffer,
|
||||
_In_ SIZE_T InputCount,
|
||||
_Out_writes_opt_z_(OutputCount) PWSTR OutputBuffer,
|
||||
@@ -1697,7 +1691,6 @@ BOOLEAN PhCopyStringZFromUtf8(
|
||||
SIZE_T i;
|
||||
ULONG inputBytes;
|
||||
ULONG unicodeBytes;
|
||||
BOOLEAN copied;
|
||||
|
||||
// Determine the length of the input string.
|
||||
|
||||
@@ -1720,7 +1713,7 @@ BOOLEAN PhCopyStringZFromUtf8(
|
||||
if (ReturnCount)
|
||||
*ReturnCount = SIZE_MAX;
|
||||
|
||||
return FALSE;
|
||||
return status;
|
||||
}
|
||||
|
||||
// Determine the length of the output string.
|
||||
@@ -1738,7 +1731,7 @@ BOOLEAN PhCopyStringZFromUtf8(
|
||||
if (ReturnCount)
|
||||
*ReturnCount = SIZE_MAX;
|
||||
|
||||
return FALSE;
|
||||
return status;
|
||||
}
|
||||
|
||||
// Convert the string to Unicode if there is enough room.
|
||||
@@ -1757,22 +1750,19 @@ BOOLEAN PhCopyStringZFromUtf8(
|
||||
{
|
||||
// RtlUTF8ToUnicodeN doesn't null terminate the string.
|
||||
*(PWCHAR)PTR_ADD_OFFSET(OutputBuffer, unicodeBytes) = UNICODE_NULL;
|
||||
copied = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
copied = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
copied = FALSE;
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (ReturnCount)
|
||||
{
|
||||
*ReturnCount = (unicodeBytes + sizeof(UNICODE_NULL)) / sizeof(WCHAR);
|
||||
}
|
||||
|
||||
return copied;
|
||||
return status;
|
||||
}
|
||||
|
||||
FORCEINLINE LONG PhpCompareRightNatural(
|
||||
@@ -1938,20 +1928,17 @@ FORCEINLINE LONG PhpCompareStringZNatural(
|
||||
/**
|
||||
* Compares two strings in natural sort order.
|
||||
*
|
||||
* \param A The first string.
|
||||
* \param B The second string.
|
||||
* \param IgnoreCase Whether to ignore character cases.
|
||||
* \param String1 The first string.
|
||||
* \param String2 The second string.
|
||||
* \param IgnoreCase TRUE to perform a case-insensitive comparison, otherwise FALSE.
|
||||
*/
|
||||
LONG PhCompareStringZNatural(
|
||||
_In_ PCWSTR A,
|
||||
_In_ PCWSTR B,
|
||||
_In_ PCWSTR String1,
|
||||
_In_ PCWSTR String2,
|
||||
_In_ BOOLEAN IgnoreCase
|
||||
)
|
||||
{
|
||||
if (!IgnoreCase)
|
||||
return PhpCompareStringZNatural(A, B, FALSE);
|
||||
else
|
||||
return PhpCompareStringZNatural(A, B, TRUE);
|
||||
return PhpCompareStringZNatural(String1, String2, IgnoreCase);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3092,17 +3079,21 @@ PPH_STRING PhReferenceEmptyString(
|
||||
* Concatenates multiple strings.
|
||||
*
|
||||
* \param Count The number of strings to concatenate.
|
||||
* \param ... The list of strings.
|
||||
*/
|
||||
PPH_STRING PhConcatStrings(
|
||||
_In_ ULONG Count,
|
||||
...
|
||||
)
|
||||
{
|
||||
PPH_STRING string;
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, Count);
|
||||
string = PhConcatStrings_V(Count, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
return PhConcatStrings_V(Count, argptr);
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3315,11 +3306,14 @@ PPH_STRING PhFormatString(
|
||||
...
|
||||
)
|
||||
{
|
||||
PPH_STRING string;
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, Format);
|
||||
string = PhFormatString_V(Format, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
return PhFormatString_V(Format, argptr);
|
||||
return string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3338,7 +3332,7 @@ PPH_STRING PhFormatString_V(
|
||||
|
||||
length = _vscwprintf(Format, ArgPtr);
|
||||
|
||||
if (length == -1)
|
||||
if (length == INT_ERROR)
|
||||
return NULL;
|
||||
|
||||
string = PhCreateStringEx(NULL, length * sizeof(WCHAR));
|
||||
@@ -3399,7 +3393,7 @@ PPH_BYTES PhFormatBytes_V(
|
||||
|
||||
length = _vscprintf(Format, ArgPtr);
|
||||
|
||||
if (length == -1)
|
||||
if (length == INT_ERROR)
|
||||
return NULL;
|
||||
|
||||
string = PhCreateBytesEx(NULL, length * sizeof(CHAR));
|
||||
@@ -3413,11 +3407,14 @@ PPH_BYTES PhFormatBytes(
|
||||
...
|
||||
)
|
||||
{
|
||||
PPH_BYTES string;
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, Format);
|
||||
string = PhFormatBytes_V(Format, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
return PhFormatBytes_V(Format, argptr);
|
||||
return string;
|
||||
}
|
||||
|
||||
BOOLEAN PhWriteUnicodeDecoder(
|
||||
@@ -3538,7 +3535,7 @@ BOOLEAN PhpDecodeUtf8Error(
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
_Use_decl_annotations_
|
||||
BOOLEAN PhDecodeUnicodeDecoder(
|
||||
_Inout_ PPH_UNICODE_DECODER Decoder,
|
||||
_Out_ PULONG CodePoint
|
||||
@@ -3736,7 +3733,7 @@ BOOLEAN PhDecodeUnicodeDecoder(
|
||||
}
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
_Use_decl_annotations_
|
||||
BOOLEAN PhEncodeUnicode(
|
||||
_In_ UCHAR Encoding,
|
||||
_In_ ULONG CodePoint,
|
||||
@@ -4062,32 +4059,35 @@ PPH_BYTES PhConvertUtf16ToMultiByteEx(
|
||||
return bytes;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhConvertUtf8ToUtf16Size(
|
||||
NTSTATUS PhConvertUtf8ToUtf16Size(
|
||||
_Out_ PSIZE_T BytesInUtf16String,
|
||||
_In_reads_bytes_(BytesInUtf8String) PCCH Utf8String,
|
||||
_In_ SIZE_T BytesInUtf8String
|
||||
)
|
||||
{
|
||||
#if (PH_NATIVE_STRING_CONVERSION)
|
||||
#if defined(PH_NATIVE_STRING_CONVERSION)
|
||||
NTSTATUS status;
|
||||
ULONG bytesInUtf16String = 0;
|
||||
|
||||
if (NT_SUCCESS(RtlUTF8ToUnicodeN(
|
||||
status = RtlUTF8ToUnicodeN(
|
||||
NULL,
|
||||
0,
|
||||
&bytesInUtf16String,
|
||||
Utf8String,
|
||||
(ULONG)BytesInUtf8String
|
||||
)))
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
if (BytesInUtf16String)
|
||||
{
|
||||
*BytesInUtf16String = bytesInUtf16String;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return status;
|
||||
#else
|
||||
BOOLEAN result;
|
||||
NTSTATUS status;
|
||||
PH_UNICODE_DECODER decoder;
|
||||
PCH in;
|
||||
SIZE_T inRemaining;
|
||||
@@ -4095,7 +4095,7 @@ BOOLEAN PhConvertUtf8ToUtf16Size(
|
||||
ULONG codePoint;
|
||||
ULONG numberOfCodeUnits;
|
||||
|
||||
result = TRUE;
|
||||
status = STATUS_SUCCESS;
|
||||
PhInitializeUnicodeDecoder(&decoder, PH_UNICODE_UTF8);
|
||||
in = Utf8String;
|
||||
inRemaining = BytesInUtf8String;
|
||||
@@ -4110,20 +4110,27 @@ BOOLEAN PhConvertUtf8ToUtf16Size(
|
||||
while (PhDecodeUnicodeDecoder(&decoder, &codePoint))
|
||||
{
|
||||
if (PhEncodeUnicode(PH_UNICODE_UTF16, codePoint, NULL, &numberOfCodeUnits))
|
||||
{
|
||||
bytesInUtf16String += numberOfCodeUnits * sizeof(WCHAR);
|
||||
}
|
||||
else
|
||||
result = FALSE;
|
||||
{
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
break;
|
||||
}
|
||||
|
||||
*BytesInUtf16String = bytesInUtf16String;
|
||||
|
||||
return result;
|
||||
return status;
|
||||
#endif
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhConvertUtf8ToUtf16Buffer(
|
||||
NTSTATUS PhConvertUtf8ToUtf16Buffer(
|
||||
_Out_writes_bytes_to_(MaxBytesInUtf16String, *BytesInUtf16String) PWCH Utf16String,
|
||||
_In_ SIZE_T MaxBytesInUtf16String,
|
||||
_Out_opt_ PSIZE_T BytesInUtf16String,
|
||||
@@ -4131,25 +4138,29 @@ BOOLEAN PhConvertUtf8ToUtf16Buffer(
|
||||
_In_ SIZE_T BytesInUtf8String
|
||||
)
|
||||
{
|
||||
#if (PH_NATIVE_STRING_CONVERSION)
|
||||
#if defined(PH_NATIVE_STRING_CONVERSION)
|
||||
NTSTATUS status;
|
||||
ULONG bytesInUtf16String = 0;
|
||||
|
||||
if (NT_SUCCESS(RtlUTF8ToUnicodeN(
|
||||
status = RtlUTF8ToUnicodeN(
|
||||
Utf16String,
|
||||
(ULONG)MaxBytesInUtf16String,
|
||||
&bytesInUtf16String,
|
||||
Utf8String,
|
||||
(ULONG)BytesInUtf8String
|
||||
)))
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
if (BytesInUtf16String)
|
||||
{
|
||||
*BytesInUtf16String = bytesInUtf16String;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return status;
|
||||
#else
|
||||
BOOLEAN result;
|
||||
NTSTATUS status;
|
||||
PH_UNICODE_DECODER decoder;
|
||||
PCH in;
|
||||
SIZE_T inRemaining;
|
||||
@@ -4160,7 +4171,7 @@ BOOLEAN PhConvertUtf8ToUtf16Buffer(
|
||||
USHORT codeUnits[2];
|
||||
ULONG numberOfCodeUnits;
|
||||
|
||||
result = TRUE;
|
||||
status = STATUS_SUCCESS;
|
||||
PhInitializeUnicodeDecoder(&decoder, PH_UNICODE_UTF8);
|
||||
in = Utf8String;
|
||||
inRemaining = BytesInUtf8String;
|
||||
@@ -4191,20 +4202,25 @@ BOOLEAN PhConvertUtf8ToUtf16Buffer(
|
||||
}
|
||||
else
|
||||
{
|
||||
result = FALSE;
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = FALSE;
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
break;
|
||||
}
|
||||
|
||||
if (BytesInUtf16String)
|
||||
*BytesInUtf16String = bytesInUtf16String;
|
||||
|
||||
return result;
|
||||
return status;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4223,27 +4239,29 @@ PPH_STRING PhConvertUtf8ToUtf16Ex(
|
||||
_In_ SIZE_T Length
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
PPH_STRING string;
|
||||
SIZE_T utf16Bytes;
|
||||
|
||||
if (!PhConvertUtf8ToUtf16Size(
|
||||
status = PhConvertUtf8ToUtf16Size(
|
||||
&utf16Bytes,
|
||||
Buffer,
|
||||
Length
|
||||
))
|
||||
{
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
string = PhCreateStringEx(NULL, utf16Bytes);
|
||||
|
||||
if (!PhConvertUtf8ToUtf16Buffer(
|
||||
status = PhConvertUtf8ToUtf16Buffer(
|
||||
string->Buffer,
|
||||
string->Length,
|
||||
NULL,
|
||||
Buffer,
|
||||
Length
|
||||
))
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
PhDereferenceObject(string);
|
||||
return NULL;
|
||||
@@ -4252,32 +4270,35 @@ PPH_STRING PhConvertUtf8ToUtf16Ex(
|
||||
return string;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhConvertUtf16ToUtf8Size(
|
||||
NTSTATUS PhConvertUtf16ToUtf8Size(
|
||||
_Out_ PSIZE_T BytesInUtf8String,
|
||||
_In_reads_bytes_(BytesInUtf16String) PCWCH Utf16String,
|
||||
_In_ SIZE_T BytesInUtf16String
|
||||
)
|
||||
{
|
||||
#if (PH_NATIVE_STRING_CONVERSION)
|
||||
#if defined(PH_NATIVE_STRING_CONVERSION)
|
||||
NTSTATUS status;
|
||||
ULONG bytesInUtf8String = 0;
|
||||
|
||||
if (NT_SUCCESS(RtlUnicodeToUTF8N(
|
||||
status = RtlUnicodeToUTF8N(
|
||||
NULL,
|
||||
0,
|
||||
&bytesInUtf8String,
|
||||
Utf16String,
|
||||
(ULONG)BytesInUtf16String
|
||||
)))
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
if (BytesInUtf8String)
|
||||
{
|
||||
*BytesInUtf8String = bytesInUtf8String;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return status;
|
||||
#else
|
||||
BOOLEAN result;
|
||||
NTSTATUS status;
|
||||
PH_UNICODE_DECODER decoder;
|
||||
PWCH in;
|
||||
SIZE_T inRemaining;
|
||||
@@ -4285,7 +4306,7 @@ BOOLEAN PhConvertUtf16ToUtf8Size(
|
||||
ULONG codePoint;
|
||||
ULONG numberOfCodeUnits;
|
||||
|
||||
result = TRUE;
|
||||
status = STATUS_SUCCESS;
|
||||
PhInitializeUnicodeDecoder(&decoder, PH_UNICODE_UTF16);
|
||||
in = Utf16String;
|
||||
inRemaining = BytesInUtf16String / sizeof(WCHAR);
|
||||
@@ -4300,20 +4321,27 @@ BOOLEAN PhConvertUtf16ToUtf8Size(
|
||||
while (PhDecodeUnicodeDecoder(&decoder, &codePoint))
|
||||
{
|
||||
if (PhEncodeUnicode(PH_UNICODE_UTF8, codePoint, NULL, &numberOfCodeUnits))
|
||||
{
|
||||
bytesInUtf8String += numberOfCodeUnits;
|
||||
}
|
||||
else
|
||||
result = FALSE;
|
||||
{
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
break;
|
||||
}
|
||||
|
||||
*BytesInUtf8String = bytesInUtf8String;
|
||||
|
||||
return result;
|
||||
return status;
|
||||
#endif
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhConvertUtf16ToUtf8Buffer(
|
||||
NTSTATUS PhConvertUtf16ToUtf8Buffer(
|
||||
_Out_writes_bytes_to_(MaxBytesInUtf8String, *BytesInUtf8String) PCH Utf8String,
|
||||
_In_ SIZE_T MaxBytesInUtf8String,
|
||||
_Out_opt_ PSIZE_T BytesInUtf8String,
|
||||
@@ -4321,25 +4349,29 @@ BOOLEAN PhConvertUtf16ToUtf8Buffer(
|
||||
_In_ SIZE_T BytesInUtf16String
|
||||
)
|
||||
{
|
||||
#if (PH_NATIVE_STRING_CONVERSION)
|
||||
#if defined(PH_NATIVE_STRING_CONVERSION)
|
||||
NTSTATUS status;
|
||||
ULONG bytesInUtf8String = 0;
|
||||
|
||||
if (NT_SUCCESS(RtlUnicodeToUTF8N(
|
||||
status = RtlUnicodeToUTF8N(
|
||||
Utf8String,
|
||||
(ULONG)MaxBytesInUtf8String,
|
||||
&bytesInUtf8String,
|
||||
Utf16String,
|
||||
(ULONG)BytesInUtf16String
|
||||
)))
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
if (BytesInUtf8String)
|
||||
{
|
||||
*BytesInUtf8String = bytesInUtf8String;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return status;
|
||||
#else
|
||||
BOOLEAN result;
|
||||
NTSTATUS status;
|
||||
PH_UNICODE_DECODER decoder;
|
||||
PWCH in;
|
||||
SIZE_T inRemaining;
|
||||
@@ -4385,20 +4417,27 @@ BOOLEAN PhConvertUtf16ToUtf8Buffer(
|
||||
}
|
||||
else
|
||||
{
|
||||
result = FALSE;
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = FALSE;
|
||||
status = STATUS_BUFFER_TOO_SMALL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
break;
|
||||
}
|
||||
|
||||
if (BytesInUtf8String)
|
||||
{
|
||||
*BytesInUtf8String = bytesInUtf8String;
|
||||
}
|
||||
|
||||
return result;
|
||||
return status;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4417,27 +4456,29 @@ PPH_BYTES PhConvertUtf16ToUtf8Ex(
|
||||
_In_ SIZE_T Length
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
PPH_BYTES bytes;
|
||||
SIZE_T utf8Bytes;
|
||||
|
||||
if (!PhConvertUtf16ToUtf8Size(
|
||||
status = PhConvertUtf16ToUtf8Size(
|
||||
&utf8Bytes,
|
||||
Buffer,
|
||||
Length
|
||||
))
|
||||
{
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bytes = PhCreateBytesEx(NULL, utf8Bytes);
|
||||
|
||||
if (!PhConvertUtf16ToUtf8Buffer(
|
||||
status = PhConvertUtf16ToUtf8Buffer(
|
||||
bytes->Buffer,
|
||||
bytes->Length,
|
||||
NULL,
|
||||
Buffer,
|
||||
Length
|
||||
))
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
PhDereferenceObject(bytes);
|
||||
return NULL;
|
||||
@@ -4644,6 +4685,7 @@ VOID PhAppendCharStringBuilder2(
|
||||
*
|
||||
* \param StringBuilder A string builder object.
|
||||
* \param Format The format-control string.
|
||||
* \param ... The list of strings.
|
||||
*/
|
||||
VOID PhAppendFormatStringBuilder(
|
||||
_Inout_ PPH_STRING_BUILDER StringBuilder,
|
||||
@@ -4669,7 +4711,7 @@ VOID PhAppendFormatStringBuilder_V(
|
||||
|
||||
length = _vscwprintf(Format, ArgPtr);
|
||||
|
||||
if (length == -1 || length == 0)
|
||||
if (length == INT_ERROR || length == 0)
|
||||
return;
|
||||
|
||||
lengthInBytes = length * sizeof(WCHAR);
|
||||
@@ -4986,7 +5028,7 @@ VOID PhAppendFormatBytesBuilder_V(
|
||||
|
||||
length = _vscprintf(Format, ArgPtr);
|
||||
|
||||
if (length == -1 || length == 0)
|
||||
if (length == INT_ERROR || length == 0)
|
||||
return;
|
||||
|
||||
lengthInBytes = length * sizeof(CHAR);
|
||||
@@ -5293,7 +5335,6 @@ VOID PhClearList(
|
||||
List->Count = 0;
|
||||
}
|
||||
|
||||
_Success_(return != -1)
|
||||
/**
|
||||
* Locates an item in a list.
|
||||
*
|
||||
@@ -5303,14 +5344,13 @@ _Success_(return != -1)
|
||||
* \return The index of the item. If the
|
||||
* item was not found, -1 is returned.
|
||||
*/
|
||||
_Use_decl_annotations_
|
||||
ULONG PhFindItemList(
|
||||
_In_ PPH_LIST List,
|
||||
_In_ PVOID Item
|
||||
)
|
||||
{
|
||||
ULONG i;
|
||||
|
||||
for (i = 0; i < List->Count; i++)
|
||||
for (ULONG i = 0; i < List->Count; i++)
|
||||
{
|
||||
if (List->Items[i] == Item)
|
||||
return i;
|
||||
@@ -5536,7 +5576,7 @@ HANDLE PhAddItemPointerList(
|
||||
return PhpPointerListIndexToHandle(index);
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
_Use_decl_annotations_
|
||||
BOOLEAN PhEnumPointerListEx(
|
||||
_In_ PPH_POINTER_LIST PointerList,
|
||||
_Inout_ PULONG EnumerationKey,
|
||||
@@ -5905,7 +5945,7 @@ VOID PhClearHashtable(
|
||||
* this function). Otherwise, the function may behave unexpectedly. You may reset the
|
||||
* \a EnumerationKey variable to 0 if you wish to restart the enumeration.
|
||||
*/
|
||||
_Success_(return)
|
||||
_Use_decl_annotations_
|
||||
BOOLEAN PhEnumHashtable(
|
||||
_In_ PPH_HASHTABLE Hashtable,
|
||||
_Out_ PVOID *Entry,
|
||||
@@ -6160,11 +6200,6 @@ ULONG PhHashStringRefEx(
|
||||
if (String->Length == 0)
|
||||
return 0;
|
||||
|
||||
if (IgnoreCase)
|
||||
{
|
||||
NOTHING;
|
||||
}
|
||||
|
||||
return PhHashXXH32(String->Buffer, String->Length, 0);
|
||||
}
|
||||
}
|
||||
@@ -6674,6 +6709,7 @@ BOOLEAN PhHexStringToBufferEx(
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a byte array into a sequence of hexadecimal digits.
|
||||
*
|
||||
@@ -6725,7 +6761,7 @@ PPH_STRING PhBufferToHexStringEx(
|
||||
return string;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
_Use_decl_annotations_
|
||||
BOOLEAN PhBufferToHexStringBuffer(
|
||||
_In_reads_bytes_(InputLength) PUCHAR InputBuffer,
|
||||
_In_ SIZE_T InputLength,
|
||||
@@ -6825,7 +6861,7 @@ BOOLEAN PhpStringToInteger64(
|
||||
*
|
||||
* If there is no recognized prefix, base 10 is used.
|
||||
*/
|
||||
_Success_(return)
|
||||
_Use_decl_annotations_
|
||||
BOOLEAN PhStringToInteger64(
|
||||
_In_ PCPH_STRINGREF String,
|
||||
_In_opt_ ULONG Base,
|
||||
@@ -6909,7 +6945,7 @@ BOOLEAN PhStringToInteger64(
|
||||
return valid;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
_Use_decl_annotations_
|
||||
BOOLEAN PhStringToUInt64(
|
||||
_In_ PCPH_STRINGREF String,
|
||||
_In_opt_ ULONG Base,
|
||||
|
||||
+93
-10
@@ -12,25 +12,91 @@
|
||||
#include <phbase.h>
|
||||
#include <fastlock.h>
|
||||
|
||||
// FastLock is a port of FastResourceLock from PH 1.x.
|
||||
// FastLock is a fast resource (reader-writer) lock.
|
||||
//
|
||||
// The code contains no comments because it is a direct port. Please see FastResourceLock.cs in PH
|
||||
// The code is a direct port of FastResourceLock from PH 1.x. Please see FastResourceLock.cs in PH
|
||||
// 1.x for details.
|
||||
|
||||
//
|
||||
// The fast lock is around 7% faster than the critical section when there is no contention, when
|
||||
// used solely for mutual exclusion. It is also much smaller than the critical section.
|
||||
//
|
||||
// There are three types of acquire methods:
|
||||
// * Normal methods (AcquireExclusive, AcquireShared) are preferred for general purpose use.
|
||||
// * Busy wait methods (SpinAcquireExclusive, SpinAcquireShared) are preferred if
|
||||
// very little time is spent while the lock is acquired. However, these do not give exclusive
|
||||
// acquires precedence over shared acquires.
|
||||
// * Try methods (TryAcquireExclusive, TryAcquireShared) can be used to quickly test if the lock is available.
|
||||
//
|
||||
// Note that all three types of functions can be used concurrently by the same FastLock instance.
|
||||
//
|
||||
// Details
|
||||
//
|
||||
// Resource lock value width: 32 bits.
|
||||
// Lock owned (either exclusive or shared): L (1 bit).
|
||||
// Exclusive waking: W (1 bit).
|
||||
// Shared owners count: SC (10 bits).
|
||||
// Shared waiters count: SW (10 bits).
|
||||
// Exclusive waiters count: EW (10 bits).
|
||||
//
|
||||
// Acquire exclusive:
|
||||
// {L=0,W=0,SC=0,SW,EW=0} -> {L=1,W=0,SC=0,SW,EW=0}
|
||||
// {L=0,W=1,SC=0,SW,EW} or {L=1,W,SC,SW,EW} ->
|
||||
// {L,W,SC,SW,EW+1},
|
||||
// wait on event,
|
||||
// {L=0,W=1,SC=0,SW,EW} -> {L=1,W=0,SC=0,SW,EW}
|
||||
//
|
||||
// Acquire shared:
|
||||
// {L=0,W=0,SC=0,SW,EW=0} -> {L=1,W=0,SC=1,SW,EW=0}
|
||||
// {L=1,W=0,SC>0,SW,EW=0} -> {L=1,W=0,SC+1,SW,EW=0}
|
||||
// {L=1,W=0,SC=0,SW,EW=0} or {L,W=1,SC,SW,EW} or
|
||||
// {L,W,SC,SW,EW>0} -> {L,W,SC,SW+1,EW},
|
||||
// wait on event,
|
||||
// retry.
|
||||
//
|
||||
// Release exclusive:
|
||||
// {L=1,W=0,SC=0,SW,EW>0} ->
|
||||
// {L=0,W=1,SC=0,SW,EW-1},
|
||||
// release one exclusive waiter.
|
||||
// {L=1,W=0,SC=0,SW,EW=0} ->
|
||||
// {L=0,W=0,SC=0,SW=0,EW=0},
|
||||
// release all shared waiters.
|
||||
//
|
||||
// Note that we never do a direct acquire when W=1
|
||||
// (i.e. L=0 if W=1), so here we don't have to check
|
||||
// the value of W.
|
||||
//
|
||||
// Release shared:
|
||||
// {L=1,W=0,SC>1,SW,EW} -> {L=1,W=0,SC-1,SW,EW}
|
||||
// {L=1,W=0,SC=1,SW,EW=0} -> {L=0,W=0,SC=0,SW,EW=0}
|
||||
// {L=1,W=0,SC=1,SW,EW>0} ->
|
||||
// {L=0,W=1,SC=0,SW,EW-1},
|
||||
// release one exclusive waiter.
|
||||
//
|
||||
// Again, we don't need to check the value of W.
|
||||
//
|
||||
// Convert exclusive to shared:
|
||||
// {L=1,W=0,SC=0,SW,EW} ->
|
||||
// {L=1,W=0,SC=1,SW=0,EW},
|
||||
// release all shared waiters.
|
||||
//
|
||||
// Convert shared to exclusive:
|
||||
// {L=1,W=0,SC=1,SW,EW} ->
|
||||
// {L=1,W=0,SC=0,SW,EW}
|
||||
//
|
||||
|
||||
// Lock owned: 1 bit.
|
||||
#define PH_LOCK_OWNED 0x1
|
||||
// Exclusive waking: 1 bit.
|
||||
#define PH_LOCK_EXCLUSIVE_WAKING 0x2
|
||||
|
||||
// Shared owners count: 10 bits.
|
||||
#define PH_LOCK_SHARED_OWNERS_SHIFT 2
|
||||
#define PH_LOCK_SHARED_OWNERS_MASK 0x3fful
|
||||
#define PH_LOCK_SHARED_OWNERS_INC 0x4
|
||||
|
||||
// Shared waiters count: 10 bits.
|
||||
#define PH_LOCK_SHARED_WAITERS_SHIFT 12
|
||||
#define PH_LOCK_SHARED_WAITERS_MASK 0x3fful
|
||||
#define PH_LOCK_SHARED_WAITERS_INC 0x1000
|
||||
|
||||
// Exclusive waiters count: 10 bits.
|
||||
#define PH_LOCK_EXCLUSIVE_WAITERS_SHIFT 22
|
||||
#define PH_LOCK_EXCLUSIVE_WAITERS_MASK 0x3fful
|
||||
#define PH_LOCK_EXCLUSIVE_WAITERS_INC 0x400000
|
||||
@@ -69,20 +135,37 @@ FORCEINLINE VOID PhpEnsureEventCreated(
|
||||
_Inout_ PHANDLE Handle
|
||||
)
|
||||
{
|
||||
HANDLE handle;
|
||||
HANDLE semaphoreHandle;
|
||||
OBJECT_ATTRIBUTES objectAttributes;
|
||||
|
||||
if (ReadPointerAcquire(Handle))
|
||||
return;
|
||||
|
||||
NtCreateSemaphore(&handle, SEMAPHORE_ALL_ACCESS, NULL, 0, MAXLONG);
|
||||
InitializeObjectAttributes(
|
||||
&objectAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
NtCreateSemaphore(
|
||||
&semaphoreHandle,
|
||||
SEMAPHORE_ALL_ACCESS,
|
||||
&objectAttributes,
|
||||
0,
|
||||
MAXLONG
|
||||
);
|
||||
|
||||
assert(semaphoreHandle);
|
||||
|
||||
if (_InterlockedCompareExchangePointer(
|
||||
Handle,
|
||||
handle,
|
||||
semaphoreHandle,
|
||||
NULL
|
||||
) != NULL)
|
||||
{
|
||||
NtClose(handle);
|
||||
NtClose(semaphoreHandle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-6
@@ -129,10 +129,9 @@ NTSTATUS PhCreateFilePool(
|
||||
}
|
||||
|
||||
// Create a section.
|
||||
status = NtCreateSection(
|
||||
status = PhCreateSection(
|
||||
§ionHandle,
|
||||
SECTION_ALL_ACCESS,
|
||||
NULL,
|
||||
&fileSize,
|
||||
!ReadOnly ? PAGE_READWRITE : PAGE_READONLY,
|
||||
SEC_COMMIT,
|
||||
@@ -754,14 +753,13 @@ NTSTATUS PhFppMapRange(
|
||||
sectionOffset.QuadPart = Offset;
|
||||
viewSize = Size;
|
||||
|
||||
status = NtMapViewOfSection(
|
||||
status = PhMapViewOfSection(
|
||||
Pool->SectionHandle,
|
||||
NtCurrentProcess(),
|
||||
&baseAddress,
|
||||
0,
|
||||
viewSize,
|
||||
§ionOffset,
|
||||
&viewSize,
|
||||
viewSize,
|
||||
ViewUnmap,
|
||||
0,
|
||||
!Pool->ReadOnly ? PAGE_READWRITE : PAGE_READONLY
|
||||
@@ -784,7 +782,7 @@ NTSTATUS PhFppUnmapRange(
|
||||
_In_ PVOID Base
|
||||
)
|
||||
{
|
||||
return NtUnmapViewOfSection(NtCurrentProcess(), Base);
|
||||
return PhUnmapViewOfSection(NtCurrentProcess(), Base);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+9
-7
@@ -799,7 +799,7 @@ NTSTATUS PhWriteStringAsUtf8FileStreamEx(
|
||||
{
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
PH_STRINGREF block;
|
||||
SIZE_T inPlaceUtf8Size;
|
||||
SIZE_T inPlaceUtf8Size = 0;
|
||||
PCHAR inPlaceUtf8 = NULL;
|
||||
PPH_BYTES utf8 = NULL;
|
||||
|
||||
@@ -822,17 +822,16 @@ NTSTATUS PhWriteStringAsUtf8FileStreamEx(
|
||||
{
|
||||
SIZE_T bytesInUtf8String;
|
||||
|
||||
if (!PhConvertUtf16ToUtf8Buffer(
|
||||
status = PhConvertUtf16ToUtf8Buffer(
|
||||
inPlaceUtf8,
|
||||
inPlaceUtf8Size,
|
||||
&bytesInUtf8String,
|
||||
block.Buffer,
|
||||
block.Length
|
||||
))
|
||||
{
|
||||
status = STATUS_INVALID_PARAMETER;
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
}
|
||||
|
||||
status = PhWriteFileStream(FileStream, inPlaceUtf8, (ULONG)bytesInUtf8String);
|
||||
}
|
||||
@@ -886,9 +885,12 @@ NTSTATUS PhWriteStringFormatAsUtf8FileStream(
|
||||
...
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, Format);
|
||||
status = PhWriteStringFormatAsUtf8FileStream_V(FileStream, Format, argptr);
|
||||
va_end(argptr);
|
||||
|
||||
return PhWriteStringFormatAsUtf8FileStream_V(FileStream, Format, argptr);
|
||||
return status;
|
||||
}
|
||||
|
||||
+34
-9
@@ -45,7 +45,26 @@ static CONST PH_STRINGREF PhpSizeUnitNamesCounted[7] =
|
||||
PH_STRINGREF_INIT(L"PB"),
|
||||
PH_STRINGREF_INIT(L"EB")
|
||||
};
|
||||
|
||||
CONST PH_STRINGREF PhPrefixUnitNamesCounted[7] =
|
||||
{
|
||||
PH_STRINGREF_INIT(L""),
|
||||
PH_STRINGREF_INIT(L"k"),
|
||||
PH_STRINGREF_INIT(L"M"),
|
||||
PH_STRINGREF_INIT(L"B"),
|
||||
PH_STRINGREF_INIT(L"T"),
|
||||
PH_STRINGREF_INIT(L"P"),
|
||||
PH_STRINGREF_INIT(L"E")
|
||||
};
|
||||
CONST PH_STRINGREF PhSiPrefixUnitNamesCounted[7] =
|
||||
{
|
||||
PH_STRINGREF_INIT(L" Bps"),
|
||||
PH_STRINGREF_INIT(L" Kbps"),
|
||||
PH_STRINGREF_INIT(L" Mbps"),
|
||||
PH_STRINGREF_INIT(L" Gbps"),
|
||||
PH_STRINGREF_INIT(L" Tbps"),
|
||||
PH_STRINGREF_INIT(L" Pbps"),
|
||||
PH_STRINGREF_INIT(L" Ebps")
|
||||
};
|
||||
static PH_INITONCE PhpFormatInitOnce = PH_INITONCE_INIT;
|
||||
static WCHAR PhpFormatDecimalSeparator = L'.';
|
||||
static WCHAR PhpFormatThousandSeparator = L',';
|
||||
@@ -56,20 +75,23 @@ VOID PhpFormatSingleToUtf8Locale(
|
||||
_In_ ULONG Type,
|
||||
_In_ LONG Precision,
|
||||
_Out_writes_bytes_(BufferLength) PSTR Buffer,
|
||||
_In_opt_ SIZE_T BufferLength
|
||||
_In_opt_ SIZE_T BufferLength,
|
||||
_Out_opt_ PSIZE_T ReturnLength
|
||||
)
|
||||
{
|
||||
if (!PhFormatSingleToUtf8(
|
||||
if (!NT_SUCCESS(PhFormatSingleToUtf8(
|
||||
Value,
|
||||
Type,
|
||||
Precision,
|
||||
Buffer,
|
||||
BufferLength,
|
||||
NULL
|
||||
))
|
||||
ReturnLength
|
||||
)))
|
||||
{
|
||||
if (Buffer)
|
||||
*Buffer = ANSI_NULL;
|
||||
if (ReturnLength)
|
||||
*ReturnLength = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -102,20 +124,23 @@ VOID PhpFormatDoubleToUtf8Locale(
|
||||
_In_ ULONG Type,
|
||||
_In_ LONG Precision,
|
||||
_Out_writes_bytes_(BufferLength) PSTR Buffer,
|
||||
_In_opt_ SIZE_T BufferLength
|
||||
_In_opt_ SIZE_T BufferLength,
|
||||
_Out_opt_ PSIZE_T ReturnLength
|
||||
)
|
||||
{
|
||||
if (!PhFormatDoubleToUtf8(
|
||||
if (!NT_SUCCESS(PhFormatDoubleToUtf8(
|
||||
Value,
|
||||
Type,
|
||||
Precision,
|
||||
Buffer,
|
||||
BufferLength,
|
||||
NULL
|
||||
))
|
||||
ReturnLength
|
||||
)))
|
||||
{
|
||||
if (Buffer)
|
||||
*Buffer = ANSI_NULL;
|
||||
if (ReturnLength)
|
||||
*ReturnLength = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+12
-3
@@ -284,6 +284,7 @@ CommonInt64Format:
|
||||
DataType value; \
|
||||
PSTR temp; \
|
||||
ULONG length; \
|
||||
SIZE_T returnLength; \
|
||||
\
|
||||
if ((Format)->Type & FormatUsePrecision) \
|
||||
{ \
|
||||
@@ -299,20 +300,28 @@ CommonInt64Format:
|
||||
\
|
||||
value = (Format)->u.FormatType; \
|
||||
temp = (PSTR)tempBuffer + 1; /* leave one character so we can insert a prefix if needed */ \
|
||||
returnLength = 0; \
|
||||
FormatToBufferUtf8( \
|
||||
value, \
|
||||
(Format)->Type, \
|
||||
precision, \
|
||||
temp, \
|
||||
sizeof(tempBuffer) - 1 \
|
||||
sizeof(tempBuffer) - 1, \
|
||||
&returnLength \
|
||||
); \
|
||||
\
|
||||
/* if (((Format)->Type & FormatForceDecimalPoint) && precision == 0) */ \
|
||||
/* _forcdecpt_l(tempBufferAnsi, PhpFormatUserLocale); */ \
|
||||
if ((Format)->Type & FormatCropZeros) \
|
||||
{ \
|
||||
PhpCropZeros(temp); \
|
||||
\
|
||||
length = (ULONG)strlen(temp); \
|
||||
\
|
||||
length = (ULONG)strlen(temp); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
length = (ULONG)returnLength; \
|
||||
} \
|
||||
\
|
||||
if (temp[0] == '-') \
|
||||
{ \
|
||||
|
||||
+240
-12
@@ -14,16 +14,20 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhFormatSingleToUtf8(
|
||||
extern NTSTATUS PhErrcToNtStatus(
|
||||
_In_ std::errc ec
|
||||
);
|
||||
|
||||
NTSTATUS PhFormatSingleToUtf8(
|
||||
_In_ FLOAT Value,
|
||||
_In_ ULONG Type,
|
||||
_In_ ULONG Precision,
|
||||
_In_ LONG Precision,
|
||||
_Out_writes_bytes_(BufferLength) PSTR Buffer,
|
||||
_In_opt_ SIZE_T BufferLength,
|
||||
_Out_opt_ PSIZE_T ReturnLength
|
||||
)
|
||||
{
|
||||
#if defined(PH_TOCHARS_BUFFER)
|
||||
chars_format format = chars_format::fixed;
|
||||
to_chars_result result;
|
||||
SIZE_T returnLength;
|
||||
@@ -43,12 +47,12 @@ BOOLEAN PhFormatSingleToUtf8(
|
||||
);
|
||||
|
||||
if (result.ec != static_cast<std::errc>(0))
|
||||
return FALSE;
|
||||
return PhErrcToNtStatus(result.ec);
|
||||
|
||||
returnLength = result.ptr - buffer;
|
||||
|
||||
if (returnLength == 0)
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
|
||||
// This could be removed in favor of directly passing the input buffer to std:to_chars but
|
||||
// for now use memcpy so that failures writing a value don't touch the input buffer (dmex)
|
||||
@@ -58,19 +62,53 @@ BOOLEAN PhFormatSingleToUtf8(
|
||||
if (ReturnLength)
|
||||
*ReturnLength = returnLength;
|
||||
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
#else
|
||||
chars_format format;
|
||||
to_chars_result result;
|
||||
SIZE_T returnLength;
|
||||
|
||||
if (FlagOn(Type, FormatStandardForm))
|
||||
format = chars_format::general;
|
||||
else if (FlagOn(Type, FormatHexadecimalForm))
|
||||
format = chars_format::hex;
|
||||
else
|
||||
format = chars_format::fixed;
|
||||
|
||||
result = to_chars(
|
||||
Buffer,
|
||||
Buffer + BufferLength - sizeof(ANSI_NULL), // Reserve space for null terminator
|
||||
Value,
|
||||
format,
|
||||
Precision
|
||||
);
|
||||
|
||||
if (result.ec != static_cast<std::errc>(0))
|
||||
return PhErrcToNtStatus(result.ec);
|
||||
|
||||
returnLength = result.ptr - Buffer;
|
||||
|
||||
if (ReturnLength)
|
||||
{
|
||||
*ReturnLength = returnLength;
|
||||
}
|
||||
|
||||
Buffer[returnLength] = ANSI_NULL;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhFormatDoubleToUtf8(
|
||||
NTSTATUS PhFormatDoubleToUtf8(
|
||||
_In_ DOUBLE Value,
|
||||
_In_ ULONG Type,
|
||||
_In_ ULONG Precision,
|
||||
_In_ LONG Precision,
|
||||
_Out_writes_bytes_(BufferLength) PSTR Buffer,
|
||||
_In_opt_ SIZE_T BufferLength,
|
||||
_Out_opt_ PSIZE_T ReturnLength
|
||||
)
|
||||
{
|
||||
#if defined(PH_TOCHARS_BUFFER)
|
||||
chars_format format = chars_format::fixed;
|
||||
to_chars_result result;
|
||||
SIZE_T returnLength;
|
||||
@@ -90,12 +128,12 @@ BOOLEAN PhFormatDoubleToUtf8(
|
||||
);
|
||||
|
||||
if (result.ec != static_cast<std::errc>(0))
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
|
||||
returnLength = result.ptr - buffer;
|
||||
|
||||
if (returnLength == 0)
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
|
||||
// This could be removed in favor of directly passing the input buffer to std:to_chars but
|
||||
// for now use memcpy so that failures writing a value don't touch the input buffer (dmex)
|
||||
@@ -105,5 +143,195 @@ BOOLEAN PhFormatDoubleToUtf8(
|
||||
if (ReturnLength)
|
||||
*ReturnLength = returnLength;
|
||||
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
#else
|
||||
chars_format format;
|
||||
to_chars_result result;
|
||||
SIZE_T returnLength;
|
||||
|
||||
if (FlagOn(Type, FormatStandardForm))
|
||||
format = chars_format::general;
|
||||
else if (FlagOn(Type, FormatHexadecimalForm))
|
||||
format = chars_format::hex;
|
||||
else
|
||||
format = chars_format::fixed;
|
||||
|
||||
result = to_chars(
|
||||
Buffer,
|
||||
Buffer + BufferLength - sizeof(ANSI_NULL), // Reserve space for null terminator
|
||||
Value,
|
||||
format,
|
||||
Precision
|
||||
);
|
||||
|
||||
if (result.ec != static_cast<std::errc>(0))
|
||||
return PhErrcToNtStatus(result.ec);
|
||||
|
||||
returnLength = result.ptr - Buffer;
|
||||
|
||||
if (ReturnLength)
|
||||
{
|
||||
*ReturnLength = returnLength;
|
||||
}
|
||||
|
||||
Buffer[returnLength] = ANSI_NULL;
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
NTSTATUS PhErrcToNtStatus(
|
||||
_In_ std::errc ec
|
||||
)
|
||||
{
|
||||
switch (ec)
|
||||
{
|
||||
case std::errc::address_family_not_supported:
|
||||
return STATUS_NOT_SUPPORTED;
|
||||
case std::errc::address_in_use:
|
||||
return STATUS_ADDRESS_ALREADY_ASSOCIATED;
|
||||
case std::errc::address_not_available:
|
||||
return STATUS_ADDRESS_NOT_ASSOCIATED;
|
||||
case std::errc::already_connected:
|
||||
return STATUS_CONNECTION_ACTIVE;
|
||||
case std::errc::argument_list_too_long:
|
||||
case std::errc::argument_out_of_domain:
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
case std::errc::bad_address:
|
||||
return STATUS_INVALID_ADDRESS;
|
||||
case std::errc::bad_file_descriptor:
|
||||
return STATUS_INVALID_HANDLE;
|
||||
case std::errc::bad_message:
|
||||
return STATUS_DATA_ERROR;
|
||||
case std::errc::broken_pipe:
|
||||
return STATUS_PIPE_BROKEN;
|
||||
case std::errc::connection_aborted:
|
||||
return STATUS_CONNECTION_ABORTED;
|
||||
case std::errc::connection_already_in_progress:
|
||||
return STATUS_CONNECTION_ACTIVE;
|
||||
case std::errc::connection_refused:
|
||||
return STATUS_CONNECTION_REFUSED;
|
||||
case std::errc::connection_reset:
|
||||
return STATUS_CONNECTION_RESET;
|
||||
case std::errc::cross_device_link:
|
||||
return STATUS_NOT_SAME_DEVICE;
|
||||
case std::errc::destination_address_required:
|
||||
return STATUS_DESTINATION_ELEMENT_FULL;
|
||||
case std::errc::device_or_resource_busy:
|
||||
return STATUS_DEVICE_BUSY;
|
||||
case std::errc::directory_not_empty:
|
||||
return STATUS_DIRECTORY_NOT_EMPTY;
|
||||
case std::errc::executable_format_error:
|
||||
return STATUS_INVALID_IMAGE_FORMAT;
|
||||
case std::errc::file_exists:
|
||||
return STATUS_OBJECT_NAME_COLLISION;
|
||||
case std::errc::file_too_large:
|
||||
return STATUS_FILE_TOO_LARGE;
|
||||
case std::errc::filename_too_long:
|
||||
return STATUS_NAME_TOO_LONG;
|
||||
case std::errc::function_not_supported:
|
||||
return STATUS_NOT_SUPPORTED;
|
||||
case std::errc::host_unreachable:
|
||||
return STATUS_HOST_UNREACHABLE;
|
||||
case std::errc::identifier_removed:
|
||||
return STATUS_OBJECT_NAME_NOT_FOUND;
|
||||
case std::errc::illegal_byte_sequence:
|
||||
return STATUS_ILLEGAL_CHARACTER;
|
||||
case std::errc::inappropriate_io_control_operation:
|
||||
return STATUS_INVALID_DEVICE_REQUEST;
|
||||
case std::errc::interrupted:
|
||||
return STATUS_ALERTED;
|
||||
case std::errc::invalid_argument:
|
||||
case std::errc::invalid_seek:
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
case std::errc::io_error:
|
||||
return STATUS_IO_DEVICE_ERROR;
|
||||
case std::errc::is_a_directory:
|
||||
return STATUS_FILE_IS_A_DIRECTORY;
|
||||
case std::errc::message_size:
|
||||
return STATUS_BUFFER_OVERFLOW;
|
||||
case std::errc::network_down:
|
||||
return STATUS_NETWORK_UNREACHABLE;
|
||||
case std::errc::network_reset:
|
||||
return STATUS_CONNECTION_RESET;
|
||||
case std::errc::network_unreachable:
|
||||
return STATUS_NETWORK_UNREACHABLE;
|
||||
case std::errc::no_buffer_space:
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
case std::errc::no_child_process:
|
||||
return STATUS_INVALID_CID;
|
||||
case std::errc::no_link:
|
||||
return STATUS_NOT_FOUND;
|
||||
case std::errc::no_lock_available:
|
||||
return STATUS_LOCK_NOT_GRANTED;
|
||||
case std::errc::no_message:
|
||||
return STATUS_NO_DATA_DETECTED;
|
||||
case std::errc::no_protocol_option:
|
||||
return STATUS_PROTOCOL_UNREACHABLE;
|
||||
case std::errc::no_space_on_device:
|
||||
return STATUS_DISK_FULL;
|
||||
case std::errc::no_such_device_or_address:
|
||||
return STATUS_INVALID_ADDRESS;
|
||||
case std::errc::no_such_device:
|
||||
return STATUS_NO_SUCH_DEVICE;
|
||||
case std::errc::no_such_file_or_directory:
|
||||
return STATUS_OBJECT_NAME_NOT_FOUND;
|
||||
case std::errc::no_such_process:
|
||||
return STATUS_INVALID_CID;
|
||||
case std::errc::not_a_directory:
|
||||
return STATUS_NOT_A_DIRECTORY;
|
||||
case std::errc::not_a_socket:
|
||||
return STATUS_OBJECT_TYPE_MISMATCH;
|
||||
case std::errc::not_connected:
|
||||
return STATUS_CONNECTION_DISCONNECTED;
|
||||
case std::errc::not_enough_memory:
|
||||
return STATUS_NO_MEMORY;
|
||||
case std::errc::not_supported:
|
||||
return STATUS_NOT_SUPPORTED;
|
||||
case std::errc::operation_canceled:
|
||||
return STATUS_CANCELLED;
|
||||
case std::errc::operation_in_progress:
|
||||
return STATUS_PENDING;
|
||||
case std::errc::operation_not_permitted:
|
||||
return STATUS_PRIVILEGE_NOT_HELD;
|
||||
case std::errc::operation_not_supported:
|
||||
return STATUS_NOT_SUPPORTED;
|
||||
case std::errc::operation_would_block:
|
||||
return STATUS_DEVICE_BUSY;
|
||||
case std::errc::owner_dead:
|
||||
return STATUS_INVALID_CID;
|
||||
case std::errc::permission_denied:
|
||||
return STATUS_ACCESS_DENIED;
|
||||
case std::errc::protocol_error:
|
||||
case std::errc::protocol_not_supported:
|
||||
return STATUS_PROTOCOL_UNREACHABLE;
|
||||
case std::errc::read_only_file_system:
|
||||
return STATUS_MEDIA_WRITE_PROTECTED;
|
||||
case std::errc::resource_deadlock_would_occur:
|
||||
return STATUS_POSSIBLE_DEADLOCK;
|
||||
case std::errc::resource_unavailable_try_again:
|
||||
return STATUS_DEVICE_BUSY;
|
||||
case std::errc::result_out_of_range:
|
||||
return STATUS_INTEGER_OVERFLOW;
|
||||
case std::errc::state_not_recoverable:
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
case std::errc::text_file_busy:
|
||||
return STATUS_FILE_LOCK_CONFLICT;
|
||||
case std::errc::timed_out:
|
||||
return STATUS_TIMEOUT;
|
||||
case std::errc::too_many_files_open_in_system:
|
||||
case std::errc::too_many_files_open:
|
||||
return STATUS_TOO_MANY_OPENED_FILES;
|
||||
case std::errc::too_many_links:
|
||||
case std::errc::too_many_symbolic_link_levels:
|
||||
return STATUS_TOO_MANY_LINKS;
|
||||
case std::errc::value_too_large:
|
||||
return STATUS_INTEGER_OVERFLOW;
|
||||
case std::errc::wrong_protocol_type:
|
||||
return STATUS_PROTOCOL_UNREACHABLE;
|
||||
case std::errc():
|
||||
return STATUS_SUCCESS;
|
||||
default:
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
}
|
||||
|
||||
+75
-53
@@ -11,28 +11,26 @@
|
||||
*/
|
||||
|
||||
#include <ph.h>
|
||||
#include <phconsole.h>
|
||||
#include <phintrnl.h>
|
||||
|
||||
#include <trace.h>
|
||||
|
||||
VOID PhInitializeRuntimeInformation(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhInitializeSystemInformation(
|
||||
NTSTATUS PhInitializeSystemInformation(
|
||||
VOID
|
||||
);
|
||||
|
||||
VOID PhInitializeWindowsInformation(
|
||||
NTSTATUS PhInitializeWindowsInformation(
|
||||
VOID
|
||||
);
|
||||
|
||||
BOOLEAN PhHeapInitialization(
|
||||
NTSTATUS PhHeapInitialization(
|
||||
VOID
|
||||
);
|
||||
|
||||
BOOLEAN PhInitializeProcessorInformation(
|
||||
NTSTATUS PhInitializeProcessorInformation(
|
||||
VOID
|
||||
);
|
||||
|
||||
@@ -50,32 +48,30 @@ PHLIB_STATISTICS_BLOCK PhLibStatisticsBlock;
|
||||
#endif
|
||||
|
||||
NTSTATUS PhInitializePhLib(
|
||||
_In_ PCWSTR ApplicationName,
|
||||
_In_ PVOID ImageBaseAddress
|
||||
_In_ PCWSTR ApplicationName
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
|
||||
WPP_INIT_TRACING(ApplicationName);
|
||||
|
||||
PhTraceInfo("%ls initializing", ApplicationName);
|
||||
|
||||
PhApplicationName = ApplicationName;
|
||||
PhInstanceHandle = ImageBaseAddress;
|
||||
PhInstanceHandle = NtCurrentImageBase();
|
||||
|
||||
PhInitializeRuntimeInformation();
|
||||
PhInitializeWindowsInformation();
|
||||
PhInitializeSystemInformation();
|
||||
|
||||
if (!PhHeapInitialization())
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
|
||||
if (!PhQueuedLockInitialization())
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
|
||||
if (!PhRefInitialization())
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
|
||||
if (!PhBaseInitialization())
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
if (!NT_SUCCESS(status = PhHeapInitialization()))
|
||||
return status;
|
||||
if (!NT_SUCCESS(status = PhQueuedLockInitialization()))
|
||||
return status;
|
||||
if (!NT_SUCCESS(status = PhRefInitialization()))
|
||||
return status;
|
||||
if (!NT_SUCCESS(status = PhBaseInitialization()))
|
||||
return status;
|
||||
|
||||
PhInitializeProcessorInformation();
|
||||
|
||||
@@ -115,10 +111,11 @@ VOID PhInitializeRuntimeInformation(
|
||||
//_wsetlocale(LC_ALL, L".UTF8");
|
||||
}
|
||||
|
||||
VOID PhInitializeSystemInformation(
|
||||
NTSTATUS PhInitializeSystemInformation(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
SYSTEM_BASIC_INFORMATION basicInfo = { 0 };
|
||||
|
||||
PhSystemBasicInformation.PageSize = PAGE_SIZE;
|
||||
@@ -129,12 +126,14 @@ VOID PhInitializeSystemInformation(
|
||||
PhSystemBasicInformation.MaximumUserModeAddress = 0x10000;
|
||||
PhSystemBasicInformation.ActiveProcessorsAffinityMask = USHRT_MAX;
|
||||
|
||||
if (NT_SUCCESS(NtQuerySystemInformation(
|
||||
status = NtQuerySystemInformation(
|
||||
SystemBasicInformation,
|
||||
&basicInfo,
|
||||
sizeof(SYSTEM_BASIC_INFORMATION),
|
||||
NULL
|
||||
)))
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
PhSystemBasicInformation.PageSize = (USHORT)basicInfo.PageSize;
|
||||
PhSystemBasicInformation.NumberOfProcessors = (USHORT)basicInfo.NumberOfProcessors;
|
||||
@@ -144,12 +143,17 @@ VOID PhInitializeSystemInformation(
|
||||
PhSystemBasicInformation.MaximumUserModeAddress = basicInfo.MaximumUserModeAddress;
|
||||
PhSystemBasicInformation.ActiveProcessorsAffinityMask = basicInfo.ActiveProcessorsAffinityMask;
|
||||
}
|
||||
|
||||
PhTraceInfo("InitializeSystemInformation: %!STATUS!", status);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
VOID PhInitializeWindowsInformation(
|
||||
NTSTATUS PhInitializeWindowsInformation(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
RTL_OSVERSIONINFOEX versionInfo;
|
||||
ULONG majorVersion;
|
||||
ULONG minorVersion;
|
||||
@@ -158,10 +162,10 @@ VOID PhInitializeWindowsInformation(
|
||||
memset(&versionInfo, 0, sizeof(RTL_OSVERSIONINFOEX));
|
||||
versionInfo.OSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEX);
|
||||
|
||||
if (!NT_SUCCESS(RtlGetVersion(&versionInfo)))
|
||||
if (!NT_SUCCESS(status = RtlGetVersion(&versionInfo)))
|
||||
{
|
||||
WindowsVersion = WINDOWS_ANCIENT;
|
||||
return;
|
||||
return status;
|
||||
}
|
||||
|
||||
memcpy(&PhOsVersion, &versionInfo, sizeof(RTL_OSVERSIONINFOEX));
|
||||
@@ -276,54 +280,67 @@ VOID PhInitializeWindowsInformation(
|
||||
{
|
||||
WindowsVersion = WINDOWS_NEW;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
BOOLEAN PhHeapInitialization(
|
||||
NTSTATUS PhHeapInitialization(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
#if defined(PH_DEBUG_HEAP)
|
||||
PhHeapHandle = RtlProcessHeap();
|
||||
#else
|
||||
#if !defined(PH_DEBUG_HEAP)
|
||||
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||
|
||||
if (WindowsVersion >= WINDOWS_8)
|
||||
{
|
||||
PhHeapHandle = RtlCreateHeap(
|
||||
if (PhHeapHandle = RtlCreateHeap(
|
||||
HEAP_GROWABLE | HEAP_CREATE_SEGMENT_HEAP | HEAP_CLASS_1,
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
))
|
||||
{
|
||||
status = STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
if (!PhHeapHandle)
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
PhHeapHandle = RtlCreateHeap(
|
||||
if (PhHeapHandle = RtlCreateHeap(
|
||||
HEAP_GROWABLE | HEAP_CLASS_1,
|
||||
NULL,
|
||||
2 * 1024 * 1024, // 2 MB
|
||||
1024 * 1024, // 1 MB
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
))
|
||||
{
|
||||
status = STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (!PhHeapHandle)
|
||||
return FALSE;
|
||||
|
||||
const ULONG defaultHeapCompatibilityMode = HEAP_COMPATIBILITY_MODE_LFH;
|
||||
RtlSetHeapInformation(
|
||||
PhHeapHandle,
|
||||
HeapCompatibilityInformation,
|
||||
&defaultHeapCompatibilityMode,
|
||||
sizeof(ULONG)
|
||||
);
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
const ULONG defaultHeapCompatibilityMode = HEAP_COMPATIBILITY_MODE_LFH;
|
||||
RtlSetHeapInformation(
|
||||
PhHeapHandle,
|
||||
HeapCompatibilityInformation,
|
||||
&defaultHeapCompatibilityMode,
|
||||
sizeof(ULONG)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
PhTraceInfo("HeapInitialization: %!STATUS!", status);
|
||||
return status;
|
||||
#else
|
||||
PhHeapHandle = RtlProcessHeap();
|
||||
return STATUS_SUCCESS;
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOLEAN PhInitializeProcessorInformation(
|
||||
NTSTATUS PhInitializeProcessorInformation(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
@@ -337,20 +354,24 @@ BOOLEAN PhInitializeProcessorInformation(
|
||||
PhSystemProcessorInformation.NumberOfProcessors = PhSystemBasicInformation.NumberOfProcessors;
|
||||
PhSystemProcessorInformation.NumberOfProcessorGroups = 1;
|
||||
PhSystemProcessorInformation.ActiveProcessorsAffinityMasks = &PhSystemBasicInformation.ActiveProcessorsAffinityMask;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
NTSTATUS status;
|
||||
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX processorInformation;
|
||||
ULONG processorInformationLength;
|
||||
USHORT numberOfProcessorGroups = 0;
|
||||
USHORT numberOfProcessors = 0;
|
||||
USHORT i;
|
||||
|
||||
if (NT_SUCCESS(PhGetSystemLogicalProcessorInformation(
|
||||
status = PhGetSystemLogicalProcessorInformation(
|
||||
RelationGroup,
|
||||
&processorInformation,
|
||||
&processorInformationLength
|
||||
)))
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
numberOfProcessorGroups = processorInformation->Group.ActiveGroupCount;
|
||||
|
||||
@@ -388,12 +409,13 @@ BOOLEAN PhInitializeProcessorInformation(
|
||||
PhSystemProcessorInformation.SingleProcessorGroup = TRUE;
|
||||
PhSystemProcessorInformation.NumberOfProcessors = PhSystemBasicInformation.NumberOfProcessors;
|
||||
PhSystemProcessorInformation.NumberOfProcessorGroups = 1;
|
||||
PhSystemProcessorInformation.ActiveProcessorsAffinityMasks = PhAllocate(sizeof(KAFFINITY));
|
||||
PhSystemProcessorInformation.ActiveProcessorsAffinityMasks[0] = PhSystemBasicInformation.ActiveProcessorsAffinityMask;
|
||||
PhSystemProcessorInformation.ActiveProcessorsAffinityMasks = &PhSystemBasicInformation.ActiveProcessorsAffinityMask;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
PhTraceInfo("InitializeProcessorInformation: %!STATUS!", status);
|
||||
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
_Use_decl_annotations_
|
||||
|
||||
+150
-31
@@ -23,21 +23,32 @@
|
||||
#include <wincodec.h>
|
||||
#include <uxtheme.h>
|
||||
|
||||
_Function_class_(PH_HASHTABLE_EQUAL_FUNCTION)
|
||||
BOOLEAN NTAPI PhpWindowContextHashtableEqualFunction(
|
||||
_In_ PVOID Entry1,
|
||||
_In_ PVOID Entry2
|
||||
);
|
||||
|
||||
_Function_class_(PH_HASHTABLE_HASH_FUNCTION)
|
||||
ULONG NTAPI PhpWindowContextHashtableHashFunction(
|
||||
_In_ PVOID Entry
|
||||
);
|
||||
|
||||
_Function_class_(PH_HASHTABLE_EQUAL_FUNCTION)
|
||||
BOOLEAN NTAPI PhpWindowCallbackHashtableEqualFunction(
|
||||
_In_ PVOID Entry1,
|
||||
_In_ PVOID Entry2
|
||||
);
|
||||
|
||||
_Function_class_(PH_HASHTABLE_HASH_FUNCTION)
|
||||
ULONG NTAPI PhpWindowCallbackHashtableHashFunction(
|
||||
_In_ PVOID Entry
|
||||
);
|
||||
|
||||
VOID NTAPI PhWindowCallbackHashtableFlsCallback(
|
||||
_In_ PVOID FlsData
|
||||
);
|
||||
|
||||
typedef struct _PH_WINDOW_PROPERTY_CONTEXT
|
||||
{
|
||||
ULONG PropertyHash;
|
||||
@@ -59,8 +70,7 @@ static PH_QUEUED_LOCK SharedIconCacheLock = PH_QUEUED_LOCK_INIT;
|
||||
|
||||
static PPH_HASHTABLE WindowCallbackHashTable = NULL;
|
||||
static PH_QUEUED_LOCK WindowCallbackListLock = PH_QUEUED_LOCK_INIT;
|
||||
static PPH_HASHTABLE WindowContextHashTable = NULL;
|
||||
static PH_QUEUED_LOCK WindowContextListLock = PH_QUEUED_LOCK_INIT;
|
||||
static ULONG WindowCallbackFlsIndex = FLS_OUT_OF_INDEXES;
|
||||
|
||||
static __typeof__(&OpenThemeDataForDpi) OpenThemeDataForDpi_I = NULL;
|
||||
static __typeof__(&OpenThemeData) OpenThemeData_I = NULL;
|
||||
@@ -93,18 +103,15 @@ VOID PhGuiSupportInitialization(
|
||||
{
|
||||
PVOID baseAddress;
|
||||
|
||||
//RtlFlsAlloc(PhWindowCallbackHashtableFlsCallback, &WindowCallbackFlsIndex);
|
||||
WindowCallbackFlsIndex = FlsAlloc(PhWindowCallbackHashtableFlsCallback);
|
||||
|
||||
WindowCallbackHashTable = PhCreateHashtable(
|
||||
sizeof(PH_PLUGIN_WINDOW_CALLBACK_REGISTRATION),
|
||||
PhpWindowCallbackHashtableEqualFunction,
|
||||
PhpWindowCallbackHashtableHashFunction,
|
||||
10
|
||||
);
|
||||
WindowContextHashTable = PhCreateHashtable(
|
||||
sizeof(PH_WINDOW_PROPERTY_CONTEXT),
|
||||
PhpWindowContextHashtableEqualFunction,
|
||||
PhpWindowContextHashtableHashFunction,
|
||||
10
|
||||
);
|
||||
|
||||
if (baseAddress = PhLoadLibrary(L"uxtheme.dll"))
|
||||
{
|
||||
@@ -2341,6 +2348,7 @@ VOID PhLayoutManagerLayout(
|
||||
}
|
||||
}
|
||||
|
||||
_Use_decl_annotations_
|
||||
BOOLEAN NTAPI PhpWindowContextHashtableEqualFunction(
|
||||
_In_ PVOID Entry1,
|
||||
_In_ PVOID Entry2
|
||||
@@ -2354,6 +2362,7 @@ BOOLEAN NTAPI PhpWindowContextHashtableEqualFunction(
|
||||
entry1->PropertyHash == entry2->PropertyHash;
|
||||
}
|
||||
|
||||
_Use_decl_annotations_
|
||||
ULONG NTAPI PhpWindowContextHashtableHashFunction(
|
||||
_In_ PVOID Entry
|
||||
)
|
||||
@@ -2363,6 +2372,40 @@ ULONG NTAPI PhpWindowContextHashtableHashFunction(
|
||||
return PhHashIntPtr((ULONG_PTR)entry->WindowHandle) ^ entry->PropertyHash; // PhHashInt32
|
||||
}
|
||||
|
||||
VOID NTAPI PhWindowCallbackHashtableFlsCallback(
|
||||
_In_ PVOID FlsData
|
||||
)
|
||||
{
|
||||
PPH_HASHTABLE hashtable = (PPH_HASHTABLE)FlsData;
|
||||
|
||||
PhClearReference(&hashtable);
|
||||
}
|
||||
|
||||
static PPH_HASHTABLE PhGetWindowContextHashTable(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
PPH_HASHTABLE hashtable;
|
||||
|
||||
if (hashtable = FlsGetValue(WindowCallbackFlsIndex))
|
||||
return hashtable;
|
||||
|
||||
hashtable = PhCreateHashtable(
|
||||
sizeof(PH_WINDOW_PROPERTY_CONTEXT),
|
||||
PhpWindowContextHashtableEqualFunction,
|
||||
PhpWindowContextHashtableHashFunction,
|
||||
5
|
||||
);
|
||||
|
||||
if (!FlsSetValue(WindowCallbackFlsIndex, hashtable))
|
||||
{
|
||||
PhShowStatus(NULL, L"Unable to create the window context.", 0, PhGetLastError());
|
||||
RtlFailFast(FAST_FAIL_INVALID_FLS_DATA);
|
||||
}
|
||||
|
||||
return hashtable;
|
||||
}
|
||||
|
||||
PVOID PhGetWindowContext(
|
||||
_In_ HWND WindowHandle,
|
||||
_In_ ULONG PropertyHash
|
||||
@@ -2374,9 +2417,7 @@ PVOID PhGetWindowContext(
|
||||
lookupEntry.WindowHandle = WindowHandle;
|
||||
lookupEntry.PropertyHash = PropertyHash;
|
||||
|
||||
PhAcquireQueuedLockShared(&WindowContextListLock);
|
||||
entry = PhFindEntryHashtable(WindowContextHashTable, &lookupEntry);
|
||||
PhReleaseQueuedLockShared(&WindowContextListLock);
|
||||
entry = PhFindEntryHashtable(PhGetWindowContextHashTable(), &lookupEntry);
|
||||
|
||||
if (entry)
|
||||
return entry->Context;
|
||||
@@ -2396,9 +2437,7 @@ VOID PhSetWindowContext(
|
||||
entry.PropertyHash = PropertyHash;
|
||||
entry.Context = Context;
|
||||
|
||||
PhAcquireQueuedLockExclusive(&WindowContextListLock);
|
||||
PhAddEntryHashtable(WindowContextHashTable, &entry);
|
||||
PhReleaseQueuedLockExclusive(&WindowContextListLock);
|
||||
PhAddEntryHashtable(PhGetWindowContextHashTable(), &entry);
|
||||
}
|
||||
|
||||
VOID PhRemoveWindowContext(
|
||||
@@ -2411,17 +2450,50 @@ VOID PhRemoveWindowContext(
|
||||
lookupEntry.WindowHandle = WindowHandle;
|
||||
lookupEntry.PropertyHash = PropertyHash;
|
||||
|
||||
PhAcquireQueuedLockExclusive(&WindowContextListLock);
|
||||
PhRemoveEntryHashtable(WindowContextHashTable, &lookupEntry);
|
||||
PhReleaseQueuedLockExclusive(&WindowContextListLock);
|
||||
PhRemoveEntryHashtable(PhGetWindowContextHashTable(), &lookupEntry);
|
||||
}
|
||||
|
||||
VOID PhEnumWindows(
|
||||
_In_ PH_ENUM_CALLBACK Callback,
|
||||
typedef struct _PH_WINDOW_ENUM_CONTEXT
|
||||
{
|
||||
_Function_class_(PH_WINDOW_ENUM_CALLBACK)
|
||||
_In_ PPH_WINDOW_ENUM_CALLBACK Callback;
|
||||
_In_opt_ PVOID Context;
|
||||
} PH_WINDOW_ENUM_CONTEXT, *PPH_WINDOW_ENUM_CONTEXT;
|
||||
|
||||
static BOOL CALLBACK PhEnumWindowsCallback(
|
||||
_In_ HWND WindowHandle,
|
||||
_In_opt_ LPARAM Context
|
||||
)
|
||||
{
|
||||
PPH_WINDOW_ENUM_CONTEXT context = (PPH_WINDOW_ENUM_CONTEXT)Context;
|
||||
|
||||
if (context->Callback(WindowHandle, context->Context))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enumerates all top-level windows on the screen.
|
||||
*
|
||||
* \param Callback The callback function to be called for each child window.
|
||||
* \param Context An optional context parameter to be passed to the callback function.
|
||||
*/
|
||||
NTSTATUS PhEnumWindows(
|
||||
_In_ PH_WINDOW_ENUM_CALLBACK Callback,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
EnumWindows((WNDENUMPROC)Callback, (LPARAM)Context);
|
||||
PH_WINDOW_ENUM_CONTEXT context;
|
||||
|
||||
memset(&context, 0, sizeof(PH_WINDOW_ENUM_CONTEXT));
|
||||
context.Callback = Callback;
|
||||
context.Context = Context;
|
||||
|
||||
if (EnumWindows(PhEnumWindowsCallback, (LPARAM)&context))
|
||||
return STATUS_SUCCESS;
|
||||
|
||||
return PhGetLastWin32ErrorAsNtStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2432,14 +2504,21 @@ VOID PhEnumWindows(
|
||||
* \param Callback The callback function to be called for each child window.
|
||||
* \param Context An optional context parameter to be passed to the callback function.
|
||||
*/
|
||||
VOID PhEnumChildWindows(
|
||||
NTSTATUS PhEnumChildWindows(
|
||||
_In_opt_ HWND WindowHandle,
|
||||
_In_ ULONG Limit,
|
||||
_In_ PH_CHILD_ENUM_CALLBACK Callback,
|
||||
_In_ PH_WINDOW_ENUM_CALLBACK Callback,
|
||||
_In_opt_ PVOID Context
|
||||
)
|
||||
{
|
||||
EnumChildWindows(WindowHandle, (WNDENUMPROC)Callback, (LPARAM)Context);
|
||||
PH_WINDOW_ENUM_CONTEXT context;
|
||||
|
||||
memset(&context, 0, sizeof(PH_WINDOW_ENUM_CONTEXT));
|
||||
context.Callback = Callback;
|
||||
context.Context = Context;
|
||||
|
||||
if (EnumChildWindows(WindowHandle, PhEnumWindowsCallback, (LPARAM)&context))
|
||||
return STATUS_SUCCESS;
|
||||
|
||||
//HWND childWindow = NULL;
|
||||
//ULONG i = 0;
|
||||
@@ -2451,6 +2530,9 @@ VOID PhEnumChildWindows(
|
||||
//
|
||||
// i++;
|
||||
//}
|
||||
|
||||
// Note: EnumChildWindows doesn't support GetLastError. (dmex)
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
typedef struct _GET_PROCESS_MAIN_WINDOW_CONTEXT
|
||||
@@ -2462,25 +2544,26 @@ typedef struct _GET_PROCESS_MAIN_WINDOW_CONTEXT
|
||||
BOOLEAN SkipInvisible;
|
||||
} GET_PROCESS_MAIN_WINDOW_CONTEXT, *PGET_PROCESS_MAIN_WINDOW_CONTEXT;
|
||||
|
||||
BOOL CALLBACK PhpGetProcessMainWindowEnumWindowsProc(
|
||||
BOOLEAN CALLBACK PhpGetProcessMainWindowEnumWindowsProc(
|
||||
_In_ HWND WindowHandle,
|
||||
_In_ PVOID Context
|
||||
)
|
||||
{
|
||||
PGET_PROCESS_MAIN_WINDOW_CONTEXT context = (PGET_PROCESS_MAIN_WINDOW_CONTEXT)Context;
|
||||
ULONG processId;
|
||||
CLIENT_ID clientId;
|
||||
WINDOWINFO windowInfo;
|
||||
|
||||
if (context->SkipInvisible && !IsWindowVisible(WindowHandle))
|
||||
return TRUE;
|
||||
|
||||
GetWindowThreadProcessId(WindowHandle, &processId);
|
||||
if (!NT_SUCCESS(PhGetWindowClientId(WindowHandle, &clientId)))
|
||||
return TRUE;
|
||||
|
||||
//if (UlongToHandle(processId) == context->ProcessId && (context->SkipInvisible ?
|
||||
// !((parentWindow = GetParent(WindowHandle)) && IsWindowVisible(parentWindow)) && // skip windows with a visible parent
|
||||
// PhGetWindowTextEx(WindowHandle, PH_GET_WINDOW_TEXT_INTERNAL | PH_GET_WINDOW_TEXT_LENGTH_ONLY, NULL) != 0 : TRUE)) // skip windows with no title
|
||||
|
||||
if (UlongToHandle(processId) == context->ProcessId)
|
||||
if (clientId.UniqueProcess == context->ProcessId)
|
||||
{
|
||||
if (!context->ImmersiveWindow && context->IsImmersive &&
|
||||
GetProp(WindowHandle, L"Windows.ImmersiveShell.IdentifyAsMainCoreWindow"))
|
||||
@@ -2562,6 +2645,14 @@ ULONG PhGetDialogItemValue(
|
||||
return (ULONG)controlValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the text of a control in a dialog box to the string representation of a specified integer value.
|
||||
*
|
||||
* \param WindowHandle The handle of the parent window.
|
||||
* \param ControlID The control to be changed.
|
||||
* \param Value The integer value used to generate the item text.
|
||||
* \param Signed Indicates whether the Value parameter is signed or unsigned.
|
||||
*/
|
||||
VOID PhSetDialogItemValue(
|
||||
_In_ HWND WindowHandle,
|
||||
_In_ LONG ControlID,
|
||||
@@ -2583,7 +2674,14 @@ VOID PhSetDialogItemValue(
|
||||
}
|
||||
}
|
||||
|
||||
VOID PhSetDialogItemText(
|
||||
/**
|
||||
* Sets the title or text of a control in a dialog box.
|
||||
*
|
||||
* \param WindowHandle The handle of the parent window.
|
||||
* \param ControlID The control with a title or text to be set.
|
||||
* \param WindowText The text to be copied to the control.
|
||||
*/
|
||||
BOOLEAN PhSetDialogItemText(
|
||||
_In_ HWND WindowHandle,
|
||||
_In_ LONG ControlID,
|
||||
_In_ PCWSTR WindowText
|
||||
@@ -2593,16 +2691,35 @@ VOID PhSetDialogItemText(
|
||||
|
||||
if (controlHandle = GetDlgItem(WindowHandle, ControlID))
|
||||
{
|
||||
PhSetWindowText(controlHandle, WindowText);
|
||||
if (PhSetWindowText(controlHandle, WindowText))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
VOID PhSetWindowText(
|
||||
/**
|
||||
* Sets the title or text of a control.
|
||||
*
|
||||
* \param WindowHandle The handle of the parent window.
|
||||
* \param WindowText The text to be copied to the control.
|
||||
*/
|
||||
BOOLEAN PhSetWindowText(
|
||||
_In_ HWND WindowHandle,
|
||||
_In_ PCWSTR WindowText
|
||||
)
|
||||
{
|
||||
SendMessage(WindowHandle, WM_SETTEXT, 0, (LPARAM)WindowText); // TODO: DefWindowProc (dmex)
|
||||
if (SendMessage(WindowHandle, WM_SETTEXT, 0, (LPARAM)WindowText) > 0)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//if (DefWindowProc(WindowHandle, WM_SETTEXT, 0, (LPARAM)WindowText) > 0)
|
||||
//{
|
||||
// return TRUE;
|
||||
//}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
VOID PhSetGroupBoxText(
|
||||
@@ -2634,6 +2751,7 @@ VOID PhSetWindowAlwaysOnTop(
|
||||
);
|
||||
}
|
||||
|
||||
_Use_decl_annotations_
|
||||
BOOLEAN NTAPI PhpWindowCallbackHashtableEqualFunction(
|
||||
_In_ PVOID Entry1,
|
||||
_In_ PVOID Entry2
|
||||
@@ -2644,6 +2762,7 @@ BOOLEAN NTAPI PhpWindowCallbackHashtableEqualFunction(
|
||||
((PPH_PLUGIN_WINDOW_CALLBACK_REGISTRATION)Entry2)->WindowHandle;
|
||||
}
|
||||
|
||||
_Use_decl_annotations_
|
||||
ULONG NTAPI PhpWindowCallbackHashtableHashFunction(
|
||||
_In_ PVOID Entry
|
||||
)
|
||||
|
||||
+3
-4
@@ -873,14 +873,13 @@ NTSTATUS PhGetSectionFileName(
|
||||
viewSize = PAGE_SIZE;
|
||||
viewBase = NULL;
|
||||
|
||||
status = NtMapViewOfSection(
|
||||
status = PhMapViewOfSection(
|
||||
SectionHandle,
|
||||
NtCurrentProcess(),
|
||||
&viewBase,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&viewSize,
|
||||
viewSize,
|
||||
ViewUnmap,
|
||||
WindowsVersion >= WINDOWS_10_RS2 ? MEM_MAPPED : 0,
|
||||
PAGE_READONLY
|
||||
@@ -890,7 +889,7 @@ NTSTATUS PhGetSectionFileName(
|
||||
return status;
|
||||
|
||||
status = PhGetProcessMappedFileName(NtCurrentProcess(), viewBase, FileName);
|
||||
NtUnmapViewOfSection(NtCurrentProcess(), viewBase);
|
||||
PhUnmapViewOfSection(NtCurrentProcess(), viewBase);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ NTSTATUS PhHvSocketOpenSystemControl(
|
||||
stringRef.Buffer = formatBuffer;
|
||||
|
||||
if (!PhStringRefToUnicodeString(&stringRef, &objectName))
|
||||
return STATUS_NO_MEMORY;
|
||||
return STATUS_NAME_TOO_LONG;
|
||||
#endif
|
||||
|
||||
InitializeObjectAttributes(
|
||||
|
||||
+26
-14
@@ -1141,7 +1141,9 @@ PhLoadMenu(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
BOOLEAN PhModalPropertySheet(
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
PhModalPropertySheet(
|
||||
_Inout_ PROPSHEETHEADER *Header
|
||||
);
|
||||
|
||||
@@ -1342,25 +1344,28 @@ PhRemoveDialogContext(
|
||||
#endif
|
||||
}
|
||||
|
||||
typedef BOOL (CALLBACK* PH_ENUM_CALLBACK)(
|
||||
typedef _Function_class_(PH_WINDOW_ENUM_CALLBACK)
|
||||
BOOLEAN NTAPI PH_WINDOW_ENUM_CALLBACK(
|
||||
_In_ HWND WindowHandle,
|
||||
_In_opt_ PVOID Context
|
||||
);
|
||||
typedef PH_WINDOW_ENUM_CALLBACK* PPH_WINDOW_ENUM_CALLBACK;
|
||||
|
||||
VOID PhEnumWindows(
|
||||
_In_ PH_ENUM_CALLBACK Callback,
|
||||
PHLIBAPI
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhEnumWindows(
|
||||
_In_ PH_WINDOW_ENUM_CALLBACK Callback,
|
||||
_In_opt_ PVOID Context
|
||||
);
|
||||
|
||||
typedef BOOLEAN (CALLBACK *PH_CHILD_ENUM_CALLBACK)(
|
||||
_In_ HWND WindowHandle,
|
||||
_In_opt_ PVOID Context
|
||||
);
|
||||
|
||||
VOID PhEnumChildWindows(
|
||||
PHLIBAPI
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhEnumChildWindows(
|
||||
_In_opt_ HWND WindowHandle,
|
||||
_In_ ULONG Limit,
|
||||
_In_ PH_CHILD_ENUM_CALLBACK Callback,
|
||||
_In_ PH_WINDOW_ENUM_CALLBACK Callback,
|
||||
_In_opt_ PVOID Context
|
||||
);
|
||||
|
||||
@@ -1398,7 +1403,7 @@ PhSetDialogItemValue(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
VOID
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
PhSetDialogItemText(
|
||||
_In_ HWND WindowHandle,
|
||||
@@ -1407,7 +1412,7 @@ PhSetDialogItemText(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
VOID
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
PhSetWindowText(
|
||||
_In_ HWND WindowHandle,
|
||||
@@ -2530,7 +2535,7 @@ HFONT
|
||||
NTAPI
|
||||
PhDuplicateFont(
|
||||
_In_ HFONT Font
|
||||
);
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
HFONT
|
||||
@@ -2645,6 +2650,13 @@ HICON PhGdiplusConvertHBitmapToHIcon(
|
||||
_In_ HBITMAP BitmapHandle
|
||||
);
|
||||
|
||||
LRESULT PhTnSendMessage(
|
||||
_In_ HWND WindowHandle,
|
||||
_In_ ULONG WindowMessage,
|
||||
_In_ WPARAM wParam,
|
||||
_In_ LPARAM lParam
|
||||
);
|
||||
|
||||
EXTERN_C_END
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,33 +28,45 @@
|
||||
*
|
||||
* \return TRUE if the message was handled by this callback, FALSE otherwise.
|
||||
*/
|
||||
typedef
|
||||
BOOLEAN (NTAPI *PKPH_COMMS_CALLBACK)(
|
||||
typedef _Function_class_(KPH_COMMS_CALLBACK)
|
||||
BOOLEAN NTAPI KPH_COMMS_CALLBACK(
|
||||
_In_ ULONG_PTR ReplyToken,
|
||||
_In_ PCKPH_MESSAGE Message
|
||||
);
|
||||
typedef KPH_COMMS_CALLBACK* PKPH_COMMS_CALLBACK;
|
||||
|
||||
_Must_inspect_result_
|
||||
NTSTATUS KphCommsStart(
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
KphCommsStart(
|
||||
_In_ PCPH_STRINGREF PortName,
|
||||
_In_opt_ PKPH_COMMS_CALLBACK Callback
|
||||
);
|
||||
|
||||
VOID KphCommsStop(
|
||||
VOID
|
||||
NTAPI
|
||||
KphCommsStop(
|
||||
VOID
|
||||
);
|
||||
|
||||
BOOLEAN KphCommsIsConnected(
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
KphCommsIsConnected(
|
||||
VOID
|
||||
);
|
||||
|
||||
NTSTATUS KphCommsReplyMessage(
|
||||
_Must_inspect_result_
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
KphCommsReplyMessage(
|
||||
_In_ ULONG_PTR ReplyToken,
|
||||
_In_ PKPH_MESSAGE Message
|
||||
);
|
||||
|
||||
_Must_inspect_result_
|
||||
NTSTATUS KphCommsSendMessage(
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
KphCommsSendMessage(
|
||||
_Inout_ PKPH_MESSAGE Message
|
||||
);
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ PhMappedImageVaToVa(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhGetMappedImageSectionName(
|
||||
_In_ PIMAGE_SECTION_HEADER Section,
|
||||
@@ -505,6 +505,7 @@ PhGetMappedImageDelayImports(
|
||||
_In_ PPH_MAPPED_IMAGE MappedImage
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
USHORT
|
||||
NTAPI
|
||||
PhCheckSum(
|
||||
@@ -1167,19 +1168,21 @@ PhGetMappedImageVolatileMetadata(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
PPH_STRING
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhGetMappedImageAuthenticodeHash(
|
||||
_In_ PPH_MAPPED_IMAGE MappedImage,
|
||||
_In_ PH_HASH_ALGORITHM Algorithm
|
||||
_In_ PH_HASH_ALGORITHM Algorithm,
|
||||
_Out_ PPH_STRING* AuthenticodeHash
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
PPH_STRING
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhGetMappedImageWdacHash(
|
||||
_In_ PPH_MAPPED_IMAGE MappedImage,
|
||||
_In_ PH_HASH_ALGORITHM Algorithm
|
||||
_In_ PH_HASH_ALGORITHM Algorithm,
|
||||
_Out_ PPH_STRING* WdacHash
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
|
||||
+129
-60
@@ -16,7 +16,7 @@
|
||||
EXTERN_C_START
|
||||
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhBaseInitialization(
|
||||
VOID
|
||||
@@ -898,8 +898,7 @@ PhDuplicateStringZ(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhCopyBytesZ(
|
||||
_In_ PCSTR InputBuffer,
|
||||
@@ -910,8 +909,7 @@ PhCopyBytesZ(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhCopyStringZ(
|
||||
_In_ PCWSTR InputBuffer,
|
||||
@@ -922,8 +920,7 @@ PhCopyStringZ(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhCopyStringZFromBytes(
|
||||
_In_ PCSTR InputBuffer,
|
||||
@@ -934,8 +931,7 @@ PhCopyStringZFromBytes(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhCopyStringZFromMultiByte(
|
||||
_In_ PCSTR InputBuffer,
|
||||
@@ -946,8 +942,7 @@ PhCopyStringZFromMultiByte(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhCopyStringZFromUtf8(
|
||||
_In_ PCSTR InputBuffer,
|
||||
@@ -957,15 +952,6 @@ PhCopyStringZFromUtf8(
|
||||
_Out_opt_ PSIZE_T ReturnCount
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
LONG
|
||||
NTAPI
|
||||
PhCompareStringZNatural(
|
||||
_In_ PCWSTR A,
|
||||
_In_ PCWSTR B,
|
||||
_In_ BOOLEAN IgnoreCase
|
||||
);
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
PhAreCharactersDifferent(
|
||||
@@ -1022,20 +1008,6 @@ PhEqualBytesZ(
|
||||
return strcmp(String1, String2) == 0;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
LONG
|
||||
PhCompareStringZ(
|
||||
_In_ PCWSTR String1,
|
||||
_In_ PCWSTR String2,
|
||||
_In_ BOOLEAN IgnoreCase
|
||||
)
|
||||
{
|
||||
if (IgnoreCase)
|
||||
return _wcsicmp(String1, String2);
|
||||
else
|
||||
return wcscmp(String1, String2);
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
PhEqualStringZ(
|
||||
@@ -1130,12 +1102,22 @@ PhInitializeEmptyStringRef(
|
||||
String->Buffer = NULL;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
PhInitializeEmptyBytesRef(
|
||||
_Out_ PPH_BYTESREF String
|
||||
)
|
||||
{
|
||||
String->Length = 0;
|
||||
String->Buffer = NULL;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
NTAPI
|
||||
PhInitializeBufferStringRef(
|
||||
_Out_ PPH_STRINGREF String,
|
||||
_Writable_bytes_(Length) _When_(Length != 0, _Notnull_) PWCHAR Buffer,
|
||||
_Writable_bytes_(Length) _When_(Length != 0, _Notnull_) PWCH Buffer,
|
||||
_In_ SIZE_T Length
|
||||
)
|
||||
{
|
||||
@@ -1144,6 +1126,20 @@ PhInitializeBufferStringRef(
|
||||
String->Buffer = Buffer;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
NTAPI
|
||||
PhInitializeBufferBytesRef(
|
||||
_Out_ PPH_BYTESREF String,
|
||||
_Writable_bytes_(Length) _When_(Length != 0, _Notnull_) PCH Buffer,
|
||||
_In_ SIZE_T Length
|
||||
)
|
||||
{
|
||||
memset(String, 0, sizeof(PH_BYTESREF));
|
||||
String->Length = Length;
|
||||
String->Buffer = Buffer;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
PhStringRefToUnicodeString(
|
||||
@@ -1151,6 +1147,7 @@ PhStringRefToUnicodeString(
|
||||
_Out_ PUNICODE_STRING UnicodeString
|
||||
)
|
||||
{
|
||||
memset(UnicodeString, 0, sizeof(UNICODE_STRING));
|
||||
UnicodeString->Length = (USHORT)String->Length;
|
||||
UnicodeString->MaximumLength = (USHORT)String->Length + sizeof(UNICODE_NULL);
|
||||
UnicodeString->Buffer = String->Buffer;
|
||||
@@ -1165,10 +1162,34 @@ PhUnicodeStringToStringRef(
|
||||
_Out_ PPH_STRINGREF String
|
||||
)
|
||||
{
|
||||
memset(String, 0, sizeof(PH_STRINGREF));
|
||||
String->Length = UnicodeString->Length;
|
||||
String->Buffer = UnicodeString->Buffer;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
LONG
|
||||
PhCompareStringZ(
|
||||
_In_ PCWSTR String1,
|
||||
_In_ PCWSTR String2,
|
||||
_In_ BOOLEAN IgnoreCase
|
||||
)
|
||||
{
|
||||
if (IgnoreCase)
|
||||
return _wcsicmp(String1, String2);
|
||||
else
|
||||
return wcscmp(String1, String2);
|
||||
}
|
||||
|
||||
PHLIBAPI
|
||||
LONG
|
||||
NTAPI
|
||||
PhCompareStringZNatural(
|
||||
_In_ PCWSTR A,
|
||||
_In_ PCWSTR B,
|
||||
_In_ BOOLEAN IgnoreCase
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
LONG
|
||||
NTAPI
|
||||
@@ -1489,6 +1510,7 @@ PhReferenceEmptyString(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhCreateString2(
|
||||
_In_ PCPH_STRINGREF String
|
||||
)
|
||||
@@ -1506,7 +1528,7 @@ PhCreateString2(
|
||||
*/
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI
|
||||
NTAPI_INLINE
|
||||
PhCreateStringZ(
|
||||
_In_z_ PCWSTR String
|
||||
)
|
||||
@@ -1528,7 +1550,7 @@ PhCreateStringZ(
|
||||
*/
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI
|
||||
NTAPI_INLINE
|
||||
PhCreateStringZ2(
|
||||
_In_reads_or_z_(MaximumLength / sizeof(WCHAR)) PCWSTR String,
|
||||
_In_ SIZE_T MaximumLength
|
||||
@@ -1560,7 +1582,7 @@ PhCreateString3(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI
|
||||
NTAPI_INLINE
|
||||
PhTrimStringZ(
|
||||
_In_ PCPH_STRINGREF String,
|
||||
_In_ ULONG Flags,
|
||||
@@ -1576,7 +1598,7 @@ PhTrimStringZ(
|
||||
|
||||
FORCEINLINE
|
||||
WCHAR
|
||||
NTAPI
|
||||
NTAPI_INLINE
|
||||
PhUpcaseUnicodeChar(
|
||||
_In_ WCHAR SourceCharacter
|
||||
)
|
||||
@@ -1592,7 +1614,7 @@ PhUpcaseUnicodeChar(
|
||||
|
||||
FORCEINLINE
|
||||
WCHAR
|
||||
NTAPI
|
||||
NTAPI_INLINE
|
||||
PhDowncaseUnicodeChar(
|
||||
_In_ WCHAR SourceCharacter
|
||||
)
|
||||
@@ -1606,6 +1628,7 @@ PhDowncaseUnicodeChar(
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
NTAPI_INLINE
|
||||
PhUpperStringRefInto(
|
||||
_Inout_ PPH_STRINGREF Destination,
|
||||
_In_ PCPH_STRINGREF Source
|
||||
@@ -1620,6 +1643,7 @@ PhUpperStringRefInto(
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
NTAPI_INLINE
|
||||
PhUpperStringRef(
|
||||
_Inout_ PPH_STRINGREF String
|
||||
)
|
||||
@@ -1629,6 +1653,7 @@ PhUpperStringRef(
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
NTAPI_INLINE
|
||||
PhLowerStringRefInto(
|
||||
_Inout_ PPH_STRINGREF Destination,
|
||||
_In_ PCPH_STRINGREF Source
|
||||
@@ -1643,6 +1668,7 @@ PhLowerStringRefInto(
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
NTAPI_INLINE
|
||||
PhLowerStringRef(
|
||||
_Inout_ PPH_STRINGREF String
|
||||
)
|
||||
@@ -1650,8 +1676,38 @@ PhLowerStringRef(
|
||||
PhLowerStringRefInto(String, String);
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
NTAPI_INLINE
|
||||
PhLowerStringZ(
|
||||
_Inout_ PCWSTR String
|
||||
)
|
||||
{
|
||||
PH_STRINGREF string;
|
||||
|
||||
PhInitializeStringRef(&string, String);
|
||||
PhLowerStringRefInto(&string, &string);
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
NTAPI_INLINE
|
||||
PhLowerStringMaxZ(
|
||||
_In_reads_or_z_(MaximumLength / sizeof(WCHAR)) PCWSTR String,
|
||||
_In_ SIZE_T MaximumLength
|
||||
)
|
||||
{
|
||||
PH_STRINGREF string;
|
||||
|
||||
string.Length = wcsnlen(String, MaximumLength / sizeof(WCHAR)) * sizeof(WCHAR);
|
||||
string.Buffer = (PWSTR)String;
|
||||
|
||||
PhLowerStringRefInto(&string, &string);
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhCreateStringFromUnicodeString(
|
||||
_In_ PCUNICODE_STRING UnicodeString
|
||||
)
|
||||
@@ -2578,8 +2634,7 @@ PhConvertUtf16ToMultiByteEx(
|
||||
// In-place: RtlUTF8ToUnicodeN
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhConvertUtf8ToUtf16Size(
|
||||
_Out_ PSIZE_T BytesInUtf16String,
|
||||
@@ -2588,8 +2643,7 @@ PhConvertUtf8ToUtf16Size(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhConvertUtf8ToUtf16Buffer(
|
||||
_Out_writes_bytes_to_(MaxBytesInUtf16String, *BytesInUtf16String) PWCH Utf16String,
|
||||
@@ -2618,8 +2672,7 @@ PhConvertUtf8ToUtf16Ex(
|
||||
// In-place: RtlUnicodeToUTF8N
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhConvertUtf16ToUtf8Size(
|
||||
_Out_ PSIZE_T BytesInUtf8String,
|
||||
@@ -2628,8 +2681,7 @@ PhConvertUtf16ToUtf8Size(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhConvertUtf16ToUtf8Buffer(
|
||||
_Out_writes_bytes_to_(MaxBytesInUtf8String, *BytesInUtf8String) PCH Utf8String,
|
||||
@@ -3238,8 +3290,8 @@ PhAddItemPointerList(
|
||||
_In_ PVOID Pointer
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
PhEnumPointerListEx(
|
||||
@@ -3662,8 +3714,8 @@ PhClearHashtable(
|
||||
_Inout_ PPH_HASHTABLE Hashtable
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTAPI
|
||||
PhEnumHashtable(
|
||||
@@ -3699,6 +3751,7 @@ typedef struct _PH_HASHTABLE_ENUM_CONTEXT
|
||||
|
||||
FORCEINLINE
|
||||
VOID
|
||||
NTAPI_INLINE
|
||||
PhBeginEnumHashtable(
|
||||
_In_ PPH_HASHTABLE Hashtable,
|
||||
_Out_ PPH_HASHTABLE_ENUM_CONTEXT Context
|
||||
@@ -3711,6 +3764,7 @@ PhBeginEnumHashtable(
|
||||
|
||||
FORCEINLINE
|
||||
PVOID
|
||||
NTAPI_INLINE
|
||||
PhNextEnumHashtable(
|
||||
_Inout_ PPH_HASHTABLE_ENUM_CONTEXT Context
|
||||
)
|
||||
@@ -3845,7 +3899,7 @@ PhFindItemSimpleHashtable(
|
||||
|
||||
FORCEINLINE
|
||||
PVOID
|
||||
NTAPI
|
||||
NTAPI_INLINE
|
||||
PhFindItemSimpleHashtable2(
|
||||
_In_ PPH_HASHTABLE SimpleHashtable,
|
||||
_In_opt_ PVOID Key
|
||||
@@ -4086,6 +4140,7 @@ PhBufferToHexString(
|
||||
_In_ SIZE_T Length
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
PPH_STRING
|
||||
NTAPI
|
||||
PhBufferToHexStringEx(
|
||||
@@ -4337,6 +4392,7 @@ PhSetLastError(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhaCreateString(
|
||||
_In_ PCWSTR Buffer
|
||||
)
|
||||
@@ -4346,6 +4402,7 @@ PhaCreateString(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhaCreateStringEx(
|
||||
_In_opt_ PCWSTR Buffer,
|
||||
_In_ SIZE_T Length
|
||||
@@ -4356,6 +4413,7 @@ PhaCreateStringEx(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhaDuplicateString(
|
||||
_In_ PPH_STRING String
|
||||
)
|
||||
@@ -4365,20 +4423,25 @@ PhaDuplicateString(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhaConcatStrings(
|
||||
_In_ ULONG Count,
|
||||
...
|
||||
)
|
||||
{
|
||||
PPH_STRING string;
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, Count);
|
||||
string = PH_AUTO_T(PH_STRING, PhConcatStrings_V(Count, argptr));
|
||||
va_end(argptr);
|
||||
|
||||
return PH_AUTO_T(PH_STRING, PhConcatStrings_V(Count, argptr));
|
||||
return string;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhaConcatStrings2(
|
||||
_In_ PCWSTR String1,
|
||||
_In_ PCWSTR String2
|
||||
@@ -4389,20 +4452,25 @@ PhaConcatStrings2(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhaFormatString(
|
||||
_In_ _Printf_format_string_ PCWSTR Format,
|
||||
...
|
||||
)
|
||||
{
|
||||
PPH_STRING string;
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr, Format);
|
||||
string = PH_AUTO_T(PH_STRING, PhFormatString_V(Format, argptr));
|
||||
va_end(argptr);
|
||||
|
||||
return PH_AUTO_T(PH_STRING, PhFormatString_V(Format, argptr));
|
||||
return string;
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhLowerString(
|
||||
_In_ PPH_STRING String
|
||||
)
|
||||
@@ -4412,6 +4480,7 @@ PhLowerString(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhaLowerString(
|
||||
_In_ PPH_STRING String
|
||||
)
|
||||
@@ -4421,7 +4490,7 @@ PhaLowerString(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI
|
||||
NTAPI_INLINE
|
||||
PhUpperString(
|
||||
_In_ PPH_STRING String
|
||||
)
|
||||
@@ -4431,6 +4500,7 @@ PhUpperString(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhaUpperString(
|
||||
_In_ PPH_STRING String
|
||||
)
|
||||
@@ -4440,6 +4510,7 @@ PhaUpperString(
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
NTAPI_INLINE
|
||||
PhaSubstring(
|
||||
_In_ PPH_STRING String,
|
||||
_In_ SIZE_T StartIndex,
|
||||
@@ -4886,26 +4957,24 @@ PhFormatToBuffer(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhFormatSingleToUtf8(
|
||||
_In_ FLOAT Value,
|
||||
_In_ ULONG Type,
|
||||
_In_ ULONG Precision,
|
||||
_In_ LONG Precision,
|
||||
_Out_writes_bytes_(BufferLength) PSTR Buffer,
|
||||
_In_opt_ SIZE_T BufferLength,
|
||||
_Out_opt_ PSIZE_T ReturnLength
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhFormatDoubleToUtf8(
|
||||
_In_ DOUBLE Value,
|
||||
_In_ ULONG Type,
|
||||
_In_ ULONG Precision,
|
||||
_In_ LONG Precision,
|
||||
_Out_writes_bytes_(BufferLength) PSTR Buffer,
|
||||
_In_opt_ SIZE_T BufferLength,
|
||||
_Out_opt_ PSIZE_T ReturnLength
|
||||
|
||||
@@ -61,8 +61,7 @@ PHLIBAPI
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhInitializePhLib(
|
||||
_In_ PCWSTR ApplicationName,
|
||||
_In_ PVOID ImageBaseAddress
|
||||
_In_ PCWSTR ApplicationName
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
|
||||
@@ -426,9 +426,8 @@ typedef struct _PH_ENVIRONMENT_VARIABLE
|
||||
PH_STRINGREF Value;
|
||||
} PH_ENVIRONMENT_VARIABLE, *PPH_ENVIRONMENT_VARIABLE;
|
||||
|
||||
_Success_(return)
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhEnumProcessEnvironmentVariables(
|
||||
_In_ PVOID Environment,
|
||||
@@ -1390,6 +1389,26 @@ PhReleasePebLock(
|
||||
#endif
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhAcquireLoaderLock(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhReleaseLoaderLock(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
return RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
USHORT
|
||||
NTAPI
|
||||
@@ -1657,7 +1676,7 @@ PhSetTokenSessionId(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhSetTokenPrivilege(
|
||||
_In_ HANDLE TokenHandle,
|
||||
@@ -1667,7 +1686,7 @@ PhSetTokenPrivilege(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhSetTokenPrivilege2(
|
||||
_In_ HANDLE TokenHandle,
|
||||
@@ -3142,6 +3161,34 @@ PhSetValueKeyZ(
|
||||
);
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhSetValueKeyStringZ(
|
||||
_In_ HANDLE KeyHandle,
|
||||
_In_ PCWSTR ValueName,
|
||||
_In_ ULONG ValueType,
|
||||
_In_ PCPH_STRINGREF String
|
||||
)
|
||||
{
|
||||
PH_STRINGREF valueName;
|
||||
|
||||
if (String->Length > ULONG_MAX)
|
||||
{
|
||||
return STATUS_INTEGER_OVERFLOW;
|
||||
}
|
||||
|
||||
PhInitializeStringRef(&valueName, ValueName);
|
||||
|
||||
return PhSetValueKey(
|
||||
KeyHandle,
|
||||
&valueName,
|
||||
ValueType,
|
||||
String->Buffer,
|
||||
(ULONG)String->Length + sizeof(UNICODE_NULL)
|
||||
);
|
||||
}
|
||||
|
||||
PHLIBAPI
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
@@ -3538,17 +3585,47 @@ NTSTATUS
|
||||
NTAPI
|
||||
PhCreateNamedPipe(
|
||||
_Out_ PHANDLE PipeHandle,
|
||||
_In_ PCWSTR PipeName
|
||||
_In_ PCPH_STRINGREF PipeName
|
||||
);
|
||||
|
||||
FORCEINLINE
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhCreateNamedPipeZ(
|
||||
_Out_ PHANDLE PipeHandle,
|
||||
_In_ PCWSTR PipeName
|
||||
)
|
||||
{
|
||||
PH_STRINGREF pipeName;
|
||||
|
||||
PhInitializeStringRef(&pipeName, PipeName);
|
||||
|
||||
return PhCreateNamedPipe(PipeHandle, &pipeName);
|
||||
}
|
||||
|
||||
PHLIBAPI
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhConnectPipe(
|
||||
_Out_ PHANDLE PipeHandle,
|
||||
_In_ PCWSTR PipeName
|
||||
_In_ PCPH_STRINGREF PipeName
|
||||
);
|
||||
|
||||
FORCEINLINE
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhConnectPipeZ(
|
||||
_Out_ PHANDLE PipeHandle,
|
||||
_In_ PCWSTR PipeName
|
||||
)
|
||||
{
|
||||
PH_STRINGREF pipeName;
|
||||
|
||||
PhInitializeStringRef(&pipeName, PipeName);
|
||||
|
||||
return PhConnectPipe(PipeHandle, &pipeName);
|
||||
}
|
||||
|
||||
PHLIBAPI
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
|
||||
@@ -793,7 +793,7 @@ PhGetProcessAppMemoryInformation(
|
||||
|
||||
FORCEINLINE
|
||||
NTSTATUS
|
||||
PhGetProcessMitigationPolicyInformation(
|
||||
PhGetProcessMitigationPolicy(
|
||||
_In_ HANDLE ProcessHandle,
|
||||
_In_ PROCESS_MITIGATION_POLICY Policy,
|
||||
_Out_ PPROCESS_MITIGATION_POLICY_INFORMATION MitigationPolicy
|
||||
|
||||
+84
-22
@@ -19,6 +19,8 @@ extern CONST WCHAR *PhSizeUnitNames[7];
|
||||
extern ULONG PhMaxSizeUnit;
|
||||
extern USHORT PhMaxPrecisionUnit;
|
||||
extern FLOAT PhMaxPrecisionLimit;
|
||||
extern CONST PH_STRINGREF PhPrefixUnitNamesCounted[7];
|
||||
extern CONST PH_STRINGREF PhSiPrefixUnitNamesCounted[7];
|
||||
|
||||
typedef struct _PH_INTEGER_PAIR
|
||||
{
|
||||
@@ -357,9 +359,8 @@ PhTaskDialogNavigatePage(
|
||||
_In_ PTASKDIALOGCONFIG Config
|
||||
)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
assert(HandleToUlong(NtCurrentThreadId()) == GetWindowThreadProcessId(WindowHandle, NULL));
|
||||
#endif
|
||||
|
||||
#define WM_TDM_NAVIGATE_PAGE (WM_USER + 101)
|
||||
|
||||
SendMessage(WindowHandle, WM_TDM_NAVIGATE_PAGE, 0, (LPARAM)(Config));
|
||||
@@ -896,22 +897,23 @@ PhIsFileVersionInfo32(
|
||||
}
|
||||
|
||||
PHLIBAPI
|
||||
PVOID
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhGetFileVersionInfo(
|
||||
_In_ PCWSTR FileName
|
||||
_In_ PCWSTR FileName,
|
||||
_Out_ PVOID* VersionInfo
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
PVOID
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhGetFileVersionInfoEx(
|
||||
_In_ PCPH_STRINGREF FileName
|
||||
_In_ PCPH_STRINGREF FileName,
|
||||
_Out_ PVOID* VersionInfo
|
||||
);
|
||||
|
||||
_Success_(return)
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhGetFileVersionInfoKey(
|
||||
_In_ PVS_VERSION_INFO_STRUCT32 VersionInfo,
|
||||
@@ -920,9 +922,8 @@ PhGetFileVersionInfoKey(
|
||||
_Out_opt_ PVOID* Buffer
|
||||
);
|
||||
|
||||
_Success_(return)
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhGetFileVersionVarFileInfoValue(
|
||||
_In_ PVOID VersionInfo,
|
||||
@@ -932,7 +933,7 @@ PhGetFileVersionVarFileInfoValue(
|
||||
);
|
||||
|
||||
FORCEINLINE
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhGetFileVersionVarFileInfoValueZ(
|
||||
_In_ PVOID VersionInfo,
|
||||
@@ -994,8 +995,7 @@ typedef struct _PH_IMAGE_VERSION_INFO
|
||||
} PH_IMAGE_VERSION_INFO, *PPH_IMAGE_VERSION_INFO;
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhInitializeImageVersionInfo(
|
||||
_Out_ PPH_IMAGE_VERSION_INFO ImageVersionInfo,
|
||||
@@ -1003,8 +1003,7 @@ PhInitializeImageVersionInfo(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
_Success_(return)
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhInitializeImageVersionInfoEx(
|
||||
_Out_ PPH_IMAGE_VERSION_INFO ImageVersionInfo,
|
||||
@@ -1029,9 +1028,8 @@ PhFormatImageVersionInfo(
|
||||
_In_opt_ ULONG LineLimit
|
||||
);
|
||||
|
||||
_Success_(return)
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhInitializeImageVersionInfoCached(
|
||||
_Out_ PPH_IMAGE_VERSION_INFO ImageVersionInfo,
|
||||
@@ -1076,6 +1074,24 @@ PhExpandEnvironmentStringsZ(
|
||||
return PhExpandEnvironmentStrings(&string);
|
||||
}
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
PhConvertNtPathSeperatorToAltSeperator(
|
||||
_In_ PPH_STRING String
|
||||
)
|
||||
{
|
||||
if (String)
|
||||
{
|
||||
for (ULONG i = 0; i < String->Length / sizeof(WCHAR); i++)
|
||||
{
|
||||
if (String->Buffer[i] == OBJ_NAME_PATH_SEPARATOR) // RtlNtPathSeperatorString
|
||||
String->Buffer[i] = OBJ_NAME_ALTPATH_SEPARATOR; // RtlAlternateDosPathSeperatorString
|
||||
}
|
||||
}
|
||||
|
||||
return String;
|
||||
}
|
||||
|
||||
PHLIBAPI
|
||||
PPH_STRING
|
||||
NTAPI
|
||||
@@ -1178,6 +1194,24 @@ PhGetApplicationFileNameWin32(
|
||||
VOID
|
||||
);
|
||||
|
||||
FORCEINLINE
|
||||
PPH_STRING
|
||||
PhGetApplicationFileNameZ(
|
||||
_In_ PCPH_STRINGREF Suffix
|
||||
)
|
||||
{
|
||||
PPH_STRING fileName = NULL;
|
||||
PPH_STRING applicationFileName;
|
||||
|
||||
if (applicationFileName = PhGetApplicationFileName())
|
||||
{
|
||||
fileName = PhConcatStringRef2(&applicationFileName->sr, Suffix);
|
||||
PhDereferenceObject(applicationFileName);
|
||||
}
|
||||
|
||||
return fileName;
|
||||
}
|
||||
|
||||
PHLIBAPI
|
||||
PPH_STRING
|
||||
NTAPI
|
||||
@@ -1897,12 +1931,19 @@ PhCrc32C(
|
||||
|
||||
typedef enum _PH_HASH_ALGORITHM
|
||||
{
|
||||
Crc32HashAlgorithm,
|
||||
Crc32CHashAlgorithm,
|
||||
Md5HashAlgorithm,
|
||||
Sha1HashAlgorithm,
|
||||
Crc32HashAlgorithm,
|
||||
Sha256HashAlgorithm
|
||||
} PH_HASH_ALGORITHM;
|
||||
|
||||
#define PH_HASH_CRC32_LENGTH 4
|
||||
#define PH_HASH_MD5_LENGTH 16
|
||||
#define PH_HASH_SHA1_LENGTH 20
|
||||
#define PH_HASH_SHA256_LENGTH 32
|
||||
|
||||
typedef struct _PH_HASH_CONTEXT
|
||||
{
|
||||
PH_HASH_ALGORITHM Algorithm;
|
||||
@@ -1910,7 +1951,7 @@ typedef struct _PH_HASH_CONTEXT
|
||||
} PH_HASH_CONTEXT, *PPH_HASH_CONTEXT;
|
||||
|
||||
PHLIBAPI
|
||||
VOID
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhInitializeHash(
|
||||
_Out_ PPH_HASH_CONTEXT Context,
|
||||
@@ -1918,24 +1959,45 @@ PhInitializeHash(
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
VOID
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhUpdateHash(
|
||||
_Inout_ PPH_HASH_CONTEXT Context,
|
||||
_In_ PPH_HASH_CONTEXT Context,
|
||||
_In_reads_bytes_(Length) PVOID Buffer,
|
||||
_In_ ULONG Length
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
BOOLEAN
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhFinalHash(
|
||||
_Inout_ PPH_HASH_CONTEXT Context,
|
||||
_In_ PPH_HASH_CONTEXT Context,
|
||||
_Out_writes_bytes_(HashLength) PVOID Hash,
|
||||
_In_ ULONG HashLength,
|
||||
_Out_opt_ PULONG ReturnLength
|
||||
);
|
||||
|
||||
FORCEINLINE
|
||||
NTSTATUS
|
||||
NTAPI
|
||||
PhFinalHashString(
|
||||
_In_ PPH_HASH_CONTEXT Context,
|
||||
_Out_ PPH_STRING* HashString
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
UCHAR hash[PH_HASH_SHA256_LENGTH];
|
||||
|
||||
status = PhFinalHash(Context, hash, sizeof(hash), NULL);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
*HashString = PhBufferToHexString(hash, sizeof(hash));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
typedef enum _PH_COMMAND_LINE_OPTION_TYPE
|
||||
{
|
||||
NoArgumentType,
|
||||
|
||||
@@ -103,7 +103,7 @@ VOID
|
||||
NTAPI
|
||||
PhSetIntervalProviderThread(
|
||||
_Inout_ PPH_PROVIDER_THREAD ProviderThread,
|
||||
_In_ ULONG Interval
|
||||
_In_ LONG Interval
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
|
||||
@@ -64,7 +64,7 @@ typedef struct DECLSPEC_ALIGN(16) _PH_QUEUED_WAIT_BLOCK
|
||||
|
||||
static_assert((sizeof(PH_QUEUED_WAIT_BLOCK) % MEMORY_ALLOCATION_ALIGNMENT) == 0, "PH_QUEUED_WAIT_BLOCK alignment invalid");
|
||||
|
||||
BOOLEAN PhQueuedLockInitialization(
|
||||
NTSTATUS PhQueuedLockInitialization(
|
||||
VOID
|
||||
);
|
||||
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ extern PH_QUEUED_LOCK PhDbgObjectListLock;
|
||||
extern PPH_CREATE_OBJECT_HOOK PhDbgCreateObjectHook;
|
||||
#endif
|
||||
|
||||
BOOLEAN PhRefInitialization(
|
||||
NTSTATUS PhRefInitialization(
|
||||
VOID
|
||||
);
|
||||
|
||||
|
||||
@@ -28,6 +28,16 @@ PhCoSetProxyBlanket(
|
||||
_In_ IUnknown* InterfacePtr
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
HRESULT
|
||||
NTAPI
|
||||
PhGetWbemClassObjectDependency(
|
||||
_Out_ PVOID* WbemClassObjectDependency,
|
||||
_In_ struct IWbemClassObject* WbemClassObject,
|
||||
_In_ struct IWbemServices* WbemServices,
|
||||
_In_ PCWSTR Name
|
||||
);
|
||||
|
||||
PHLIBAPI
|
||||
PPH_STRING
|
||||
NTAPI
|
||||
|
||||
@@ -14,26 +14,24 @@
|
||||
|
||||
EXTERN_C_START
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhWslQueryDistroProcessCommandLine(
|
||||
NTSTATUS PhWslQueryDistroProcessCommandLine(
|
||||
_In_ PPH_STRINGREF FileName,
|
||||
_In_ ULONG LxssProcessId,
|
||||
_Out_ PPH_STRING* Result
|
||||
);
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhWslQueryDistroProcessEnvironment(
|
||||
NTSTATUS PhWslQueryDistroProcessEnvironment(
|
||||
_In_ PPH_STRINGREF FileName,
|
||||
_In_ ULONG LxssProcessId,
|
||||
_Out_ PPH_STRING* Result
|
||||
);
|
||||
|
||||
BOOLEAN PhInitializeLxssImageVersionInfo(
|
||||
NTSTATUS PhInitializeLxssImageVersionInfo(
|
||||
_Inout_ PPH_IMAGE_VERSION_INFO ImageVersionInfo,
|
||||
_In_ PPH_STRINGREF FileName
|
||||
);
|
||||
|
||||
BOOLEAN PhCreateProcessLxss(
|
||||
NTSTATUS PhCreateProcessLxss(
|
||||
_In_ PPH_STRING LxssDistribution,
|
||||
_In_ PPH_STRING LxssCommandLine,
|
||||
_Out_ PPH_STRING *Result
|
||||
|
||||
+348
-268
@@ -208,7 +208,6 @@ NTSTATUS PhLoadMappedImageHeaderPageSize(
|
||||
{
|
||||
NTSTATUS status;
|
||||
BOOLEAN openedFile = FALSE;
|
||||
OBJECT_ATTRIBUTES sectionAttributes;
|
||||
LARGE_INTEGER sectionSize;
|
||||
HANDLE sectionHandle;
|
||||
SIZE_T viewSize;
|
||||
@@ -235,20 +234,11 @@ NTSTATUS PhLoadMappedImageHeaderPageSize(
|
||||
openedFile = TRUE;
|
||||
}
|
||||
|
||||
InitializeObjectAttributes(
|
||||
§ionAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
sectionSize.QuadPart = PAGE_SIZE;
|
||||
|
||||
status = NtCreateSection(
|
||||
status = PhCreateSection(
|
||||
§ionHandle,
|
||||
SECTION_QUERY | SECTION_MAP_READ,
|
||||
§ionAttributes,
|
||||
§ionSize,
|
||||
PAGE_READONLY,
|
||||
SEC_COMMIT,
|
||||
@@ -264,14 +254,13 @@ NTSTATUS PhLoadMappedImageHeaderPageSize(
|
||||
viewSize = PAGE_SIZE;
|
||||
viewBase = NULL;
|
||||
|
||||
status = NtMapViewOfSection(
|
||||
status = PhMapViewOfSection(
|
||||
sectionHandle,
|
||||
NtCurrentProcess(),
|
||||
&viewBase,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&viewSize,
|
||||
viewSize,
|
||||
ViewUnmap,
|
||||
0,
|
||||
PAGE_READONLY
|
||||
@@ -297,7 +286,7 @@ NTSTATUS PhUnloadMappedImage(
|
||||
{
|
||||
if (MappedImage->ViewBase)
|
||||
{
|
||||
NtUnmapViewOfSection(NtCurrentProcess(), MappedImage->ViewBase);
|
||||
PhUnmapViewOfSection(NtCurrentProcess(), MappedImage->ViewBase);
|
||||
MappedImage->ViewBase = NULL;
|
||||
}
|
||||
|
||||
@@ -313,7 +302,6 @@ NTSTATUS PhMapViewOfEntireFile(
|
||||
{
|
||||
NTSTATUS status;
|
||||
BOOLEAN openedFile = FALSE;
|
||||
OBJECT_ATTRIBUTES sectionAttributes;
|
||||
LARGE_INTEGER sectionSize;
|
||||
HANDLE sectionHandle;
|
||||
SIZE_T viewSize;
|
||||
@@ -348,18 +336,9 @@ NTSTATUS PhMapViewOfEntireFile(
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
InitializeObjectAttributes(
|
||||
§ionAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
status = NtCreateSection(
|
||||
status = PhCreateSection(
|
||||
§ionHandle,
|
||||
SECTION_QUERY | SECTION_MAP_READ,
|
||||
§ionAttributes,
|
||||
§ionSize,
|
||||
PAGE_READONLY,
|
||||
SEC_COMMIT,
|
||||
@@ -374,14 +353,13 @@ NTSTATUS PhMapViewOfEntireFile(
|
||||
viewSize = (SIZE_T)sectionSize.QuadPart;
|
||||
viewBase = NULL;
|
||||
|
||||
status = NtMapViewOfSection(
|
||||
status = PhMapViewOfSection(
|
||||
sectionHandle,
|
||||
NtCurrentProcess(),
|
||||
&viewBase,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&viewSize,
|
||||
viewSize,
|
||||
ViewUnmap,
|
||||
0,
|
||||
PAGE_READONLY
|
||||
@@ -411,7 +389,6 @@ NTSTATUS PhMapViewOfEntireFileEx(
|
||||
{
|
||||
NTSTATUS status;
|
||||
BOOLEAN openedFile = FALSE;
|
||||
OBJECT_ATTRIBUTES sectionAttributes;
|
||||
LARGE_INTEGER sectionSize;
|
||||
HANDLE sectionHandle;
|
||||
SIZE_T viewSize;
|
||||
@@ -446,18 +423,9 @@ NTSTATUS PhMapViewOfEntireFileEx(
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
InitializeObjectAttributes(
|
||||
§ionAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
status = NtCreateSection(
|
||||
status = PhCreateSection(
|
||||
§ionHandle,
|
||||
SECTION_QUERY | SECTION_MAP_READ,
|
||||
§ionAttributes,
|
||||
§ionSize,
|
||||
PAGE_READONLY,
|
||||
SEC_COMMIT,
|
||||
@@ -467,19 +435,18 @@ NTSTATUS PhMapViewOfEntireFileEx(
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
// Map the section.
|
||||
|
||||
viewSize = (SIZE_T)sectionSize.QuadPart;
|
||||
viewBase = NULL;
|
||||
|
||||
status = NtMapViewOfSection(
|
||||
// Map the section.
|
||||
|
||||
status = PhMapViewOfSection(
|
||||
sectionHandle,
|
||||
NtCurrentProcess(),
|
||||
&viewBase,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&viewSize,
|
||||
viewSize,
|
||||
ViewUnmap,
|
||||
0,
|
||||
PAGE_READONLY
|
||||
@@ -523,12 +490,12 @@ PIMAGE_SECTION_HEADER PhMappedImageSectionByName(
|
||||
{
|
||||
WCHAR sectionName[IMAGE_SIZEOF_SHORT_NAME + 1];
|
||||
|
||||
if (PhGetMappedImageSectionName(
|
||||
if (NT_SUCCESS(PhGetMappedImageSectionName(
|
||||
&MappedImage->Sections[i],
|
||||
sectionName,
|
||||
RTL_NUMBER_OF(sectionName),
|
||||
NULL
|
||||
) && PhEqualStringZ(sectionName, Name, IgnoreCase))
|
||||
)) && PhEqualStringZ(sectionName, Name, IgnoreCase))
|
||||
{
|
||||
return &MappedImage->Sections[i];
|
||||
}
|
||||
@@ -645,17 +612,17 @@ PVOID PhMappedImageRvaToFileOffset(
|
||||
);
|
||||
}
|
||||
|
||||
BOOLEAN PhGetMappedImageSectionName(
|
||||
NTSTATUS PhGetMappedImageSectionName(
|
||||
_In_ PIMAGE_SECTION_HEADER Section,
|
||||
_Out_writes_opt_z_(Count) PWSTR Buffer,
|
||||
_In_ ULONG Count,
|
||||
_Out_opt_ PULONG ReturnCount
|
||||
)
|
||||
{
|
||||
BOOLEAN result;
|
||||
SIZE_T returnCount;
|
||||
NTSTATUS status;
|
||||
SIZE_T returnCount = 0;
|
||||
|
||||
result = PhCopyStringZFromUtf8(
|
||||
status = PhCopyStringZFromUtf8(
|
||||
(PCSTR)Section->Name,
|
||||
IMAGE_SIZEOF_SHORT_NAME,
|
||||
Buffer,
|
||||
@@ -666,7 +633,7 @@ BOOLEAN PhGetMappedImageSectionName(
|
||||
if (ReturnCount)
|
||||
*ReturnCount = (ULONG)returnCount;
|
||||
|
||||
return result;
|
||||
return status;
|
||||
}
|
||||
|
||||
NTSTATUS PhGetMappedImageDataDirectory(
|
||||
@@ -3310,14 +3277,17 @@ NTSTATUS PhGetMappedImageProdIdHeader(
|
||||
__try
|
||||
{
|
||||
PH_HASH_CONTEXT hashContext;
|
||||
UCHAR hash[32];
|
||||
PPH_STRING hashString = NULL;
|
||||
|
||||
PhInitializeHash(&hashContext, Md5HashAlgorithm);
|
||||
PhUpdateHash(&hashContext, richHeaderStart, richHeaderLength);
|
||||
|
||||
if (PhFinalHash(&hashContext, hash, 16, NULL))
|
||||
if (NT_SUCCESS(PhInitializeHash(&hashContext, Md5HashAlgorithm)))
|
||||
{
|
||||
hashRawContentString = PhBufferToHexString(hash, 16);
|
||||
if (NT_SUCCESS(PhUpdateHash(&hashContext, richHeaderStart, richHeaderLength)))
|
||||
{
|
||||
if (NT_SUCCESS(PhFinalHashString(&hashContext, &hashString)))
|
||||
{
|
||||
hashRawContentString = hashString;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
@@ -3337,7 +3307,7 @@ NTSTATUS PhGetMappedImageProdIdHeader(
|
||||
PULONG richHeaderContentBuffer;
|
||||
PULONG richHeaderContentOffset;
|
||||
PH_HASH_CONTEXT hashContext;
|
||||
UCHAR hash[32];
|
||||
UCHAR hash[PH_HASH_MD5_LENGTH];
|
||||
|
||||
// Recalculate the length needed for the hash since VT doesn't include the remaining entry.
|
||||
richHeaderContentEnd = PTR_ADD_OFFSET(MappedImage->ViewBase, richHeaderEndOffset);
|
||||
@@ -3367,12 +3337,15 @@ NTSTATUS PhGetMappedImageProdIdHeader(
|
||||
*richHeaderContentOffset ^= richHeaderKey;
|
||||
}
|
||||
|
||||
PhInitializeHash(&hashContext, Md5HashAlgorithm);
|
||||
PhUpdateHash(&hashContext, richHeaderContentBuffer, richHeaderContentLength);
|
||||
|
||||
if (PhFinalHash(&hashContext, hash, 16, NULL))
|
||||
if (NT_SUCCESS(PhInitializeHash(&hashContext, Md5HashAlgorithm)))
|
||||
{
|
||||
hashContentString = PhBufferToHexString(hash, 16);
|
||||
if (NT_SUCCESS(PhUpdateHash(&hashContext, richHeaderContentBuffer, richHeaderContentLength)))
|
||||
{
|
||||
if (NT_SUCCESS(PhFinalHash(&hashContext, hash, sizeof(hash), NULL)))
|
||||
{
|
||||
hashContentString = PhBufferToHexString(hash, sizeof(hash));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PhFree(richHeaderContentBuffer);
|
||||
@@ -5373,40 +5346,54 @@ NTSTATUS PhGetMappedImageVolatileMetadata(
|
||||
return status;
|
||||
}
|
||||
|
||||
static VOID PhpMappedImageUpdateHashData(
|
||||
NTSTATUS PhMappedImageUpdateHashData(
|
||||
_In_ PPH_HASH_CONTEXT HashContext,
|
||||
_In_ PVOID Buffer,
|
||||
_In_ ULONG64 BufferLength
|
||||
)
|
||||
{
|
||||
if (BufferLength >= ULONG_MAX)
|
||||
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||
|
||||
__try
|
||||
{
|
||||
PBYTE address;
|
||||
ULONG64 numberOfBytes;
|
||||
ULONG blockSize;
|
||||
|
||||
// Chunk the data into smaller blocks when the buffer length
|
||||
// overflows the maximum length of the BCryptHashData function.
|
||||
|
||||
address = (PBYTE)Buffer;
|
||||
numberOfBytes = BufferLength;
|
||||
blockSize = PAGE_SIZE * 64;
|
||||
|
||||
while (numberOfBytes != 0)
|
||||
if (BufferLength >= ULONG_MAX)
|
||||
{
|
||||
if (blockSize > numberOfBytes)
|
||||
blockSize = (ULONG)numberOfBytes;
|
||||
PBYTE address;
|
||||
ULONG64 numberOfBytes;
|
||||
ULONG blockSize;
|
||||
|
||||
PhUpdateHash(HashContext, address, blockSize);
|
||||
// Chunk the data into smaller blocks when the buffer length
|
||||
// overflows the maximum length of the BCryptHashData function.
|
||||
|
||||
address += blockSize;
|
||||
numberOfBytes -= blockSize;
|
||||
address = (PBYTE)Buffer;
|
||||
numberOfBytes = BufferLength;
|
||||
blockSize = PAGE_SIZE * 64;
|
||||
|
||||
while (numberOfBytes != 0)
|
||||
{
|
||||
if (blockSize > numberOfBytes)
|
||||
blockSize = (ULONG)numberOfBytes;
|
||||
|
||||
status = PhUpdateHash(HashContext, address, blockSize);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
break;
|
||||
|
||||
address += blockSize;
|
||||
numberOfBytes -= blockSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = PhUpdateHash(HashContext, Buffer, (ULONG)BufferLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
PhUpdateHash(HashContext, Buffer, (ULONG)BufferLength);
|
||||
status = GetExceptionCode();
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
typedef struct _PH_MAPPED_IMAGE_HASH_REGION
|
||||
@@ -5415,12 +5402,14 @@ typedef struct _PH_MAPPED_IMAGE_HASH_REGION
|
||||
ULONG64 Length;
|
||||
} PH_MAPPED_IMAGE_HASH_REGION;
|
||||
|
||||
PPH_STRING PhGetMappedImageAuthenticodeHash(
|
||||
NTSTATUS PhGetMappedImageAuthenticodeHash(
|
||||
_In_ PPH_MAPPED_IMAGE MappedImage,
|
||||
_In_ PH_HASH_ALGORITHM Algorithm
|
||||
_In_ PH_HASH_ALGORITHM Algorithm,
|
||||
_Out_ PPH_STRING* AuthenticodeHash
|
||||
)
|
||||
{
|
||||
PIMAGE_DOS_HEADER imageDosHeader = (PIMAGE_DOS_HEADER)MappedImage->ViewBase;
|
||||
NTSTATUS status;
|
||||
PIMAGE_DOS_HEADER imageDosHeader;
|
||||
PPH_STRING hashString = NULL;
|
||||
ULONG imageChecksumOffset;
|
||||
ULONG imageSecurityOffset;
|
||||
@@ -5430,87 +5419,112 @@ PPH_STRING PhGetMappedImageAuthenticodeHash(
|
||||
PIMAGE_DATA_DIRECTORY dataDirectory;
|
||||
PH_HASH_CONTEXT hashContext;
|
||||
|
||||
if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
|
||||
__try
|
||||
{
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
}
|
||||
else if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
|
||||
{
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
imageDosHeader = (PIMAGE_DOS_HEADER)MappedImage->ViewBase;
|
||||
|
||||
PhMappedImagePrefetch(MappedImage);
|
||||
|
||||
if (NT_SUCCESS(PhGetMappedImageDataDirectory(MappedImage, IMAGE_DIRECTORY_ENTRY_SECURITY, &dataDirectory)))
|
||||
{
|
||||
imageSecurityAddress = dataDirectory->VirtualAddress;
|
||||
imageSecuritySize = dataDirectory->Size;
|
||||
}
|
||||
|
||||
// BaseAddress -> Checksum
|
||||
imageHashBlock[0].Offset = 0;
|
||||
imageHashBlock[0].Length = imageChecksumOffset;
|
||||
|
||||
// Checksum -> Security directory
|
||||
imageHashBlock[1].Offset = imageChecksumOffset + RTL_FIELD_SIZE(IMAGE_OPTIONAL_HEADER, CheckSum);
|
||||
imageHashBlock[1].Length = imageSecurityOffset - imageHashBlock[1].Offset;
|
||||
|
||||
if (imageSecurityAddress && imageSecuritySize)
|
||||
{
|
||||
// Security directory -> Certificate data
|
||||
imageHashBlock[2].Offset = UInt32Add32To64(imageSecurityOffset, sizeof(IMAGE_DATA_DIRECTORY));
|
||||
imageHashBlock[2].Length = imageSecurityAddress - imageHashBlock[2].Offset;
|
||||
|
||||
// Certificate data -> End of file
|
||||
imageHashBlock[3].Offset = UInt32Add32To64(imageSecurityAddress, imageSecuritySize);
|
||||
imageHashBlock[3].Length = MappedImage->ViewSize - imageHashBlock[3].Offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Security directory -> End of file
|
||||
imageHashBlock[2].Offset = UInt32Add32To64(imageSecurityOffset, sizeof(IMAGE_DATA_DIRECTORY));
|
||||
imageHashBlock[2].Length = MappedImage->ViewSize - imageHashBlock[2].Offset;
|
||||
}
|
||||
|
||||
PhInitializeHash(&hashContext, Algorithm);
|
||||
|
||||
for (ULONG i = 0; i < ARRAYSIZE(imageHashBlock); i++)
|
||||
{
|
||||
if (imageHashBlock[i].Length)
|
||||
if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
|
||||
{
|
||||
PhpMappedImageUpdateHashData(
|
||||
&hashContext,
|
||||
PTR_ADD_OFFSET(MappedImage->ViewBase, imageHashBlock[i].Offset),
|
||||
imageHashBlock[i].Length
|
||||
);
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
}
|
||||
else if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
|
||||
{
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return STATUS_INVALID_IMAGE_FORMAT;
|
||||
}
|
||||
|
||||
PhMappedImagePrefetch(MappedImage);
|
||||
|
||||
if (NT_SUCCESS(PhGetMappedImageDataDirectory(MappedImage, IMAGE_DIRECTORY_ENTRY_SECURITY, &dataDirectory)))
|
||||
{
|
||||
imageSecurityAddress = dataDirectory->VirtualAddress;
|
||||
imageSecuritySize = dataDirectory->Size;
|
||||
}
|
||||
|
||||
// BaseAddress -> Checksum
|
||||
imageHashBlock[0].Offset = 0;
|
||||
imageHashBlock[0].Length = imageChecksumOffset;
|
||||
|
||||
// Checksum -> Security directory
|
||||
imageHashBlock[1].Offset = imageChecksumOffset + RTL_FIELD_SIZE(IMAGE_OPTIONAL_HEADER, CheckSum);
|
||||
imageHashBlock[1].Length = imageSecurityOffset - imageHashBlock[1].Offset;
|
||||
|
||||
if (imageSecurityAddress && imageSecuritySize)
|
||||
{
|
||||
// Security directory -> Certificate data
|
||||
imageHashBlock[2].Offset = UInt32Add32To64(imageSecurityOffset, sizeof(IMAGE_DATA_DIRECTORY));
|
||||
imageHashBlock[2].Length = imageSecurityAddress - imageHashBlock[2].Offset;
|
||||
|
||||
// Certificate data -> End of file
|
||||
imageHashBlock[3].Offset = UInt32Add32To64(imageSecurityAddress, imageSecuritySize);
|
||||
imageHashBlock[3].Length = MappedImage->ViewSize - imageHashBlock[3].Offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Security directory -> End of file
|
||||
imageHashBlock[2].Offset = UInt32Add32To64(imageSecurityOffset, sizeof(IMAGE_DATA_DIRECTORY));
|
||||
imageHashBlock[2].Length = MappedImage->ViewSize - imageHashBlock[2].Offset;
|
||||
}
|
||||
|
||||
status = PhInitializeHash(&hashContext, Algorithm);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
for (ULONG i = 0; i < RTL_NUMBER_OF(imageHashBlock); i++)
|
||||
{
|
||||
if (imageHashBlock[i].Length)
|
||||
{
|
||||
status = PhMappedImageUpdateHashData(
|
||||
&hashContext,
|
||||
PTR_ADD_OFFSET(MappedImage->ViewBase, imageHashBlock[i].Offset),
|
||||
imageHashBlock[i].Length
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
ULONG hashLength = PH_HASH_SHA256_LENGTH;
|
||||
UCHAR hash[PH_HASH_SHA256_LENGTH];
|
||||
|
||||
status = PhFinalHash(&hashContext, hash, hashLength, &hashLength);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
hashString = PhBufferToHexString(hash, sizeof(hash));
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
*AuthenticodeHash = hashString;
|
||||
}
|
||||
}
|
||||
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
ULONG hashLength = 32;
|
||||
UCHAR hash[32];
|
||||
|
||||
if (PhFinalHash(&hashContext, hash, hashLength, &hashLength))
|
||||
{
|
||||
hashString = PhBufferToHexString(hash, hashLength);
|
||||
}
|
||||
status = GetExceptionCode();
|
||||
}
|
||||
|
||||
return hashString;
|
||||
return status;
|
||||
}
|
||||
|
||||
PPH_STRING PhGetMappedImageAuthenticodeLegacy(
|
||||
NTSTATUS PhGetMappedImageAuthenticodeLegacy(
|
||||
_In_ PPH_MAPPED_IMAGE MappedImage,
|
||||
_In_ PH_HASH_ALGORITHM Algorithm
|
||||
_In_ PH_HASH_ALGORITHM Algorithm,
|
||||
_Out_ PPH_STRING* AuthenticodeHash
|
||||
)
|
||||
{
|
||||
PIMAGE_DOS_HEADER imageDosHeader = (PIMAGE_DOS_HEADER)MappedImage->ViewBase;
|
||||
NTSTATUS status;
|
||||
PIMAGE_DOS_HEADER imageDosHeader;
|
||||
PPH_STRING hashString = NULL;
|
||||
ULONG64 offset = 0;
|
||||
ULONG imageChecksumOffset;
|
||||
@@ -5520,80 +5534,119 @@ PPH_STRING PhGetMappedImageAuthenticodeLegacy(
|
||||
PIMAGE_DATA_DIRECTORY dataDirectory;
|
||||
PH_HASH_CONTEXT hashContext;
|
||||
|
||||
if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
|
||||
__try
|
||||
{
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
}
|
||||
else if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
|
||||
{
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
imageDosHeader = (PIMAGE_DOS_HEADER)MappedImage->ViewBase;
|
||||
|
||||
PhMappedImagePrefetch(MappedImage);
|
||||
|
||||
if (NT_SUCCESS(PhGetMappedImageDataDirectory(MappedImage, IMAGE_DIRECTORY_ENTRY_SECURITY, &dataDirectory)))
|
||||
{
|
||||
directoryAddress = dataDirectory->VirtualAddress;
|
||||
directorySize = dataDirectory->Size;
|
||||
}
|
||||
|
||||
PhInitializeHash(&hashContext, Algorithm);
|
||||
|
||||
while (offset < imageChecksumOffset)
|
||||
{
|
||||
PhUpdateHash(&hashContext, PTR_ADD_OFFSET(MappedImage->ViewBase, offset), sizeof(BYTE));
|
||||
offset++;
|
||||
}
|
||||
|
||||
offset += RTL_FIELD_SIZE(IMAGE_OPTIONAL_HEADER, CheckSum);
|
||||
|
||||
while (offset < imageSecurityOffset)
|
||||
{
|
||||
PhUpdateHash(&hashContext, PTR_ADD_OFFSET(MappedImage->ViewBase, offset), sizeof(BYTE));
|
||||
offset++;
|
||||
}
|
||||
|
||||
offset += sizeof(IMAGE_DATA_DIRECTORY);
|
||||
|
||||
while (offset < directoryAddress)
|
||||
{
|
||||
PhUpdateHash(&hashContext, PTR_ADD_OFFSET(MappedImage->ViewBase, offset), sizeof(BYTE));
|
||||
offset++;
|
||||
}
|
||||
|
||||
offset += directorySize;
|
||||
|
||||
while (offset < MappedImage->ViewSize)
|
||||
{
|
||||
PhUpdateHash(&hashContext, PTR_ADD_OFFSET(MappedImage->ViewBase, offset), sizeof(BYTE));
|
||||
offset++;
|
||||
}
|
||||
|
||||
{
|
||||
ULONG hashLength = 32;
|
||||
UCHAR hash[32];
|
||||
|
||||
if (PhFinalHash(&hashContext, hash, hashLength, &hashLength))
|
||||
if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
|
||||
{
|
||||
hashString = PhBufferToHexString(hash, hashLength);
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
}
|
||||
else if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
|
||||
{
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return STATUS_INVALID_IMAGE_FORMAT;
|
||||
}
|
||||
|
||||
PhMappedImagePrefetch(MappedImage);
|
||||
|
||||
if (NT_SUCCESS(PhGetMappedImageDataDirectory(MappedImage, IMAGE_DIRECTORY_ENTRY_SECURITY, &dataDirectory)))
|
||||
{
|
||||
directoryAddress = dataDirectory->VirtualAddress;
|
||||
directorySize = dataDirectory->Size;
|
||||
}
|
||||
|
||||
status = PhInitializeHash(&hashContext, Algorithm);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
while (offset < imageChecksumOffset)
|
||||
{
|
||||
if (!NT_SUCCESS(status = PhUpdateHash(&hashContext, PTR_ADD_OFFSET(MappedImage->ViewBase, offset), sizeof(BYTE))))
|
||||
break;
|
||||
|
||||
offset++;
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
offset += RTL_FIELD_SIZE(IMAGE_OPTIONAL_HEADER, CheckSum);
|
||||
|
||||
while (offset < imageSecurityOffset)
|
||||
{
|
||||
if (!NT_SUCCESS(status = PhUpdateHash(&hashContext, PTR_ADD_OFFSET(MappedImage->ViewBase, offset), sizeof(BYTE))))
|
||||
break;
|
||||
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
offset += sizeof(IMAGE_DATA_DIRECTORY);
|
||||
|
||||
while (offset < directoryAddress)
|
||||
{
|
||||
if (!NT_SUCCESS(status = PhUpdateHash(&hashContext, PTR_ADD_OFFSET(MappedImage->ViewBase, offset), sizeof(BYTE))))
|
||||
break;
|
||||
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
offset += directorySize;
|
||||
|
||||
while (offset < MappedImage->ViewSize)
|
||||
{
|
||||
if (!NT_SUCCESS(status = PhUpdateHash(&hashContext, PTR_ADD_OFFSET(MappedImage->ViewBase, offset), sizeof(BYTE))))
|
||||
break;
|
||||
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
ULONG hashLength = PH_HASH_SHA256_LENGTH;
|
||||
UCHAR hash[PH_HASH_SHA256_LENGTH];
|
||||
|
||||
status = PhFinalHash(&hashContext, hash, hashLength, &hashLength);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
hashString = PhBufferToHexString(hash, sizeof(hash));
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
*AuthenticodeHash = hashString;
|
||||
}
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
status = GetExceptionCode();
|
||||
}
|
||||
|
||||
return hashString;
|
||||
return status;
|
||||
}
|
||||
|
||||
PPH_STRING PhGetMappedImageWdacHash(
|
||||
NTSTATUS PhGetMappedImageWdacHash(
|
||||
_In_ PPH_MAPPED_IMAGE MappedImage,
|
||||
_In_ PH_HASH_ALGORITHM Algorithm
|
||||
_In_ PH_HASH_ALGORITHM Algorithm,
|
||||
_Out_ PPH_STRING* WdacHash
|
||||
)
|
||||
{
|
||||
PIMAGE_DOS_HEADER imageDosHeader = (PIMAGE_DOS_HEADER)MappedImage->ViewBase;
|
||||
NTSTATUS status;
|
||||
PIMAGE_DOS_HEADER imageDosHeader;
|
||||
PPH_STRING hashString = NULL;
|
||||
ULONG offset = 0;
|
||||
ULONG imageChecksumOffset;
|
||||
@@ -5601,61 +5654,88 @@ PPH_STRING PhGetMappedImageWdacHash(
|
||||
ULONG imageSizeOfHeaders;
|
||||
PH_HASH_CONTEXT hashContext;
|
||||
|
||||
if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
|
||||
__try
|
||||
{
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
imageSizeOfHeaders = ((PIMAGE_OPTIONAL_HEADER32)&MappedImage->NtHeaders32->OptionalHeader)->SizeOfHeaders;
|
||||
}
|
||||
else if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
|
||||
{
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
imageSizeOfHeaders = ((PIMAGE_OPTIONAL_HEADER64)&MappedImage->NtHeaders->OptionalHeader)->SizeOfHeaders;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
imageDosHeader = (PIMAGE_DOS_HEADER)MappedImage->ViewBase;
|
||||
|
||||
PhInitializeHash(&hashContext, Algorithm);
|
||||
|
||||
while (offset < PAGE_SIZE)
|
||||
{
|
||||
if (offset == imageChecksumOffset)
|
||||
offset += RTL_FIELD_SIZE(IMAGE_OPTIONAL_HEADER, CheckSum);
|
||||
if (offset == imageSecurityOffset)
|
||||
offset += sizeof(IMAGE_DATA_DIRECTORY);
|
||||
if (offset >= imageSizeOfHeaders)
|
||||
break;
|
||||
|
||||
PhUpdateHash(&hashContext, PTR_ADD_OFFSET(MappedImage->ViewBase, offset), sizeof(BYTE));
|
||||
offset++;
|
||||
}
|
||||
|
||||
if (offset < PAGE_SIZE)
|
||||
{
|
||||
ULONG paddingLength;
|
||||
PVOID paddingBuffer;
|
||||
|
||||
paddingLength = PAGE_SIZE - offset;
|
||||
paddingBuffer = PhAllocateZero(paddingLength);
|
||||
|
||||
PhUpdateHash(&hashContext, paddingBuffer, paddingLength);
|
||||
PhFree(paddingBuffer);
|
||||
}
|
||||
|
||||
{
|
||||
ULONG hashLength = 32;
|
||||
UCHAR hash[32];
|
||||
|
||||
if (PhFinalHash(&hashContext, hash, hashLength, &hashLength))
|
||||
if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR32_MAGIC)
|
||||
{
|
||||
hashString = PhBufferToHexString(hash, hashLength);
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS32, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
imageSizeOfHeaders = ((PIMAGE_OPTIONAL_HEADER32)&MappedImage->NtHeaders32->OptionalHeader)->SizeOfHeaders;
|
||||
}
|
||||
else if (MappedImage->Magic == IMAGE_NT_OPTIONAL_HDR64_MAGIC)
|
||||
{
|
||||
imageChecksumOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.CheckSum);
|
||||
imageSecurityOffset = imageDosHeader->e_lfanew + UFIELD_OFFSET(IMAGE_NT_HEADERS64, OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_SECURITY]);
|
||||
imageSizeOfHeaders = ((PIMAGE_OPTIONAL_HEADER64)&MappedImage->NtHeaders->OptionalHeader)->SizeOfHeaders;
|
||||
}
|
||||
else
|
||||
{
|
||||
return STATUS_INVALID_IMAGE_FORMAT;
|
||||
}
|
||||
|
||||
status = PhInitializeHash(&hashContext, Algorithm);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
while (offset < PAGE_SIZE)
|
||||
{
|
||||
if (offset == imageChecksumOffset)
|
||||
offset += RTL_FIELD_SIZE(IMAGE_OPTIONAL_HEADER, CheckSum);
|
||||
if (offset == imageSecurityOffset)
|
||||
offset += sizeof(IMAGE_DATA_DIRECTORY);
|
||||
if (offset >= imageSizeOfHeaders)
|
||||
break;
|
||||
|
||||
status = PhUpdateHash(&hashContext, PTR_ADD_OFFSET(MappedImage->ViewBase, offset), sizeof(BYTE));
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
break;
|
||||
|
||||
offset++;
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
if (offset < PAGE_SIZE)
|
||||
{
|
||||
ULONG paddingLength;
|
||||
PVOID paddingBuffer;
|
||||
|
||||
paddingLength = PAGE_SIZE - offset;
|
||||
paddingBuffer = PhAllocateZero(paddingLength);
|
||||
|
||||
status = PhUpdateHash(&hashContext, paddingBuffer, paddingLength);
|
||||
PhFree(paddingBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
ULONG hashLength = PH_HASH_SHA256_LENGTH;
|
||||
UCHAR hash[PH_HASH_SHA256_LENGTH];
|
||||
|
||||
status = PhFinalHash(&hashContext, hash, hashLength, &hashLength);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
hashString = PhBufferToHexString(hash, hashLength);
|
||||
}
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
*WdacHash = hashString;
|
||||
}
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
{
|
||||
status = GetExceptionCode();
|
||||
}
|
||||
|
||||
return hashString;
|
||||
return status;
|
||||
}
|
||||
|
||||
BOOLEAN PhGetMappedImageEntropy(
|
||||
|
||||
+29
-69
@@ -207,23 +207,12 @@ NTSTATUS PhLoadLibraryAsResource(
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
OBJECT_ATTRIBUTES sectionAttributes;
|
||||
HANDLE sectionHandle;
|
||||
PVOID imageBaseAddress;
|
||||
SIZE_T imageBaseSize;
|
||||
|
||||
InitializeObjectAttributes(
|
||||
§ionAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
status = NtCreateSection(
|
||||
status = PhCreateSection(
|
||||
§ionHandle,
|
||||
SECTION_QUERY | SECTION_MAP_READ,
|
||||
§ionAttributes,
|
||||
NULL,
|
||||
PAGE_READONLY,
|
||||
WindowsVersion < WINDOWS_8 ? SEC_IMAGE : SEC_IMAGE_NO_EXECUTE,
|
||||
@@ -233,19 +222,15 @@ NTSTATUS PhLoadLibraryAsResource(
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
imageBaseAddress = NULL;
|
||||
imageBaseSize = 0;
|
||||
|
||||
NtSuppressDebugMessage(TRUE);
|
||||
|
||||
status = NtMapViewOfSection(
|
||||
status = PhMapViewOfSection(
|
||||
sectionHandle,
|
||||
NtCurrentProcess(),
|
||||
&imageBaseAddress,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&imageBaseSize,
|
||||
0,
|
||||
ViewUnmap,
|
||||
WindowsVersion < WINDOWS_10_RS2 ? 0 : MEM_MAPPED,
|
||||
PAGE_READONLY
|
||||
@@ -323,7 +308,7 @@ NTSTATUS PhFreeLibraryAsImageResource(
|
||||
|
||||
NtSuppressDebugMessage(TRUE);
|
||||
|
||||
status = NtUnmapViewOfSection(
|
||||
status = PhUnmapViewOfSection(
|
||||
NtCurrentProcess(),
|
||||
LDR_IMAGEMAPPING_TO_MAPPEDVIEW(BaseAddress)
|
||||
);
|
||||
@@ -916,7 +901,7 @@ PPH_STRING PhGetDllFileName(
|
||||
PPH_STRING fileName;
|
||||
ULONG_PTR indexOfFileName;
|
||||
|
||||
RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhAcquireLoaderLock();
|
||||
|
||||
entry = PhFindLoaderEntry(DllBase, NULL, NULL);
|
||||
|
||||
@@ -925,7 +910,7 @@ PPH_STRING PhGetDllFileName(
|
||||
else
|
||||
fileName = NULL;
|
||||
|
||||
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhReleaseLoaderLock();
|
||||
|
||||
if (!fileName)
|
||||
return NULL;
|
||||
@@ -958,7 +943,7 @@ BOOLEAN PhGetLoaderEntryData(
|
||||
BOOLEAN result = FALSE;
|
||||
PLDR_DATA_TABLE_ENTRY entry;
|
||||
|
||||
RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhAcquireLoaderLock();
|
||||
|
||||
entry = PhFindLoaderEntry(NULL, NULL, BaseDllName);
|
||||
|
||||
@@ -995,7 +980,7 @@ BOOLEAN PhGetLoaderEntryData(
|
||||
}
|
||||
}
|
||||
|
||||
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhReleaseLoaderLock();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -1007,7 +992,7 @@ PVOID PhGetLoaderEntryAddressDllBase(
|
||||
PLDR_DATA_TABLE_ENTRY entry;
|
||||
PVOID baseAddress;
|
||||
|
||||
RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhAcquireLoaderLock();
|
||||
|
||||
entry = PhFindLoaderEntryAddress(Address);
|
||||
|
||||
@@ -1016,7 +1001,7 @@ PVOID PhGetLoaderEntryAddressDllBase(
|
||||
else
|
||||
baseAddress = NULL;
|
||||
|
||||
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhReleaseLoaderLock();
|
||||
|
||||
return baseAddress;
|
||||
}
|
||||
@@ -1029,7 +1014,7 @@ PVOID PhGetLoaderEntryDllBase(
|
||||
PLDR_DATA_TABLE_ENTRY entry;
|
||||
PVOID baseAddress;
|
||||
|
||||
RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhAcquireLoaderLock();
|
||||
|
||||
if (WindowsVersion >= WINDOWS_8 && !FullDllName && BaseDllName)
|
||||
{
|
||||
@@ -1047,7 +1032,7 @@ PVOID PhGetLoaderEntryDllBase(
|
||||
else
|
||||
baseAddress = NULL;
|
||||
|
||||
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhReleaseLoaderLock();
|
||||
|
||||
return baseAddress;
|
||||
}
|
||||
@@ -1069,7 +1054,7 @@ PVOID PhGetDllBaseProcedureAddress(
|
||||
if (PhBeginInitOnce(&initOnce))
|
||||
{
|
||||
if ((WindowsVersion >= WINDOWS_10_RS2) &&
|
||||
NT_SUCCESS(PhGetProcessMitigationPolicyInformation(NtCurrentProcess(), ProcessControlFlowGuardPolicy, &mitigation)) &&
|
||||
NT_SUCCESS(PhGetProcessMitigationPolicy(NtCurrentProcess(), ProcessControlFlowGuardPolicy, &mitigation)) &&
|
||||
mitigation.ControlFlowGuardPolicy.EnableExportSuppression)
|
||||
{
|
||||
exportSuppressionEnabled = TRUE;
|
||||
@@ -1890,7 +1875,7 @@ NTSTATUS PhLoaderEntrySnapImportDirectory(
|
||||
|
||||
if (PhEqualBytesZ(importName, ImportDllName, FALSE))
|
||||
{
|
||||
importBaseAddress = PhInstanceHandle;
|
||||
importBaseAddress = NtCurrentImageBase();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2226,7 +2211,7 @@ static NTSTATUS PhpFixupLoaderEntryImageDelayImports(
|
||||
{
|
||||
if (PhEqualBytesZ(importName, "SystemInformer.exe", FALSE))
|
||||
{
|
||||
importBaseAddress = PhInstanceHandle;
|
||||
importBaseAddress = NtCurrentImageBase();
|
||||
status = STATUS_SUCCESS;
|
||||
}
|
||||
else if (ReadPointerAcquire(importHandle))
|
||||
@@ -2542,10 +2527,8 @@ NTSTATUS PhLoaderEntryLoadDll(
|
||||
{
|
||||
NTSTATUS status;
|
||||
HANDLE fileHandle;
|
||||
OBJECT_ATTRIBUTES sectionAttributes;
|
||||
HANDLE sectionHandle;
|
||||
PVOID imageBaseAddress;
|
||||
SIZE_T imageBaseOffset;
|
||||
|
||||
status = PhCreateFile(
|
||||
&fileHandle,
|
||||
@@ -2560,18 +2543,9 @@ NTSTATUS PhLoaderEntryLoadDll(
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
InitializeObjectAttributes(
|
||||
§ionAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
status = NtCreateSection(
|
||||
status = PhCreateSection(
|
||||
§ionHandle,
|
||||
SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_EXECUTE,
|
||||
§ionAttributes,
|
||||
NULL,
|
||||
PAGE_EXECUTE,
|
||||
SEC_IMAGE,
|
||||
@@ -2594,16 +2568,14 @@ NTSTATUS PhLoaderEntryLoadDll(
|
||||
}
|
||||
|
||||
imageBaseAddress = NULL;
|
||||
imageBaseOffset = 0;
|
||||
|
||||
status = NtMapViewOfSection(
|
||||
|
||||
status = PhMapViewOfSection(
|
||||
sectionHandle,
|
||||
NtCurrentProcess(),
|
||||
&imageBaseAddress,
|
||||
0,
|
||||
0,
|
||||
NULL,
|
||||
&imageBaseOffset,
|
||||
0,
|
||||
ViewUnmap,
|
||||
0,
|
||||
PAGE_EXECUTE
|
||||
@@ -2613,9 +2585,7 @@ NTSTATUS PhLoaderEntryLoadDll(
|
||||
|
||||
if (status == STATUS_IMAGE_NOT_AT_BASE)
|
||||
{
|
||||
status = PhLoaderEntryRelocateImage(
|
||||
imageBaseAddress
|
||||
);
|
||||
status = PhLoaderEntryRelocateImage(imageBaseAddress);
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
@@ -2627,10 +2597,7 @@ NTSTATUS PhLoaderEntryLoadDll(
|
||||
}
|
||||
else
|
||||
{
|
||||
NtUnmapViewOfSection(
|
||||
NtCurrentProcess(),
|
||||
imageBaseAddress
|
||||
);
|
||||
PhUnmapViewOfSection(NtCurrentProcess(), imageBaseAddress);
|
||||
}
|
||||
|
||||
return status;
|
||||
@@ -2664,7 +2631,7 @@ NTSTATUS PhLoaderEntryUnloadDll(
|
||||
if (!imageEntryRoutine(BaseAddress, DLL_PROCESS_DETACH, NULL))
|
||||
status = STATUS_DLL_INIT_FAILED;
|
||||
|
||||
NtUnmapViewOfSection(NtCurrentProcess(), BaseAddress);
|
||||
PhUnmapViewOfSection(NtCurrentProcess(), BaseAddress);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -2724,8 +2691,10 @@ NTSTATUS PhLoadPluginImage(
|
||||
UNICODE_STRING imageFileName;
|
||||
ULONG imageType;
|
||||
|
||||
if (!PhStringRefToUnicodeString(FileName, &imageFileName))
|
||||
return STATUS_NAME_TOO_LONG;
|
||||
|
||||
imageType = IMAGE_FILE_EXECUTABLE_IMAGE;
|
||||
PhStringRefToUnicodeString(FileName, &imageFileName);
|
||||
|
||||
status = LdrLoadDll(
|
||||
NULL,
|
||||
@@ -2734,7 +2703,7 @@ NTSTATUS PhLoadPluginImage(
|
||||
&imageBaseAddress
|
||||
);
|
||||
#else
|
||||
RtlEnterCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhAcquireLoaderLock();
|
||||
|
||||
status = PhLoaderEntryLoadDll(
|
||||
FileName,
|
||||
@@ -2745,7 +2714,7 @@ NTSTATUS PhLoadPluginImage(
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
#if !defined(PH_NATIVE_PLUGIN_IMAGE_LOAD)
|
||||
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhReleaseLoaderLock();
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
@@ -2808,7 +2777,7 @@ CleanupExit:
|
||||
}
|
||||
|
||||
#if !defined(PH_NATIVE_PLUGIN_IMAGE_LOAD)
|
||||
RtlLeaveCriticalSection(NtCurrentPeb()->LoaderLock);
|
||||
PhReleaseLoaderLock();
|
||||
#endif
|
||||
|
||||
return status;
|
||||
@@ -2860,18 +2829,9 @@ NTSTATUS PhGetFileBinaryTypeWin32(
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
InitializeObjectAttributes(
|
||||
&objectAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
status = NtCreateSection(
|
||||
status = PhCreateSection(
|
||||
§ionHandle,
|
||||
SECTION_QUERY | SECTION_MAP_READ | SECTION_MAP_EXECUTE,
|
||||
&objectAttributes,
|
||||
NULL,
|
||||
PAGE_EXECUTE,
|
||||
SEC_IMAGE,
|
||||
|
||||
+6
-4
@@ -236,7 +236,7 @@ NTSTATUS PhpGetMappedArchiveMemberFromHeader(
|
||||
|
||||
// Read the size string, terminate it after the last digit and parse it.
|
||||
|
||||
if (!PhCopyStringZFromBytes(Header->Size, 10, integerString, 11, NULL))
|
||||
if (!NT_SUCCESS(PhCopyStringZFromBytes(Header->Size, 10, integerString, 11, NULL)))
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
|
||||
string.Buffer = integerString;
|
||||
@@ -262,7 +262,7 @@ NTSTATUS PhpGetMappedArchiveMemberFromHeader(
|
||||
|
||||
// Parse the name.
|
||||
|
||||
if (!PhCopyBytesZ(Header->Name, 16, Member->NameBuffer, 20, NULL))
|
||||
if (!NT_SUCCESS(PhCopyBytesZ(Header->Name, 16, Member->NameBuffer, 20, NULL)))
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
|
||||
Member->Name = Member->NameBuffer;
|
||||
@@ -321,10 +321,12 @@ NTSTATUS PhpGetMappedArchiveMemberFromHeader(
|
||||
|
||||
// Parse the offset and make sure it lies within the longnames member.
|
||||
|
||||
if (!PhCopyStringZFromBytes(slash + 1, -1, integerString, 11, NULL))
|
||||
if (!NT_SUCCESS(PhCopyStringZFromBytes(slash + 1, -1, integerString, 11, NULL)))
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
|
||||
PhInitializeStringRefLongHint(&string, integerString);
|
||||
if (!PhStringToInteger64(&string, 10, &offset64))
|
||||
|
||||
if (!PhStringToUInt64(&string, 10, &offset64))
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
|
||||
offset = (ULONG)offset64;
|
||||
|
||||
+22
-40
@@ -115,8 +115,7 @@ NTSTATUS PhSetObjectSecurity(
|
||||
);
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhEnumProcessEnvironmentVariables(
|
||||
NTSTATUS PhEnumProcessEnvironmentVariables(
|
||||
_In_ PVOID Environment,
|
||||
_In_ ULONG EnvironmentLength,
|
||||
_Inout_ PULONG EnumerationKey,
|
||||
@@ -143,11 +142,11 @@ BOOLEAN PhEnumProcessEnvironmentVariables(
|
||||
while (TRUE)
|
||||
{
|
||||
if (currentIndex >= length)
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
if (*currentChar == L'=' && startIndex != currentIndex)
|
||||
break; // equality sign is considered as a delimiter unless it is the first character (diversenok)
|
||||
if (*currentChar == UNICODE_NULL)
|
||||
return FALSE; // no more variables
|
||||
return STATUS_UNSUCCESSFUL; // no more variables
|
||||
|
||||
currentIndex++;
|
||||
currentChar++;
|
||||
@@ -164,7 +163,7 @@ BOOLEAN PhEnumProcessEnvironmentVariables(
|
||||
while (TRUE)
|
||||
{
|
||||
if (currentIndex >= length)
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
if (*currentChar == UNICODE_NULL)
|
||||
break;
|
||||
|
||||
@@ -182,7 +181,7 @@ BOOLEAN PhEnumProcessEnvironmentVariables(
|
||||
Variable->Value.Buffer = value;
|
||||
Variable->Value.Length = valueLength * sizeof(WCHAR);
|
||||
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS PhQueryEnvironmentVariableStringRef(
|
||||
@@ -349,20 +348,15 @@ NTSTATUS PhGetProcessSectionFileName(
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
SIZE_T viewSize;
|
||||
PVOID viewBase;
|
||||
PVOID baseAddress;
|
||||
|
||||
viewSize = PAGE_SIZE;
|
||||
viewBase = NULL;
|
||||
|
||||
status = NtMapViewOfSection(
|
||||
status = PhMapViewOfSection(
|
||||
SectionHandle,
|
||||
ProcessHandle,
|
||||
&viewBase,
|
||||
0,
|
||||
&baseAddress,
|
||||
0,
|
||||
NULL,
|
||||
&viewSize,
|
||||
PAGE_SIZE,
|
||||
ViewUnmap,
|
||||
0,
|
||||
PAGE_READONLY
|
||||
@@ -373,11 +367,11 @@ NTSTATUS PhGetProcessSectionFileName(
|
||||
|
||||
status = PhGetProcessMappedFileName(
|
||||
ProcessHandle,
|
||||
viewBase,
|
||||
baseAddress,
|
||||
FileName
|
||||
);
|
||||
|
||||
NtUnmapViewOfSection(ProcessHandle, viewBase);
|
||||
PhUnmapViewOfSection(ProcessHandle, baseAddress);
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -7167,8 +7161,7 @@ static BOOLEAN NTAPI PhpKnownDllObjectsCallback(
|
||||
HANDLE sectionHandle;
|
||||
OBJECT_ATTRIBUTES objectAttributes;
|
||||
UNICODE_STRING objectName;
|
||||
PVOID viewBase;
|
||||
SIZE_T viewSize;
|
||||
PVOID baseAddress;
|
||||
PPH_STRING fileName;
|
||||
|
||||
if (!PhStringRefToUnicodeString(Name, &objectName))
|
||||
@@ -7191,17 +7184,13 @@ static BOOLEAN NTAPI PhpKnownDllObjectsCallback(
|
||||
if (!NT_SUCCESS(status))
|
||||
return TRUE;
|
||||
|
||||
viewSize = PAGE_SIZE;
|
||||
viewBase = NULL;
|
||||
|
||||
status = NtMapViewOfSection(
|
||||
status = PhMapViewOfSection(
|
||||
sectionHandle,
|
||||
NtCurrentProcess(),
|
||||
&viewBase,
|
||||
0,
|
||||
&baseAddress,
|
||||
0,
|
||||
NULL,
|
||||
&viewSize,
|
||||
PAGE_SIZE,
|
||||
ViewUnmap,
|
||||
WindowsVersion < WINDOWS_10_RS2 ? 0 : MEM_MAPPED,
|
||||
PAGE_READONLY
|
||||
@@ -7214,11 +7203,11 @@ static BOOLEAN NTAPI PhpKnownDllObjectsCallback(
|
||||
|
||||
status = PhGetProcessMappedFileName(
|
||||
NtCurrentProcess(),
|
||||
viewBase,
|
||||
baseAddress,
|
||||
&fileName
|
||||
);
|
||||
|
||||
NtUnmapViewOfSection(NtCurrentProcess(), viewBase);
|
||||
PhUnmapViewOfSection(NtCurrentProcess(), baseAddress);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
@@ -7236,23 +7225,16 @@ VOID PhInitializeKnownDlls(
|
||||
_In_ PCWSTR ObjectName
|
||||
)
|
||||
{
|
||||
UNICODE_STRING directoryName;
|
||||
OBJECT_ATTRIBUTES objectAttributes;
|
||||
PH_STRINGREF directoryName;
|
||||
HANDLE directoryHandle;
|
||||
|
||||
RtlInitUnicodeString(&directoryName, ObjectName);
|
||||
InitializeObjectAttributes(
|
||||
&objectAttributes,
|
||||
&directoryName,
|
||||
OBJ_CASE_INSENSITIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
PhInitializeStringRef(&directoryName, ObjectName);
|
||||
|
||||
if (NT_SUCCESS(NtOpenDirectoryObject(
|
||||
if (NT_SUCCESS(PhOpenDirectoryObject(
|
||||
&directoryHandle,
|
||||
DIRECTORY_QUERY,
|
||||
&objectAttributes
|
||||
NULL,
|
||||
&directoryName
|
||||
)))
|
||||
{
|
||||
PhEnumDirectoryObjects(
|
||||
|
||||
+48
-14
@@ -27,6 +27,14 @@ NTSTATUS PhCreatePipe(
|
||||
return PhCreatePipeEx(PipeReadHandle, PipeWriteHandle, NULL, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an anonymous pipe.
|
||||
*
|
||||
* \param[out] PipeReadHandle The pipe read handle.
|
||||
* \param[out] PipeWriteHandle The pipe write handle.
|
||||
* \param[in] PipeReadAttributes Optional pipe read attributes.
|
||||
* \param[in] PipeWriteAttributes Optional pipe write attributes.
|
||||
*/
|
||||
NTSTATUS PhCreatePipeEx(
|
||||
_Out_ PHANDLE PipeReadHandle,
|
||||
_Out_ PHANDLE PipeWriteHandle,
|
||||
@@ -98,13 +106,27 @@ NTSTATUS PhCreatePipeEx(
|
||||
|
||||
if (!objectAttributes.SecurityDescriptor)
|
||||
{
|
||||
if (NT_SUCCESS(PhDefaultNpAcl(&pipeAcl)))
|
||||
{
|
||||
PhCreateSecurityDescriptor(&securityDescriptor, SECURITY_DESCRIPTOR_REVISION);
|
||||
PhSetDaclSecurityDescriptor(&securityDescriptor, TRUE, pipeAcl, FALSE);
|
||||
status = PhDefaultNpAcl(&pipeAcl);
|
||||
|
||||
objectAttributes.SecurityDescriptor = &securityDescriptor;
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
status = PhCreateSecurityDescriptor(&securityDescriptor, SECURITY_DESCRIPTOR_REVISION);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
status = PhSetDaclSecurityDescriptor(&securityDescriptor, TRUE, pipeAcl, FALSE);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
objectAttributes.SecurityDescriptor = &securityDescriptor;
|
||||
}
|
||||
|
||||
assert(RtlValidSecurityDescriptor(&securityDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
}
|
||||
|
||||
status = NtCreateNamedPipeFile(
|
||||
@@ -183,9 +205,10 @@ CleanupExit:
|
||||
*/
|
||||
NTSTATUS PhCreateNamedPipe(
|
||||
_Out_ PHANDLE PipeHandle,
|
||||
_In_ PCWSTR PipeName
|
||||
_In_ PCPH_STRINGREF PipeName
|
||||
)
|
||||
{
|
||||
static CONST PH_STRINGREF deviceName = PH_STRINGREF_INIT(DEVICE_NAMED_PIPE);
|
||||
NTSTATUS status;
|
||||
PACL pipeAcl = NULL;
|
||||
HANDLE pipeHandle;
|
||||
@@ -203,8 +226,13 @@ NTSTATUS PhCreateNamedPipe(
|
||||
FALSE
|
||||
};
|
||||
|
||||
pipeName = PhConcatStrings2(DEVICE_NAMED_PIPE, PipeName);
|
||||
PhStringRefToUnicodeString(&pipeName->sr, &pipeNameUs);
|
||||
pipeName = PhConcatStringRef2(&deviceName, PipeName);
|
||||
|
||||
if (!PhStringRefToUnicodeString(&pipeName->sr, &pipeNameUs))
|
||||
{
|
||||
PhDereferenceObject(pipeName);
|
||||
return STATUS_NAME_TOO_LONG;
|
||||
}
|
||||
|
||||
InitializeObjectAttributes(
|
||||
&objectAttributes,
|
||||
@@ -256,9 +284,10 @@ NTSTATUS PhCreateNamedPipe(
|
||||
|
||||
NTSTATUS PhConnectPipe(
|
||||
_Out_ PHANDLE PipeHandle,
|
||||
_In_ PCWSTR PipeName
|
||||
_In_ PCPH_STRINGREF PipeName
|
||||
)
|
||||
{
|
||||
static CONST PH_STRINGREF deviceName = PH_STRINGREF_INIT(DEVICE_NAMED_PIPE);
|
||||
NTSTATUS status;
|
||||
HANDLE pipeHandle;
|
||||
PPH_STRING pipeName;
|
||||
@@ -273,8 +302,13 @@ NTSTATUS PhConnectPipe(
|
||||
FALSE
|
||||
};
|
||||
|
||||
pipeName = PhConcatStrings2(DEVICE_NAMED_PIPE, PipeName);
|
||||
PhStringRefToUnicodeString(&pipeName->sr, &pipeNameUs);
|
||||
pipeName = PhConcatStringRef2(&deviceName, PipeName);
|
||||
|
||||
if (!PhStringRefToUnicodeString(&pipeName->sr, &pipeNameUs))
|
||||
{
|
||||
PhDereferenceObject(pipeName);
|
||||
return STATUS_NAME_TOO_LONG;
|
||||
}
|
||||
|
||||
InitializeObjectAttributes(
|
||||
&objectAttributes,
|
||||
@@ -438,7 +472,7 @@ NTSTATUS PhPeekNamedPipe(
|
||||
}
|
||||
|
||||
NTSTATUS PhCallNamedPipe(
|
||||
_In_ PWSTR PipeName,
|
||||
_In_ PCWSTR PipeName,
|
||||
_In_reads_bytes_(InputBufferLength) PVOID InputBuffer,
|
||||
_In_ ULONG InputBufferLength,
|
||||
_Out_writes_bytes_(OutputBufferLength) PVOID OutputBuffer,
|
||||
@@ -448,13 +482,13 @@ NTSTATUS PhCallNamedPipe(
|
||||
NTSTATUS status;
|
||||
HANDLE pipeHandle = NULL;
|
||||
|
||||
status = PhConnectPipe(&pipeHandle, PipeName);
|
||||
status = PhConnectPipeZ(&pipeHandle, PipeName);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
PhWaitForNamedPipe(PipeName, 1000);
|
||||
|
||||
status = PhConnectPipe(&pipeHandle, PipeName);
|
||||
status = PhConnectPipeZ(&pipeHandle, PipeName);
|
||||
}
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
|
||||
+18
-16
@@ -23,7 +23,7 @@ PH_TOKEN_ATTRIBUTES PhGetOwnTokenAttributes(
|
||||
)
|
||||
{
|
||||
static PH_INITONCE initOnce = PH_INITONCE_INIT;
|
||||
static PH_TOKEN_ATTRIBUTES attributes = { NULL };
|
||||
static PH_TOKEN_ATTRIBUTES attributes = { NULL, {0}, 0, NULL };
|
||||
|
||||
if (PhBeginInitOnce(&initOnce))
|
||||
{
|
||||
@@ -539,7 +539,6 @@ NTSTATUS PhGetTokenSecurityAttribute(
|
||||
returnLength = 0;
|
||||
bufferLength = 0x200;
|
||||
buffer = PhAllocate(bufferLength);
|
||||
memset(buffer, 0, bufferLength);
|
||||
|
||||
status = NtQuerySecurityAttributesToken(
|
||||
TokenHandle,
|
||||
@@ -554,7 +553,6 @@ NTSTATUS PhGetTokenSecurityAttribute(
|
||||
{
|
||||
bufferLength = returnLength;
|
||||
buffer = PhAllocate(bufferLength);
|
||||
memset(buffer, 0, bufferLength);
|
||||
|
||||
status = NtQuerySecurityAttributesToken(
|
||||
TokenHandle,
|
||||
@@ -987,7 +985,7 @@ BOOLEAN PhPrivilegeCheckAny(
|
||||
* specify a name in the \a PrivilegeName parameter.
|
||||
* \param Attributes The new attributes of the privilege.
|
||||
*/
|
||||
BOOLEAN PhSetTokenPrivilege(
|
||||
NTSTATUS PhSetTokenPrivilege(
|
||||
_In_ HANDLE TokenHandle,
|
||||
_In_opt_ PCWSTR PrivilegeName,
|
||||
_In_opt_ PLUID PrivilegeLuid,
|
||||
@@ -1010,36 +1008,40 @@ BOOLEAN PhSetTokenPrivilege(
|
||||
|
||||
PhInitializeStringRefLongHint(&privilegeName, PrivilegeName);
|
||||
|
||||
if (!NT_SUCCESS(status = PhLookupPrivilegeValue(
|
||||
status = PhLookupPrivilegeValue(
|
||||
&privilegeName,
|
||||
&privileges.Privileges[0].Luid
|
||||
)))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
return STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(status = NtAdjustPrivilegesToken(
|
||||
status = NtAdjustPrivilegesToken(
|
||||
TokenHandle,
|
||||
FALSE,
|
||||
&privileges,
|
||||
0,
|
||||
NULL,
|
||||
NULL
|
||||
)))
|
||||
return FALSE;
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
if (status == STATUS_NOT_ALL_ASSIGNED)
|
||||
return FALSE;
|
||||
{
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return status;
|
||||
}
|
||||
|
||||
BOOLEAN PhSetTokenPrivilege2(
|
||||
NTSTATUS PhSetTokenPrivilege2(
|
||||
_In_ HANDLE TokenHandle,
|
||||
_In_ LONG Privilege,
|
||||
_In_ ULONG Attributes
|
||||
|
||||
+28
-4
@@ -227,15 +227,38 @@ VOID PhStartProviderThread(
|
||||
_Inout_ PPH_PROVIDER_THREAD ProviderThread
|
||||
)
|
||||
{
|
||||
OBJECT_ATTRIBUTES objectAttributes;
|
||||
|
||||
if (ProviderThread->State != ProviderThreadStopped)
|
||||
return;
|
||||
|
||||
// Create and set the timer.
|
||||
NtCreateTimer(&ProviderThread->TimerHandle, TIMER_ALL_ACCESS, NULL, SynchronizationTimer);
|
||||
// Create the synchronization timer.
|
||||
|
||||
InitializeObjectAttributes(
|
||||
&objectAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
NtCreateTimer(
|
||||
&ProviderThread->TimerHandle,
|
||||
TIMER_ALL_ACCESS,
|
||||
&objectAttributes,
|
||||
SynchronizationTimer
|
||||
);
|
||||
assert(ProviderThread->TimerHandle);
|
||||
|
||||
// Set the run interval for the timer.
|
||||
|
||||
PhSetIntervalProviderThread(ProviderThread, ProviderThread->Interval);
|
||||
|
||||
// Create and start the thread.
|
||||
|
||||
PhCreateThreadEx(&ProviderThread->ThreadHandle, PhpProviderThreadStart, ProviderThread);
|
||||
assert(ProviderThread->ThreadHandle);
|
||||
|
||||
ProviderThread->State = ProviderThreadRunning;
|
||||
}
|
||||
|
||||
@@ -258,8 +281,9 @@ VOID PhStopProviderThread(
|
||||
|
||||
// Free resources.
|
||||
NtClose(ProviderThread->ThreadHandle);
|
||||
NtClose(ProviderThread->TimerHandle);
|
||||
ProviderThread->ThreadHandle = NULL;
|
||||
|
||||
NtClose(ProviderThread->TimerHandle);
|
||||
ProviderThread->TimerHandle = NULL;
|
||||
|
||||
ProviderThread->State = ProviderThreadStopped;
|
||||
@@ -273,7 +297,7 @@ VOID PhStopProviderThread(
|
||||
*/
|
||||
VOID PhSetIntervalProviderThread(
|
||||
_Inout_ PPH_PROVIDER_THREAD ProviderThread,
|
||||
_In_ ULONG Interval
|
||||
_In_ LONG Interval
|
||||
)
|
||||
{
|
||||
ProviderThread->Interval = Interval;
|
||||
|
||||
+19
-6
@@ -85,24 +85,37 @@ VOID FASTCALL PhpfWakeQueuedLockEx(
|
||||
static HANDLE PhQueuedLockKeyedEventHandle;
|
||||
static ULONG PhQueuedLockSpinCount = 2000;
|
||||
|
||||
BOOLEAN PhQueuedLockInitialization(
|
||||
NTSTATUS PhQueuedLockInitialization(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
if (!NT_SUCCESS(NtCreateKeyedEvent(
|
||||
NTSTATUS status;
|
||||
OBJECT_ATTRIBUTES objectAttributes;
|
||||
|
||||
InitializeObjectAttributes(
|
||||
&objectAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
status = NtCreateKeyedEvent(
|
||||
&PhQueuedLockKeyedEventHandle,
|
||||
KEYEDEVENT_ALL_ACCESS,
|
||||
NULL,
|
||||
&objectAttributes,
|
||||
0
|
||||
)))
|
||||
return FALSE;
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
if (PhSystemBasicInformation.NumberOfProcessors > 1)
|
||||
PhQueuedLockSpinCount = 4000;
|
||||
else
|
||||
PhQueuedLockSpinCount = 0;
|
||||
|
||||
return TRUE;
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-3
@@ -36,7 +36,7 @@ PPH_CREATE_OBJECT_HOOK PhDbgCreateObjectHook = NULL;
|
||||
/**
|
||||
* Initializes the object manager module.
|
||||
*/
|
||||
BOOLEAN PhRefInitialization(
|
||||
NTSTATUS PhRefInitialization(
|
||||
VOID
|
||||
)
|
||||
{
|
||||
@@ -71,9 +71,9 @@ BOOLEAN PhRefInitialization(
|
||||
PhpAutoPoolTlsIndex = PhTlsAlloc();
|
||||
|
||||
if (PhpAutoPoolTlsIndex == TLS_OUT_OF_INDEXES)
|
||||
return FALSE;
|
||||
return STATUS_NO_MEMORY;
|
||||
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+42
-4
@@ -134,6 +134,48 @@ HRESULT PhCoSetProxyBlanket(
|
||||
return status;
|
||||
}
|
||||
|
||||
HRESULT PhGetWbemClassObjectDependency(
|
||||
_Out_ PVOID* WbemClassObjectDependency,
|
||||
_In_ IWbemClassObject* WbemClassObject,
|
||||
_In_ IWbemServices* WbemServices,
|
||||
_In_ PCWSTR Name
|
||||
)
|
||||
{
|
||||
HRESULT status;
|
||||
IWbemClassObject* dependency;
|
||||
VARIANT variant = { 0 };
|
||||
|
||||
status = IWbemClassObject_Get(
|
||||
WbemClassObject,
|
||||
Name,
|
||||
0,
|
||||
&variant,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (SUCCEEDED(status))
|
||||
{
|
||||
status = IWbemServices_GetObject(
|
||||
WbemServices,
|
||||
V_BSTR(&variant),
|
||||
WBEM_FLAG_RETURN_WBEM_COMPLETE,
|
||||
NULL,
|
||||
&dependency,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (SUCCEEDED(status))
|
||||
{
|
||||
*WbemClassObjectDependency = dependency;
|
||||
}
|
||||
|
||||
SysFreeString(V_BSTR(&variant));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
PPH_STRING PhGetWbemClassObjectString(
|
||||
_In_ PVOID WbemClassObject,
|
||||
_In_ PCWSTR Name
|
||||
@@ -536,7 +578,6 @@ CleanupExit:
|
||||
IWbemLocator_Release(wbemLocator);
|
||||
|
||||
VariantClear(&variantArrayValue);
|
||||
VariantClear(&variantReturnValue);
|
||||
PhClearReference(&querySelectString);
|
||||
|
||||
if (wbemMethodString)
|
||||
@@ -766,7 +807,6 @@ CleanupExit:
|
||||
if (freeSecurityDescriptor && relativeSecurityDescriptor)
|
||||
PhFree(relativeSecurityDescriptor);
|
||||
|
||||
VariantClear(&variantReturnValue);
|
||||
VariantClear(&variantArrayValue);
|
||||
//if (safeArray) SafeArrayDestroy(safeArray);
|
||||
|
||||
@@ -893,8 +933,6 @@ CleanupExit:
|
||||
if (wbemLocator)
|
||||
IWbemLocator_Release(wbemLocator);
|
||||
|
||||
VariantClear(&variantReturnValue);
|
||||
|
||||
if (wbemMethodString)
|
||||
SysFreeString(wbemMethodString);
|
||||
if (wbemObjectString)
|
||||
|
||||
+26
-24
@@ -32,7 +32,9 @@
|
||||
#define PH_THREAD_STACK_NATIVE_MACHINE IMAGE_FILE_MACHINE_I386
|
||||
#endif
|
||||
|
||||
#define PAC_DECODE_ADDRESS(address) (address & ~(USER_SHARED_DATA->UserPointerAuthMask))
|
||||
#if defined(_ARM64_)
|
||||
#define PAC_DECODE_ADDRESS(Address) ((Address) & ~(USER_SHARED_DATA->UserPointerAuthMask))
|
||||
#endif
|
||||
|
||||
typedef struct _PH_SYMBOL_MODULE
|
||||
{
|
||||
@@ -362,27 +364,27 @@ BOOL CALLBACK PhpSymbolCallbackFunction(
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
case CBA_READ_MEMORY:
|
||||
#ifndef _ARM64_
|
||||
{
|
||||
PIMAGEHLP_CBA_READ_MEMORY callbackData = (PIMAGEHLP_CBA_READ_MEMORY)CallbackData;
|
||||
|
||||
if (symbolProvider->IsRealHandle)
|
||||
{
|
||||
if (NT_SUCCESS(NtReadVirtualMemory(
|
||||
ProcessHandle,
|
||||
(PVOID)callbackData->addr,
|
||||
callbackData->buf,
|
||||
(SIZE_T)callbackData->bytes,
|
||||
(PSIZE_T)callbackData->bytesread
|
||||
)))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return FALSE;
|
||||
// case CBA_READ_MEMORY:
|
||||
//#ifndef _ARM64_
|
||||
// {
|
||||
// PIMAGEHLP_CBA_READ_MEMORY callbackData = (PIMAGEHLP_CBA_READ_MEMORY)CallbackData;
|
||||
//
|
||||
// if (symbolProvider->IsRealHandle)
|
||||
// {
|
||||
// if (NT_SUCCESS(NtReadVirtualMemory(
|
||||
// ProcessHandle,
|
||||
// (PVOID)callbackData->addr,
|
||||
// callbackData->buf,
|
||||
// (SIZE_T)callbackData->bytes,
|
||||
// (PSIZE_T)callbackData->bytesread
|
||||
// )))
|
||||
// {
|
||||
// return TRUE;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//#endif
|
||||
// return FALSE;
|
||||
case CBA_DEFERRED_SYMBOL_LOAD_CANCEL:
|
||||
{
|
||||
if (symbolProvider->Terminating)
|
||||
@@ -464,7 +466,7 @@ VOID PhpSymbolProviderCompleteInitialization(
|
||||
PhDereferenceObject(dbghelpName);
|
||||
}
|
||||
|
||||
if (dbghelpHandle && (symsrvName = PhConcatStringRef3(&PhWin32ExtendedPathPrefix, &winsdkPath->sr, &symsrvFileName)))
|
||||
if (symsrvName = PhConcatStringRef3(&PhWin32ExtendedPathPrefix, &winsdkPath->sr, &symsrvFileName))
|
||||
{
|
||||
symsrvHandle = PhLoadLibrary(PhGetString(symsrvName));
|
||||
PhDereferenceObject(symsrvName);
|
||||
@@ -494,7 +496,7 @@ VOID PhpSymbolProviderCompleteInitialization(
|
||||
PhDereferenceObject(dbghelpName);
|
||||
}
|
||||
|
||||
if (dbghelpHandle && (symsrvName = PhConcatStringRef3(&PhWin32ExtendedPathPrefix, &applicationDirectory->sr, &symsrvFileName)))
|
||||
if (symsrvName = PhConcatStringRef3(&PhWin32ExtendedPathPrefix, &applicationDirectory->sr, &symsrvFileName))
|
||||
{
|
||||
symsrvHandle = PhLoadLibrary(symsrvName->Buffer);
|
||||
PhDereferenceObject(symsrvName);
|
||||
|
||||
+357
-260
File diff suppressed because it is too large
Load Diff
+18
-1
@@ -331,7 +331,24 @@ HANDLE PhpGetSemaphoreWorkQueue(
|
||||
|
||||
if (!semaphoreHandle)
|
||||
{
|
||||
NtCreateSemaphore(&semaphoreHandle, SEMAPHORE_ALL_ACCESS, NULL, 0, MAXLONG);
|
||||
OBJECT_ATTRIBUTES objectAttributes;
|
||||
|
||||
InitializeObjectAttributes(
|
||||
&objectAttributes,
|
||||
NULL,
|
||||
OBJ_EXCLUSIVE,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
NtCreateSemaphore(
|
||||
&semaphoreHandle,
|
||||
SEMAPHORE_ALL_ACCESS,
|
||||
&objectAttributes,
|
||||
0,
|
||||
MAXLONG
|
||||
);
|
||||
|
||||
assert(semaphoreHandle);
|
||||
|
||||
if (_InterlockedCompareExchangePointer(
|
||||
|
||||
+361
-285
@@ -13,169 +13,209 @@
|
||||
#include <wslsup.h>
|
||||
#include <mapldr.h>
|
||||
|
||||
BOOLEAN NTAPI PhpWslDistributionNamesCallback(
|
||||
typedef struct _PH_WSL_ENUM_CONTEXT
|
||||
{
|
||||
BOOLEAN Found;
|
||||
PPH_STRINGREF FileName;
|
||||
PPH_STRING DistributionName;
|
||||
PPH_STRING DistributionPath;
|
||||
PPH_STRING TranslatedPath;
|
||||
} PH_WSL_ENUM_CONTEXT, *PPH_WSL_ENUM_CONTEXT;
|
||||
|
||||
_Function_class_(PH_ENUM_KEY_CALLBACK)
|
||||
BOOLEAN NTAPI PhWslDistributionNamesCallback(
|
||||
_In_ HANDLE RootDirectory,
|
||||
_In_ PKEY_BASIC_INFORMATION Information,
|
||||
_In_ PVOID Information,
|
||||
_In_ PVOID Context
|
||||
)
|
||||
{
|
||||
PhAddItemList(Context, PhCreateStringEx(Information->Name, Information->NameLength));
|
||||
PKEY_BASIC_INFORMATION information = (PKEY_BASIC_INFORMATION)Information;
|
||||
PPH_WSL_ENUM_CONTEXT context = (PPH_WSL_ENUM_CONTEXT)Context;
|
||||
HANDLE keyHandle;
|
||||
PH_STRINGREF keyName;
|
||||
|
||||
keyName.Buffer = information->Name;
|
||||
keyName.Length = information->NameLength;
|
||||
|
||||
if (NT_SUCCESS(PhOpenKey(
|
||||
&keyHandle,
|
||||
KEY_READ,
|
||||
RootDirectory,
|
||||
&keyName,
|
||||
0
|
||||
)))
|
||||
{
|
||||
PPH_STRING lxssBasePathName;
|
||||
|
||||
if (lxssBasePathName = PhQueryRegistryStringZ(keyHandle, L"BasePath"))
|
||||
{
|
||||
PhMoveReference(&lxssBasePathName, PhDosPathNameToNtPathName(&lxssBasePathName->sr));
|
||||
|
||||
if (lxssBasePathName && PhStartsWithStringRef(context->FileName, &lxssBasePathName->sr, TRUE))
|
||||
{
|
||||
context->DistributionName = PhQueryRegistryStringZ(keyHandle, L"DistributionName");
|
||||
context->DistributionPath = lxssBasePathName;
|
||||
|
||||
if (context->TranslatedPath = PhCreateString2(context->FileName))
|
||||
{
|
||||
PhSkipStringRef(&context->TranslatedPath->sr, lxssBasePathName->Length);
|
||||
PhSkipStringRef(&context->TranslatedPath->sr, sizeof(L"rootfs"));
|
||||
}
|
||||
|
||||
NtClose(keyHandle);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
PhClearReference(&lxssBasePathName);
|
||||
}
|
||||
|
||||
NtClose(keyHandle);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhGetWslDistributionFromPath(
|
||||
NTSTATUS PhGetWslDistributionFromPath(
|
||||
_In_ PPH_STRINGREF FileName,
|
||||
_Out_opt_ PPH_STRING *LxssDistroName,
|
||||
_Out_opt_ PPH_STRING *LxssDistroPath,
|
||||
_Out_opt_ PPH_STRING *LxssFileName
|
||||
_Out_opt_ PPH_STRING *DistributionName,
|
||||
_Out_opt_ PPH_STRING *DistributionPath,
|
||||
_Out_opt_ PPH_STRING *TranslatedPath
|
||||
)
|
||||
{
|
||||
static CONST PH_STRINGREF lxssKeyPath = PH_STRINGREF_INIT(L"Software\\Microsoft\\Windows\\CurrentVersion\\Lxss");
|
||||
PPH_STRING lxssDistributionName = NULL;
|
||||
PPH_STRING lxssDistroPath = NULL;
|
||||
PPH_STRING lxssFileName = NULL;
|
||||
PH_WSL_ENUM_CONTEXT enumContext;
|
||||
NTSTATUS status;
|
||||
HANDLE keyHandle;
|
||||
ULONG i;
|
||||
|
||||
if (NT_SUCCESS(PhOpenKey(
|
||||
memset(&enumContext, 0, sizeof(PH_WSL_ENUM_CONTEXT));
|
||||
enumContext.FileName = FileName;
|
||||
|
||||
status = PhOpenKey(
|
||||
&keyHandle,
|
||||
KEY_READ,
|
||||
PH_KEY_CURRENT_USER,
|
||||
&lxssKeyPath,
|
||||
0
|
||||
)))
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
PPH_LIST distributionGuidList;
|
||||
|
||||
distributionGuidList = PhCreateList(1);
|
||||
PhEnumerateKey(keyHandle, KeyBasicInformation, PhpWslDistributionNamesCallback, distributionGuidList);
|
||||
|
||||
for (i = 0; i < distributionGuidList->Count; i++)
|
||||
{
|
||||
HANDLE subKeyHandle;
|
||||
PPH_STRING subKeyName;
|
||||
|
||||
subKeyName = distributionGuidList->Items[i];
|
||||
|
||||
if (NT_SUCCESS(PhOpenKey(
|
||||
&subKeyHandle,
|
||||
KEY_READ,
|
||||
keyHandle,
|
||||
&subKeyName->sr,
|
||||
0
|
||||
)))
|
||||
{
|
||||
PPH_STRING lxssBasePathName;
|
||||
|
||||
if (lxssBasePathName = PhQueryRegistryStringZ(subKeyHandle, L"BasePath"))
|
||||
{
|
||||
PhMoveReference(&lxssBasePathName, PhDosPathNameToNtPathName(&lxssBasePathName->sr));
|
||||
}
|
||||
|
||||
if (lxssBasePathName && PhStartsWithStringRef(FileName, &lxssBasePathName->sr, TRUE))
|
||||
{
|
||||
lxssDistributionName = PhQueryRegistryStringZ(subKeyHandle, L"DistributionName");
|
||||
|
||||
if (LxssDistroPath)
|
||||
{
|
||||
PhSetReference(&lxssDistroPath, lxssBasePathName);
|
||||
}
|
||||
|
||||
if (LxssFileName)
|
||||
{
|
||||
lxssFileName = PhCreateString2(FileName);
|
||||
PhSkipStringRef(&lxssFileName->sr, lxssBasePathName->Length);
|
||||
PhSkipStringRef(&lxssFileName->sr, sizeof(L"rootfs"));
|
||||
}
|
||||
}
|
||||
|
||||
PhClearReference(&lxssBasePathName);
|
||||
NtClose(subKeyHandle);
|
||||
}
|
||||
|
||||
if (lxssDistributionName)
|
||||
break;
|
||||
}
|
||||
|
||||
PhDereferenceObjects(distributionGuidList->Items, distributionGuidList->Count);
|
||||
PhDereferenceObject(distributionGuidList);
|
||||
status = PhEnumerateKey(
|
||||
keyHandle,
|
||||
KeyBasicInformation,
|
||||
PhWslDistributionNamesCallback,
|
||||
&enumContext
|
||||
);
|
||||
|
||||
NtClose(keyHandle);
|
||||
}
|
||||
|
||||
if (LxssDistroPath)
|
||||
*LxssDistroPath = lxssDistroPath;
|
||||
else
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
if (lxssDistroPath)
|
||||
PhDereferenceObject(lxssDistroPath);
|
||||
if (DistributionName)
|
||||
*DistributionName = enumContext.DistributionName;
|
||||
else
|
||||
PhClearReference(&enumContext.DistributionName);
|
||||
|
||||
if (DistributionPath)
|
||||
*DistributionPath = enumContext.DistributionPath;
|
||||
else
|
||||
PhClearReference(&enumContext.DistributionPath);
|
||||
|
||||
if (TranslatedPath)
|
||||
*TranslatedPath = PhConvertNtPathSeperatorToAltSeperator(enumContext.TranslatedPath);
|
||||
else
|
||||
PhClearReference(&enumContext.TranslatedPath);
|
||||
}
|
||||
|
||||
if (LxssFileName)
|
||||
{
|
||||
if (lxssFileName)
|
||||
{
|
||||
for (i = 0; i < lxssFileName->Length / sizeof(WCHAR); i++)
|
||||
{
|
||||
if (lxssFileName->Buffer[i] == OBJ_NAME_PATH_SEPARATOR) // RtlNtPathSeperatorString
|
||||
lxssFileName->Buffer[i] = OBJ_NAME_ALTPATH_SEPARATOR; // RtlAlternateDosPathSeperatorString
|
||||
}
|
||||
}
|
||||
|
||||
*LxssFileName = lxssFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lxssFileName)
|
||||
PhDereferenceObject(lxssFileName);
|
||||
}
|
||||
|
||||
if (LxssDistroName)
|
||||
{
|
||||
*LxssDistroName = lxssDistributionName;
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (lxssDistributionName)
|
||||
PhDereferenceObject(lxssDistributionName);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return status;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhDosPathNameToWslPathName(
|
||||
PPH_STRING PhGetWslDistributionCommandLine(
|
||||
_In_ PPH_STRING DistributionName,
|
||||
_In_ PPH_STRING CommandLine
|
||||
)
|
||||
{
|
||||
PH_FORMAT format[4];
|
||||
PPH_STRING systemDirectory;
|
||||
PPH_STRING commandLine;
|
||||
|
||||
// "wsl.exe -u root -d %s -e %s"
|
||||
PhInitFormatS(&format[0], L"wsl.exe -u root -d ");
|
||||
PhInitFormatSR(&format[1], DistributionName->sr);
|
||||
PhInitFormatS(&format[2], L" -e ");
|
||||
PhInitFormatSR(&format[3], CommandLine->sr);
|
||||
|
||||
if (commandLine = PhFormat(format, RTL_NUMBER_OF(format), 0))
|
||||
{
|
||||
if (systemDirectory = PhGetSystemDirectory())
|
||||
{
|
||||
PhMoveReference(&commandLine, PhConcatStringRef3(
|
||||
&systemDirectory->sr,
|
||||
&PhNtPathSeparatorString,
|
||||
&commandLine->sr
|
||||
));
|
||||
PhDereferenceObject(systemDirectory);
|
||||
}
|
||||
|
||||
return commandLine;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PPH_STRING PhGetWslPathCommandLine(
|
||||
_In_ PPH_STRING win32FileName
|
||||
)
|
||||
{
|
||||
PH_FORMAT format[3];
|
||||
|
||||
PhInitFormatS(&format[0], L"wslpath -a -u \"");
|
||||
PhInitFormatSR(&format[1], win32FileName->sr);
|
||||
PhInitFormatC(&format[2], L'\"');
|
||||
|
||||
return PhFormat(format, RTL_NUMBER_OF(format), 0x100);
|
||||
}
|
||||
|
||||
NTSTATUS PhDosPathNameToWslPathName(
|
||||
_In_ PPH_STRINGREF FileName,
|
||||
_Out_ PPH_STRING* LxssFileName
|
||||
)
|
||||
{
|
||||
BOOLEAN success = FALSE;
|
||||
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||
PPH_STRING win32FileName = NULL;
|
||||
PPH_STRING lxssDistroName = NULL;
|
||||
PPH_STRING distributionName = NULL;
|
||||
PPH_STRING lxssCommandLine = NULL;
|
||||
PPH_STRING lxssCommandResult = NULL;
|
||||
PH_FORMAT format[3];
|
||||
|
||||
win32FileName = PhCreateString2(FileName);
|
||||
PhMoveReference(&win32FileName, PhGetFileName(win32FileName));
|
||||
|
||||
if (PhIsNullOrEmptyString(win32FileName))
|
||||
return FALSE;
|
||||
|
||||
if (!PhGetWslDistributionFromPath(FileName, &lxssDistroName, NULL, NULL))
|
||||
goto CleanupExit;
|
||||
|
||||
PhInitFormatS(&format[0], L"wslpath -a -u \"");
|
||||
PhInitFormatSR(&format[1], win32FileName->sr);
|
||||
PhInitFormatC(&format[2], L'\"');
|
||||
lxssCommandLine = PhFormat(format, RTL_NUMBER_OF(format), 0x100);
|
||||
lxssCommandLine = PhGetWslPathCommandLine(win32FileName);
|
||||
|
||||
if (!PhCreateProcessLxss(lxssDistroName, lxssCommandLine, &lxssCommandResult))
|
||||
if (PhIsNullOrEmptyString(win32FileName))
|
||||
goto CleanupExit;
|
||||
|
||||
if (PhIsNullOrEmptyString(lxssCommandResult))
|
||||
status = PhGetWslDistributionFromPath(
|
||||
FileName,
|
||||
&distributionName,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
status = PhCreateProcessLxss(
|
||||
distributionName,
|
||||
lxssCommandLine,
|
||||
&lxssCommandResult
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
if (PhEndsWithString2(lxssCommandResult, L"\n", FALSE))
|
||||
@@ -185,47 +225,53 @@ BOOLEAN PhDosPathNameToWslPathName(
|
||||
}
|
||||
|
||||
*LxssFileName = PhReferenceObject(lxssCommandResult);
|
||||
success = TRUE;
|
||||
status = STATUS_SUCCESS;
|
||||
|
||||
CleanupExit:
|
||||
|
||||
if (lxssCommandResult) PhDereferenceObject(lxssCommandResult);
|
||||
if (lxssCommandLine) PhDereferenceObject(lxssCommandLine);
|
||||
if (lxssDistroName) PhDereferenceObject(lxssDistroName);
|
||||
if (win32FileName) PhDereferenceObject(win32FileName);
|
||||
PhClearReference(&lxssCommandResult);
|
||||
PhClearReference(&lxssCommandLine);
|
||||
PhClearReference(&distributionName);
|
||||
PhClearReference(&win32FileName);
|
||||
|
||||
return success;
|
||||
return status;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhWslQueryDistroProcessCommandLine(
|
||||
NTSTATUS PhWslQueryDistroProcessCommandLine(
|
||||
_In_ PPH_STRINGREF FileName,
|
||||
_In_ ULONG LxssProcessId,
|
||||
_Out_ PPH_STRING* Result
|
||||
)
|
||||
{
|
||||
PPH_STRING lxssCommandResult = NULL;
|
||||
PPH_STRING lxssCommandLine = NULL;
|
||||
PPH_STRING lxssDistroName = NULL;
|
||||
NTSTATUS status;
|
||||
PPH_STRING distributionCommand = NULL;
|
||||
PPH_STRING distributionResult = NULL;
|
||||
PPH_STRING distributionName = NULL;
|
||||
PH_FORMAT format[5];
|
||||
|
||||
if (!PhGetWslDistributionFromPath(FileName, &lxssDistroName, NULL, NULL))
|
||||
return FALSE;
|
||||
status = PhGetWslDistributionFromPath(
|
||||
FileName,
|
||||
&distributionName,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
PhInitFormatS(&format[0], L"\\Device\\Mup\\wsl.localhost\\");
|
||||
PhInitFormatSR(&format[1], lxssDistroName->sr);
|
||||
PhInitFormatSR(&format[1], distributionName->sr);
|
||||
PhInitFormatS(&format[2], L"\\proc\\");
|
||||
PhInitFormatIU(&format[3], LxssProcessId);
|
||||
PhInitFormatS(&format[4], L"\\cmdline");
|
||||
|
||||
if (lxssCommandLine = PhFormat(format, RTL_NUMBER_OF(format), 0x100))
|
||||
if (distributionCommand = PhFormat(format, RTL_NUMBER_OF(format), 0x100))
|
||||
{
|
||||
NTSTATUS status;
|
||||
HANDLE fileHandle;
|
||||
|
||||
status = PhCreateFile(
|
||||
&fileHandle,
|
||||
&lxssCommandLine->sr,
|
||||
&distributionCommand->sr,
|
||||
FILE_GENERIC_READ,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
FILE_SHARE_READ | FILE_SHARE_DELETE,
|
||||
@@ -236,16 +282,17 @@ BOOLEAN PhWslQueryDistroProcessCommandLine(
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
status = PhGetFileText(
|
||||
&lxssCommandResult,
|
||||
&distributionResult,
|
||||
fileHandle,
|
||||
TRUE
|
||||
);
|
||||
NtClose(fileHandle);
|
||||
}
|
||||
else if (status == STATUS_ACCESS_DENIED)
|
||||
|
||||
if (status == STATUS_ACCESS_DENIED)
|
||||
{
|
||||
PPH_STRING lxssRootCommandLine;
|
||||
PPH_STRING lxssRootCommandResult;
|
||||
PPH_STRING commandLine;
|
||||
PPH_STRING commandResult;
|
||||
|
||||
// Note: The WSL P9 Multiple UNC Provider (MUP) doesn't allow administrators to read /proc unless the distro wsl.conf default user is root.
|
||||
// Changing the default user to root fixes permission issues when accessing files from Windows but results in everything owned by root and inaccessible from WSL.
|
||||
@@ -256,60 +303,72 @@ BOOLEAN PhWslQueryDistroProcessCommandLine(
|
||||
PhInitFormatIU(&format[1], LxssProcessId);
|
||||
PhInitFormatS(&format[2], L"/cmdline");
|
||||
|
||||
if (lxssRootCommandLine = PhFormat(format, 3, 0x100))
|
||||
if (commandLine = PhFormat(format, 3, 0x100))
|
||||
{
|
||||
if (PhCreateProcessLxss(lxssDistroName, lxssRootCommandLine, &lxssRootCommandResult))
|
||||
status = PhCreateProcessLxss(
|
||||
distributionName,
|
||||
commandLine,
|
||||
&commandResult
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
lxssCommandResult = lxssRootCommandResult;
|
||||
distributionResult = commandResult;
|
||||
}
|
||||
|
||||
PhDereferenceObject(lxssRootCommandLine);
|
||||
PhDereferenceObject(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
PhDereferenceObject(lxssCommandLine);
|
||||
PhDereferenceObject(distributionCommand);
|
||||
}
|
||||
|
||||
PhDereferenceObject(lxssDistroName);
|
||||
PhDereferenceObject(distributionName);
|
||||
|
||||
if (lxssCommandResult)
|
||||
if (distributionResult)
|
||||
{
|
||||
*Result = lxssCommandResult;
|
||||
return TRUE;
|
||||
*Result = distributionResult;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhWslQueryDistroProcessEnvironment(
|
||||
NTSTATUS PhWslQueryDistroProcessEnvironment(
|
||||
_In_ PPH_STRINGREF FileName,
|
||||
_In_ ULONG LxssProcessId,
|
||||
_Out_ PPH_STRING* Result
|
||||
)
|
||||
{
|
||||
PPH_STRING lxssCommandResult = NULL;
|
||||
PPH_STRING lxssCommandLine = NULL;
|
||||
PPH_STRING lxssDistroName = NULL;
|
||||
NTSTATUS status;
|
||||
PPH_STRING distributionCommand = NULL;
|
||||
PPH_STRING distributionResult = NULL;
|
||||
PPH_STRING distributionName = NULL;
|
||||
PH_FORMAT format[5];
|
||||
|
||||
if (!PhGetWslDistributionFromPath(FileName, &lxssDistroName, NULL, NULL))
|
||||
return FALSE;
|
||||
status = PhGetWslDistributionFromPath(
|
||||
FileName,
|
||||
&distributionName,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
PhInitFormatS(&format[0], L"\\Device\\Mup\\wsl.localhost\\");
|
||||
PhInitFormatSR(&format[1], lxssDistroName->sr);
|
||||
PhInitFormatSR(&format[1], distributionName->sr);
|
||||
PhInitFormatS(&format[2], L"\\proc\\");
|
||||
PhInitFormatIU(&format[3], LxssProcessId);
|
||||
PhInitFormatS(&format[4], L"\\environ");
|
||||
|
||||
if (lxssCommandLine = PhFormat(format, RTL_NUMBER_OF(format), 0x100))
|
||||
if (distributionCommand = PhFormat(format, RTL_NUMBER_OF(format), 0x100))
|
||||
{
|
||||
NTSTATUS status;
|
||||
HANDLE fileHandle;
|
||||
|
||||
status = PhCreateFile(
|
||||
&fileHandle,
|
||||
&lxssCommandLine->sr,
|
||||
&distributionCommand->sr,
|
||||
FILE_GENERIC_READ,
|
||||
FILE_ATTRIBUTE_NORMAL,
|
||||
FILE_SHARE_READ | FILE_SHARE_DELETE,
|
||||
@@ -320,16 +379,17 @@ BOOLEAN PhWslQueryDistroProcessEnvironment(
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
status = PhGetFileText(
|
||||
&lxssCommandResult,
|
||||
&distributionResult,
|
||||
fileHandle,
|
||||
TRUE
|
||||
);
|
||||
NtClose(fileHandle);
|
||||
}
|
||||
else if (status == STATUS_ACCESS_DENIED)
|
||||
|
||||
if (status == STATUS_ACCESS_DENIED)
|
||||
{
|
||||
PPH_STRING lxssRootCommandLine;
|
||||
PPH_STRING lxssRootCommandResult;
|
||||
PPH_STRING commandLine;
|
||||
PPH_STRING commandResult;
|
||||
|
||||
// Note: The WSL P9 Multiple UNC Provider (MUP) doesn't allow administrators to read /proc unless the distro wsl.conf default user is root.
|
||||
// Changing the default user to root fixes permission issues when accessing files from Windows but results in everything owned by root and inaccessible from WSL.
|
||||
@@ -340,68 +400,77 @@ BOOLEAN PhWslQueryDistroProcessEnvironment(
|
||||
PhInitFormatIU(&format[1], LxssProcessId);
|
||||
PhInitFormatS(&format[2], L"/environ");
|
||||
|
||||
if (lxssRootCommandLine = PhFormat(format, 3, 0x100))
|
||||
if (commandLine = PhFormat(format, 3, 0x100))
|
||||
{
|
||||
if (PhCreateProcessLxss(lxssDistroName, lxssRootCommandLine, &lxssRootCommandResult))
|
||||
status = PhCreateProcessLxss(
|
||||
distributionName,
|
||||
commandLine,
|
||||
&commandResult
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
lxssCommandResult = lxssRootCommandResult;
|
||||
distributionResult = commandResult;
|
||||
}
|
||||
|
||||
PhDereferenceObject(lxssRootCommandLine);
|
||||
PhDereferenceObject(commandLine);
|
||||
}
|
||||
}
|
||||
|
||||
PhDereferenceObject(lxssCommandLine);
|
||||
PhDereferenceObject(distributionCommand);
|
||||
}
|
||||
|
||||
PhDereferenceObject(lxssDistroName);
|
||||
PhDereferenceObject(distributionName);
|
||||
|
||||
if (lxssCommandResult)
|
||||
if (distributionResult)
|
||||
{
|
||||
*Result = lxssCommandResult;
|
||||
return TRUE;
|
||||
*Result = distributionResult;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhWslQueryRpmPackageFromFileName(
|
||||
_In_ PPH_STRING LxssDistribution,
|
||||
NTSTATUS PhWslQueryRpmPackageFromFileName(
|
||||
_In_ PPH_STRING DistributionName,
|
||||
_In_ PPH_STRING LxssFileName,
|
||||
_Out_ PPH_STRING* Result
|
||||
)
|
||||
{
|
||||
PPH_STRING lxssCommandLine;
|
||||
PPH_STRING lxssCommandResult;
|
||||
NTSTATUS status;
|
||||
PPH_STRING commandLine;
|
||||
PPH_STRING commandResult;
|
||||
PH_FORMAT format[3];
|
||||
|
||||
// "rpm -qf %s --queryformat \"%%{VERSION}|%%{VENDOR}|%%{SUMMARY}\""
|
||||
PhInitFormatS(&format[0], L"rpm -qf \"");
|
||||
PhInitFormatSR(&format[1], LxssFileName->sr);
|
||||
PhInitFormatS(&format[2], L"\" --queryformat \"%%{VERSION}|%%{VENDOR}|%%{SUMMARY}\"");
|
||||
lxssCommandLine = PhFormat(format, RTL_NUMBER_OF(format), 0x100);
|
||||
commandLine = PhFormat(format, RTL_NUMBER_OF(format), 0x100);
|
||||
|
||||
if (PhCreateProcessLxss(LxssDistribution, lxssCommandLine, &lxssCommandResult))
|
||||
status = PhCreateProcessLxss(
|
||||
DistributionName,
|
||||
commandLine,
|
||||
&commandResult
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(status))
|
||||
{
|
||||
*Result = lxssCommandResult;
|
||||
PhDereferenceObject(lxssCommandLine);
|
||||
return TRUE;
|
||||
*Result = commandResult;
|
||||
}
|
||||
|
||||
PhDereferenceObject(lxssCommandLine);
|
||||
return FALSE;
|
||||
PhDereferenceObject(commandLine);
|
||||
return status;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhWslQueryDebianPackageFromFileName(
|
||||
NTSTATUS PhWslQueryDebianPackageFromFileName(
|
||||
_In_ PPH_STRING LxssDistribution,
|
||||
_In_ PPH_STRING LxssFileName,
|
||||
_Out_ PPH_STRING* Result
|
||||
)
|
||||
{
|
||||
BOOLEAN success = FALSE;
|
||||
PPH_STRING lxssCommandLine;
|
||||
NTSTATUS status = STATUS_UNSUCCESSFUL;
|
||||
PPH_STRING commandLine;
|
||||
PPH_STRING lxssCommandResult = NULL;
|
||||
PPH_STRING lxssPackageName = NULL;
|
||||
PH_FORMAT format[3];
|
||||
@@ -410,9 +479,15 @@ BOOLEAN PhWslQueryDebianPackageFromFileName(
|
||||
PhInitFormatS(&format[0], L"dpkg -S \"");
|
||||
PhInitFormatSR(&format[1], LxssFileName->sr);
|
||||
PhInitFormatS(&format[2], L"\"");
|
||||
lxssCommandLine = PhFormat(format, RTL_NUMBER_OF(format), 0x100);
|
||||
commandLine = PhFormat(format, RTL_NUMBER_OF(format), 0x100);
|
||||
|
||||
if (!PhCreateProcessLxss(LxssDistribution, lxssCommandLine, &lxssCommandResult))
|
||||
status = PhCreateProcessLxss(
|
||||
LxssDistribution,
|
||||
commandLine,
|
||||
&lxssCommandResult
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
// The dpkg metadata doesn't contain information for symbolic links
|
||||
// from "/usr/bin -> /bin" so remove the /usr prefix and try again. (dmex)
|
||||
@@ -425,9 +500,15 @@ BOOLEAN PhWslQueryDebianPackageFromFileName(
|
||||
PhInitFormatS(&format[0], L"dpkg -S \"");
|
||||
PhInitFormatSR(&format[1], LxssFileName->sr);
|
||||
PhInitFormatS(&format[2], L"\"");
|
||||
PhMoveReference(&lxssCommandLine, PhFormat(format, RTL_NUMBER_OF(format), 0x100));
|
||||
PhMoveReference(&commandLine, PhFormat(format, RTL_NUMBER_OF(format), 0x100));
|
||||
|
||||
if (!PhCreateProcessLxss(LxssDistribution, lxssCommandLine, &lxssCommandResult))
|
||||
status = PhCreateProcessLxss(
|
||||
LxssDistribution,
|
||||
commandLine,
|
||||
&lxssCommandResult
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
{
|
||||
goto CleanupExit;
|
||||
}
|
||||
@@ -458,26 +539,28 @@ BOOLEAN PhWslQueryDebianPackageFromFileName(
|
||||
PhInitFormatS(&format[0], L"dpkg-query -W -f=${Version}|${Maintainer}|${binary:Summary} \"");
|
||||
PhInitFormatSR(&format[1], lxssPackageName->sr);
|
||||
PhInitFormatS(&format[2], L"\"");
|
||||
PhMoveReference(&lxssCommandLine, PhFormat(format, RTL_NUMBER_OF(format), 0x100));
|
||||
PhMoveReference(&commandLine, PhFormat(format, RTL_NUMBER_OF(format), 0x100));
|
||||
|
||||
if (!PhCreateProcessLxss(LxssDistribution, lxssCommandLine, &lxssCommandResult))
|
||||
{
|
||||
status = PhCreateProcessLxss(
|
||||
LxssDistribution,
|
||||
commandLine,
|
||||
&lxssCommandResult
|
||||
);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
}
|
||||
|
||||
*Result = PhReferenceObject(lxssCommandResult);
|
||||
success = TRUE;
|
||||
|
||||
CleanupExit:
|
||||
if (lxssPackageName) PhDereferenceObject(lxssPackageName);
|
||||
if (lxssCommandResult) PhDereferenceObject(lxssCommandResult);
|
||||
if (lxssCommandLine) PhDereferenceObject(lxssCommandLine);
|
||||
if (commandLine) PhDereferenceObject(commandLine);
|
||||
|
||||
return success;
|
||||
return status;
|
||||
}
|
||||
|
||||
_Success_(return)
|
||||
BOOLEAN PhWslParsePackageVersionInfo(
|
||||
NTSTATUS PhWslParsePackageVersionInfo(
|
||||
_Inout_ PPH_IMAGE_VERSION_INFO ImageVersionInfo,
|
||||
_In_ PPH_STRING LxssCommandResult
|
||||
)
|
||||
@@ -488,7 +571,7 @@ BOOLEAN PhWslParsePackageVersionInfo(
|
||||
PH_STRINGREF versionPart;
|
||||
|
||||
if (PhIsNullOrEmptyString(LxssCommandResult))
|
||||
return FALSE;
|
||||
return STATUS_UNSUCCESSFUL;
|
||||
|
||||
remainingPart = PhGetStringRef(LxssCommandResult);
|
||||
PhSplitStringRefAtChar(&remainingPart, L'|', &versionPart, &remainingPart);
|
||||
@@ -510,84 +593,96 @@ BOOLEAN PhWslParsePackageVersionInfo(
|
||||
ImageVersionInfo->FileDescription = PhCreateString2(&descriptionPart);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
BOOLEAN PhInitializeLxssImageVersionInfo(
|
||||
NTSTATUS PhInitializeLxssImageVersionInfo(
|
||||
_Inout_ PPH_IMAGE_VERSION_INFO ImageVersionInfo,
|
||||
_In_ PPH_STRINGREF FileName
|
||||
)
|
||||
{
|
||||
BOOLEAN success = FALSE;
|
||||
PPH_STRING lxssCommandResult = NULL;
|
||||
PPH_STRING lxssDistroName = NULL;
|
||||
PPH_STRING lxssFileName = NULL;
|
||||
NTSTATUS success;
|
||||
PPH_STRING distributionCommand = NULL;
|
||||
PPH_STRING distributionName = NULL;
|
||||
PPH_STRING translatedPath = NULL;
|
||||
|
||||
if (!PhGetWslDistributionFromPath(FileName, &lxssDistroName, NULL, &lxssFileName))
|
||||
return FALSE;
|
||||
if (PhIsNullOrEmptyString(lxssFileName))
|
||||
goto CleanupExit;
|
||||
if (PhEqualString2(lxssFileName, L"/init", FALSE))
|
||||
goto CleanupExit;
|
||||
success = PhGetWslDistributionFromPath(
|
||||
FileName,
|
||||
&distributionName,
|
||||
NULL,
|
||||
&translatedPath
|
||||
);
|
||||
|
||||
if (PhWslQueryDebianPackageFromFileName(lxssDistroName, lxssFileName, &lxssCommandResult))
|
||||
if (!NT_SUCCESS(success))
|
||||
return success;
|
||||
|
||||
if (PhEqualString2(translatedPath, L"/init", FALSE))
|
||||
{
|
||||
if (PhWslParsePackageVersionInfo(ImageVersionInfo, lxssCommandResult))
|
||||
{
|
||||
success = TRUE;
|
||||
goto CleanupExit;
|
||||
}
|
||||
success = STATUS_UNSUCCESSFUL;
|
||||
goto CleanupExit;
|
||||
}
|
||||
|
||||
if (PhWslQueryRpmPackageFromFileName(lxssDistroName, lxssFileName, &lxssCommandResult))
|
||||
success = PhWslQueryDebianPackageFromFileName(
|
||||
distributionName,
|
||||
translatedPath,
|
||||
&distributionCommand
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(success))
|
||||
{
|
||||
if (PhWslParsePackageVersionInfo(ImageVersionInfo, lxssCommandResult))
|
||||
{
|
||||
success = TRUE;
|
||||
success = PhWslParsePackageVersionInfo(ImageVersionInfo, distributionCommand);
|
||||
|
||||
if (NT_SUCCESS(success))
|
||||
goto CleanupExit;
|
||||
}
|
||||
|
||||
success = PhWslQueryRpmPackageFromFileName(
|
||||
distributionName,
|
||||
translatedPath,
|
||||
&distributionCommand
|
||||
);
|
||||
|
||||
if (NT_SUCCESS(success))
|
||||
{
|
||||
success = PhWslParsePackageVersionInfo(ImageVersionInfo, distributionCommand);
|
||||
|
||||
if (NT_SUCCESS(success))
|
||||
goto CleanupExit;
|
||||
}
|
||||
}
|
||||
|
||||
CleanupExit:
|
||||
PhClearReference(&lxssCommandResult);
|
||||
PhClearReference(&lxssDistroName);
|
||||
PhClearReference(&lxssFileName);
|
||||
PhClearReference(&distributionCommand);
|
||||
PhClearReference(&distributionName);
|
||||
PhClearReference(&translatedPath);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
BOOLEAN PhCreateProcessLxss(
|
||||
NTSTATUS PhCreateProcessLxss(
|
||||
_In_ PPH_STRING LxssDistribution,
|
||||
_In_ PPH_STRING LxssCommandLine,
|
||||
_Out_ PPH_STRING *Result
|
||||
)
|
||||
{
|
||||
static SECURITY_ATTRIBUTES securityAttributes = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
|
||||
static HRESULT (WINAPI* CreatePseudoConsole_I)(
|
||||
_In_ COORD size,
|
||||
_In_ HANDLE hInput,
|
||||
_In_ HANDLE hOutput,
|
||||
_In_ DWORD dwFlags,
|
||||
_Out_ HPCON* phPC
|
||||
) = NULL;
|
||||
static VOID (WINAPI* ClosePseudoConsole_I)(_In_ HPCON hPC) = NULL;
|
||||
#if defined(PH_WSL_PSEUDOCONSOLE)
|
||||
static __typeof__(&CreatePseudoConsole) CreatePseudoConsole_I = NULL;
|
||||
static __typeof__(&ClosePseudoConsole) ClosePseudoConsole_I = NULL;
|
||||
static PH_INITONCE initOnce = PH_INITONCE_INIT;
|
||||
|
||||
NTSTATUS status;
|
||||
BOOLEAN result = FALSE;
|
||||
PPH_STRING lxssOutputString = NULL;
|
||||
PPH_STRING lxssCommandLine;
|
||||
PPH_STRING systemDirectory;
|
||||
HANDLE processHandle = NULL;
|
||||
HPCON pseudoConsoleHandle = NULL;
|
||||
#endif
|
||||
NTSTATUS status;
|
||||
PPH_STRING distributionCommand = NULL;
|
||||
PPH_STRING distributionCommandLine;
|
||||
HANDLE processHandle = NULL;
|
||||
HANDLE outputReadHandle = NULL, outputWriteHandle = NULL;
|
||||
HANDLE inputReadHandle = NULL, inputWriteHandle = NULL;
|
||||
PPROC_THREAD_ATTRIBUTE_LIST attributeList = NULL;
|
||||
HANDLE handleList[2];
|
||||
STARTUPINFOEX startupInfo = { 0 };
|
||||
PROCESS_BASIC_INFORMATION basicInfo;
|
||||
PH_FORMAT format[4];
|
||||
|
||||
#if defined(PH_WSL_PSEUDOCONSOLE)
|
||||
if (PhBeginInitOnce(&initOnce))
|
||||
{
|
||||
if (WindowsVersion >= WINDOWS_10_RS5)
|
||||
@@ -604,32 +699,14 @@ BOOLEAN PhCreateProcessLxss(
|
||||
PhEndInitOnce(&initOnce);
|
||||
}
|
||||
|
||||
*Result = NULL;
|
||||
|
||||
if (!CreatePseudoConsole_I || !ClosePseudoConsole_I)
|
||||
return FALSE;
|
||||
return STATUS_PROCEDURE_NOT_FOUND;
|
||||
#endif
|
||||
|
||||
// "wsl.exe -u root -d %s -e %s"
|
||||
PhInitFormatS(&format[0], L"wsl.exe -u root -d ");
|
||||
PhInitFormatSR(&format[1], LxssDistribution->sr);
|
||||
PhInitFormatS(&format[2], L" -e ");
|
||||
PhInitFormatSR(&format[3], LxssCommandLine->sr);
|
||||
distributionCommandLine = PhGetWslDistributionCommandLine(LxssDistribution, LxssCommandLine);
|
||||
|
||||
lxssCommandLine = PhFormat(
|
||||
format,
|
||||
RTL_NUMBER_OF(format),
|
||||
0x100
|
||||
);
|
||||
|
||||
if (systemDirectory = PhGetSystemDirectory())
|
||||
{
|
||||
PhMoveReference(&lxssCommandLine, PhConcatStringRef3(
|
||||
&systemDirectory->sr,
|
||||
&PhNtPathSeparatorString,
|
||||
&lxssCommandLine->sr
|
||||
));
|
||||
PhDereferenceObject(systemDirectory);
|
||||
}
|
||||
if (PhIsNullOrEmptyString(distributionCommandLine))
|
||||
return STATUS_OBJECT_NAME_NOT_FOUND;
|
||||
|
||||
status = PhCreatePipeEx(
|
||||
&outputReadHandle,
|
||||
@@ -651,12 +728,14 @@ BOOLEAN PhCreateProcessLxss(
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
#if defined(PH_WSL_PSEUDOCONSOLE)
|
||||
COORD coord = { 80, 25 };
|
||||
if (HR_FAILED(CreatePseudoConsole_I(coord, inputReadHandle, outputWriteHandle, 0, &pseudoConsoleHandle)))
|
||||
{
|
||||
status = STATUS_UNSUCCESSFUL;
|
||||
goto CleanupExit;
|
||||
}
|
||||
#endif
|
||||
|
||||
status = PhInitializeProcThreadAttributeList(&attributeList, 2);
|
||||
|
||||
@@ -676,6 +755,7 @@ BOOLEAN PhCreateProcessLxss(
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
#if defined(PH_WSL_PSEUDOCONSOLE)
|
||||
status = PhUpdateProcThreadAttribute(
|
||||
attributeList,
|
||||
PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE,
|
||||
@@ -685,6 +765,7 @@ BOOLEAN PhCreateProcessLxss(
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
#endif
|
||||
|
||||
memset(&startupInfo, 0, sizeof(STARTUPINFOEX));
|
||||
startupInfo.StartupInfo.cb = sizeof(STARTUPINFOEX);
|
||||
@@ -697,7 +778,7 @@ BOOLEAN PhCreateProcessLxss(
|
||||
|
||||
status = PhCreateProcessWin32Ex(
|
||||
NULL,
|
||||
PhGetString(lxssCommandLine),
|
||||
PhGetString(distributionCommandLine),
|
||||
NULL,
|
||||
NULL,
|
||||
&startupInfo,
|
||||
@@ -717,7 +798,7 @@ BOOLEAN PhCreateProcessLxss(
|
||||
NtClose(outputWriteHandle); outputWriteHandle = NULL;
|
||||
|
||||
// Read the pipe data. (dmex)
|
||||
status = PhGetFileText(&lxssOutputString, outputReadHandle, TRUE);
|
||||
status = PhGetFileText(&distributionCommand, outputReadHandle, TRUE);
|
||||
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
@@ -733,22 +814,17 @@ BOOLEAN PhCreateProcessLxss(
|
||||
if (!NT_SUCCESS(status))
|
||||
goto CleanupExit;
|
||||
|
||||
if (PhIsNullOrEmptyString(lxssOutputString))
|
||||
{
|
||||
status = STATUS_UNSUCCESSFUL;
|
||||
goto CleanupExit;
|
||||
}
|
||||
|
||||
*Result = PhReferenceObject(lxssOutputString);
|
||||
result = TRUE;
|
||||
*Result = PhReferenceObject(distributionCommand);
|
||||
|
||||
CleanupExit:
|
||||
|
||||
if (processHandle)
|
||||
NtClose(processHandle);
|
||||
|
||||
#if defined(PH_WSL_PSEUDOCONSOLE)
|
||||
if (pseudoConsoleHandle)
|
||||
ClosePseudoConsole_I(pseudoConsoleHandle);
|
||||
#endif
|
||||
|
||||
if (outputWriteHandle)
|
||||
NtClose(outputWriteHandle);
|
||||
@@ -762,10 +838,10 @@ CleanupExit:
|
||||
if (attributeList)
|
||||
PhDeleteProcThreadAttributeList(attributeList);
|
||||
|
||||
if (lxssOutputString)
|
||||
PhDereferenceObject(lxssOutputString);
|
||||
if (lxssCommandLine)
|
||||
PhDereferenceObject(lxssCommandLine);
|
||||
if (distributionCommand)
|
||||
PhDereferenceObject(distributionCommand);
|
||||
if (distributionCommandLine)
|
||||
PhDereferenceObject(distributionCommandLine);
|
||||
|
||||
return result;
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -12,11 +12,13 @@
|
||||
|
||||
#include "wndexp.h"
|
||||
|
||||
_Function_class_(PH_HASHTABLE_EQUAL_FUNCTION)
|
||||
BOOLEAN WepWindowNodeHashtableEqualFunction(
|
||||
_In_ PVOID Entry1,
|
||||
_In_ PVOID Entry2
|
||||
);
|
||||
|
||||
_Function_class_(PH_HASHTABLE_HASH_FUNCTION)
|
||||
ULONG WepWindowNodeHashtableHashFunction(
|
||||
_In_ PVOID Entry
|
||||
);
|
||||
@@ -192,6 +194,7 @@ VOID WeInitializeWindowTreeImageList(
|
||||
}
|
||||
}
|
||||
|
||||
_Use_decl_annotations_
|
||||
BOOLEAN WepWindowNodeHashtableEqualFunction(
|
||||
_In_ PVOID Entry1,
|
||||
_In_ PVOID Entry2
|
||||
@@ -203,6 +206,7 @@ BOOLEAN WepWindowNodeHashtableEqualFunction(
|
||||
return windowNode1->WindowHandle == windowNode2->WindowHandle;
|
||||
}
|
||||
|
||||
_Use_decl_annotations_
|
||||
ULONG WepWindowNodeHashtableHashFunction(
|
||||
_In_ PVOID Entry
|
||||
)
|
||||
@@ -244,16 +248,17 @@ PWE_WINDOW_NODE WeAddWindowNode(
|
||||
CLIENT_ID clientId;
|
||||
PPH_PROCESS_ITEM processItem;
|
||||
|
||||
PhGetWindowClientId(WindowHandle, &clientId);
|
||||
|
||||
if (clientId.UniqueProcess && (processItem = PhReferenceProcessItem(clientId.UniqueProcess)))
|
||||
if (NT_SUCCESS(PhGetWindowClientId(WindowHandle, &clientId)))
|
||||
{
|
||||
windowNode->ProcessItem = processItem;
|
||||
|
||||
if (PhTestEvent(&processItem->Stage1Event))
|
||||
if (clientId.UniqueProcess && (processItem = PhReferenceProcessItem(clientId.UniqueProcess)))
|
||||
{
|
||||
windowNode->WindowIconIndex = processItem->SmallIconIndex;
|
||||
windowNode->ProcessIconValid = TRUE;
|
||||
windowNode->ProcessItem = processItem;
|
||||
|
||||
if (PhTestEvent(&processItem->Stage1Event))
|
||||
{
|
||||
windowNode->WindowIconIndex = processItem->SmallIconIndex;
|
||||
windowNode->ProcessIconValid = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -334,12 +339,13 @@ VOID WepDestroyWindowNode(
|
||||
_In_ const void *_elem2 \
|
||||
) \
|
||||
{ \
|
||||
PWE_WINDOW_TREE_CONTEXT context = (PWE_WINDOW_TREE_CONTEXT)_context; \
|
||||
PWE_WINDOW_NODE node1 = *(PWE_WINDOW_NODE *)_elem1; \
|
||||
PWE_WINDOW_NODE node2 = *(PWE_WINDOW_NODE *)_elem2; \
|
||||
int sortResult = 0;
|
||||
|
||||
#define END_SORT_FUNCTION \
|
||||
return PhModifySort(sortResult, ((PWE_WINDOW_TREE_CONTEXT)_context)->TreeNewSortOrder); \
|
||||
return PhModifySort(sortResult, context->TreeNewSortOrder); \
|
||||
}
|
||||
|
||||
BEGIN_SORT_FUNCTION(Class)
|
||||
@@ -356,7 +362,7 @@ END_SORT_FUNCTION
|
||||
|
||||
BEGIN_SORT_FUNCTION(Text)
|
||||
{
|
||||
sortResult = PhCompareStringWithNull(node1->WindowText, node2->WindowText, TRUE);
|
||||
sortResult = PhCompareStringWithNullSortOrder(node1->WindowText, node2->WindowText, context->TreeNewSortOrder, TRUE);
|
||||
}
|
||||
END_SORT_FUNCTION
|
||||
|
||||
@@ -371,7 +377,7 @@ END_SORT_FUNCTION
|
||||
|
||||
BEGIN_SORT_FUNCTION(Module)
|
||||
{
|
||||
sortResult = PhCompareStringWithNull(node1->ModuleString, node2->ModuleString, TRUE);
|
||||
sortResult = PhCompareStringWithNullSortOrder(node1->ModuleString, node2->ModuleString, context->TreeNewSortOrder, TRUE);
|
||||
}
|
||||
END_SORT_FUNCTION
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,2 +0,0 @@
|
||||
"
|
||||
À—5E<ÚÄ»¦±R‘rM‚¾óf4q͆<ìcW¯ëÛ9Àx”Šh0š²Ù~Hxiz„jÌj_Ùƒñv—u<"Ž�¢WڧϹ¦›h¸/SGjùN#…Ó)N£ÂP¨þIiõh&¯6:p)
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
ƒ¢Ë¿ßQé8€0͆ŠÃ|•¹ëðíÒ僤€¤2‡/,L»Ø„̧K» �ÄXXOPºKÃsõ¤ý¿¦�º§n&dÈGˆýæ?GQ‡f€ò¼ið`Ð[œä‰ ˜^T@F�âV¹|WÀ�§ûXK=<Æ
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
mxqÃ�ñ<Ë?oÓeæU7Ñ]ô^A¢hø¼(¿y©ªa%�H4æ„Ô'‹Œ¥ç`^óÚsTæ0ÜèQ²/M?³Ðé団¨*zWÕz74+A{ö‰†6>™'R© ¬Ð0_�S~ž5ÝÄôˆiŠ1Þ
|
||||
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
ώ*ya¤Ν��Η6ώo�-ν+υ…›‚8ΘeοΙ1ΈX±έ‚M›U‘wΑΞHΞι�„©¥τ2���V/ΗΛΔn±`¤›-‰[L“‹ΐ~(%^.XKpy¬Ίλ»&g―'1W�=‹ ‰ΡΑτ �
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
íDcÅy˜zÅïwš.ÿµ…�g>C¾aú>1ðTzÀ,I²Þévd§½2lXqÏmþ‡)?Ù—%øµTµp¯$ë=f XtHß÷4X5Gem—ÉÖ˜èÑÞÕŠ×v7õ¹€?¸½Ð`ëé]1*&
9zW%
|
||||
Binary file not shown.
@@ -18,8 +18,8 @@
|
||||
<uap10:PackageIntegrity>
|
||||
<uap10:Content Enforcement="on" />
|
||||
</uap10:PackageIntegrity>
|
||||
<!-- <desktop6:FileSystemWriteVirtualization>disabled</desktop6:FileSystemWriteVirtualization>
|
||||
<desktop6:RegistryWriteVirtualization>disabled</desktop6:RegistryWriteVirtualization> -->
|
||||
<desktop6:FileSystemWriteVirtualization>disabled</desktop6:FileSystemWriteVirtualization>
|
||||
<desktop6:RegistryWriteVirtualization>disabled</desktop6:RegistryWriteVirtualization>
|
||||
</Properties>
|
||||
<Resources>
|
||||
<Resource Language="en-US" />
|
||||
|
||||
@@ -252,6 +252,8 @@ PvSearchControlMatchPointerRange(
|
||||
|
||||
#define WM_PV_SEARCH_FINISHED (WM_APP + 701)
|
||||
#define WM_PV_SEARCH_SHOWMENU (WM_APP + 702)
|
||||
#define WM_PV_SEARCH_SETREDRAW (WM_APP + 703)
|
||||
#define WM_PV_SEARCH_NODESSTRUCTURED (WM_APP + 704)
|
||||
|
||||
extern ULONG SearchResultsAddIndex;
|
||||
extern PPH_LIST SearchResults;
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ INT WINAPI wWinMain(
|
||||
};
|
||||
PH_STRINGREF commandLine;
|
||||
|
||||
if (!NT_SUCCESS(PhInitializePhLib(L"PE Viewer", hInstance)))
|
||||
if (!NT_SUCCESS(PhInitializePhLib(L"PE Viewer")))
|
||||
return 1;
|
||||
if (!PvInitializeExceptionPolicy())
|
||||
return 1;
|
||||
|
||||
@@ -42,11 +42,10 @@ VOID PvCreateSections(
|
||||
if (!NT_SUCCESS(status))
|
||||
return;
|
||||
|
||||
status = NtCreateSection(
|
||||
status = PhCreateSection(
|
||||
ImageSection,
|
||||
SECTION_QUERY | SECTION_MAP_READ,
|
||||
NULL,
|
||||
NULL,
|
||||
PAGE_READONLY,
|
||||
WindowsVersion < WINDOWS_8 ? SEC_IMAGE : SEC_IMAGE_NO_EXECUTE,
|
||||
fileHandle
|
||||
@@ -54,11 +53,10 @@ VOID PvCreateSections(
|
||||
if (!NT_SUCCESS(status))
|
||||
*ImageSection = NULL;
|
||||
|
||||
status = NtCreateSection(
|
||||
status = PhCreateSection(
|
||||
DataSection,
|
||||
SECTION_QUERY | SECTION_MAP_READ,
|
||||
NULL,
|
||||
NULL,
|
||||
PAGE_READONLY,
|
||||
SEC_COMMIT,
|
||||
fileHandle
|
||||
|
||||
+8
-5
@@ -942,12 +942,15 @@ PPH_STRING PvHashBuffer(
|
||||
|
||||
__try
|
||||
{
|
||||
PhInitializeHash(&hashContext, Md5HashAlgorithm); // PhGetIntegerSetting(L"HashAlgorithm")
|
||||
PhUpdateHash(&hashContext, Buffer, Length);
|
||||
|
||||
if (PhFinalHash(&hashContext, hash, 16, NULL))
|
||||
if (NT_SUCCESS(PhInitializeHash(&hashContext, Md5HashAlgorithm))) // PhGetIntegerSetting(L"HashAlgorithm")
|
||||
{
|
||||
value = PhBufferToHexString(hash, 16);
|
||||
if (NT_SUCCESS(PhUpdateHash(&hashContext, Buffer, Length)))
|
||||
{
|
||||
if (NT_SUCCESS(PhFinalHash(&hashContext, hash, 16, NULL)))
|
||||
{
|
||||
value = PhBufferToHexString(hash, 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||
|
||||
+14
-4
@@ -759,7 +759,7 @@ VOID PvAddPendingSymbolNodes(
|
||||
ULONG i;
|
||||
BOOLEAN needsFullUpdate = FALSE;
|
||||
|
||||
TreeNew_SetRedraw(Context->TreeNewHandle, FALSE);
|
||||
SendMessage(Context->WindowHandle, WM_PV_SEARCH_SETREDRAW, FALSE, 0);
|
||||
|
||||
PhAcquireQueuedLockExclusive(&SearchResultsLock);
|
||||
|
||||
@@ -773,8 +773,8 @@ VOID PvAddPendingSymbolNodes(
|
||||
PhReleaseQueuedLockExclusive(&SearchResultsLock);
|
||||
|
||||
if (needsFullUpdate)
|
||||
TreeNew_NodesStructured(Context->TreeNewHandle);
|
||||
TreeNew_SetRedraw(Context->TreeNewHandle, TRUE);
|
||||
SendMessage(Context->WindowHandle, WM_PV_SEARCH_NODESSTRUCTURED, 0, 0);
|
||||
SendMessage(Context->WindowHandle, WM_PV_SEARCH_SETREDRAW, TRUE, 0);
|
||||
}
|
||||
|
||||
HANDLE PvSymbolGetGlobalTimerQueue(
|
||||
@@ -1083,6 +1083,16 @@ INT_PTR CALLBACK PvpSymbolsDlgProc(
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_PV_SEARCH_SETREDRAW:
|
||||
{
|
||||
TreeNew_SetRedraw(context->TreeNewHandle, wParam);
|
||||
}
|
||||
break;
|
||||
case WM_PV_SEARCH_NODESSTRUCTURED:
|
||||
{
|
||||
TreeNew_NodesStructured(context->TreeNewHandle);
|
||||
}
|
||||
break;
|
||||
case WM_CTLCOLORBTN:
|
||||
case WM_CTLCOLORDLG:
|
||||
case WM_CTLCOLORSTATIC:
|
||||
@@ -1166,7 +1176,7 @@ VOID PvPdbProperties(
|
||||
}
|
||||
else
|
||||
{
|
||||
NtUnmapViewOfSection(NtCurrentProcess(), viewBase);
|
||||
PhUnmapViewOfSection(NtCurrentProcess(), viewBase);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -243,12 +243,7 @@ VOID PvpPeEnumerateImageDataDirectory(
|
||||
ULONG sectionNameLength = 0;
|
||||
WCHAR sectionName[IMAGE_SIZEOF_SHORT_NAME + 1];
|
||||
|
||||
if (PhGetMappedImageSectionName(
|
||||
directorySection,
|
||||
sectionName,
|
||||
RTL_NUMBER_OF(sectionName),
|
||||
§ionNameLength
|
||||
))
|
||||
if (NT_SUCCESS(PhGetMappedImageSectionName(directorySection, sectionName, RTL_NUMBER_OF(sectionName), §ionNameLength)))
|
||||
{
|
||||
directoryNode->SectionNameString = PhCreateStringEx(sectionName, sectionNameLength * sizeof(WCHAR));
|
||||
}
|
||||
|
||||
@@ -196,12 +196,7 @@ VOID PvEnumerateDynamicRelocationEntries(
|
||||
{
|
||||
WCHAR sectionName[IMAGE_SIZEOF_SHORT_NAME + 1];
|
||||
|
||||
if (PhGetMappedImageSectionName(
|
||||
section,
|
||||
sectionName,
|
||||
RTL_NUMBER_OF(sectionName),
|
||||
NULL
|
||||
))
|
||||
if (NT_SUCCESS(PhGetMappedImageSectionName(section, sectionName, RTL_NUMBER_OF(sectionName), NULL)))
|
||||
{
|
||||
PhSetListViewSubItem(ListViewHandle, lvItemIndex, 4, sectionName);
|
||||
}
|
||||
|
||||
@@ -107,12 +107,7 @@ VOID PvEnumerateExceptionEntries(
|
||||
{
|
||||
WCHAR sectionName[IMAGE_SIZEOF_SHORT_NAME + 1];
|
||||
|
||||
if (PhGetMappedImageSectionName(
|
||||
directorySection,
|
||||
sectionName,
|
||||
RTL_NUMBER_OF(sectionName),
|
||||
NULL
|
||||
))
|
||||
if (NT_SUCCESS(PhGetMappedImageSectionName(directorySection, sectionName, RTL_NUMBER_OF(sectionName), NULL)))
|
||||
{
|
||||
PhSetListViewSubItem(Context->ListViewHandle, lvItemIndex, 3, sectionName);
|
||||
}
|
||||
@@ -171,12 +166,7 @@ VOID PvEnumerateExceptionEntries(
|
||||
{
|
||||
WCHAR sectionName[IMAGE_SIZEOF_SHORT_NAME + 1];
|
||||
|
||||
if (PhGetMappedImageSectionName(
|
||||
directorySection,
|
||||
sectionName,
|
||||
RTL_NUMBER_OF(sectionName),
|
||||
NULL
|
||||
))
|
||||
if (NT_SUCCESS(PhGetMappedImageSectionName(directorySection, sectionName, RTL_NUMBER_OF(sectionName), NULL)))
|
||||
{
|
||||
PhSetListViewSubItem(Context->ListViewHandle, lvItemIndex, 6, sectionName);
|
||||
}
|
||||
@@ -279,12 +269,7 @@ VOID PvEnumerateExceptionEntries(
|
||||
{
|
||||
WCHAR sectionName[IMAGE_SIZEOF_SHORT_NAME + 1];
|
||||
|
||||
if (PhGetMappedImageSectionName(
|
||||
directorySection,
|
||||
sectionName,
|
||||
RTL_NUMBER_OF(sectionName),
|
||||
NULL
|
||||
))
|
||||
if (NT_SUCCESS(PhGetMappedImageSectionName(directorySection, sectionName, RTL_NUMBER_OF(sectionName), NULL)))
|
||||
{
|
||||
PhSetListViewSubItem(Context->ListViewHandle, lvItemIndex, 7, sectionName);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ VOID PvEnumerateImagePogoSections(
|
||||
{
|
||||
WCHAR sectionName[IMAGE_SIZEOF_SHORT_NAME + 1];
|
||||
|
||||
if (PhGetMappedImageSectionName(section, sectionName, RTL_NUMBER_OF(sectionName), NULL))
|
||||
if (NT_SUCCESS(PhGetMappedImageSectionName(section, sectionName, RTL_NUMBER_OF(sectionName), NULL)))
|
||||
{
|
||||
PhSetListViewSubItem(ListViewHandle, lvItemIndex, 5, sectionName);
|
||||
}
|
||||
|
||||
@@ -85,12 +85,7 @@ VOID PvEnumerateRelocationEntries(
|
||||
{
|
||||
WCHAR sectionName[IMAGE_SIZEOF_SHORT_NAME + 1];
|
||||
|
||||
if (PhGetMappedImageSectionName(
|
||||
directorySection,
|
||||
sectionName,
|
||||
RTL_NUMBER_OF(sectionName),
|
||||
NULL
|
||||
))
|
||||
if (NT_SUCCESS(PhGetMappedImageSectionName(directorySection, sectionName, RTL_NUMBER_OF(sectionName), NULL)))
|
||||
{
|
||||
PhSetListViewSubItem(ListViewHandle, lvItemIndex, 3, sectionName);
|
||||
}
|
||||
|
||||
@@ -281,12 +281,7 @@ NTSTATUS PvpPeSectionsEnumerateThread(
|
||||
sectionNode->UniqueIdString = PhFormatUInt64(sectionNode->UniqueId, FALSE);
|
||||
sectionNode->SectionHeader = &PvMappedImage.Sections[i];
|
||||
|
||||
if (PhGetMappedImageSectionName(
|
||||
&PvMappedImage.Sections[i],
|
||||
sectionName,
|
||||
RTL_NUMBER_OF(sectionName),
|
||||
§ionNameLength
|
||||
))
|
||||
if (NT_SUCCESS(PhGetMappedImageSectionName(&PvMappedImage.Sections[i], sectionName, RTL_NUMBER_OF(sectionName), §ionNameLength)))
|
||||
{
|
||||
sectionNode->SectionNameString = PhCreateStringEx(sectionName, sectionNameLength * sizeof(WCHAR) - sizeof(UNICODE_NULL));
|
||||
}
|
||||
|
||||
@@ -95,12 +95,12 @@ BOOLEAN PvDumpFileVersionInfo(
|
||||
PH_FORMAT format[3];
|
||||
WCHAR langNameString[65];
|
||||
|
||||
if (!PhGetFileVersionInfoKey(
|
||||
if (!NT_SUCCESS(PhGetFileVersionInfoKey(
|
||||
VersionInfo,
|
||||
blockInfoName.Length / sizeof(WCHAR),
|
||||
blockInfoName.Buffer,
|
||||
&blockStringInfo
|
||||
))
|
||||
)))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -112,12 +112,12 @@ BOOLEAN PvDumpFileVersionInfo(
|
||||
if (!PhFormatToBuffer(format, 1, langNameString, sizeof(langNameString), &returnLength))
|
||||
return FALSE;
|
||||
|
||||
if (!PhGetFileVersionInfoKey(
|
||||
if (!NT_SUCCESS(PhGetFileVersionInfoKey(
|
||||
blockStringInfo,
|
||||
returnLength / sizeof(WCHAR) - sizeof(ANSI_NULL),
|
||||
langNameString,
|
||||
&blockLangInfo
|
||||
))
|
||||
)))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -260,14 +260,15 @@ VOID PvEnumVersionInfo(
|
||||
_In_ HWND ListViewHandle
|
||||
)
|
||||
{
|
||||
NTSTATUS status;
|
||||
ULONG count = 0;
|
||||
VS_FIXEDFILEINFO* rootBlock;
|
||||
PVOID versionInfo;
|
||||
ULONG langCodePage;
|
||||
|
||||
versionInfo = PhGetFileVersionInfo(PvFileName->Buffer);
|
||||
status = PhGetFileVersionInfo(PvFileName->Buffer, &versionInfo);
|
||||
|
||||
if (!versionInfo)
|
||||
if (!NT_SUCCESS(status))
|
||||
return;
|
||||
|
||||
if (rootBlock = PhGetFileVersionFixedInfo(versionInfo))
|
||||
|
||||
Reference in New Issue
Block a user