32 _In_opt_ SIZE_T PortSectionSize
37 LARGE_INTEGER sectionSize;
40 SECURITY_QUALITY_OF_SERVICE securityQos;
41 ULONG maxMessageLength;
43 ULONG connectInfoLength;
46 return STATUS_ADDRESS_ALREADY_EXISTS;
48 if (PortSectionSize == 0)
49 PortSectionSize = 512 * 1024;
53 sectionSize.QuadPart = PortSectionSize;
70 clientView.
ViewSize = PortSectionSize;
78 securityQos.Length =
sizeof(SECURITY_QUALITY_OF_SERVICE);
79 securityQos.ImpersonationLevel = SecurityImpersonation;
80 securityQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
81 securityQos.EffectiveOnly =
TRUE;
95 NtClose(sectionHandle);
116 return STATUS_INSUFFICIENT_RESOURCES;
172 _In_opt_ PVOID String,
186 if (length > MAXULONG32)
195 memcpy(memory, String, length);
197 StringRef->Length = (ULONG)length;
198 StringRef->Offset = offset;
211 Message->h.u2.ZeroInit = 0;
218 return Message->p.ReturnStatus;
223 _In_reads_bytes_opt_(InLength) PVOID InBuffer,
225 _Out_writes_bytes_opt_(OutLength) PVOID OutBuffer,
236 return STATUS_PORT_DISCONNECTED;
237 if (InLength >
sizeof(m.
p.
u.Plugin.i.Data))
238 return STATUS_BUFFER_OVERFLOW;
243 return STATUS_NO_MEMORY;
246 memcpy(m.
p.
u.Plugin.i.Data, InBuffer, InLength);
251 memcpy(OutBuffer, m.
p.
u.Plugin.o.Data, min(OutLength,
sizeof(m.
p.
u.Plugin.o.Data)));
266 PVOID userName = NULL;
267 PVOID password = NULL;
268 ULONG passwordLength;
269 PVOID currentDirectory = NULL;
270 PVOID commandLine = NULL;
271 PVOID fileName = NULL;
272 PVOID desktopName = NULL;
273 PVOID serviceName = NULL;
278 return STATUS_PORT_DISCONNECTED;
282 m.
p.
u.ExecuteRunAsCommand.i.ProcessId = Parameters->ProcessId;
283 m.
p.
u.ExecuteRunAsCommand.i.LogonType = Parameters->LogonType;
284 m.
p.
u.ExecuteRunAsCommand.i.SessionId = Parameters->SessionId;
285 m.
p.
u.ExecuteRunAsCommand.i.UseLinkedToken = Parameters->UseLinkedToken;
287 status = STATUS_NO_MEMORY;
289 if (Parameters->UserName && !(userName =
PhSvcpCreateString(Parameters->UserName, -1, &m.
p.
u.ExecuteRunAsCommand.i.UserName)))
292 if (Parameters->Password)
294 if (!(password =
PhSvcpCreateString(Parameters->Password, -1, &m.
p.
u.ExecuteRunAsCommand.i.Password)))
297 passwordLength = m.
p.
u.ExecuteRunAsCommand.i.Password.Length;
300 if (Parameters->CurrentDirectory && !(currentDirectory =
PhSvcpCreateString(Parameters->CurrentDirectory, -1, &m.
p.
u.ExecuteRunAsCommand.i.CurrentDirectory)))
302 if (Parameters->CommandLine && !(commandLine =
PhSvcpCreateString(Parameters->CommandLine, -1, &m.
p.
u.ExecuteRunAsCommand.i.CommandLine)))
304 if (Parameters->FileName && !(fileName =
PhSvcpCreateString(Parameters->FileName, -1, &m.
p.
u.ExecuteRunAsCommand.i.FileName)))
306 if (Parameters->DesktopName && !(desktopName =
PhSvcpCreateString(Parameters->DesktopName, -1, &m.
p.
u.ExecuteRunAsCommand.i.DesktopName)))
308 if (Parameters->ServiceName && !(serviceName =
PhSvcpCreateString(Parameters->ServiceName, -1, &m.
p.
u.ExecuteRunAsCommand.i.ServiceName)))
322 RtlSecureZeroMemory(password, passwordLength);
339 _In_opt_ PVOID BaseAddress,
350 return STATUS_PORT_DISCONNECTED;
354 m.
p.
u.UnloadDriver.i.BaseAddress = BaseAddress;
361 return STATUS_NO_MEMORY;
381 return STATUS_PORT_DISCONNECTED;
385 m.
p.
u.ControlProcess.i.Command = Command;
386 m.
p.
u.ControlProcess.i.Argument = Argument;
401 return STATUS_PORT_DISCONNECTED;
406 m.
p.
u.ControlService.i.Command = Command;
414 status = STATUS_NO_MEMORY;
425 _In_opt_ PWSTR DisplayName,
426 _In_ ULONG ServiceType,
427 _In_ ULONG StartType,
428 _In_ ULONG ErrorControl,
429 _In_opt_ PWSTR BinaryPathName,
430 _In_opt_ PWSTR LoadOrderGroup,
431 _Out_opt_ PULONG TagId,
432 _In_opt_ PWSTR Dependencies,
433 _In_opt_ PWSTR ServiceStartName,
434 _In_opt_ PWSTR Password
439 PVOID serviceName = NULL;
440 PVOID displayName = NULL;
441 PVOID binaryPathName = NULL;
442 PVOID loadOrderGroup = NULL;
443 PVOID dependencies = NULL;
444 PVOID serviceStartName = NULL;
445 PVOID password = NULL;
446 ULONG passwordLength;
451 return STATUS_PORT_DISCONNECTED;
455 m.
p.
u.CreateService.i.ServiceType = ServiceType;
456 m.
p.
u.CreateService.i.StartType = StartType;
457 m.
p.
u.CreateService.i.ErrorControl = ErrorControl;
458 m.
p.
u.CreateService.i.TagIdSpecified = TagId != NULL;
460 status = STATUS_NO_MEMORY;
464 if (DisplayName && !(displayName =
PhSvcpCreateString(DisplayName, -1, &m.
p.
u.CreateService.i.DisplayName)))
466 if (BinaryPathName && !(binaryPathName =
PhSvcpCreateString(BinaryPathName, -1, &m.
p.
u.CreateService.i.BinaryPathName)))
468 if (LoadOrderGroup && !(loadOrderGroup =
PhSvcpCreateString(LoadOrderGroup, -1, &m.
p.
u.CreateService.i.LoadOrderGroup)))
473 SIZE_T dependenciesLength;
477 dependenciesLength =
sizeof(WCHAR);
484 dependenciesLength += partCount *
sizeof(WCHAR);
485 }
while (partCount != 1);
487 if (!(dependencies =
PhSvcpCreateString(Dependencies, dependenciesLength, &m.
p.
u.CreateService.i.Dependencies)))
491 if (ServiceStartName && !(serviceStartName =
PhSvcpCreateString(ServiceStartName, -1, &m.
p.
u.CreateService.i.ServiceStartName)))
499 passwordLength = m.
p.
u.CreateService.i.Password.Length;
507 *TagId = m.
p.
u.CreateService.o.TagId;
513 RtlSecureZeroMemory(password, passwordLength);
529 _In_ ULONG ServiceType,
530 _In_ ULONG StartType,
531 _In_ ULONG ErrorControl,
532 _In_opt_ PWSTR BinaryPathName,
533 _In_opt_ PWSTR LoadOrderGroup,
534 _Out_opt_ PULONG TagId,
535 _In_opt_ PWSTR Dependencies,
536 _In_opt_ PWSTR ServiceStartName,
537 _In_opt_ PWSTR Password,
538 _In_opt_ PWSTR DisplayName
543 PVOID serviceName = NULL;
544 PVOID binaryPathName = NULL;
545 PVOID loadOrderGroup = NULL;
546 PVOID dependencies = NULL;
547 PVOID serviceStartName = NULL;
548 PVOID password = NULL;
549 ULONG passwordLength;
550 PVOID displayName = NULL;
555 return STATUS_PORT_DISCONNECTED;
559 m.
p.
u.ChangeServiceConfig.i.ServiceType = ServiceType;
560 m.
p.
u.ChangeServiceConfig.i.StartType = StartType;
561 m.
p.
u.ChangeServiceConfig.i.ErrorControl = ErrorControl;
562 m.
p.
u.ChangeServiceConfig.i.TagIdSpecified = TagId != NULL;
564 status = STATUS_NO_MEMORY;
566 if (!(serviceName =
PhSvcpCreateString(ServiceName, -1, &m.
p.
u.ChangeServiceConfig.i.ServiceName)))
568 if (BinaryPathName && !(binaryPathName =
PhSvcpCreateString(BinaryPathName, -1, &m.
p.
u.ChangeServiceConfig.i.BinaryPathName)))
570 if (LoadOrderGroup && !(loadOrderGroup =
PhSvcpCreateString(LoadOrderGroup, -1, &m.
p.
u.ChangeServiceConfig.i.LoadOrderGroup)))
575 SIZE_T dependenciesLength;
579 dependenciesLength =
sizeof(WCHAR);
586 dependenciesLength += partCount *
sizeof(WCHAR);
587 }
while (partCount != 1);
589 if (!(dependencies =
PhSvcpCreateString(Dependencies, dependenciesLength, &m.
p.
u.ChangeServiceConfig.i.Dependencies)))
593 if (ServiceStartName && !(serviceStartName =
PhSvcpCreateString(ServiceStartName, -1, &m.
p.
u.ChangeServiceConfig.i.ServiceStartName)))
601 passwordLength = m.
p.
u.ChangeServiceConfig.i.Password.Length;
604 if (DisplayName && !(displayName =
PhSvcpCreateString(DisplayName, -1, &m.
p.
u.ChangeServiceConfig.i.DisplayName)))
612 *TagId = m.
p.
u.ChangeServiceConfig.o.TagId;
620 RtlSecureZeroMemory(password, passwordLength);
644 _Inout_ PVOID *PointerInBytesBuilder,
646 _In_ SIZE_T Alignment,
647 _In_ ULONG NumberOfPointersToRebase,
659 oldBase = (ULONG_PTR)BytesBuilder->Bytes->Buffer;
660 oldLength = BytesBuilder->Bytes->Length;
661 assert((ULONG_PTR)PointerInBytesBuilder >= oldBase && (ULONG_PTR)PointerInBytesBuilder +
sizeof(PVOID) <= oldBase + oldLength);
663 if (!*PointerInBytesBuilder)
667 newBase = (ULONG_PTR)BytesBuilder->Bytes->Buffer;
669 PointerInBytesBuilder = (PVOID *)((ULONG_PTR)PointerInBytesBuilder - oldBase + newBase);
670 *PointerInBytesBuilder = (PVOID)offset;
674 for (i = 0; i < NumberOfPointersToRebase; i++)
676 pointer = va_arg(argptr, PVOID *);
677 assert(!*pointer || ((ULONG_PTR)*pointer >= oldBase && (ULONG_PTR)*pointer +
sizeof(PVOID) <= oldBase + oldLength));
680 *pointer = (PVOID)((ULONG_PTR)*pointer - oldBase + newBase);
686 _Inout_ PVOID *PointerInBytesBuilder,
688 _In_ SIZE_T Alignment,
689 _In_ ULONG NumberOfPointersToRebase,
695 va_start(argptr, NumberOfPointersToRebase);
696 PhSvcpPackBuffer_V(BytesBuilder, PointerInBytesBuilder, Length, Alignment, NumberOfPointersToRebase, argptr);
700 _In_opt_ PWSTR String,
716 length += (partCount + 1) *
sizeof(WCHAR);
721 part += partCount + 1;
735 _In_ ULONG InfoLevel,
741 PVOID serviceName = NULL;
746 return STATUS_PORT_DISCONNECTED;
750 m.
p.
u.ChangeServiceConfig2.i.InfoLevel = InfoLevel;
752 if (serviceName =
PhSvcpCreateString(ServiceName, -1, &m.
p.
u.ChangeServiceConfig2.i.ServiceName))
756 case SERVICE_CONFIG_FAILURE_ACTIONS:
758 LPSERVICE_FAILURE_ACTIONS failureActions = Info;
759 LPSERVICE_FAILURE_ACTIONS packedFailureActions;
762 packedFailureActions =
PhSvcpPackRoot(&bb, failureActions,
sizeof(SERVICE_FAILURE_ACTIONS));
764 1, &packedFailureActions);
766 1, &packedFailureActions);
768 if (failureActions->cActions != 0 && failureActions->lpsaActions)
770 PhSvcpPackBuffer(&bb, &packedFailureActions->lpsaActions, failureActions->cActions *
sizeof(SC_ACTION), __alignof(SC_ACTION),
771 1, &packedFailureActions);
778 case SERVICE_CONFIG_DELAYED_AUTO_START_INFO:
779 info =
PhSvcpCreateString(Info,
sizeof(SERVICE_DELAYED_AUTO_START_INFO), &m.
p.
u.ChangeServiceConfig2.i.Info);
781 case SERVICE_CONFIG_FAILURE_ACTIONS_FLAG:
782 info =
PhSvcpCreateString(Info,
sizeof(SERVICE_FAILURE_ACTIONS_FLAG), &m.
p.
u.ChangeServiceConfig2.i.Info);
784 case SERVICE_CONFIG_SERVICE_SID_INFO:
787 case SERVICE_CONFIG_REQUIRED_PRIVILEGES_INFO:
789 LPSERVICE_REQUIRED_PRIVILEGES_INFO requiredPrivilegesInfo = Info;
790 LPSERVICE_REQUIRED_PRIVILEGES_INFO packedRequiredPrivilegesInfo;
793 packedRequiredPrivilegesInfo =
PhSvcpPackRoot(&bb, requiredPrivilegesInfo,
sizeof(SERVICE_REQUIRED_PRIVILEGES_INFO));
795 1, &packedRequiredPrivilegesInfo);
801 case SERVICE_CONFIG_PRESHUTDOWN_INFO:
802 info =
PhSvcpCreateString(Info,
sizeof(SERVICE_PRESHUTDOWN_INFO), &m.
p.
u.ChangeServiceConfig2.i.Info);
804 case SERVICE_CONFIG_TRIGGER_INFO:
806 PSERVICE_TRIGGER_INFO triggerInfo = Info;
807 PSERVICE_TRIGGER_INFO packedTriggerInfo;
809 PSERVICE_TRIGGER packedTrigger;
811 PSERVICE_TRIGGER_SPECIFIC_DATA_ITEM packedDataItem;
815 packedTriggerInfo =
PhSvcpPackRoot(&bb, triggerInfo,
sizeof(SERVICE_TRIGGER_INFO));
817 if (triggerInfo->cTriggers != 0 && triggerInfo->pTriggers)
819 PhSvcpPackBuffer(&bb, &packedTriggerInfo->pTriggers, triggerInfo->cTriggers *
sizeof(SERVICE_TRIGGER), __alignof(SERVICE_TRIGGER),
820 1, &packedTriggerInfo);
822 for (i = 0; i < triggerInfo->cTriggers; i++)
824 packedTrigger =
PhOffsetBytesBuilder(&bb, (SIZE_T)packedTriggerInfo->pTriggers + i *
sizeof(SERVICE_TRIGGER));
826 PhSvcpPackBuffer(&bb, &packedTrigger->pTriggerSubtype,
sizeof(GUID), __alignof(GUID),
827 2, &packedTriggerInfo, &packedTrigger);
829 if (packedTrigger->cDataItems != 0 && packedTrigger->pDataItems)
831 PhSvcpPackBuffer(&bb, &packedTrigger->pDataItems, packedTrigger->cDataItems *
sizeof(SERVICE_TRIGGER_SPECIFIC_DATA_ITEM), __alignof(SERVICE_TRIGGER_SPECIFIC_DATA_ITEM),
832 2, &packedTriggerInfo, &packedTrigger);
834 for (j = 0; j < packedTrigger->cDataItems; j++)
836 packedDataItem =
PhOffsetBytesBuilder(&bb, (SIZE_T)packedTrigger->pDataItems + j *
sizeof(SERVICE_TRIGGER_SPECIFIC_DATA_ITEM));
839 switch (packedDataItem->dwDataType)
841 case SERVICE_TRIGGER_DATA_TYPE_BINARY:
842 case SERVICE_TRIGGER_DATA_TYPE_LEVEL:
843 alignment =
sizeof(CHAR);
845 case SERVICE_TRIGGER_DATA_TYPE_STRING:
846 alignment =
sizeof(WCHAR);
848 case SERVICE_TRIGGER_DATA_TYPE_KEYWORD_ANY:
849 case SERVICE_TRIGGER_DATA_TYPE_KEYWORD_ALL:
850 alignment =
sizeof(ULONG64);
854 PhSvcpPackBuffer(&bb, &packedDataItem->pData, packedDataItem->cbData, alignment,
855 3, &packedTriggerInfo, &packedTrigger, &packedDataItem);
865 case SERVICE_CONFIG_LAUNCH_PROTECTED:
866 info =
PhSvcpCreateString(Info,
sizeof(SERVICE_LAUNCH_PROTECTED_INFO), &m.
p.
u.ChangeServiceConfig2.i.Info);
869 status = STATUS_INVALID_PARAMETER;
874 if (serviceName && info)
880 status = STATUS_NO_MEMORY;
906 return STATUS_PORT_DISCONNECTED;
910 m.
p.
u.SetTcpEntry.i.State = tcpRow->dwState;
911 m.
p.
u.SetTcpEntry.i.LocalAddress = tcpRow->dwLocalAddr;
912 m.
p.
u.SetTcpEntry.i.LocalPort = tcpRow->dwLocalPort;
913 m.
p.
u.SetTcpEntry.i.RemoteAddress = tcpRow->dwRemoteAddr;
914 m.
p.
u.SetTcpEntry.i.RemotePort = tcpRow->dwRemotePort;
920 _In_ HANDLE ThreadId,
928 return STATUS_PORT_DISCONNECTED;
931 m.
p.
u.ControlThread.i.ThreadId = ThreadId;
932 m.
p.
u.ControlThread.i.Command = Command;
933 m.
p.
u.ControlThread.i.Argument = Argument;
939 _In_ PSID AccountSid,
945 PVOID accountSid = NULL;
946 PVOID userRight = NULL;
949 return STATUS_PORT_DISCONNECTED;
953 status = STATUS_NO_MEMORY;
957 if (!(userRight =
PhSvcpCreateString(UserRight->Buffer, UserRight->Length, &m.
p.
u.AddAccountRight.i.UserRight)))
983 return STATUS_PORT_DISCONNECTED;
986 m.
p.
u.IssueMemoryListCommand.i.Command = Command;
1001 return STATUS_PORT_DISCONNECTED;
1004 m.
p.
u.PostMessage.i.hWnd = hWnd;
1005 m.
p.
u.PostMessage.i.Msg = Msg;
1006 m.
p.
u.PostMessage.i.wParam = wParam;
1007 m.
p.
u.PostMessage.i.lParam = lParam;
1022 return STATUS_PORT_DISCONNECTED;
1025 m.
p.
u.PostMessage.i.hWnd = hWnd;
1026 m.
p.
u.PostMessage.i.Msg = Msg;
1027 m.
p.
u.PostMessage.i.wParam = wParam;
1028 m.
p.
u.PostMessage.i.lParam = lParam;
1039 PVOID fileName = NULL;
1044 return STATUS_PORT_DISCONNECTED;
1047 fileName =
PhSvcpCreateString(FileName, -1, &m.
p.
u.CreateProcessIgnoreIfeoDebugger.i.FileName);
1050 return STATUS_NO_MEMORY;
1061 _In_ PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
1062 _Out_ PULONG BufferSize
1066 ULONG bufferSize = 0;
1067 PSECURITY_DESCRIPTOR selfRelativeSecurityDescriptor;
1071 if (status != STATUS_BUFFER_TOO_SMALL)
1074 selfRelativeSecurityDescriptor = PhAllocate(bufferSize);
1079 PhFree(selfRelativeSecurityDescriptor);
1083 *BufferSize = bufferSize;
1085 return selfRelativeSecurityDescriptor;
1090 _In_ SECURITY_INFORMATION SecurityInformation,
1091 _In_ PSECURITY_DESCRIPTOR SecurityDescriptor
1096 PSECURITY_DESCRIPTOR selfRelativeSecurityDescriptor = NULL;
1098 PVOID serviceName = NULL;
1099 PVOID copiedSelfRelativeSecurityDescriptor = NULL;
1102 return STATUS_PORT_DISCONNECTED;
1106 if (!selfRelativeSecurityDescriptor)
1108 status = STATUS_BAD_DESCRIPTOR_FORMAT;
1113 m.
p.
u.SetServiceSecurity.i.SecurityInformation = SecurityInformation;
1114 status = STATUS_NO_MEMORY;
1116 if (!(serviceName =
PhSvcpCreateString(ServiceName, -1, &m.
p.
u.SetServiceSecurity.i.ServiceName)))
1118 if (!(copiedSelfRelativeSecurityDescriptor =
PhSvcpCreateString(selfRelativeSecurityDescriptor, bufferSize, &m.
p.
u.SetServiceSecurity.i.SecurityDescriptor)))
1124 if (selfRelativeSecurityDescriptor)
PhFree(selfRelativeSecurityDescriptor);
1126 if (copiedSelfRelativeSecurityDescriptor)
PhSvcpFreeHeap(copiedSelfRelativeSecurityDescriptor);
1132 _In_ PWSTR DbgHelpPath
1137 PVOID dbgHelpPath = NULL;
1142 return STATUS_PORT_DISCONNECTED;
1148 return STATUS_NO_MEMORY;
1159 _In_ HANDLE ProcessHandle,
1161 _In_ HANDLE FileHandle,
1167 HANDLE serverHandle = NULL;
1168 HANDLE remoteProcessHandle = NULL;
1169 HANDLE remoteFileHandle = NULL;
1174 return STATUS_PORT_DISCONNECTED;
1193 FILE_GENERIC_WRITE, 0, 0)))
1198 m.
p.
u.WriteMiniDumpProcess.i.LocalProcessHandle = HandleToUlong(remoteProcessHandle);
1199 m.
p.
u.WriteMiniDumpProcess.i.ProcessId = HandleToUlong(ProcessId);
1200 m.
p.
u.WriteMiniDumpProcess.i.LocalFileHandle = HandleToUlong(remoteFileHandle);
1201 m.
p.
u.WriteMiniDumpProcess.i.DumpType = DumpType;
1208 if (remoteProcessHandle)
1209 PhDuplicateObject(serverHandle, remoteProcessHandle, NULL, NULL, 0, 0, DUPLICATE_CLOSE_SOURCE);
1210 if (remoteFileHandle)
1211 PhDuplicateObject(serverHandle, remoteFileHandle, NULL, NULL, 0, 0, DUPLICATE_CLOSE_SOURCE);
1213 NtClose(serverHandle);