### ms-scmr.idl
"""
RPC definitions for the following interfaces:
- svcctl (v2.0): 367ABB81-9844-35F1-AD32-98F038001003
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRByteField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfVarStrLenField,
    NDRConfVarStrLenFieldUtf16,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRContextHandle,
    NDRFullPointerField,
    NDRIntEnumField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRShortField,
    NDRSignedIntField,
    NDRUnionField,
    register_dcerpc_interface,
)


class RCloseServiceHandle_Request(NDRPacket):
    fields_desc = [NDRPacketField("hSCObject", NDRContextHandle(), NDRContextHandle)]


class RCloseServiceHandle_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCObject", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class LPSERVICE_STATUS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwCurrentState", 0),
        NDRIntField("dwControlsAccepted", 0),
        NDRIntField("dwWin32ExitCode", 0),
        NDRIntField("dwServiceSpecificExitCode", 0),
        NDRIntField("dwCheckPoint", 0),
        NDRIntField("dwWaitHint", 0),
    ]


class RControlService_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwControl", 0),
    ]


class RControlService_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("lpServiceStatus", LPSERVICE_STATUS(), LPSERVICE_STATUS),
        NDRIntField("status", 0),
    ]


class RDeleteService_Request(NDRPacket):
    fields_desc = [NDRPacketField("hService", NDRContextHandle(), NDRContextHandle)]


class RDeleteService_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class RLockServiceDatabase_Request(NDRPacket):
    fields_desc = [NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle)]


class RLockServiceDatabase_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("lpLock", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class RQueryServiceObjectSecurity_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwSecurityInformation", 0),
        NDRIntField("cbBufSize", 0),
    ]


class RQueryServiceObjectSecurity_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField(
            "lpSecurityDescriptor", "", size_is=lambda pkt: pkt.cbBufSize
        ),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("status", 0),
    ]


class RSetServiceObjectSecurity_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwSecurityInformation", 0),
        NDRConfStrLenField(
            "lpSecurityDescriptor", "", size_is=lambda pkt: pkt.cbBufSize
        ),
        NDRIntField("cbBufSize", None, size_of="lpSecurityDescriptor"),
    ]


class RSetServiceObjectSecurity_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class RQueryServiceStatus_Request(NDRPacket):
    fields_desc = [NDRPacketField("hService", NDRContextHandle(), NDRContextHandle)]


class RQueryServiceStatus_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("lpServiceStatus", LPSERVICE_STATUS(), LPSERVICE_STATUS),
        NDRIntField("status", 0),
    ]


class RSetServiceStatus_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hServiceStatus", NDRContextHandle(), NDRContextHandle),
        NDRPacketField("lpServiceStatus", LPSERVICE_STATUS(), LPSERVICE_STATUS),
    ]


class RSetServiceStatus_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class RUnlockServiceDatabase_Request(NDRPacket):
    fields_desc = [NDRPacketField("Lock", NDRContextHandle(), NDRContextHandle)]


class RUnlockServiceDatabase_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("Lock", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class RNotifyBootConfigStatus_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpMachineName", "")),
        NDRIntField("BootAcceptable", 0),
    ]


class RNotifyBootConfigStatus_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class RChangeServiceConfigW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwStartType", 0),
        NDRIntField("dwErrorControl", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpBinaryPathName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpLoadOrderGroup", "")),
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRFullPointerField(
            NDRConfStrLenField(
                "lpDependencies", "", size_is=lambda pkt: pkt.dwDependSize
            )
        ),
        NDRIntField("dwDependSize", None, size_of="lpDependencies"),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpServiceStartName", "")),
        NDRFullPointerField(
            NDRConfStrLenField("lpPassword", "", size_is=lambda pkt: pkt.dwPwSize)
        ),
        NDRIntField("dwPwSize", None, size_of="lpPassword"),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpDisplayName", "")),
    ]


class RChangeServiceConfigW_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRIntField("status", 0),
    ]


class RCreateServiceW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullFieldUtf16("lpServiceName", ""),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpDisplayName", "")),
        NDRIntField("dwDesiredAccess", 0),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwStartType", 0),
        NDRIntField("dwErrorControl", 0),
        NDRConfVarStrNullFieldUtf16("lpBinaryPathName", ""),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpLoadOrderGroup", "")),
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRFullPointerField(
            NDRConfStrLenField(
                "lpDependencies", "", size_is=lambda pkt: pkt.dwDependSize
            )
        ),
        NDRIntField("dwDependSize", None, size_of="lpDependencies"),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpServiceStartName", "")),
        NDRFullPointerField(
            NDRConfStrLenField("lpPassword", "", size_is=lambda pkt: pkt.dwPwSize)
        ),
        NDRIntField("dwPwSize", None, size_of="lpPassword"),
    ]


class RCreateServiceW_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRPacketField("lpServiceHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class REnumDependentServicesW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwServiceState", 0),
        NDRIntField("cbBufSize", 0),
    ]


class REnumDependentServicesW_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpServices", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("lpServicesReturned", 0),
        NDRIntField("status", 0),
    ]


class REnumServicesStatusW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwServiceState", 0),
        NDRIntField("cbBufSize", 0),
        NDRFullPointerField(NDRIntField("lpResumeIndex", 0)),
    ]


class REnumServicesStatusW_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpBuffer", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("lpServicesReturned", 0),
        NDRFullPointerField(NDRIntField("lpResumeIndex", 0)),
        NDRIntField("status", 0),
    ]


class ROpenSCManagerW_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpMachineName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpDatabaseName", "")),
        NDRIntField("dwDesiredAccess", 0),
    ]


class ROpenSCManagerW_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("lpScHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class ROpenServiceW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullFieldUtf16("lpServiceName", ""),
        NDRIntField("dwDesiredAccess", 0),
    ]


class ROpenServiceW_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("lpServiceHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class LPQUERY_SERVICE_CONFIGW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwStartType", 0),
        NDRIntField("dwErrorControl", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpBinaryPathName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpLoadOrderGroup", ""), deferred=True
        ),
        NDRIntField("dwTagId", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpDependencies", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpServiceStartName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpDisplayName", ""), deferred=True
        ),
    ]


class RQueryServiceConfigW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("cbBufSize", 0),
    ]


class RQueryServiceConfigW_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "lpServiceConfig", LPQUERY_SERVICE_CONFIGW(), LPQUERY_SERVICE_CONFIGW
        ),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("status", 0),
    ]


class LPQUERY_SERVICE_LOCK_STATUSW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("fIsLocked", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpLockOwner", ""), deferred=True
        ),
        NDRIntField("dwLockDuration", 0),
    ]


class RQueryServiceLockStatusW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRIntField("cbBufSize", 0),
    ]


class RQueryServiceLockStatusW_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "lpLockStatus", LPQUERY_SERVICE_LOCK_STATUSW(), LPQUERY_SERVICE_LOCK_STATUSW
        ),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("status", 0),
    ]


class LPSTRING_PTRSW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("StringPtr", ""), deferred=True)
    ]


class RStartServiceW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("argc", None, size_of="argv"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "argv", [LPSTRING_PTRSW()], LPSTRING_PTRSW, size_is=lambda pkt: pkt.argc
            )
        ),
    ]


class RStartServiceW_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class RGetServiceDisplayNameW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullFieldUtf16("lpServiceName", ""),
        NDRIntField("lpcchBuffer", 0),
    ]


class RGetServiceDisplayNameW_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenFieldUtf16(
            "lpDisplayName", "", size_is=lambda pkt: (pkt.lpcchBuffer + 1)
        ),
        NDRIntField(
            "lpcchBuffer", None, size_of="lpDisplayName", adjust=lambda _, x: (x - 1)
        ),
        NDRIntField("status", 0),
    ]


class RGetServiceKeyNameW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullFieldUtf16("lpDisplayName", ""),
        NDRIntField("lpcchBuffer", 0),
    ]


class RGetServiceKeyNameW_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenFieldUtf16(
            "lpServiceName", "", size_is=lambda pkt: (pkt.lpcchBuffer + 1)
        ),
        NDRIntField(
            "lpcchBuffer", None, size_of="lpServiceName", adjust=lambda _, x: (x - 1)
        ),
        NDRIntField("status", 0),
    ]


class RChangeServiceConfigA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwStartType", 0),
        NDRIntField("dwErrorControl", 0),
        NDRFullPointerField(NDRConfVarStrNullField("lpBinaryPathName", "")),
        NDRFullPointerField(NDRConfVarStrNullField("lpLoadOrderGroup", "")),
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRFullPointerField(
            NDRConfStrLenField(
                "lpDependencies", "", size_is=lambda pkt: pkt.dwDependSize
            )
        ),
        NDRIntField("dwDependSize", None, size_of="lpDependencies"),
        NDRFullPointerField(NDRConfVarStrNullField("lpServiceStartName", "")),
        NDRFullPointerField(
            NDRConfStrLenField("lpPassword", "", size_is=lambda pkt: pkt.dwPwSize)
        ),
        NDRIntField("dwPwSize", None, size_of="lpPassword"),
        NDRFullPointerField(NDRConfVarStrNullField("lpDisplayName", "")),
    ]


class RChangeServiceConfigA_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRIntField("status", 0),
    ]


class RCreateServiceA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullField("lpServiceName", ""),
        NDRFullPointerField(NDRConfVarStrNullField("lpDisplayName", "")),
        NDRIntField("dwDesiredAccess", 0),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwStartType", 0),
        NDRIntField("dwErrorControl", 0),
        NDRConfVarStrNullField("lpBinaryPathName", ""),
        NDRFullPointerField(NDRConfVarStrNullField("lpLoadOrderGroup", "")),
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRFullPointerField(
            NDRConfStrLenField(
                "lpDependencies", "", size_is=lambda pkt: pkt.dwDependSize
            )
        ),
        NDRIntField("dwDependSize", None, size_of="lpDependencies"),
        NDRFullPointerField(NDRConfVarStrNullField("lpServiceStartName", "")),
        NDRFullPointerField(
            NDRConfStrLenField("lpPassword", "", size_is=lambda pkt: pkt.dwPwSize)
        ),
        NDRIntField("dwPwSize", None, size_of="lpPassword"),
    ]


class RCreateServiceA_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRPacketField("lpServiceHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class REnumDependentServicesA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwServiceState", 0),
        NDRIntField("cbBufSize", 0),
    ]


class REnumDependentServicesA_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpServices", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("lpServicesReturned", 0),
        NDRIntField("status", 0),
    ]


class REnumServicesStatusA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwServiceState", 0),
        NDRIntField("cbBufSize", 0),
        NDRFullPointerField(NDRIntField("lpResumeIndex", 0)),
    ]


class REnumServicesStatusA_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpBuffer", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("lpServicesReturned", 0),
        NDRFullPointerField(NDRIntField("lpResumeIndex", 0)),
        NDRIntField("status", 0),
    ]


class ROpenSCManagerA_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullField("lpMachineName", "")),
        NDRFullPointerField(NDRConfVarStrNullField("lpDatabaseName", "")),
        NDRIntField("dwDesiredAccess", 0),
    ]


class ROpenSCManagerA_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("lpScHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class ROpenServiceA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullField("lpServiceName", ""),
        NDRIntField("dwDesiredAccess", 0),
    ]


class ROpenServiceA_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("lpServiceHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class LPQUERY_SERVICE_CONFIGA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwStartType", 0),
        NDRIntField("dwErrorControl", 0),
        NDRFullPointerField(
            NDRConfVarStrNullField("lpBinaryPathName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullField("lpLoadOrderGroup", ""), deferred=True
        ),
        NDRIntField("dwTagId", 0),
        NDRFullPointerField(
            NDRConfVarStrNullField("lpDependencies", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullField("lpServiceStartName", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullField("lpDisplayName", ""), deferred=True),
    ]


class RQueryServiceConfigA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("cbBufSize", 0),
    ]


class RQueryServiceConfigA_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "lpServiceConfig", LPQUERY_SERVICE_CONFIGA(), LPQUERY_SERVICE_CONFIGA
        ),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("status", 0),
    ]


class LPQUERY_SERVICE_LOCK_STATUSA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("fIsLocked", 0),
        NDRFullPointerField(NDRConfVarStrNullField("lpLockOwner", ""), deferred=True),
        NDRIntField("dwLockDuration", 0),
    ]


class RQueryServiceLockStatusA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRIntField("cbBufSize", 0),
    ]


class RQueryServiceLockStatusA_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "lpLockStatus", LPQUERY_SERVICE_LOCK_STATUSA(), LPQUERY_SERVICE_LOCK_STATUSA
        ),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("status", 0),
    ]


class LPSTRING_PTRSA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullField("StringPtr", ""), deferred=True)
    ]


class RStartServiceA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("argc", None, size_of="argv"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "argv", [LPSTRING_PTRSA()], LPSTRING_PTRSA, size_is=lambda pkt: pkt.argc
            )
        ),
    ]


class RStartServiceA_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class RGetServiceDisplayNameA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullField("lpServiceName", ""),
        NDRIntField("lpcchBuffer", 0),
    ]


class RGetServiceDisplayNameA_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullField("lpDisplayName", ""),
        NDRIntField("lpcchBuffer", None, size_of="lpDisplayName"),
        NDRIntField("status", 0),
    ]


class RGetServiceKeyNameA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullField("lpDisplayName", ""),
        NDRIntField("lpcchBuffer", 0),
    ]


class RGetServiceKeyNameA_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullField("lpKeyName", ""),
        NDRIntField("lpcchBuffer", None, size_of="lpKeyName"),
        NDRIntField("status", 0),
    ]


class REnumServiceGroupW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwServiceState", 0),
        NDRIntField("cbBufSize", 0),
        NDRFullPointerField(NDRIntField("lpResumeIndex", 0)),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszGroupName", "")),
    ]


class REnumServiceGroupW_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpBuffer", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("lpServicesReturned", 0),
        NDRFullPointerField(NDRIntField("lpResumeIndex", 0)),
        NDRIntField("status", 0),
    ]


class LPSERVICE_DESCRIPTIONA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullField("lpDescription", ""), deferred=True)
    ]


class SC_ACTION_TYPE(IntEnum):
    SC_ACTION_NONE = 0
    SC_ACTION_RESTART = 1
    SC_ACTION_REBOOT = 2
    SC_ACTION_RUN_COMMAND = 3


class SC_ACTION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntEnumField("Type", 0, SC_ACTION_TYPE), NDRIntField("Delay", 0)]


class LPSERVICE_FAILURE_ACTIONSA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwResetPeriod", 0),
        NDRFullPointerField(NDRConfVarStrNullField("lpRebootMsg", ""), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullField("lpCommand", ""), deferred=True),
        NDRIntField("cActions", None, size_of="lpsaActions"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "lpsaActions", [], SC_ACTION, size_is=lambda pkt: pkt.cActions
            ),
            deferred=True,
        ),
    ]


class LPSERVICE_DELAYED_AUTO_START_INFO(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRSignedIntField("fDelayedAutostart", 0)]


class LPSERVICE_FAILURE_ACTIONS_FLAG(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRSignedIntField("fFailureActionsOnNonCrashFailures", 0)]


class LPSERVICE_SID_INFO(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwServiceSidType", 0)]


class LPSERVICE_RPC_REQUIRED_PRIVILEGES_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cbRequiredPrivileges", None, size_of="pRequiredPrivileges"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "pRequiredPrivileges", "", size_is=lambda pkt: pkt.cbRequiredPrivileges
            ),
            deferred=True,
        ),
    ]


class LPSERVICE_PRESHUTDOWN_INFO(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwPreshutdownTimeout", 0)]


class GUID(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Data1", 0),
        NDRShortField("Data2", 0),
        NDRShortField("Data3", 0),
        StrFixedLenField("Data4", "", length=8),
    ]


class PSERVICE_TRIGGER_SPECIFIC_DATA_ITEM(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwDataType", 0),
        NDRIntField("cbData", None, size_of="pData"),
        NDRFullPointerField(
            NDRConfStrLenField("pData", "", size_is=lambda pkt: pkt.cbData),
            deferred=True,
        ),
    ]


class PSERVICE_TRIGGER(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwTriggerType", 0),
        NDRIntField("dwAction", 0),
        NDRFullPointerField(
            NDRPacketField("pTriggerSubtype", GUID(), GUID), deferred=True
        ),
        NDRIntField("cDataItems", None, size_of="pDataItems"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pDataItems",
                [PSERVICE_TRIGGER_SPECIFIC_DATA_ITEM()],
                PSERVICE_TRIGGER_SPECIFIC_DATA_ITEM,
                size_is=lambda pkt: pkt.cDataItems,
            ),
            deferred=True,
        ),
    ]


class PSERVICE_TRIGGER_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cTriggers", None, size_of="pTriggers"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pTriggers",
                [PSERVICE_TRIGGER()],
                PSERVICE_TRIGGER,
                size_is=lambda pkt: pkt.cTriggers,
            ),
            deferred=True,
        ),
        NDRFullPointerField(NDRByteField("pReserved", 0), deferred=True),
    ]


class LPSERVICE_PREFERRED_NODE_INFO(NDRPacket):
    ALIGNMENT = (2, 2)
    fields_desc = [NDRShortField("usPreferredNode", 0), NDRByteField("fDelete", 0)]


class SC_RPC_CONFIG_INFOA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwInfoLevel", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value", LPSERVICE_DESCRIPTIONA(), LPSERVICE_DESCRIPTIONA
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_FAILURE_ACTIONSA(),
                            LPSERVICE_FAILURE_ACTIONSA,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_DELAYED_AUTO_START_INFO(),
                            LPSERVICE_DELAYED_AUTO_START_INFO,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_FAILURE_ACTIONS_FLAG(),
                            LPSERVICE_FAILURE_ACTIONS_FLAG,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 4),
                        (lambda _, val: val.tag == 4),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value", LPSERVICE_SID_INFO(), LPSERVICE_SID_INFO
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 5),
                        (lambda _, val: val.tag == 5),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_RPC_REQUIRED_PRIVILEGES_INFO(),
                            LPSERVICE_RPC_REQUIRED_PRIVILEGES_INFO,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 6),
                        (lambda _, val: val.tag == 6),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_PRESHUTDOWN_INFO(),
                            LPSERVICE_PRESHUTDOWN_INFO,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 7),
                        (lambda _, val: val.tag == 7),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value", PSERVICE_TRIGGER_INFO(), PSERVICE_TRIGGER_INFO
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 8),
                        (lambda _, val: val.tag == 8),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_PREFERRED_NODE_INFO(),
                            LPSERVICE_PREFERRED_NODE_INFO,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 9),
                        (lambda _, val: val.tag == 9),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class RChangeServiceConfig2A_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRPacketField("Info", SC_RPC_CONFIG_INFOA(), SC_RPC_CONFIG_INFOA),
    ]


class RChangeServiceConfig2A_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class LPSERVICE_DESCRIPTIONW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpDescription", ""), deferred=True
        )
    ]


class LPSERVICE_FAILURE_ACTIONSW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwResetPeriod", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpRebootMsg", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpCommand", ""), deferred=True
        ),
        NDRIntField("cActions", None, size_of="lpsaActions"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "lpsaActions", [], SC_ACTION, size_is=lambda pkt: pkt.cActions
            ),
            deferred=True,
        ),
    ]


class SC_RPC_CONFIG_INFOW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwInfoLevel", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value", LPSERVICE_DESCRIPTIONW(), LPSERVICE_DESCRIPTIONW
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_FAILURE_ACTIONSW(),
                            LPSERVICE_FAILURE_ACTIONSW,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_DELAYED_AUTO_START_INFO(),
                            LPSERVICE_DELAYED_AUTO_START_INFO,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_FAILURE_ACTIONS_FLAG(),
                            LPSERVICE_FAILURE_ACTIONS_FLAG,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 4),
                        (lambda _, val: val.tag == 4),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value", LPSERVICE_SID_INFO(), LPSERVICE_SID_INFO
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 5),
                        (lambda _, val: val.tag == 5),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_RPC_REQUIRED_PRIVILEGES_INFO(),
                            LPSERVICE_RPC_REQUIRED_PRIVILEGES_INFO,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 6),
                        (lambda _, val: val.tag == 6),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_PRESHUTDOWN_INFO(),
                            LPSERVICE_PRESHUTDOWN_INFO,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 7),
                        (lambda _, val: val.tag == 7),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value", PSERVICE_TRIGGER_INFO(), PSERVICE_TRIGGER_INFO
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 8),
                        (lambda _, val: val.tag == 8),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            LPSERVICE_PREFERRED_NODE_INFO(),
                            LPSERVICE_PREFERRED_NODE_INFO,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 9),
                        (lambda _, val: val.tag == 9),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class RChangeServiceConfig2W_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRPacketField("Info", SC_RPC_CONFIG_INFOW(), SC_RPC_CONFIG_INFOW),
    ]


class RChangeServiceConfig2W_Response(NDRPacket):
    fields_desc = [NDRIntField("status", 0)]


class RQueryServiceConfig2A_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInfoLevel", 0),
        NDRIntField("cbBufSize", 0),
    ]


class RQueryServiceConfig2A_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpBuffer", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("status", 0),
    ]


class RQueryServiceConfig2W_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInfoLevel", 0),
        NDRIntField("cbBufSize", 0),
    ]


class RQueryServiceConfig2W_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpBuffer", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("status", 0),
    ]


class SC_STATUS_TYPE(IntEnum):
    SC_STATUS_PROCESS_INFO = 0


class RQueryServiceStatusEx_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntEnumField("InfoLevel", 0, SC_STATUS_TYPE),
        NDRIntField("cbBufSize", 0),
    ]


class RQueryServiceStatusEx_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpBuffer", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("status", 0),
    ]


class SC_ENUM_TYPE(IntEnum):
    SC_ENUM_PROCESS_INFO = 0


class REnumServicesStatusExA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRIntEnumField("InfoLevel", 0, SC_ENUM_TYPE),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwServiceState", 0),
        NDRIntField("cbBufSize", 0),
        NDRFullPointerField(NDRIntField("lpResumeIndex", 0)),
        NDRFullPointerField(NDRConfVarStrNullField("pszGroupName", "")),
    ]


class REnumServicesStatusExA_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpBuffer", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("lpServicesReturned", 0),
        NDRFullPointerField(NDRIntField("lpResumeIndex", 0)),
        NDRIntField("status", 0),
    ]


class REnumServicesStatusExW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRIntEnumField("InfoLevel", 0, SC_ENUM_TYPE),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwServiceState", 0),
        NDRIntField("cbBufSize", 0),
        NDRFullPointerField(NDRIntField("lpResumeIndex", 0)),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszGroupName", "")),
    ]


class REnumServicesStatusExW_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpBuffer", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbBytesNeeded", 0),
        NDRIntField("lpServicesReturned", 0),
        NDRFullPointerField(NDRIntField("lpResumeIndex", 0)),
        NDRIntField("status", 0),
    ]


class RCreateServiceWOW64A_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullField("lpServiceName", ""),
        NDRFullPointerField(NDRConfVarStrNullField("lpDisplayName", "")),
        NDRIntField("dwDesiredAccess", 0),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwStartType", 0),
        NDRIntField("dwErrorControl", 0),
        NDRConfVarStrNullField("lpBinaryPathName", ""),
        NDRFullPointerField(NDRConfVarStrNullField("lpLoadOrderGroup", "")),
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRFullPointerField(
            NDRConfStrLenField(
                "lpDependencies", "", size_is=lambda pkt: pkt.dwDependSize
            )
        ),
        NDRIntField("dwDependSize", None, size_of="lpDependencies"),
        NDRFullPointerField(NDRConfVarStrNullField("lpServiceStartName", "")),
        NDRFullPointerField(
            NDRConfStrLenField("lpPassword", "", size_is=lambda pkt: pkt.dwPwSize)
        ),
        NDRIntField("dwPwSize", None, size_of="lpPassword"),
    ]


class RCreateServiceWOW64A_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRPacketField("lpServiceHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class RCreateServiceWOW64W_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullFieldUtf16("lpServiceName", ""),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpDisplayName", "")),
        NDRIntField("dwDesiredAccess", 0),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwStartType", 0),
        NDRIntField("dwErrorControl", 0),
        NDRConfVarStrNullFieldUtf16("lpBinaryPathName", ""),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpLoadOrderGroup", "")),
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRFullPointerField(
            NDRConfStrLenField(
                "lpDependencies", "", size_is=lambda pkt: pkt.dwDependSize
            )
        ),
        NDRIntField("dwDependSize", None, size_of="lpDependencies"),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpServiceStartName", "")),
        NDRFullPointerField(
            NDRConfStrLenField("lpPassword", "", size_is=lambda pkt: pkt.dwPwSize)
        ),
        NDRIntField("dwPwSize", None, size_of="lpPassword"),
    ]


class RCreateServiceWOW64W_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRPacketField("lpServiceHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class SERVICE_STATUS_PROCESS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwCurrentState", 0),
        NDRIntField("dwControlsAccepted", 0),
        NDRIntField("dwWin32ExitCode", 0),
        NDRIntField("dwServiceSpecificExitCode", 0),
        NDRIntField("dwCheckPoint", 0),
        NDRIntField("dwWaitHint", 0),
        NDRIntField("dwProcessId", 0),
        NDRIntField("dwServiceFlags", 0),
    ]


class PSERVICE_NOTIFY_STATUS_CHANGE_PARAMS_1(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRLongField("ullThreadId", 0),
        NDRIntField("dwNotifyMask", 0),
        StrFixedLenField("CallbackAddressArray", "", length=16),
        StrFixedLenField("CallbackParamAddressArray", "", length=16),
        NDRPacketField(
            "ServiceStatus", SERVICE_STATUS_PROCESS(), SERVICE_STATUS_PROCESS
        ),
        NDRIntField("dwNotificationStatus", 0),
        NDRIntField("dwSequence", 0),
    ]


class PSERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRLongField("ullThreadId", 0),
        NDRIntField("dwNotifyMask", 0),
        StrFixedLenField("CallbackAddressArray", "", length=16),
        StrFixedLenField("CallbackParamAddressArray", "", length=16),
        NDRPacketField(
            "ServiceStatus", SERVICE_STATUS_PROCESS(), SERVICE_STATUS_PROCESS
        ),
        NDRIntField("dwNotificationStatus", 0),
        NDRIntField("dwSequence", 0),
        NDRIntField("dwNotificationTriggered", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszServiceNames", ""), deferred=True
        ),
    ]


class SC_RPC_NOTIFY_PARAMS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwInfoLevel", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            PSERVICE_NOTIFY_STATUS_CHANGE_PARAMS_1(),
                            PSERVICE_NOTIFY_STATUS_CHANGE_PARAMS_1,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "value",
                            PSERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2(),
                            PSERVICE_NOTIFY_STATUS_CHANGE_PARAMS_2,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class RNotifyServiceStatusChange_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRPacketField("NotifyParams", SC_RPC_NOTIFY_PARAMS(), SC_RPC_NOTIFY_PARAMS),
        NDRPacketField("pClientProcessGuid", GUID(), GUID),
    ]


class RNotifyServiceStatusChange_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pSCMProcessGuid", GUID(), GUID),
        NDRSignedIntField("pfCreateRemoteQueue", 0),
        NDRPacketField("phNotify", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class PSC_RPC_NOTIFY_PARAMS_LIST(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["NotifyParamsArray"]
    fields_desc = [
        NDRIntField("cElements", None, size_of="NotifyParamsArray"),
        NDRConfPacketListField(
            "NotifyParamsArray",
            [],
            SC_RPC_NOTIFY_PARAMS,
            size_is=lambda pkt: pkt.cElements,
            conformant_in_struct=True,
        ),
    ]


class RGetNotifyResults_Request(NDRPacket):
    fields_desc = [NDRPacketField("hNotify", NDRContextHandle(), NDRContextHandle)]


class RGetNotifyResults_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ppNotifyParams",
                PSC_RPC_NOTIFY_PARAMS_LIST(),
                PSC_RPC_NOTIFY_PARAMS_LIST,
            )
        ),
        NDRIntField("status", 0),
    ]


class RCloseNotifyHandle_Request(NDRPacket):
    fields_desc = [NDRPacketField("phNotify", NDRContextHandle(), NDRContextHandle)]


class RCloseNotifyHandle_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("phNotify", NDRContextHandle(), NDRContextHandle),
        NDRSignedIntField("pfApcFired", 0),
        NDRIntField("status", 0),
    ]


class PSERVICE_CONTROL_STATUS_REASON_IN_PARAMSA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwReason", 0),
        NDRFullPointerField(NDRConfVarStrNullField("pszComment", ""), deferred=True),
    ]


class PSERVICE_CONTROL_STATUS_REASON_OUT_PARAMS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField(
            "ServiceStatus", SERVICE_STATUS_PROCESS(), SERVICE_STATUS_PROCESS
        )
    ]


class RControlServiceExA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwControl", 0),
        NDRIntField("dwInfoLevel", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pControlInParams",
                            PSERVICE_CONTROL_STATUS_REASON_IN_PARAMSA(),
                            PSERVICE_CONTROL_STATUS_REASON_IN_PARAMSA,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pControlInParams", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class RControlServiceExA_Response(NDRPacket):
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pControlOutParams",
                            PSERVICE_CONTROL_STATUS_REASON_OUT_PARAMS(),
                            PSERVICE_CONTROL_STATUS_REASON_OUT_PARAMS,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pControlOutParams", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class PSERVICE_CONTROL_STATUS_REASON_IN_PARAMSW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwReason", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszComment", ""), deferred=True
        ),
    ]


class RControlServiceExW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwControl", 0),
        NDRIntField("dwInfoLevel", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pControlInParams",
                            PSERVICE_CONTROL_STATUS_REASON_IN_PARAMSW(),
                            PSERVICE_CONTROL_STATUS_REASON_IN_PARAMSW,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pControlInParams", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class RControlServiceExW_Response(NDRPacket):
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pControlOutParams",
                            PSERVICE_CONTROL_STATUS_REASON_OUT_PARAMS(),
                            PSERVICE_CONTROL_STATUS_REASON_OUT_PARAMS,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInfoLevel", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pControlOutParams", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class RQueryServiceConfigEx_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hService", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInfoLevel", 0),
    ]


class RQueryServiceConfigEx_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pInfo", SC_RPC_CONFIG_INFOW(), SC_RPC_CONFIG_INFOW),
        NDRIntField("status", 0),
    ]


class RCreateWowService_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hSCManager", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrNullFieldUtf16("lpServiceName", ""),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpDisplayName", "")),
        NDRIntField("dwDesiredAccess", 0),
        NDRIntField("dwServiceType", 0),
        NDRIntField("dwStartType", 0),
        NDRIntField("dwErrorControl", 0),
        NDRConfVarStrNullFieldUtf16("lpBinaryPathName", ""),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpLoadOrderGroup", "")),
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRFullPointerField(
            NDRConfStrLenField(
                "lpDependencies", "", size_is=lambda pkt: pkt.dwDependSize
            )
        ),
        NDRIntField("dwDependSize", None, size_of="lpDependencies"),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpServiceStartName", "")),
        NDRFullPointerField(
            NDRConfStrLenField("lpPassword", "", size_is=lambda pkt: pkt.dwPwSize)
        ),
        NDRIntField("dwPwSize", None, size_of="lpPassword"),
        NDRShortField("dwServiceWowType", 0),
    ]


class RCreateWowService_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRIntField("lpdwTagId", 0)),
        NDRPacketField("lpServiceHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class ROpenSCManager2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DatabaseName", "")),
        NDRIntField("DesiredAccess", 0),
    ]


class ROpenSCManager2_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("ScmHandle", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


SVCCTL_OPNUMS = {
    0: DceRpcOp(RCloseServiceHandle_Request, RCloseServiceHandle_Response),
    1: DceRpcOp(RControlService_Request, RControlService_Response),
    2: DceRpcOp(RDeleteService_Request, RDeleteService_Response),
    3: DceRpcOp(RLockServiceDatabase_Request, RLockServiceDatabase_Response),
    4: DceRpcOp(
        RQueryServiceObjectSecurity_Request, RQueryServiceObjectSecurity_Response
    ),
    5: DceRpcOp(RSetServiceObjectSecurity_Request, RSetServiceObjectSecurity_Response),
    6: DceRpcOp(RQueryServiceStatus_Request, RQueryServiceStatus_Response),
    7: DceRpcOp(RSetServiceStatus_Request, RSetServiceStatus_Response),
    8: DceRpcOp(RUnlockServiceDatabase_Request, RUnlockServiceDatabase_Response),
    9: DceRpcOp(RNotifyBootConfigStatus_Request, RNotifyBootConfigStatus_Response),
    # 10: Opnum10NotUsedOnWire,
    11: DceRpcOp(RChangeServiceConfigW_Request, RChangeServiceConfigW_Response),
    12: DceRpcOp(RCreateServiceW_Request, RCreateServiceW_Response),
    13: DceRpcOp(REnumDependentServicesW_Request, REnumDependentServicesW_Response),
    14: DceRpcOp(REnumServicesStatusW_Request, REnumServicesStatusW_Response),
    15: DceRpcOp(ROpenSCManagerW_Request, ROpenSCManagerW_Response),
    16: DceRpcOp(ROpenServiceW_Request, ROpenServiceW_Response),
    17: DceRpcOp(RQueryServiceConfigW_Request, RQueryServiceConfigW_Response),
    18: DceRpcOp(RQueryServiceLockStatusW_Request, RQueryServiceLockStatusW_Response),
    19: DceRpcOp(RStartServiceW_Request, RStartServiceW_Response),
    20: DceRpcOp(RGetServiceDisplayNameW_Request, RGetServiceDisplayNameW_Response),
    21: DceRpcOp(RGetServiceKeyNameW_Request, RGetServiceKeyNameW_Response),
    # 22: Opnum22NotUsedOnWire,
    23: DceRpcOp(RChangeServiceConfigA_Request, RChangeServiceConfigA_Response),
    24: DceRpcOp(RCreateServiceA_Request, RCreateServiceA_Response),
    25: DceRpcOp(REnumDependentServicesA_Request, REnumDependentServicesA_Response),
    26: DceRpcOp(REnumServicesStatusA_Request, REnumServicesStatusA_Response),
    27: DceRpcOp(ROpenSCManagerA_Request, ROpenSCManagerA_Response),
    28: DceRpcOp(ROpenServiceA_Request, ROpenServiceA_Response),
    29: DceRpcOp(RQueryServiceConfigA_Request, RQueryServiceConfigA_Response),
    30: DceRpcOp(RQueryServiceLockStatusA_Request, RQueryServiceLockStatusA_Response),
    31: DceRpcOp(RStartServiceA_Request, RStartServiceA_Response),
    32: DceRpcOp(RGetServiceDisplayNameA_Request, RGetServiceDisplayNameA_Response),
    33: DceRpcOp(RGetServiceKeyNameA_Request, RGetServiceKeyNameA_Response),
    # 34: Opnum34NotUsedOnWire,
    35: DceRpcOp(REnumServiceGroupW_Request, REnumServiceGroupW_Response),
    36: DceRpcOp(RChangeServiceConfig2A_Request, RChangeServiceConfig2A_Response),
    37: DceRpcOp(RChangeServiceConfig2W_Request, RChangeServiceConfig2W_Response),
    38: DceRpcOp(RQueryServiceConfig2A_Request, RQueryServiceConfig2A_Response),
    39: DceRpcOp(RQueryServiceConfig2W_Request, RQueryServiceConfig2W_Response),
    40: DceRpcOp(RQueryServiceStatusEx_Request, RQueryServiceStatusEx_Response),
    41: DceRpcOp(REnumServicesStatusExA_Request, REnumServicesStatusExA_Response),
    42: DceRpcOp(REnumServicesStatusExW_Request, REnumServicesStatusExW_Response),
    # 43: Opnum43NotUsedOnWire,
    44: DceRpcOp(RCreateServiceWOW64A_Request, RCreateServiceWOW64A_Response),
    45: DceRpcOp(RCreateServiceWOW64W_Request, RCreateServiceWOW64W_Response),
    # 46: Opnum46NotUsedOnWire,
    47: DceRpcOp(
        RNotifyServiceStatusChange_Request, RNotifyServiceStatusChange_Response
    ),
    48: DceRpcOp(RGetNotifyResults_Request, RGetNotifyResults_Response),
    49: DceRpcOp(RCloseNotifyHandle_Request, RCloseNotifyHandle_Response),
    50: DceRpcOp(RControlServiceExA_Request, RControlServiceExA_Response),
    51: DceRpcOp(RControlServiceExW_Request, RControlServiceExW_Response),
    # 52: Opnum52NotUsedOnWire,
    # 53: Opnum53NotUsedOnWire,
    # 54: Opnum54NotUsedOnWire,
    # 55: Opnum55NotUsedOnWire,
    56: DceRpcOp(RQueryServiceConfigEx_Request, RQueryServiceConfigEx_Response),
    # 57: Opnum57NotUsedOnWire,
    # 58: Opnum58NotUsedOnWire,
    # 59: Opnum59NotUsedOnWire,
    60: DceRpcOp(RCreateWowService_Request, RCreateWowService_Response),
    # 61: Opnum61NotUsedOnWire,
    # 62: Opnum62NotUsedOnWire,
    # 63: Opnum63NotUsedOnWire,
    64: DceRpcOp(ROpenSCManager2_Request, ROpenSCManager2_Response),
}
register_dcerpc_interface(
    name="svcctl",
    uuid=uuid.UUID("367ABB81-9844-35F1-AD32-98F038001003"),
    version="2.0",
    opnums=SVCCTL_OPNUMS,
)
