### ms-mqrr.idl
"""
RPC definitions for the following interfaces:
- RemoteRead (v1.0): 1a9134dd-7b39-45ba-ad88-44d01ca47f28
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,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRContextHandle,
    NDRFullPointerField,
    NDRInt3264EnumField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRShortField,
    NDRSignedIntField,
    NDRUnionField,
    register_dcerpc_interface,
)


class R_GetServerPort_Request(NDRPacket):
    fields_desc = []


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


class QUEUE_FORMAT_TYPE(IntEnum):
    QUEUE_FORMAT_TYPE_UNKNOWN = 0
    QUEUE_FORMAT_TYPE_PUBLIC = 1
    QUEUE_FORMAT_TYPE_PRIVATE = 2
    QUEUE_FORMAT_TYPE_DIRECT = 3
    QUEUE_FORMAT_TYPE_MACHINE = 4
    QUEUE_FORMAT_TYPE_CONNECTOR = 5
    QUEUE_FORMAT_TYPE_DL = 6
    QUEUE_FORMAT_TYPE_MULTICAST = 7
    QUEUE_FORMAT_TYPE_SUBQUEUE = 8


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


class OBJECTID(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("Lineage", GUID(), GUID),
        NDRIntField("Uniquifier", 0),
    ]


class DL_ID(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("m_DlGuid", GUID(), GUID),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("m_pwzDomain", ""), deferred=True
        ),
    ]


class MULTICAST_ID(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("m_address", 0), NDRIntField("m_port", 0)]


class QUEUE_FORMAT(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRByteField("m_qft", 0),
        NDRByteField("m_SuffixAndFlags", 0),
        NDRShortField("m_reserved", 0),
        NDRUnionField(
            [
                (
                    StrFixedLenField("value", "", length=0),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_UNKNOWN
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_UNKNOWN
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", GUID(), GUID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_PUBLIC
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_PUBLIC
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", OBJECTID(), OBJECTID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_PRIVATE
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_PRIVATE
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRConfVarStrNullFieldUtf16("value", ""), deferred=True
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_DIRECT
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_DIRECT
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", GUID(), GUID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_MACHINE
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_MACHINE
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", GUID(), GUID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_CONNECTOR
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_CONNECTOR
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", DL_ID(), DL_ID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_DL
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_DL
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", MULTICAST_ID(), MULTICAST_ID),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_MULTICAST
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_MULTICAST
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRConfVarStrNullFieldUtf16("value", ""), deferred=True
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_qft", None)
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_SUBQUEUE
                        ),
                        (
                            lambda _, val: val.tag
                            == QUEUE_FORMAT_TYPE.QUEUE_FORMAT_TYPE_SUBQUEUE
                        ),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(1, 8),
            switch_fmt=("B", "B"),
        ),
    ]


class R_OpenQueue_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pQueueFormat", QUEUE_FORMAT(), QUEUE_FORMAT),
        NDRIntField("dwAccess", 0),
        NDRIntField("dwShareMode", 0),
        NDRPacketField("pClientId", GUID(), GUID),
        NDRSignedIntField("fNonRoutingServer", 0),
        NDRByteField("Major", 0),
        NDRByteField("Minor", 0),
        NDRShortField("BuildNumber", 0),
        NDRSignedIntField("fWorkgroup", 0),
    ]


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


class R_CloseQueue_Request(NDRPacket):
    fields_desc = [NDRPacketField("pphContext", NDRContextHandle(), NDRContextHandle)]


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


class R_CreateCursor_Request(NDRPacket):
    fields_desc = [NDRPacketField("phContext", NDRContextHandle(), NDRContextHandle)]


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


class R_CloseCursor_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("phContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("hCursor", 0),
    ]


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


class R_PurgeQueue_Request(NDRPacket):
    fields_desc = [NDRPacketField("phContext", NDRContextHandle(), NDRContextHandle)]


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


class SectionType(IntEnum):
    stFullPacket = 0
    stBinaryFirstSection = 1
    stBinarySecondSection = 2
    stSrmpFirstSection = 3
    stSrmpSecondSection = 4


class SectionBuffer(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRInt3264EnumField("SectionBufferType", 0, SectionType),
        NDRIntField("SectionSizeAlloc", 0),
        NDRIntField("SectionSize", None, size_of="pSectionBuffer"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "pSectionBuffer", "", size_is=lambda pkt: pkt.SectionSize
            ),
            deferred=True,
        ),
    ]


class R_StartReceive_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("phContext", NDRContextHandle(), NDRContextHandle),
        NDRLongField("LookupId", 0),
        NDRIntField("hCursor", 0),
        NDRIntField("ulAction", 0),
        NDRIntField("ulTimeout", 0),
        NDRIntField("dwRequestId", 0),
        NDRIntField("dwMaxBodySize", 0),
        NDRIntField("dwMaxCompoundMessageSize", 0),
    ]


class R_StartReceive_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwArriveTime", 0),
        NDRLongField("pSequenceId", 0),
        NDRIntField("pdwNumberOfSections", None, size_of="ppPacketSections"),
        NDRConfPacketListField(
            "ppPacketSections",
            [],
            SectionBuffer,
            size_is=lambda pkt: pkt.pdwNumberOfSections,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


class R_CancelReceive_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("phContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwRequestId", 0),
    ]


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


class R_EndReceive_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("phContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwAck", 0),
        NDRIntField("dwRequestId", 0),
    ]


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


class XACTUOW(NDRPacket):
    fields_desc = [StrFixedLenField("rgb", "", length=16)]


class R_MoveMessage_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("phContextFrom", NDRContextHandle(), NDRContextHandle),
        NDRLongField("ullContextTo", 0),
        NDRLongField("LookupId", 0),
        NDRPacketField("pTransactionId", XACTUOW(), XACTUOW),
    ]


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


class R_OpenQueueForMove_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pQueueFormat", QUEUE_FORMAT(), QUEUE_FORMAT),
        NDRIntField("dwAccess", 0),
        NDRIntField("dwShareMode", 0),
        NDRPacketField("pClientId", GUID(), GUID),
        NDRSignedIntField("fNonRoutingServer", 0),
        NDRByteField("Major", 0),
        NDRByteField("Minor", 0),
        NDRShortField("BuildNumber", 0),
        NDRSignedIntField("fWorkgroup", 0),
    ]


class R_OpenQueueForMove_Response(NDRPacket):
    fields_desc = [
        NDRLongField("pMoveContext", 0),
        NDRPacketField("pphContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class R_QMEnlistRemoteTransaction_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pTransactionId", XACTUOW(), XACTUOW),
        NDRIntField("cbPropagationToken", None, size_of="pbPropagationToken"),
        NDRConfStrLenField(
            "pbPropagationToken", "", size_is=lambda pkt: pkt.cbPropagationToken
        ),
        NDRPacketField("pQueueFormat", QUEUE_FORMAT(), QUEUE_FORMAT),
    ]


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


class R_StartTransactionalReceive_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("phContext", NDRContextHandle(), NDRContextHandle),
        NDRLongField("LookupId", 0),
        NDRIntField("hCursor", 0),
        NDRIntField("ulAction", 0),
        NDRIntField("ulTimeout", 0),
        NDRIntField("dwRequestId", 0),
        NDRIntField("dwMaxBodySize", 0),
        NDRIntField("dwMaxCompoundMessageSize", 0),
        NDRPacketField("pTransactionId", XACTUOW(), XACTUOW),
    ]


class R_StartTransactionalReceive_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwArriveTime", 0),
        NDRLongField("pSequenceId", 0),
        NDRIntField("pdwNumberOfSections", None, size_of="ppPacketSections"),
        NDRConfPacketListField(
            "ppPacketSections",
            [],
            SectionBuffer,
            size_is=lambda pkt: pkt.pdwNumberOfSections,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


class R_SetUserAcknowledgementClass_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("phContext", NDRContextHandle(), NDRContextHandle),
        NDRLongField("LookupId", 0),
        NDRShortField("usClass", 0),
    ]


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


class R_EndTransactionalReceive_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("phContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwAck", 0),
        NDRIntField("dwRequestId", 0),
    ]


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


REMOTEREAD_OPNUMS = {
    0: DceRpcOp(R_GetServerPort_Request, R_GetServerPort_Response),
    # 1: Opnum1NotUsedOnWire,
    2: DceRpcOp(R_OpenQueue_Request, R_OpenQueue_Response),
    3: DceRpcOp(R_CloseQueue_Request, R_CloseQueue_Response),
    4: DceRpcOp(R_CreateCursor_Request, R_CreateCursor_Response),
    5: DceRpcOp(R_CloseCursor_Request, R_CloseCursor_Response),
    6: DceRpcOp(R_PurgeQueue_Request, R_PurgeQueue_Response),
    7: DceRpcOp(R_StartReceive_Request, R_StartReceive_Response),
    8: DceRpcOp(R_CancelReceive_Request, R_CancelReceive_Response),
    9: DceRpcOp(R_EndReceive_Request, R_EndReceive_Response),
    10: DceRpcOp(R_MoveMessage_Request, R_MoveMessage_Response),
    11: DceRpcOp(R_OpenQueueForMove_Request, R_OpenQueueForMove_Response),
    12: DceRpcOp(
        R_QMEnlistRemoteTransaction_Request, R_QMEnlistRemoteTransaction_Response
    ),
    13: DceRpcOp(
        R_StartTransactionalReceive_Request, R_StartTransactionalReceive_Response
    ),
    14: DceRpcOp(
        R_SetUserAcknowledgementClass_Request, R_SetUserAcknowledgementClass_Response
    ),
    15: DceRpcOp(R_EndTransactionalReceive_Request, R_EndTransactionalReceive_Response),
}
register_dcerpc_interface(
    name="RemoteRead",
    uuid=uuid.UUID("1a9134dd-7b39-45ba-ad88-44d01ca47f28"),
    version="1.0",
    opnums=REMOTEREAD_OPNUMS,
)
