30 #define PHP_USE_IFILEDIALOG (WINDOWS_HAS_IFILEDIALOG)
33 _In_opt_ HANDLE ServerHandle,
37 _In_ ULONG WinStationInformationLength,
38 _Out_ PULONG ReturnLength
42 _Out_ LPVOID *lpEnvironment,
43 _In_opt_ HANDLE hToken,
48 _In_ LPVOID lpEnvironment
51 DECLSPEC_SELECTANY WCHAR *
PhSizeUnitNames[7] = { L
"B", L
"kB", L
"MB", L
"GB", L
"TB", L
"PB", L
"EB" };
70 if (Rectangle->Left + Rectangle->Width > Bounds->Left + Bounds->Width)
71 Rectangle->Left = Bounds->Left + Bounds->Width - Rectangle->Width;
72 if (Rectangle->Top + Rectangle->Height > Bounds->Top + Bounds->Height)
73 Rectangle->Top = Bounds->Top + Bounds->Height - Rectangle->Height;
75 if (Rectangle->Left < Bounds->Left)
76 Rectangle->Left = Bounds->Left;
77 if (Rectangle->Top < Bounds->Top)
78 Rectangle->Top = Bounds->Top;
93 Rectangle->Left = Bounds->Left + (Bounds->Width - Rectangle->Width) / 2;
94 Rectangle->Top = Bounds->Top + (Bounds->Height - Rectangle->Height) / 2;
109 MONITORINFO monitorInfo = {
sizeof(monitorInfo) };
112 MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST),
132 _In_ HWND WindowHandle,
133 _In_opt_ HWND ParentWindowHandle
136 if (ParentWindowHandle)
138 RECT rect, parentRect;
141 GetWindowRect(WindowHandle, &rect);
142 GetWindowRect(ParentWindowHandle, &parentRect);
148 MoveWindow(WindowHandle, rectangle.
Left, rectangle.
Top,
153 MONITORINFO monitorInfo = {
sizeof(monitorInfo) };
156 MonitorFromWindow(WindowHandle, MONITOR_DEFAULTTONEAREST),
164 GetWindowRect(WindowHandle, &rect);
169 MoveWindow(WindowHandle, rectangle.
Left, rectangle.
Top,
182 _In_reads_(NumberOfObjects) PVOID *Objects,
183 _In_ ULONG NumberOfObjects
188 for (i = 0; i < NumberOfObjects; i++)
199 _In_reads_(NumberOfObjects) PVOID *Objects,
200 _In_ ULONG NumberOfObjects
205 for (i = 0; i < NumberOfObjects; i++)
222 _In_ PVOID DllHandle,
223 _In_ ULONG MessageTableId,
224 _In_ ULONG MessageLanguageId,
229 PMESSAGE_RESOURCE_ENTRY messageEntry;
245 GetSystemDefaultLangID(),
257 MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
266 if (messageEntry->Flags & MESSAGE_RESOURCE_UNICODE)
288 message =
PhGetMessage(GetModuleHandle(L
"ntdll.dll"), 0xb, GetUserDefaultLangID(), (ULONG)Status);
298 if (message->
Length >= 2 *
sizeof(WCHAR) &&
299 message->
Buffer[message->
Length /
sizeof(WCHAR) - 2] ==
'\r' &&
300 message->
Buffer[message->
Length /
sizeof(WCHAR) - 1] ==
'\n')
307 if (message->
Buffer[0] ==
'{')
330 message =
PhGetMessage(GetModuleHandle(L
"kernel32.dll"), 0xb, GetUserDefaultLangID(), Result);
336 if (message && message->
Length >= 2 *
sizeof(WCHAR) &&
337 message->
Buffer[message->
Length /
sizeof(WCHAR) - 2] ==
'\r' &&
338 message->
Buffer[message->
Length /
sizeof(WCHAR) - 1] ==
'\n')
364 va_start(argptr, Format);
388 _In_ NTSTATUS Status,
389 _In_opt_ ULONG Win32Result
396 Status == STATUS_ACCESS_DENIED ||
397 Status == STATUS_ACCESS_VIOLATION
425 _In_opt_ PWSTR Message,
426 _In_ NTSTATUS Status,
427 _In_opt_ ULONG Win32Result
442 PhShowError(hWnd, L
"Unable to perform the operation.");
474 _In_opt_ PWSTR Message,
475 _In_ NTSTATUS Status,
476 _In_opt_ ULONG Win32Result
488 result =
PhShowMessage(hWnd, MB_ICONERROR | MB_OKCANCEL, L
"%s.", Message);
492 result =
PhShowMessage(hWnd, MB_ICONERROR | MB_OKCANCEL, L
"Unable to perform the operation.");
495 return result == IDOK;
500 result =
PhShowMessage(hWnd, MB_ICONERROR | MB_OKCANCEL, L
"%s: %s", Message, statusMessage->
Buffer);
509 return result == IDOK;
528 _In_opt_ PWSTR Message,
548 TASKDIALOGCONFIG config = {
sizeof(config) };
549 TASKDIALOG_BUTTON buttons[2];
552 config.hwndParent = hWnd;
554 config.dwFlags = TDF_ALLOW_DIALOG_CANCELLATION;
556 config.pszMainIcon = Warning ? TD_WARNING_ICON : NULL;
562 buttons[0].nButtonID = IDYES;
563 buttons[0].pszButtonText = verbCaps->
Buffer;
564 buttons[1].nButtonID = IDNO;
565 buttons[1].pszButtonText = L
"Cancel";
568 config.pButtons = buttons;
569 config.nDefaultButton = IDYES;
578 return button == IDYES;
589 MB_YESNO | MB_ICONWARNING,
590 L
"Are you sure you want to %s?",
610 _In_ ULONG SizeOfKeyValuePairs,
621 *Integer = (ULONG)KeyValuePairs[i].Value;
641 _In_ ULONG SizeOfKeyValuePairs,
650 if ((ULONG)KeyValuePairs[i].Value == Integer)
652 *String = (PWSTR)KeyValuePairs[i].Key;
669 static ULONG seed = 0;
677 for (i = 0; i < 6; i++)
681 *(PUSHORT)&Guid->Data1 = (USHORT)random[0];
683 *((PUSHORT)&Guid->Data1 + 1) = (USHORT)((random[0] >> 16) | (random[1] & 0xff));
685 Guid->Data2 = (SHORT)(random[1] >> 8);
687 Guid->Data3 = (SHORT)random[2];
689 *(PUSHORT)&Guid->Data4[0] = (USHORT)((random[2] >> 16) | (random[3] & 0xff));
691 *(PUSHORT)&Guid->Data4[2] = (USHORT)(random[3] >> 8);
693 *(PUSHORT)&Guid->Data4[4] = (USHORT)random[4];
695 *(PUSHORT)&Guid->Data4[6] = (USHORT)((random[4] >> 16) | (random[5] & 0xff));
706 Guid->Data1 = _byteswap_ulong(Guid->Data1);
707 Guid->Data2 = _byteswap_ushort(Guid->Data2);
708 Guid->Data3 = _byteswap_ushort(Guid->Data3);
725 _In_
PGUID Namespace,
727 _In_ ULONG NameLength,
744 dataLength = 16 + NameLength;
745 data = PhAllocate(dataLength);
746 memcpy(data, &ns, 16);
747 memcpy(&data[16], Name, NameLength);
757 memcpy(hash, context.
digest, 16);
773 memcpy(guid->
Data, hash, 16);
789 _Out_writes_z_(Count) PWSTR Buffer,
793 static ULONG seed = 0;
799 for (i = 0; i < Count - 1; i++)
804 Buffer[Count - 1] = 0;
819 _In_ ULONG DesiredCount
823 (ULONG)String->Length / 2 <= DesiredCount ||
834 memcpy(string->
Buffer, String->Buffer, (DesiredCount - 3) * 2);
835 memcpy(&string->
Buffer[DesiredCount - 3], L
"...", 6);
854 _In_ ULONG DesiredCount
857 ULONG_PTR secondPartIndex;
861 if (secondPartIndex == -1)
863 if (secondPartIndex == -1)
867 String->Length / 2 <= DesiredCount ||
876 ULONG_PTR firstPartCopyLength;
877 ULONG_PTR secondPartCopyLength;
880 secondPartCopyLength = String->Length / 2 - secondPartIndex;
883 if (secondPartCopyLength + 3 <= DesiredCount)
886 firstPartCopyLength = DesiredCount - secondPartCopyLength - 3;
892 firstPartCopyLength = (DesiredCount - 3) / 2;
893 secondPartCopyLength = DesiredCount - 3 - firstPartCopyLength;
894 secondPartIndex = String->Length / 2 - secondPartCopyLength;
900 firstPartCopyLength * 2
903 &string->
Buffer[firstPartCopyLength],
908 &string->
Buffer[firstPartCopyLength + 3],
909 &String->Buffer[secondPartIndex],
910 secondPartCopyLength * 2
920 _In_ BOOLEAN IgnoreCase
924 BOOLEAN star =
FALSE;
929 for (s = String, p = Pattern; *s; s++, p++)
943 }
while (*Pattern ==
'*');
945 if (!*Pattern)
return TRUE;
956 if (towupper(*s) != towupper(*p))
988 _In_ BOOLEAN IgnoreCase
1015 length = String->Length /
sizeof(WCHAR);
1020 for (i = 0; i < length; i++)
1022 switch (String->Buffer[i])
1041 runStart = &String->Buffer[i];
1067 _In_ BOOLEAN IgnoreCase,
1068 _In_ BOOLEAN MatchIfPrefix
1122 if (towupper(t) != towupper(*B))
1141 _In_opt_ PSYSTEMTIME Date,
1142 _In_opt_ PWSTR Format
1148 bufferSize = GetDateFormat(LOCALE_USER_DEFAULT, 0, Date, Format, NULL, 0);
1151 if (!GetDateFormat(LOCALE_USER_DEFAULT, 0, Date, Format, string->
Buffer, bufferSize))
1170 _In_opt_ PSYSTEMTIME Time,
1171 _In_opt_ PWSTR Format
1177 bufferSize = GetTimeFormat(LOCALE_USER_DEFAULT, 0, Time, Format, NULL, 0);
1180 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, Time, Format, string->
Buffer, bufferSize))
1199 _In_opt_ PSYSTEMTIME DateTime
1203 ULONG timeBufferSize;
1204 ULONG dateBufferSize;
1207 timeBufferSize = GetTimeFormat(LOCALE_USER_DEFAULT, 0, DateTime, NULL, NULL, 0);
1208 dateBufferSize = GetDateFormat(LOCALE_USER_DEFAULT, 0, DateTime, NULL, NULL, 0);
1210 string =
PhCreateStringEx(NULL, (timeBufferSize + 1 + dateBufferSize) * 2);
1212 if (!GetTimeFormat(LOCALE_USER_DEFAULT, 0, DateTime, NULL, &string->
Buffer[0], timeBufferSize))
1219 string->Buffer[count] =
' ';
1221 if (!GetDateFormat(LOCALE_USER_DEFAULT, 0, DateTime, NULL, &string->
Buffer[count + 1], dateBufferSize))
1238 _In_ ULONG64 TimeSpan
1254 fortnights = weeks / 2;
1255 years = days / 365.2425;
1256 months = years * 12;
1257 centuries = years / 100;
1261 string =
PhaFormatString(L
"%u %s", (ULONG)centuries, (ULONG)centuries == 1 ? L
"century" : L
"centuries");
1263 else if (years >= 1)
1265 string =
PhaFormatString(L
"%u %s", (ULONG)years, (ULONG)years == 1 ? L
"year" : L
"years");
1267 else if (months >= 1)
1269 string =
PhaFormatString(L
"%u %s", (ULONG)months, (ULONG)months == 1 ? L
"month" : L
"months");
1271 else if (fortnights >= 1)
1273 string =
PhaFormatString(L
"%u %s", (ULONG)fortnights, (ULONG)fortnights == 1 ? L
"fortnight" : L
"fortnights");
1275 else if (weeks >= 1)
1277 string =
PhaFormatString(L
"%u %s", (ULONG)weeks, (ULONG)weeks == 1 ? L
"week" : L
"weeks");
1281 DOUBLE milliseconds;
1285 ULONG secondsPartial;
1286 ULONG minutesPartial;
1296 string =
PhaFormatString(L
"%u %s", (ULONG)days, (ULONG)days == 1 ? L
"day" : L
"days");
1299 if (hoursPartial >= 1)
1301 string =
PhaFormatString(L
"%s and %u %s", string->
Buffer, hoursPartial, hoursPartial == 1 ? L
"hour" : L
"hours");
1304 else if (hours >= 1)
1306 string =
PhaFormatString(L
"%u %s", (ULONG)hours, (ULONG)hours == 1 ? L
"hour" : L
"hours");
1309 if (minutesPartial >= 1)
1311 string =
PhaFormatString(L
"%s and %u %s", string->
Buffer, (ULONG)minutesPartial, (ULONG)minutesPartial == 1 ? L
"minute" : L
"minutes");
1314 else if (minutes >= 1)
1316 string =
PhaFormatString(L
"%u %s", (ULONG)minutes, (ULONG)minutes == 1 ? L
"minute" : L
"minutes");
1319 if (secondsPartial >= 1)
1321 string =
PhaFormatString(L
"%s and %u %s", string->
Buffer, (ULONG)secondsPartial, (ULONG)secondsPartial == 1 ? L
"second" : L
"seconds");
1324 else if (seconds >= 1)
1326 string =
PhaFormatString(L
"%u %s", (ULONG)seconds, (ULONG)seconds == 1 ? L
"second" : L
"seconds");
1328 else if (milliseconds >= 1)
1330 string =
PhaFormatString(L
"%u %s", (ULONG)milliseconds, (ULONG)milliseconds == 1 ? L
"millisecond" : L
"milliseconds");
1342 if (string->
Buffer[2] !=
'h')
1362 _In_ BOOLEAN GroupDigits
1375 _In_ ULONG FractionalDigits,
1376 _In_ BOOLEAN GroupDigits
1380 static WCHAR decimalSeparator[4];
1381 static WCHAR thousandSeparator[4];
1389 if (!GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, decimalSeparator, 4))
1391 decimalSeparator[0] =
'.';
1392 decimalSeparator[1] = 0;
1395 if (!GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, thousandSeparator, 4))
1397 thousandSeparator[0] =
',';
1398 thousandSeparator[1] = 0;
1404 format.NumDigits = FractionalDigits;
1405 format.LeadingZero = 0;
1406 format.Grouping = GroupDigits ? 3 : 0;
1407 format.lpDecimalSep = decimalSeparator;
1408 format.lpThousandSep = thousandSeparator;
1409 format.NegativeOrder = 1;
1411 bufferSize = GetNumberFormat(LOCALE_USER_DEFAULT, 0, Value, &format, NULL, 0);
1414 if (!GetNumberFormat(LOCALE_USER_DEFAULT, 0, Value, &format, string->
Buffer, bufferSize))
1441 _In_ ULONG MaxSizeUnit
1488 ULONG versionInfoSize;
1492 versionInfoSize = GetFileVersionInfoSize(
1497 if (versionInfoSize)
1499 versionInfo = PhAllocate(versionInfoSize);
1501 if (!GetFileVersionInfo(
1528 _In_ PVOID VersionInfo
1534 if (VerQueryValue(VersionInfo, L
"\\VarFileInfo\\Translation", &buffer, &length))
1537 return (*(PUSHORT)buffer << 16) + *((PUSHORT)buffer + 1);
1541 return (MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US) << 16) + 1252;
1552 _In_ PVOID VersionInfo,
1559 if (VerQueryValue(VersionInfo, SubBlock, &buffer, &length))
1583 _In_ PVOID VersionInfo,
1584 _In_ ULONG LangCodePage,
1585 _In_ PWSTR StringName
1594 format[1].
Width = 8;
1606 _In_ PVOID VersionInfo,
1607 _In_ ULONG LangCodePage
1628 VS_FIXEDFILEINFO *rootBlock;
1629 ULONG rootBlockLength;
1640 if (!ImageVersionInfo->CompanyName && !ImageVersionInfo->FileDescription && !ImageVersionInfo->ProductName)
1646 if (!ImageVersionInfo->CompanyName && !ImageVersionInfo->FileDescription && !ImageVersionInfo->ProductName)
1650 if (!ImageVersionInfo->CompanyName && !ImageVersionInfo->FileDescription && !ImageVersionInfo->ProductName)
1656 if (VerQueryValue(versionInfo, L
"\\", &rootBlock, &rootBlockLength) && rootBlockLength != 0)
1658 PhInitFormatU(&fileVersionFormat[0], rootBlock->dwFileVersionMS >> 16);
1660 PhInitFormatU(&fileVersionFormat[2], rootBlock->dwFileVersionMS & 0xffff);
1662 PhInitFormatU(&fileVersionFormat[4], rootBlock->dwFileVersionLS >> 16);
1664 PhInitFormatU(&fileVersionFormat[6], rootBlock->dwFileVersionLS & 0xffff);
1666 ImageVersionInfo->FileVersion =
PhFormat(fileVersionFormat, 7, 30);
1670 ImageVersionInfo->FileVersion = NULL;
1689 if (ImageVersionInfo->FileDescription)
PhDereferenceObject(ImageVersionInfo->FileDescription);
1698 _In_opt_ ULONG LineLimit
1704 LineLimit = MAXULONG32;
1731 ULONG limitForDescription;
1732 ULONG limitForVersion;
1734 if (LineLimit != MAXULONG32)
1736 limitForVersion = (LineLimit - 1) / 4;
1737 limitForDescription = LineLimit - limitForVersion;
1741 limitForDescription = MAXULONG32;
1742 limitForVersion = MAXULONG32;
1748 ImageVersionInfo->FileDescription,
1756 ImageVersionInfo->FileVersion,
1763 if (tempDescription)
1774 if (tempDescription)
1812 _In_ PWSTR FileName,
1813 _Out_opt_ PULONG IndexOfFileName
1826 if (returnLength > bufferSize)
1829 bufferSize = returnLength;
1835 if (returnLength == 0)
1843 if (IndexOfFileName)
1848 *IndexOfFileName = (ULONG)(filePart - fullPath->
Buffer);
1853 *IndexOfFileName = -1;
1878 bufferLength = 0x40;
1882 outputString.Buffer =
string->Buffer;
1891 if (status == STATUS_BUFFER_TOO_SMALL)
1897 outputString.Buffer =
string->Buffer;
1913 string->Length = outputString.
Length;
1914 string->Buffer[
string->Length / 2] = 0;
1944 static PPH_STRING cachedSystemDirectory = NULL;
1952 systemDirectory = cachedSystemDirectory;
1954 if (systemDirectory)
1960 returnLength = GetSystemDirectory(systemDirectory->
Buffer, bufferSize);
1962 if (returnLength > bufferSize)
1965 bufferSize = returnLength;
1968 returnLength = GetSystemDirectory(systemDirectory->
Buffer, bufferSize);
1971 if (returnLength == 0)
1981 &cachedSystemDirectory,
1990 return systemDirectory;
2007 *SystemRoot = systemRoot;
2011 localSystemRoot.
Buffer = USER_SHARED_DATA->NtSystemRoot;
2013 localSystemRoot.
Length = count *
sizeof(WCHAR);
2016 if (localSystemRoot.
Buffer[count - 1] ==
'\\')
2017 localSystemRoot.
Length -=
sizeof(WCHAR);
2019 *SystemRoot = localSystemRoot;
2041 _In_opt_ PVOID DllBase,
2046 PLDR_DATA_TABLE_ENTRY result = NULL;
2047 PLDR_DATA_TABLE_ENTRY entry;
2050 PLIST_ENTRY listHead;
2051 PLIST_ENTRY listEntry;
2053 listHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
2054 listEntry = listHead->Flink;
2056 while (listEntry != listHead)
2058 entry = CONTAINING_RECORD(listEntry, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
2063 (!DllBase || entry->DllBase == DllBase) &&
2072 listEntry = listEntry->Flink;
2089 _In_ PVOID DllHandle,
2090 _Out_opt_ PULONG IndexOfFileName
2093 PLDR_DATA_TABLE_ENTRY entry;
2096 ULONG_PTR indexOfFileName;
2114 fileName = newFileName;
2116 if (IndexOfFileName)
2120 if (indexOfFileName != -1)
2123 indexOfFileName = 0;
2125 *IndexOfFileName = (ULONG)indexOfFileName;
2149 ULONG indexOfFileName;
2152 fileName =
PhGetDllFileName(NtCurrentPeb()->ImageBaseAddress, &indexOfFileName);
2156 if (indexOfFileName != 0)
2176 _In_opt_ PWSTR AppendPath
2180 SIZE_T appendPathLength;
2185 appendPathLength = 0;
2189 if (SUCCEEDED(SHGetFolderPath(
2201 memcpy(&path->
Buffer[path->
Length / 2], AppendPath, appendPathLength + 2);
2202 path->
Length += appendPathLength;
2228 _In_ ULONG NumberOfHandles,
2229 _In_ PHANDLE Handles,
2234 ULONG startTickCount;
2235 ULONG currentTickCount;
2236 LONG currentTimeout;
2238 startTickCount = GetTickCount();
2239 currentTimeout = Timeout;
2243 status = MsgWaitForMultipleObjects(
2247 (ULONG)currentTimeout,
2251 if (status >= STATUS_WAIT_0 && status < (NTSTATUS)(STATUS_WAIT_0 + NumberOfHandles))
2255 else if (status == (STATUS_WAIT_0 + NumberOfHandles))
2261 while (PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE))
2263 TranslateMessage(&msg);
2264 DispatchMessage(&msg);
2274 if (Timeout != INFINITE)
2276 currentTickCount = GetTickCount();
2277 currentTimeout = Timeout - (currentTickCount - startTickCount);
2279 if (currentTimeout < 0)
2280 return STATUS_TIMEOUT;
2313 _In_ PWSTR FileName,
2315 _In_opt_ PVOID Environment,
2319 _In_opt_ HANDLE ParentProcessHandle,
2321 _Out_opt_ PHANDLE ProcessHandle,
2322 _Out_opt_ PHANDLE ThreadHandle
2340 return STATUS_OBJECT_NAME_NOT_FOUND;
2345 return STATUS_NAME_TOO_LONG;
2348 if (CurrentDirectory)
2351 return STATUS_NAME_TOO_LONG;
2356 windowTitle = Information->WindowTitle;
2357 desktopInfo = Information->DesktopInfo;
2366 windowTitle = &fileName;
2369 desktopInfo = &NtCurrentPeb()->ProcessParameters->DesktopInfo;
2374 Information ? Information->DllPath : NULL,
2375 CurrentDirectory ? ¤tDirectory : NULL,
2376 CommandLine ? &commandLine : &fileName,
2380 Information ? Information->ShellInfo : NULL,
2381 Information ? Information->RuntimeData : NULL
2392 ParentProcessHandle,
2406 NtResumeThread(processInfo.
Thread, NULL);
2412 *ProcessHandle = processInfo.
Process;
2417 *ThreadHandle = processInfo.
Thread;
2419 NtClose(processInfo.
Thread);
2442 _In_opt_ PWSTR FileName,
2443 _In_opt_ PWSTR CommandLine,
2444 _In_opt_ PVOID Environment,
2445 _In_opt_ PWSTR CurrentDirectory,
2447 _In_opt_ HANDLE TokenHandle,
2448 _Out_opt_ PHANDLE ProcessHandle,
2449 _Out_opt_ PHANDLE ThreadHandle
2475 _In_ PPROCESS_INFORMATION ProcessInfo,
2477 _Out_opt_ PHANDLE ProcessHandle,
2478 _Out_opt_ PHANDLE ThreadHandle
2483 ClientId->UniqueProcess = UlongToHandle(ProcessInfo->dwProcessId);
2484 ClientId->UniqueThread = UlongToHandle(ProcessInfo->dwThreadId);
2488 *ProcessHandle = ProcessInfo->hProcess;
2490 NtClose(ProcessInfo->hProcess);
2493 *ThreadHandle = ProcessInfo->hThread;
2495 NtClose(ProcessInfo->hThread);
2519 _In_opt_ PWSTR FileName,
2520 _In_opt_ PWSTR CommandLine,
2521 _In_opt_ PVOID Environment,
2522 _In_opt_ PWSTR CurrentDirectory,
2523 _In_opt_ STARTUPINFO *StartupInfo,
2525 _In_opt_ HANDLE TokenHandle,
2527 _Out_opt_ PHANDLE ProcessHandle,
2528 _Out_opt_ PHANDLE ThreadHandle
2533 STARTUPINFO startupInfo;
2534 PROCESS_INFORMATION processInfo;
2545 startupInfo = *StartupInfo;
2549 memset(&startupInfo, 0,
sizeof(STARTUPINFO));
2550 startupInfo.cb =
sizeof(STARTUPINFO);
2567 status = STATUS_SUCCESS;
2573 if (CreateProcessAsUser(
2586 status = STATUS_SUCCESS;
2626 _Out_opt_ PHANDLE ProcessHandle,
2627 _Out_opt_ PHANDLE ThreadHandle
2637 PVOID defaultEnvironment = NULL;
2638 STARTUPINFO startupInfo = {
sizeof(startupInfo) };
2639 BOOLEAN needsDuplicate =
FALSE;
2646 winsta = LoadLibrary(L
"winsta.dll");
2649 userEnv = LoadLibrary(L
"userenv.dll");
2657 return STATUS_INVALID_PARAMETER_2;
2658 if (!Information->ApplicationName && !Information->CommandLine)
2659 return STATUS_INVALID_PARAMETER_MIX;
2661 startupInfo.lpDesktop = Information->DesktopName;
2667 BOOLEAN useWithLogon;
2669 useWithLogon =
TRUE;
2671 if (Flags & (PH_CREATE_PROCESS_USE_PROCESS_TOKEN | PH_CREATE_PROCESS_USE_SESSION_TOKEN))
2672 useWithLogon =
FALSE;
2675 useWithLogon =
FALSE;
2679 if (Information->SessionId != NtCurrentPeb()->SessionId)
2680 useWithLogon =
FALSE;
2683 if (Information->LogonType && Information->LogonType != LOGON32_LOGON_INTERACTIVE)
2684 useWithLogon =
FALSE;
2689 PROCESS_INFORMATION processInfo;
2692 if (Information->CommandLine)
2697 if (!Information->Environment)
2703 if (CreateProcessWithLogonW(
2704 Information->UserName,
2705 Information->DomainName,
2706 Information->Password,
2708 Information->ApplicationName,
2711 Information->Environment,
2712 Information->CurrentDirectory,
2716 status = STATUS_SUCCESS;
2734 if (Flags & PH_CREATE_PROCESS_USE_PROCESS_TOKEN)
2736 HANDLE processHandle;
2741 Information->ProcessIdWithToken
2750 NtClose(processHandle);
2756 needsDuplicate =
TRUE;
2758 else if (Flags & PH_CREATE_PROCESS_USE_SESSION_TOKEN)
2763 if (!WinStationQueryInformationW_I)
2764 return STATUS_PROCEDURE_NOT_FOUND;
2766 if (!WinStationQueryInformationW_I(
2768 Information->SessionIdWithToken,
2781 needsDuplicate =
TRUE;
2787 if (Information->LogonType)
2789 logonType = Information->LogonType;
2793 logonType = LOGON32_LOGON_INTERACTIVE;
2801 logonType = LOGON32_LOGON_SERVICE;
2803 logonType = LOGON32_LOGON_NEW_CREDENTIALS;
2809 logonType = LOGON32_LOGON_SERVICE;
2815 Information->UserName,
2816 Information->DomainName,
2817 Information->Password,
2819 LOGON32_PROVIDER_DEFAULT,
2827 HANDLE linkedTokenHandle;
2828 TOKEN_TYPE tokenType;
2844 )) && tokenType == TokenPrimary)
2846 NtClose(tokenHandle);
2847 tokenHandle = linkedTokenHandle;
2848 needsDuplicate =
FALSE;
2852 NtClose(linkedTokenHandle);
2859 HANDLE newTokenHandle;
2878 NtClose(tokenHandle);
2883 tokenHandle = newTokenHandle;
2892 Information->SessionId
2895 NtClose(tokenHandle);
2900 if (!Information->Environment)
2902 if (CreateEnvironmentBlock_I)
2904 CreateEnvironmentBlock_I(&defaultEnvironment, tokenHandle,
FALSE);
2906 if (defaultEnvironment)
2912 Information->ApplicationName,
2913 Information->CommandLine,
2914 Information->Environment ? Information->Environment : defaultEnvironment,
2915 Information->CurrentDirectory,
2924 if (defaultEnvironment)
2926 if (DestroyEnvironmentBlock_I)
2927 DestroyEnvironmentBlock_I(defaultEnvironment);
2930 NtClose(tokenHandle);
2936 _In_ PSID AccountSid,
2937 _Out_ PTOKEN_PRIVILEGES *Privileges
2941 LSA_HANDLE accountHandle;
2942 PPRIVILEGE_SET accountPrivileges;
2943 PTOKEN_PRIVILEGES privileges;
2951 LsaClose(accountHandle);
2956 privileges = PhAllocate(FIELD_OFFSET(TOKEN_PRIVILEGES, Privileges) +
sizeof(LUID_AND_ATTRIBUTES) * accountPrivileges->PrivilegeCount);
2957 privileges->PrivilegeCount = accountPrivileges->PrivilegeCount;
2958 memcpy(privileges->Privileges, accountPrivileges->Privilege,
sizeof(LUID_AND_ATTRIBUTES) * accountPrivileges->PrivilegeCount);
2960 LsaFreeMemory(accountPrivileges);
2962 *Privileges = privileges;
2977 _In_ HANDLE TokenHandle,
2978 _Out_ PHANDLE NewTokenHandle
2981 static SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY;
2982 static SID_IDENTIFIER_AUTHORITY mandatoryLabelAuthority = SECURITY_MANDATORY_LABEL_AUTHORITY;
2983 static LUID_AND_ATTRIBUTES defaultAllowedPrivileges[] =
2993 UCHAR administratorsSidBuffer[FIELD_OFFSET(SID, SubAuthority) +
sizeof(ULONG) * 2];
2994 PSID administratorsSid;
2995 UCHAR usersSidBuffer[FIELD_OFFSET(SID, SubAuthority) +
sizeof(ULONG) * 2];
2997 UCHAR sidsToDisableBuffer[FIELD_OFFSET(TOKEN_GROUPS, Groups) +
sizeof(SID_AND_ATTRIBUTES)];
2998 PTOKEN_GROUPS sidsToDisable;
3003 PTOKEN_PRIVILEGES privilegesOfToken;
3004 PTOKEN_PRIVILEGES privilegesOfUsers;
3005 PTOKEN_PRIVILEGES privilegesToDelete;
3006 UCHAR lowMandatoryLevelSidBuffer[FIELD_OFFSET(SID, SubAuthority) +
sizeof(ULONG)];
3007 PSID lowMandatoryLevelSid;
3008 TOKEN_MANDATORY_LABEL mandatoryLabel;
3009 PSECURITY_DESCRIPTOR currentSecurityDescriptor;
3010 BOOLEAN currentDaclPresent;
3011 BOOLEAN currentDaclDefaulted;
3013 PTOKEN_USER currentUser;
3014 PACE_HEADER currentAce;
3015 ULONG newDaclLength;
3017 SECURITY_DESCRIPTOR newSecurityDescriptor;
3018 TOKEN_DEFAULT_DACL newDefaultDacl;
3019 HANDLE newTokenHandle;
3024 administratorsSid = (PSID)administratorsSidBuffer;
3030 usersSid = (PSID)usersSidBuffer;
3035 sidsToDisable = (PTOKEN_GROUPS)sidsToDisableBuffer;
3036 sidsToDisable->GroupCount = 1;
3037 sidsToDisable->Groups[0].Sid = administratorsSid;
3038 sidsToDisable->Groups[0].Attributes = 0;
3050 privilegesOfUsers = PhAllocate(FIELD_OFFSET(TOKEN_PRIVILEGES, Privileges) +
sizeof(defaultAllowedPrivileges));
3051 privilegesOfUsers->PrivilegeCount =
sizeof(defaultAllowedPrivileges) /
sizeof(LUID_AND_ATTRIBUTES);
3052 memcpy(privilegesOfUsers->Privileges, defaultAllowedPrivileges,
sizeof(defaultAllowedPrivileges));
3057 privilegesToDelete = PhAllocate(FIELD_OFFSET(TOKEN_PRIVILEGES, Privileges) +
sizeof(LUID_AND_ATTRIBUTES) * privilegesOfToken->PrivilegeCount);
3061 for (i = 0; i < privilegesOfToken->PrivilegeCount; i++)
3066 for (j = 0; j < privilegesOfUsers->PrivilegeCount; j++)
3068 if (
RtlIsEqualLuid(&privilegesOfToken->Privileges[i].Luid, &privilegesOfUsers->Privileges[j].Luid))
3078 privilegesToDelete->Privileges[deleteIndex].Attributes = 0;
3079 privilegesToDelete->Privileges[deleteIndex].Luid = privilegesOfToken->Privileges[i].Luid;
3084 privilegesToDelete->PrivilegeCount = deleteIndex;
3096 PhFree(privilegesToDelete);
3097 PhFree(privilegesOfUsers);
3098 PhFree(privilegesOfToken);
3106 lowMandatoryLevelSid = (PSID)lowMandatoryLevelSidBuffer;
3110 mandatoryLabel.Label.Sid = lowMandatoryLevelSid;
3111 mandatoryLabel.Label.Attributes = SE_GROUP_INTEGRITY;
3113 NtSetInformationToken(newTokenHandle, TokenIntegrityLevel, &mandatoryLabel,
sizeof(TOKEN_MANDATORY_LABEL));
3122 currentSecurityDescriptor,
3123 ¤tDaclPresent,
3125 ¤tDaclDefaulted
3128 currentDaclPresent =
FALSE;
3131 newDaclLength =
sizeof(ACL) + FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart) +
RtlLengthSid(currentUser->User.Sid);
3133 if (currentDaclPresent)
3134 newDaclLength += currentDacl->AclSize -
sizeof(ACL);
3136 newDacl = PhAllocate(newDaclLength);
3140 if (currentDaclPresent)
3142 for (i = 0; i < currentDacl->AceCount; i++)
3145 RtlAddAce(newDacl, ACL_REVISION, MAXULONG32, currentAce, currentAce->AceSize);
3161 newDefaultDacl.DefaultDacl = newDacl;
3162 NtSetInformationToken(newTokenHandle, TokenDefaultDacl, &newDefaultDacl,
sizeof(TOKEN_DEFAULT_DACL));
3169 PhFree(currentSecurityDescriptor);
3172 *NewTokenHandle = newTokenHandle;
3174 return STATUS_SUCCESS;
3186 _In_ PWSTR FileName,
3187 _In_opt_ PWSTR Parameters
3190 SHELLEXECUTEINFO info = {
sizeof(info) };
3192 info.lpFile = FileName;
3193 info.lpParameters = Parameters;
3194 info.nShow = SW_SHOW;
3197 if (!ShellExecuteEx(&info))
3221 _In_ PWSTR FileName,
3222 _In_opt_ PWSTR Parameters,
3223 _In_ ULONG ShowWindowType,
3225 _In_opt_ ULONG Timeout,
3226 _Out_opt_ PHANDLE ProcessHandle
3229 SHELLEXECUTEINFO info = {
sizeof(info) };
3231 info.lpFile = FileName;
3232 info.lpParameters = Parameters;
3233 info.fMask = SEE_MASK_NOCLOSEPROCESS;
3234 info.nShow = ShowWindowType;
3238 info.lpVerb = L
"runas";
3240 if (ShellExecuteEx(&info))
3246 LARGE_INTEGER timeout;
3257 *ProcessHandle = info.hProcess;
3259 NtClose(info.hProcess);
3288 CoTaskMemFree(item);
3292 PhShowError(hWnd, L
"The location \"%s\" could not be found.", FileName);
3316 SHELLEXECUTEINFO info = {
sizeof(info) };
3318 info.lpFile = FileName;
3319 info.nShow = SW_SHOW;
3320 info.fMask = SEE_MASK_INVOKEIDLIST;
3321 info.lpVerb = L
"properties";
3324 if (!ShellExecuteEx(&info))
3340 _In_ BOOLEAN Computer
3375 keyName = tempString;
3395 HANDLE regeditKeyHandle;
3415 NtClose(regeditKeyHandle);
3424 if (!regeditFileName)
3451 _In_ HANDLE KeyHandle,
3452 _In_opt_ PWSTR ValueName
3459 ULONG attempts = 16;
3464 buffer = PhAllocate(bufferSize);
3480 if (status == STATUS_BUFFER_OVERFLOW)
3483 buffer = PhAllocate(bufferSize);
3490 }
while (--attempts);
3507 _In_ HANDLE KeyHandle,
3508 _In_opt_ PWSTR ValueName
3519 buffer->
Type == REG_SZ ||
3520 buffer->
Type == REG_MULTI_SZ ||
3521 buffer->
Type == REG_EXPAND_SZ
3537 _Inout_ PULONG Value2,
3540 _In_ ULONG NumberOfMappings
3554 for (i = 0; i < NumberOfMappings; i++)
3556 if (Value1 & Mappings[i].Flag1)
3557 value2 |= Mappings[i].Flag2;
3559 value2 &= ~Mappings[i].Flag2;
3568 for (i = 0; i < NumberOfMappings; i++)
3570 if (Value1 & Mappings[i].Flag1)
3571 value2 |= Mappings[i].Flag2;
3579 _Inout_ PULONG Value1,
3582 _In_ ULONG NumberOfMappings
3592 for (i = 0; i < NumberOfMappings; i++)
3594 if (Value2 & Mappings[i].Flag2)
3595 value1 |= Mappings[i].Flag1;
3597 value1 &= ~Mappings[i].Flag1;
3602 for (i = 0; i < NumberOfMappings; i++)
3604 if (Value2 & Mappings[i].Flag2)
3605 value1 |= Mappings[i].Flag1;
3623 LPOFNOTIFY header = (LPOFNOTIFY)lParam;
3628 switch (header->hdr.code)
3634 returnLength = CommDlg_OpenSave_GetFilePath(
3635 header->hdr.hwndFrom,
3636 header->lpOFN->lpstrFile,
3637 header->lpOFN->nMaxFile
3640 if ((
LONG)returnLength > 0 && returnLength > header->lpOFN->nMaxFile)
3642 PhFree(header->lpOFN->lpstrFile);
3643 header->lpOFN->nMaxFile = returnLength + 0x200;
3644 header->lpOFN->lpstrFile = PhAllocate(header->lpOFN->nMaxFile * 2);
3646 returnLength = CommDlg_OpenSave_GetFilePath(
3647 header->hdr.hwndFrom,
3648 header->lpOFN->lpstrFile,
3649 header->lpOFN->nMaxFile
3668 ofn = PhAllocate(
sizeof(OPENFILENAME));
3669 memset(ofn, 0,
sizeof(OPENFILENAME));
3671 ofn->lStructSize =
sizeof(OPENFILENAME);
3672 ofn->nMaxFile = 0x400;
3673 ofn->lpstrFile = PhAllocate(ofn->nMaxFile * 2);
3674 ofn->lpstrFileTitle = NULL;
3675 ofn->Flags = OFN_ENABLEHOOK | OFN_EXPLORER;
3678 ofn->lpstrFile[0] = 0;
3684 _In_ OPENFILENAME *OpenFileName
3687 if (OpenFileName->lpstrFilter)
PhFree((PVOID)OpenFileName->lpstrFilter);
3688 if (OpenFileName->lpstrFile)
PhFree((PVOID)OpenFileName->lpstrFile);
3693 typedef struct _PHP_FILE_DIALOG
3695 BOOLEAN UseIFileDialog;
3699 OPENFILENAME *OpenFileName;
3700 IFileDialog *FileDialog;
3706 _In_opt_ OPENFILENAME *OpenFileName,
3707 _In_opt_ IFileDialog *FileDialog
3710 PPHP_FILE_DIALOG fileDialog;
3712 assert(!!OpenFileName != !!FileDialog);
3714 fileDialog->Save = Save;
3718 fileDialog->UseIFileDialog =
FALSE;
3719 fileDialog->u.OpenFileName = OpenFileName;
3721 else if (FileDialog)
3723 fileDialog->UseIFileDialog =
TRUE;
3724 fileDialog->u.FileDialog = FileDialog;
3747 PVOID ofnFileDialog;
3751 IFileDialog *fileDialog;
3753 if (SUCCEEDED(CoCreateInstance(
3754 &CLSID_FileOpenDialog,
3756 CLSCTX_INPROC_SERVER,
3770 return ofnFileDialog;
3786 PVOID ofnFileDialog;
3790 IFileDialog *fileDialog;
3792 if (SUCCEEDED(CoCreateInstance(
3793 &CLSID_FileSaveDialog,
3795 CLSCTX_INPROC_SERVER,
3809 return ofnFileDialog;
3818 _In_ PVOID FileDialog
3821 PPHP_FILE_DIALOG fileDialog = FileDialog;
3823 if (fileDialog->UseIFileDialog)
3825 IFileDialog_Release(fileDialog->u.FileDialog);
3847 _In_ PVOID FileDialog
3850 PPHP_FILE_DIALOG fileDialog = FileDialog;
3852 if (fileDialog->UseIFileDialog)
3856 IFileDialog_SetDefaultExtension(fileDialog->u.FileDialog, L
"");
3858 return SUCCEEDED(IFileDialog_Show(fileDialog->u.FileDialog, hWnd));
3862 OPENFILENAME *ofn = fileDialog->u.OpenFileName;
3864 ofn->hwndOwner = hWnd;
3867 if (!fileDialog->Save)
3869 return GetOpenFileName(ofn);
3873 return GetSaveFileName(ofn);
3910 _In_ PVOID FileDialog
3913 PPHP_FILE_DIALOG fileDialog = FileDialog;
3915 if (fileDialog->UseIFileDialog)
3917 FILEOPENDIALOGOPTIONS dialogOptions;
3920 if (SUCCEEDED(IFileDialog_GetOptions(fileDialog->u.FileDialog, &dialogOptions)))
3927 PhpFileDialogIfdMappings,
3940 OPENFILENAME *ofn = fileDialog->u.OpenFileName;
3948 PhpFileDialogOfnMappings,
3980 _In_ PVOID FileDialog,
3984 PPHP_FILE_DIALOG fileDialog = FileDialog;
3986 if (fileDialog->UseIFileDialog)
3988 FILEOPENDIALOGOPTIONS dialogOptions;
3990 if (SUCCEEDED(IFileDialog_GetOptions(fileDialog->u.FileDialog, &dialogOptions)))
3995 PhpFileDialogIfdMappings,
3999 IFileDialog_SetOptions(fileDialog->u.FileDialog, dialogOptions);
4004 OPENFILENAME *ofn = fileDialog->u.OpenFileName;
4009 PhpFileDialogOfnMappings,
4025 _In_ PVOID FileDialog
4028 PPHP_FILE_DIALOG fileDialog = FileDialog;
4030 if (fileDialog->UseIFileDialog)
4034 if (SUCCEEDED(IFileDialog_GetFileTypeIndex(fileDialog->u.FileDialog, &index)))
4045 OPENFILENAME *ofn = fileDialog->u.OpenFileName;
4047 return ofn->nFilterIndex;
4060 _In_ PVOID FileDialog,
4062 _In_ ULONG NumberOfFilters
4065 PPHP_FILE_DIALOG fileDialog = FileDialog;
4067 if (fileDialog->UseIFileDialog)
4069 IFileDialog_SetFileTypes(
4070 fileDialog->u.FileDialog,
4072 (COMDLG_FILTERSPEC *)Filters
4077 OPENFILENAME *ofn = fileDialog->u.OpenFileName;
4084 for (i = 0; i < NumberOfFilters; i++)
4094 if (ofn->lpstrFilter)
4095 PhFree((PVOID)ofn->lpstrFilter);
4113 _In_ PVOID FileDialog
4116 PPHP_FILE_DIALOG fileDialog = FileDialog;
4118 if (fileDialog->UseIFileDialog)
4123 if (SUCCEEDED(IFileDialog_GetResult(fileDialog->u.FileDialog, &result)))
4127 if (SUCCEEDED(IShellItem_GetDisplayName(result, SIGDN_FILESYSPATH, &name)))
4130 CoTaskMemFree(name);
4133 IShellItem_Release(result);
4140 if (SUCCEEDED(IFileDialog_GetFileName(fileDialog->u.FileDialog, &name)))
4143 CoTaskMemFree(name);
4162 _In_ PVOID FileDialog,
4166 PPHP_FILE_DIALOG fileDialog = FileDialog;
4171 if (fileDialog->UseIFileDialog)
4173 IShellItem *shellItem = NULL;
4189 CoTaskMemFree(item);
4197 IFileDialog_SetFolder(fileDialog->u.FileDialog, shellItem);
4198 IFileDialog_SetFileName(fileDialog->u.FileDialog, baseNamePart.
Buffer);
4199 IShellItem_Release(shellItem);
4203 IFileDialog_SetFileName(fileDialog->u.FileDialog, FileName);
4208 OPENFILENAME *ofn = fileDialog->u.OpenFileName;
4218 ofn->nMaxFile = (ULONG)max(fileName.
Length /
sizeof(WCHAR) + 1, 0x400);
4219 ofn->lpstrFile = PhAllocate(ofn->nMaxFile * 2);
4220 memcpy(ofn->lpstrFile, fileName.
Buffer, fileName.
Length +
sizeof(WCHAR));
4236 _In_ PWSTR FileName,
4237 _Out_ PBOOLEAN IsPacked,
4238 _Out_opt_ PULONG NumberOfModules,
4239 _Out_opt_ PULONG NumberOfFunctions
4277 ULONG limitNumberOfModules;
4278 ULONG numberOfModules;
4279 ULONG numberOfFunctions = 0;
4280 BOOLEAN hasTextSection =
FALSE;
4281 BOOLEAN isModuleMscoree =
FALSE;
4297 hasTextSection =
TRUE;
4331 limitNumberOfModules = min(numberOfModules, 64);
4333 for (i = 0; i < limitNumberOfModules; i++)
4343 isModuleMscoree =
TRUE;
4351 numberOfModules != 0 &&
4354 (numberOfModules < 3 && numberOfFunctions < 5 &&
4355 mappedImage.
NtHeaders->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_NATIVE) ||
4357 ((numberOfFunctions / numberOfModules) < 3 &&
4358 numberOfModules > 2 && numberOfModules < 5) ||
4360 ((numberOfFunctions / numberOfModules) < 2 &&
4361 numberOfModules > 4 && numberOfModules < 31) ||
4366 !(numberOfModules == 1 && numberOfFunctions == 1 && isModuleMscoree)
4376 *IsPacked = isPacked;
4378 if (NumberOfModules)
4379 *NumberOfModules = numberOfModules;
4380 if (NumberOfFunctions)
4381 *NumberOfFunctions = numberOfFunctions;
4391 _In_reads_(Length) PCHAR Buffer,
4398 Crc = (Crc >> 8) ^
PhCrc32Table[(Crc ^ *Buffer++) & 0xff];
4400 return Crc ^ 0xffffffff;
4420 Context->Algorithm = Algorithm;
4431 Context->Context[0] = 0;
4448 _In_reads_bytes_(Length) PVOID Buffer,
4452 switch (Context->Algorithm)
4461 Context->Context[0] =
PhCrc32(Context->Context[0], (PUCHAR)Buffer, Length);
4479 _Out_writes_bytes_(HashLength) PVOID Hash,
4480 _In_ ULONG HashLength,
4481 _Out_opt_ PULONG ReturnLength
4489 switch (Context->Algorithm)
4492 if (HashLength >= 16)
4495 memcpy(Hash, ((
MD5_CTX *)Context->Context)->digest, 16);
4503 if (HashLength >= 20)
4513 if (HashLength >= 4)
4515 *(PULONG)Hash = Context->Context[0];
4527 *ReturnLength = returnLength;
4543 _Inout_ PULONG_PTR Index
4550 ULONG numberOfBackslashes;
4554 length = CommandLine->Length / 2;
4564 numberOfBackslashes = 0;
4568 for (; i < length; i++)
4570 switch (CommandLine->Buffer[i])
4573 numberOfBackslashes++;
4576 if (numberOfBackslashes != 0)
4578 if (numberOfBackslashes & 1)
4580 numberOfBackslashes /= 2;
4582 if (numberOfBackslashes != 0)
4585 numberOfBackslashes = 0;
4594 numberOfBackslashes /= 2;
4596 numberOfBackslashes = 0;
4607 if (numberOfBackslashes != 0)
4610 numberOfBackslashes = 0;
4613 if (CommandLine->Buffer[i] ==
' ' && !inQuote)
4653 _In_ ULONG NumberOfOptions,
4656 _In_opt_ PVOID Context
4669 if (CommandLine->Length == 0)
4673 length = CommandLine->Length / 2;
4679 while (i < length && CommandLine->Buffer[i] ==
' ')
4692 cont = Callback(option, optionValue, Context);
4700 else if (CommandLine->Buffer[i] ==
'-')
4702 ULONG_PTR originalIndex;
4703 SIZE_T optionNameLength;
4712 for (; i < length; i++)
4714 if (!iswalnum(CommandLine->Buffer[i]) && CommandLine->Buffer[i] !=
'-')
4718 optionNameLength = i - originalIndex;
4720 optionName.
Buffer = &CommandLine->Buffer[originalIndex];
4721 optionName.
Length = optionNameLength * 2;
4727 for (j = 0; j < NumberOfOptions; j++)
4731 option = &Options[j];
4741 cont = Callback(option, NULL, Context);
4765 cont = Callback(NULL, value, Context);
4798 ULONG numberOfBackslashes;
4800 length = (ULONG)String->Length / 2;
4802 numberOfBackslashes = 0;
4807 for (i = 0; i < length; i++)
4809 switch (String->Buffer[i])
4812 numberOfBackslashes++;
4815 if (numberOfBackslashes != 0)
4818 numberOfBackslashes = 0;
4825 if (numberOfBackslashes != 0)
4828 numberOfBackslashes = 0;
4841 _In_ PWSTR FileName,
4842 _In_opt_ PWSTR Extension,
4843 _Out_writes_(MAX_PATH) PWSTR Buffer
4852 result = SearchPath(
4861 if (result == 0 || result >= MAX_PATH)
4919 WCHAR buffer[MAX_PATH];
4922 commandLine = *CommandLine;
4925 if (commandLine.
Length == 0)
4931 *FullFileName = NULL;
4936 if (*commandLine.
Buffer ==
'"')
4947 *FileName = commandLine;
4951 *FullFileName = NULL;
4957 *FileName = commandLine;
4958 *Arguments = arguments;
4972 *FullFileName = NULL;
4994 temp.
Buffer = PhAllocate(commandLine.
Length +
sizeof(WCHAR));
4998 remainingPart = temp;
5000 while (remainingPart.
Length != 0)
5009 originalChar = *(remainingPart.
Buffer - 1);
5010 *(remainingPart.
Buffer - 1) = 0;
5017 *(remainingPart.
Buffer - 1) = originalChar;
5022 FileName->Buffer = commandLine.
Buffer;
5023 FileName->Length = ((PCHAR)currentPart.
Buffer - (PCHAR)temp.
Buffer) + currentPart.
Length;
5026 *Arguments = remainingPart;
5039 *FileName = *CommandLine;
5043 *FullFileName = NULL;