### ms-tsts_rcmpublic.idl
"""
RPC definitions for the following interfaces:
- RCMPublic (v1.0): bde95fdf-eee0-45de-9e12-e5a61cd0d4fe
- RCMListener (v1.0): 497d95a6-2d27-4bf5-9bbd-a6046957133c
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import StrFixedLenField, StrFixedLenFieldUtf16
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfVarStrLenField,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRContextHandle,
    NDRInt3264EnumField,
    NDRIntField,
    NDRPacketField,
    NDRShortField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRUnionField,
    register_dcerpc_interface,
)


class RpcGetClientData_Request(NDRPacket):
    fields_desc = [NDRIntField("SessionId", 0)]


class RpcGetClientData_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("ppBuff", "", size_is=lambda pkt: pkt.pOutBuffByteLen),
        NDRIntField("pOutBuffByteLen", None, size_of="ppBuff"),
        NDRIntField("status", 0),
    ]


class RpcGetConfigData_Request(NDRPacket):
    fields_desc = [NDRIntField("SessionId", 0)]


class RpcGetConfigData_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("ppBuff", "", size_is=lambda pkt: pkt.pOutBuffByteLen),
        NDRIntField("pOutBuffByteLen", None, size_of="ppBuff"),
        NDRIntField("status", 0),
    ]


class PROTOCOLSTATUS_INFO_TYPE(IntEnum):
    PROTOCOLSTATUS_INFO_BASIC = 0
    PROTOCOLSTATUS_INFO_EXTENDED = 1


class RpcGetProtocolStatus_Request(NDRPacket):
    fields_desc = [
        NDRIntField("SessionId", 0),
        NDRInt3264EnumField("InfoType", 0, PROTOCOLSTATUS_INFO_TYPE),
    ]


class RpcGetProtocolStatus_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("ppProtoStatus", "", size_is=lambda pkt: pkt.pcbProtoStatus),
        NDRIntField("pcbProtoStatus", None, size_of="ppProtoStatus"),
        NDRIntField("status", 0),
    ]


class RpcGetLastInputTime_Request(NDRPacket):
    fields_desc = [NDRIntField("SessionId", 0)]


class RpcGetLastInputTime_Response(NDRPacket):
    fields_desc = [NDRSignedLongField("pLastInputTime", 0), NDRIntField("status", 0)]


class ipv4_sub0(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRShortField("sin_port", 0),
        NDRIntField("in_addr", 0),
        StrFixedLenField("sin_zero", "", length=8),
    ]


class ipv6_sub1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRShortField("sin6_port", 0),
        NDRIntField("sin6_flowinfo", 0),
        StrFixedLenFieldUtf16("sin6_addr", "", length=8 * 2),
        NDRIntField("sin6_scope_id", 0),
    ]


class PRCM_REMOTEADDRESS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRShortField("sin_family", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField("u", ipv4_sub0(), ipv4_sub0),
                    ((lambda pkt: None == 2), (lambda _, val: val.tag == 2)),
                ),
                (
                    NDRPacketField("u", ipv6_sub1(), ipv6_sub1),
                    ((lambda pkt: None == 23), (lambda _, val: val.tag == 23)),
                ),
            ],
            StrFixedLenField("u", "", length=0),
            align=(4, 4),
            switch_fmt=("I", "I"),
        ),
    ]


class RpcGetRemoteAddress_Request(NDRPacket):
    fields_desc = [NDRIntField("SessionId", 0)]


class RpcGetRemoteAddress_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pRemoteAddress", PRCM_REMOTEADDRESS(), PRCM_REMOTEADDRESS),
        NDRIntField("status", 0),
    ]


class LISTENERENUM_LEVEL1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRSignedIntField("Id", 0),
        NDRSignedIntField("bListening", 0),
        StrFixedLenFieldUtf16("Name", "", length=33 * 2),
    ]


class PLISTENERENUM(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Level", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField("Data", LISTENERENUM_LEVEL1(), LISTENERENUM_LEVEL1),
                    (
                        (lambda pkt: getattr(pkt, "Level", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("Data", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
    ]


class RpcGetAllListeners_Request(NDRPacket):
    fields_desc = [NDRIntField("Level", 0)]


class RpcGetAllListeners_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "ppListeners",
            [],
            PLISTENERENUM,
            size_is=lambda pkt: pkt.pNumListeners,
            ptr_pack=True,
        ),
        NDRIntField("pNumListeners", None, size_of="ppListeners"),
        NDRIntField("status", 0),
    ]


class RpcGetSessionProtocolLastInputTime_Request(NDRPacket):
    fields_desc = [
        NDRIntField("SessionId", 0),
        NDRInt3264EnumField("InfoType", 0, PROTOCOLSTATUS_INFO_TYPE),
    ]


class RpcGetSessionProtocolLastInputTime_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("ppProtoStatus", "", size_is=lambda pkt: pkt.pcbProtoStatus),
        NDRIntField("pcbProtoStatus", None, size_of="ppProtoStatus"),
        NDRSignedLongField("pLastInputTime", 0),
        NDRIntField("status", 0),
    ]


class RpcGetUserCertificates_Request(NDRPacket):
    fields_desc = [NDRIntField("SessionId", 0)]


class RpcGetUserCertificates_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcCerts", 0),
        NDRConfStrLenField("ppbCerts", "", size_is=lambda pkt: pkt.pcbCerts),
        NDRIntField("pcbCerts", None, size_of="ppbCerts"),
        NDRIntField("status", 0),
    ]


class QUERY_SESSION_DATA_TYPE(IntEnum):
    QUERY_SESSION_DATA_MODULE = 0
    QUERY_SESSION_DATA_WDCONFIG = 1
    QUERY_SESSION_DATA_VIRTUALDATA = 2
    QUERY_SESSION_DATA_LICENSE = 3
    QUERY_SESSION_DATA_DEVICEID = 4
    QUERY_SESSION_DATA_LICENSE_VALIDATION = 5


class RpcQuerySessionData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("SessionId", 0),
        NDRInt3264EnumField("type", 0, QUERY_SESSION_DATA_TYPE),
        NDRConfStrLenField("pbInputData", "", size_is=lambda pkt: pkt.cbInputData),
        NDRIntField("cbInputData", None, size_of="pbInputData"),
        NDRIntField("cbSessionData", 0),
    ]


class RpcQuerySessionData_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "pbSessionData",
            "",
            size_is=lambda pkt: pkt.cbSessionData,
            length_is=lambda pkt: pkt.pcbReturnLength,
        ),
        NDRIntField("pcbReturnLength", None, size_of="pbSessionData"),
        NDRIntField("pcbRequireBufferSize", 0),
        NDRIntField("status", 0),
    ]


RCMPUBLIC_OPNUMS = {
    0: DceRpcOp(RpcGetClientData_Request, RpcGetClientData_Response),
    1: DceRpcOp(RpcGetConfigData_Request, RpcGetConfigData_Response),
    2: DceRpcOp(RpcGetProtocolStatus_Request, RpcGetProtocolStatus_Response),
    3: DceRpcOp(RpcGetLastInputTime_Request, RpcGetLastInputTime_Response),
    4: DceRpcOp(RpcGetRemoteAddress_Request, RpcGetRemoteAddress_Response),
    # 5: Opnum5NotUsedOnWire,
    # 6: Opnum6NotUsedOnWire,
    # 7: Opnum7NotUsedOnWire,
    8: DceRpcOp(RpcGetAllListeners_Request, RpcGetAllListeners_Response),
    9: DceRpcOp(
        RpcGetSessionProtocolLastInputTime_Request,
        RpcGetSessionProtocolLastInputTime_Response,
    ),
    10: DceRpcOp(RpcGetUserCertificates_Request, RpcGetUserCertificates_Response),
    11: DceRpcOp(RpcQuerySessionData_Request, RpcQuerySessionData_Response),
}
register_dcerpc_interface(
    name="RCMPublic",
    uuid=uuid.UUID("bde95fdf-eee0-45de-9e12-e5a61cd0d4fe"),
    version="1.0",
    opnums=RCMPUBLIC_OPNUMS,
)


class RpcOpenListener_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("szListenerName", "")]


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


class RpcCloseListener_Request(NDRPacket):
    fields_desc = [NDRPacketField("phListener", NDRContextHandle(), NDRContextHandle)]


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


class RpcStopListener_Request(NDRPacket):
    fields_desc = [NDRPacketField("hListener", NDRContextHandle(), NDRContextHandle)]


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


class RpcStartListener_Request(NDRPacket):
    fields_desc = [NDRPacketField("hListener", NDRContextHandle(), NDRContextHandle)]


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


class RpcIsListening_Request(NDRPacket):
    fields_desc = [NDRPacketField("hListener", NDRContextHandle(), NDRContextHandle)]


class RpcIsListening_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pbIsListening", 0), NDRIntField("status", 0)]


RCMLISTENER_OPNUMS = {
    0: DceRpcOp(RpcOpenListener_Request, RpcOpenListener_Response),
    1: DceRpcOp(RpcCloseListener_Request, RpcCloseListener_Response),
    2: DceRpcOp(RpcStopListener_Request, RpcStopListener_Response),
    3: DceRpcOp(RpcStartListener_Request, RpcStartListener_Response),
    4: DceRpcOp(RpcIsListening_Request, RpcIsListening_Response),
}
register_dcerpc_interface(
    name="RCMListener",
    uuid=uuid.UUID("497d95a6-2d27-4bf5-9bbd-a6046957133c"),
    version="1.0",
    opnums=RCMLISTENER_OPNUMS,
)
