### ms-tsgu.idl
"""
RPC definitions for the following interfaces:
- TsProxyRpcInterface (v1.3): 44e265dd-7daf-42cd-8560-3cdb6e7a2729
This file is auto-generated by midl-to-scapy, do not modify.
"""

import uuid

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


class PTSG_PACKET_HEADER(NDRPacket):
    ALIGNMENT = (2, 2)
    fields_desc = [NDRShortField("ComponentId", 0), NDRShortField("PacketId", 0)]


class TSG_PACKET_HEADER(NDRPacket):
    ALIGNMENT = (2, 2)
    fields_desc = [NDRShortField("ComponentId", 0), NDRShortField("PacketId", 0)]


class TSG_CAPABILITY_NAP(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("capabilities", 0)]


class PTSG_PACKET_CAPABILITIES(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("capabilityType", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "TSGPacket", TSG_CAPABILITY_NAP(), TSG_CAPABILITY_NAP
                    ),
                    (
                        (lambda pkt: getattr(pkt, "capabilityType", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("TSGPacket", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
    ]


class PTSG_PACKET_VERSIONCAPS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("tsgHeader", TSG_PACKET_HEADER(), TSG_PACKET_HEADER),
        NDRFullPointerField(
            NDRConfPacketListField(
                "TSGCaps",
                [PTSG_PACKET_CAPABILITIES()],
                PTSG_PACKET_CAPABILITIES,
                size_is=lambda pkt: pkt.numCapabilities,
            ),
            deferred=True,
        ),
        NDRIntField("numCapabilities", None, size_of="TSGCaps"),
        NDRShortField("majorVersion", 0),
        NDRShortField("minorVersion", 0),
        NDRShortField("quarantineCapabilities", 0),
    ]


class PTSG_PACKET_QUARCONFIGREQUEST(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("flags", 0)]


class PTSG_PACKET_QUARREQUEST(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("flags", 0),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16(
                "machineName", "", size_is=lambda pkt: pkt.nameLength
            ),
            deferred=True,
        ),
        NDRIntField("nameLength", None, size_of="machineName"),
        NDRFullPointerField(
            NDRConfStrLenField("data", "", size_is=lambda pkt: pkt.dataLen),
            deferred=True,
        ),
        NDRIntField("dataLen", None, size_of="data"),
    ]


class TSG_REDIRECTION_FLAGS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRSignedIntField("enableAllRedirections", 0),
        NDRSignedIntField("disableAllRedirections", 0),
        NDRSignedIntField("driveRedirectionDisabled", 0),
        NDRSignedIntField("printerRedirectionDisabled", 0),
        NDRSignedIntField("portRedirectionDisabled", 0),
        NDRSignedIntField("reserved", 0),
        NDRSignedIntField("clipboardRedirectionDisabled", 0),
        NDRSignedIntField("pnpRedirectionDisabled", 0),
    ]


class PTSG_PACKET_RESPONSE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("flags", 0),
        NDRIntField("reserved", 0),
        NDRFullPointerField(
            NDRConfStrLenField(
                "responseData", "", size_is=lambda pkt: pkt.responseDataLen
            ),
            deferred=True,
        ),
        NDRIntField("responseDataLen", None, size_of="responseData"),
        NDRPacketField(
            "redirectionFlags", TSG_REDIRECTION_FLAGS(), TSG_REDIRECTION_FLAGS
        ),
    ]


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


class PTSG_PACKET_QUARENC_RESPONSE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("flags", 0),
        NDRIntField("certChainLen", None, size_of="certChainData"),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16(
                "certChainData", "", size_is=lambda pkt: pkt.certChainLen
            ),
            deferred=True,
        ),
        NDRPacketField("nonce", GUID(), GUID),
        NDRFullPointerField(
            NDRPacketField(
                "versionCaps", PTSG_PACKET_VERSIONCAPS(), PTSG_PACKET_VERSIONCAPS
            ),
            deferred=True,
        ),
    ]


class TSG_PACKET_QUARENC_RESPONSE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("flags", 0),
        NDRIntField("certChainLen", None, size_of="certChainData"),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16(
                "certChainData", "", size_is=lambda pkt: pkt.certChainLen
            ),
            deferred=True,
        ),
        NDRPacketField("nonce", GUID(), GUID),
        NDRFullPointerField(
            NDRPacketField(
                "versionCaps", PTSG_PACKET_VERSIONCAPS(), PTSG_PACKET_VERSIONCAPS
            ),
            deferred=True,
        ),
    ]


class PTSG_PACKET_STRING_MESSAGE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRSignedIntField("isDisplayMandatory", 0),
        NDRSignedIntField("isConsentMandatory", 0),
        NDRIntField("msgBytes", None, size_of="msgBuffer"),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16("msgBuffer", "", size_is=lambda pkt: pkt.msgBytes),
            deferred=True,
        ),
    ]


class PTSG_PACKET_REAUTH_MESSAGE(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRLongField("tunnelContext", 0)]


class TSG_PACKET_MSG_RESPONSE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("msgID", 0),
        NDRIntField("msgType", 0),
        NDRSignedIntField("isMsgPresent", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "messagePacket",
                            PTSG_PACKET_STRING_MESSAGE(),
                            PTSG_PACKET_STRING_MESSAGE,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "msgType", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "messagePacket",
                            PTSG_PACKET_STRING_MESSAGE(),
                            PTSG_PACKET_STRING_MESSAGE,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "msgType", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "messagePacket",
                            PTSG_PACKET_REAUTH_MESSAGE(),
                            PTSG_PACKET_REAUTH_MESSAGE,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "msgType", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
            ],
            StrFixedLenField("messagePacket", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class PTSG_PACKET_CAPS_RESPONSE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField(
            "pktQuarEncResponse",
            TSG_PACKET_QUARENC_RESPONSE(),
            TSG_PACKET_QUARENC_RESPONSE,
        ),
        NDRPacketField(
            "pktConsentMessage", TSG_PACKET_MSG_RESPONSE(), TSG_PACKET_MSG_RESPONSE
        ),
    ]


class PTSG_PACKET_MSG_REQUEST(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("maxMessagesPerBatch", 0)]


class PTSG_PACKET_MSG_RESPONSE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("msgID", 0),
        NDRIntField("msgType", 0),
        NDRSignedIntField("isMsgPresent", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "messagePacket",
                            PTSG_PACKET_STRING_MESSAGE(),
                            PTSG_PACKET_STRING_MESSAGE,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "msgType", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "messagePacket",
                            PTSG_PACKET_STRING_MESSAGE(),
                            PTSG_PACKET_STRING_MESSAGE,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "msgType", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "messagePacket",
                            PTSG_PACKET_REAUTH_MESSAGE(),
                            PTSG_PACKET_REAUTH_MESSAGE,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "msgType", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
            ],
            StrFixedLenField("messagePacket", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class TSG_PACKET_VERSIONCAPS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("tsgHeader", TSG_PACKET_HEADER(), TSG_PACKET_HEADER),
        NDRFullPointerField(
            NDRConfPacketListField(
                "TSGCaps",
                [PTSG_PACKET_CAPABILITIES()],
                PTSG_PACKET_CAPABILITIES,
                size_is=lambda pkt: pkt.numCapabilities,
            ),
            deferred=True,
        ),
        NDRIntField("numCapabilities", None, size_of="TSGCaps"),
        NDRShortField("majorVersion", 0),
        NDRShortField("minorVersion", 0),
        NDRShortField("quarantineCapabilities", 0),
    ]


class PTSG_PACKET_AUTH(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField(
            "TSGVersionCaps", TSG_PACKET_VERSIONCAPS(), TSG_PACKET_VERSIONCAPS
        ),
        NDRIntField("cookieLen", None, size_of="cookie"),
        NDRFullPointerField(
            NDRConfStrLenField("cookie", "", size_is=lambda pkt: pkt.cookieLen),
            deferred=True,
        ),
    ]


class PTSG_PACKET_REAUTH(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRLongField("tunnelContext", 0),
        NDRIntField("packetId", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGInitialPacket",
                            PTSG_PACKET_VERSIONCAPS(),
                            PTSG_PACKET_VERSIONCAPS,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 22083),
                        (lambda _, val: val.tag == 22083),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGInitialPacket", PTSG_PACKET_AUTH(), PTSG_PACKET_AUTH
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 16468),
                        (lambda _, val: val.tag == 16468),
                    ),
                ),
            ],
            StrFixedLenField("TSGInitialPacket", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class PTSG_PACKET(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("packetId", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket", PTSG_PACKET_HEADER(), PTSG_PACKET_HEADER
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 18500),
                        (lambda _, val: val.tag == 18500),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket",
                            PTSG_PACKET_VERSIONCAPS(),
                            PTSG_PACKET_VERSIONCAPS,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 22083),
                        (lambda _, val: val.tag == 22083),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket",
                            PTSG_PACKET_QUARCONFIGREQUEST(),
                            PTSG_PACKET_QUARCONFIGREQUEST,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 20803),
                        (lambda _, val: val.tag == 20803),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket",
                            PTSG_PACKET_QUARREQUEST(),
                            PTSG_PACKET_QUARREQUEST,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 20818),
                        (lambda _, val: val.tag == 20818),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket", PTSG_PACKET_RESPONSE(), PTSG_PACKET_RESPONSE
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 20562),
                        (lambda _, val: val.tag == 20562),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket",
                            PTSG_PACKET_QUARENC_RESPONSE(),
                            PTSG_PACKET_QUARENC_RESPONSE,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 17746),
                        (lambda _, val: val.tag == 17746),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket",
                            PTSG_PACKET_CAPS_RESPONSE(),
                            PTSG_PACKET_CAPS_RESPONSE,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 17232),
                        (lambda _, val: val.tag == 17232),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket",
                            PTSG_PACKET_MSG_REQUEST(),
                            PTSG_PACKET_MSG_REQUEST,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 18258),
                        (lambda _, val: val.tag == 18258),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket",
                            PTSG_PACKET_MSG_RESPONSE(),
                            PTSG_PACKET_MSG_RESPONSE,
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 18256),
                        (lambda _, val: val.tag == 18256),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket", PTSG_PACKET_AUTH(), PTSG_PACKET_AUTH
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 16468),
                        (lambda _, val: val.tag == 16468),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "TSGPacket", PTSG_PACKET_REAUTH(), PTSG_PACKET_REAUTH
                        ),
                        deferred=True,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "packetId", None) == 21072),
                        (lambda _, val: val.tag == 21072),
                    ),
                ),
            ],
            StrFixedLenField("TSGPacket", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class TsProxyCreateTunnel_Request(NDRPacket):
    fields_desc = [NDRPacketField("TSGPacket", PTSG_PACKET(), PTSG_PACKET)]


class TsProxyCreateTunnel_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("TSGPacketResponse", PTSG_PACKET(), PTSG_PACKET)
        ),
        NDRPacketField("tunnelContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("tunnelId", 0),
        NDRIntField("status", 0),
    ]


class TsProxyAuthorizeTunnel_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("tunnelContext", NDRContextHandle(), NDRContextHandle),
        NDRPacketField("TSGPacket", PTSG_PACKET(), PTSG_PACKET),
    ]


class TsProxyAuthorizeTunnel_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("TSGPacketResponse", PTSG_PACKET(), PTSG_PACKET)
        ),
        NDRIntField("status", 0),
    ]


class TsProxyMakeTunnelCall_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("tunnelContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("procId", 0),
        NDRPacketField("TSGPacket", PTSG_PACKET(), PTSG_PACKET),
    ]


class TsProxyMakeTunnelCall_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("TSGPacketResponse", PTSG_PACKET(), PTSG_PACKET)
        ),
        NDRIntField("status", 0),
    ]


class PTSENDPOINTINFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfFieldListField(
                "resourceName",
                [],
                NDRFullPointerField(
                    NDRConfVarStrNullFieldUtf16("resourceName", ""), deferred=True
                ),
                size_is=lambda pkt: pkt.numResourceNames,
            ),
            deferred=True,
        ),
        NDRIntField("numResourceNames", None, size_of="resourceName"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "alternateResourceNames",
                [],
                NDRFullPointerField(
                    NDRConfVarStrNullFieldUtf16("alternateResourceNames", ""),
                    deferred=True,
                ),
                size_is=lambda pkt: pkt.numAlternateResourceNames,
            ),
            deferred=True,
        ),
        NDRShortField(
            "numAlternateResourceNames", None, size_of="alternateResourceNames"
        ),
        NDRIntField("Port", 0),
    ]


class TsProxyCreateChannel_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("tunnelContext", NDRContextHandle(), NDRContextHandle),
        NDRPacketField("tsEndPointInfo", PTSENDPOINTINFO(), PTSENDPOINTINFO),
    ]


class TsProxyCreateChannel_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("channelContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("channelId", 0),
        NDRIntField("status", 0),
    ]


class TsProxyCloseChannel_Request(NDRPacket):
    fields_desc = [NDRPacketField("context", NDRContextHandle(), NDRContextHandle)]


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


class TsProxyCloseTunnel_Request(NDRPacket):
    fields_desc = [NDRPacketField("context", NDRContextHandle(), NDRContextHandle)]


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


class TsProxySetupReceivePipe_Request(NDRPacket):
    fields_desc = [NDRConfStrLenField("pRpcMessage", "", size_is=lambda pkt: 32767)]


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


class TsProxySendToServer_Request(NDRPacket):
    fields_desc = [NDRConfStrLenField("pRpcMessage", "", size_is=lambda pkt: 32767)]


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


TSPROXYRPCINTERFACE_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    1: DceRpcOp(TsProxyCreateTunnel_Request, TsProxyCreateTunnel_Response),
    2: DceRpcOp(TsProxyAuthorizeTunnel_Request, TsProxyAuthorizeTunnel_Response),
    3: DceRpcOp(TsProxyMakeTunnelCall_Request, TsProxyMakeTunnelCall_Response),
    4: DceRpcOp(TsProxyCreateChannel_Request, TsProxyCreateChannel_Response),
    # 5: Opnum5NotUsedOnWire,
    6: DceRpcOp(TsProxyCloseChannel_Request, TsProxyCloseChannel_Response),
    7: DceRpcOp(TsProxyCloseTunnel_Request, TsProxyCloseTunnel_Response),
    8: DceRpcOp(TsProxySetupReceivePipe_Request, TsProxySetupReceivePipe_Response),
    9: DceRpcOp(TsProxySendToServer_Request, TsProxySendToServer_Response),
}
register_dcerpc_interface(
    name="TsProxyRpcInterface",
    uuid=uuid.UUID("44e265dd-7daf-42cd-8560-3cdb6e7a2729"),
    version="1.3",
    opnums=TSPROXYRPCINTERFACE_OPNUMS,
)
