### ms-mqmp.idl
"""
RPC definitions for the following interfaces:
- qmcomm (v1.0): fdb3a030-065f-11d1-bb9b-00a024ea5525
- qmcomm2 (v1.0): 76d12b80-3467-11d3-91ff-0090272f9ea3
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,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRConfVarFieldListField,
    NDRConfVarStrLenField,
    NDRConfVarStrLenFieldUtf16,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRContextHandle,
    NDRFullPointerField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRRecursiveField,
    NDRShortField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRUnionField,
    NDRVarStrLenField,
    NDRVarStrLenFieldUtf16,
    register_dcerpc_interface,
)


class R_QMGetRemoteQueueName_Request(NDRPacket):
    fields_desc = [
        NDRIntField("pQueue", 0),
        NDRFullPointerField(
            NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lplpRemoteQueueName", ""))
        ),
    ]


class R_QMGetRemoteQueueName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lplpRemoteQueueName", ""))
        ),
        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_QMOpenRemoteQueue_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pQueueFormat", QUEUE_FORMAT(), QUEUE_FORMAT)
        ),
        NDRIntField("dwCallingProcessID", 0),
        NDRIntField("dwDesiredAccess", 0),
        NDRIntField("dwShareMode", 0),
        NDRPacketField("pLicGuid", GUID(), GUID),
        NDRIntField("dwMQS", 0),
    ]


class R_QMOpenRemoteQueue_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pphContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("pdwContext", 0),
        NDRIntField("dwpQueue", 0),
        NDRIntField("phQueue", 0),
        NDRIntField("status", 0),
    ]


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


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


class TRANSFER_TYPE(IntEnum):
    CACTB_SEND = 0
    CACTB_RECEIVE = 1
    CACTB_CREATECURSOR = 2


class Send_sub0(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pAdminQueueFormat", QUEUE_FORMAT(), QUEUE_FORMAT),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField("pResponseQueueFormat", QUEUE_FORMAT(), QUEUE_FORMAT),
            deferred=True,
        ),
    ]


class Receive_sub1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("RequestTimeout", 0),
        NDRIntField("Action", 0),
        NDRIntField("Asynchronous", 0),
        NDRIntField("Cursor", 0),
        NDRIntField("ulResponseFormatNameLen", None, size_of="ppResponseFormatName"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "ppResponseFormatName",
                [],
                NDRFullPointerField(
                    NDRShortField("ppResponseFormatName", 0), deferred=True
                ),
                size_is=lambda pkt: pkt.ulResponseFormatNameLen,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRIntField("pulResponseFormatNameLenProp", 0), deferred=True
        ),
        NDRIntField("ulAdminFormatNameLen", None, size_of="ppAdminFormatName"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "ppAdminFormatName",
                [],
                NDRFullPointerField(
                    NDRShortField("ppAdminFormatName", 0), deferred=True
                ),
                size_is=lambda pkt: pkt.ulAdminFormatNameLen,
            ),
            deferred=True,
        ),
        NDRFullPointerField(NDRIntField("pulAdminFormatNameLenProp", 0), deferred=True),
        NDRIntField("ulDestFormatNameLen", None, size_of="ppDestFormatName"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "ppDestFormatName",
                [],
                NDRFullPointerField(
                    NDRShortField("ppDestFormatName", 0), deferred=True
                ),
                size_is=lambda pkt: pkt.ulDestFormatNameLen,
            ),
            deferred=True,
        ),
        NDRFullPointerField(NDRIntField("pulDestFormatNameLenProp", 0), deferred=True),
        NDRIntField("ulOrderingFormatNameLen", None, size_of="ppOrderingFormatName"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "ppOrderingFormatName",
                [],
                NDRFullPointerField(
                    NDRShortField("ppOrderingFormatName", 0), deferred=True
                ),
                size_is=lambda pkt: pkt.ulOrderingFormatNameLen,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRIntField("pulOrderingFormatNameLenProp", 0), deferred=True
        ),
    ]


class CACCreateRemoteCursor(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("hCursor", 0),
        NDRIntField("srv_hACQueue", 0),
        NDRIntField("cli_pQMQueue", 0),
    ]


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


class CACTransferBufferV1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("uTransferType", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField("value", Send_sub0(), Send_sub0),
                    (
                        (
                            lambda pkt: getattr(pkt, "uTransferType", None)
                            == TRANSFER_TYPE.CACTB_SEND
                        ),
                        (lambda _, val: val.tag == TRANSFER_TYPE.CACTB_SEND),
                    ),
                ),
                (
                    NDRPacketField("value", Receive_sub1(), Receive_sub1),
                    (
                        (
                            lambda pkt: getattr(pkt, "uTransferType", None)
                            == TRANSFER_TYPE.CACTB_RECEIVE
                        ),
                        (lambda _, val: val.tag == TRANSFER_TYPE.CACTB_RECEIVE),
                    ),
                ),
                (
                    NDRPacketField(
                        "value", CACCreateRemoteCursor(), CACCreateRemoteCursor
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "uTransferType", None)
                            == TRANSFER_TYPE.CACTB_CREATECURSOR
                        ),
                        (lambda _, val: val.tag == TRANSFER_TYPE.CACTB_CREATECURSOR),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRFullPointerField(NDRShortField("pClass", 0), deferred=True),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppMessageID", OBJECTID(), OBJECTID), deferred=True
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfVarFieldListField(
                "ppCorrelationID",
                [],
                NDRFullPointerField(
                    NDRVarStrLenField("ppCorrelationID", "", length_is=lambda pkt: 20),
                    deferred=True,
                ),
                size_is=lambda pkt: 20,
                length_is=lambda pkt: 20,
            ),
            deferred=True,
        ),
        NDRFullPointerField(NDRIntField("pSentTime", 0), deferred=True),
        NDRFullPointerField(NDRIntField("pArrivedTime", 0), deferred=True),
        NDRFullPointerField(NDRByteField("pPriority", 0), deferred=True),
        NDRFullPointerField(NDRByteField("pDelivery", 0), deferred=True),
        NDRFullPointerField(NDRByteField("pAcknowledge", 0), deferred=True),
        NDRFullPointerField(NDRByteField("pAuditing", 0), deferred=True),
        NDRFullPointerField(NDRIntField("pApplicationTag", 0), deferred=True),
        NDRFullPointerField(
            NDRConfVarFieldListField(
                "ppBody",
                [],
                NDRFullPointerField(
                    NDRVarStrLenField(
                        "ppBody", "", length_is=lambda pkt: pkt.ulBodyBufferSizeInBytes
                    ),
                    deferred=True,
                ),
                size_is=lambda pkt: pkt.ulAllocBodyBufferInBytes,
                length_is=lambda pkt: pkt.ulBodyBufferSizeInBytes,
            ),
            deferred=True,
        ),
        NDRIntField("ulBodyBufferSizeInBytes", None, size_of="ppBody"),
        NDRIntField("ulAllocBodyBufferInBytes", None, size_of="ppBody"),
        NDRFullPointerField(NDRIntField("pBodySize", 0), deferred=True),
        NDRFullPointerField(
            NDRConfVarFieldListField(
                "ppTitle",
                [],
                NDRFullPointerField(
                    NDRVarStrLenFieldUtf16(
                        "ppTitle",
                        "",
                        length_is=lambda pkt: pkt.ulTitleBufferSizeInWCHARs,
                    ),
                    deferred=True,
                ),
                size_is=lambda pkt: pkt.ulTitleBufferSizeInWCHARs,
                length_is=lambda pkt: pkt.ulTitleBufferSizeInWCHARs,
            ),
            deferred=True,
        ),
        NDRIntField("ulTitleBufferSizeInWCHARs", None, size_of="ppTitle"),
        NDRFullPointerField(
            NDRIntField("pulTitleBufferSizeInWCHARs", 0), deferred=True
        ),
        NDRIntField("ulAbsoluteTimeToQueue", 0),
        NDRFullPointerField(NDRIntField("pulRelativeTimeToQueue", 0), deferred=True),
        NDRIntField("ulRelativeTimeToLive", 0),
        NDRFullPointerField(NDRIntField("pulRelativeTimeToLive", 0), deferred=True),
        NDRFullPointerField(NDRByteField("pTrace", 0), deferred=True),
        NDRFullPointerField(NDRIntField("pulSenderIDType", 0), deferred=True),
        NDRFullPointerField(
            NDRConfFieldListField(
                "ppSenderID",
                [],
                NDRFullPointerField(NDRByteField("ppSenderID", 0), deferred=True),
                size_is=lambda pkt: pkt.uSenderIDLen,
            ),
            deferred=True,
        ),
        NDRFullPointerField(NDRIntField("pulSenderIDLenProp", 0), deferred=True),
        NDRFullPointerField(NDRIntField("pulPrivLevel", 0), deferred=True),
        NDRIntField("ulAuthLevel", 0),
        NDRFullPointerField(NDRByteField("pAuthenticated", 0), deferred=True),
        NDRFullPointerField(NDRIntField("pulHashAlg", 0), deferred=True),
        NDRFullPointerField(NDRIntField("pulEncryptAlg", 0), deferred=True),
        NDRFullPointerField(
            NDRConfFieldListField(
                "ppSenderCert",
                [],
                NDRFullPointerField(NDRByteField("ppSenderCert", 0), deferred=True),
                size_is=lambda pkt: pkt.ulSenderCertLen,
            ),
            deferred=True,
        ),
        NDRIntField("ulSenderCertLen", None, size_of="ppSenderCert"),
        NDRFullPointerField(NDRIntField("pulSenderCertLenProp", 0), deferred=True),
        NDRFullPointerField(
            NDRConfFieldListField(
                "ppwcsProvName",
                [],
                NDRFullPointerField(NDRShortField("ppwcsProvName", 0), deferred=True),
                size_is=lambda pkt: pkt.ulProvNameLen,
            ),
            deferred=True,
        ),
        NDRIntField("ulProvNameLen", None, size_of="ppwcsProvName"),
        NDRFullPointerField(NDRIntField("pulAuthProvNameLenProp", 0), deferred=True),
        NDRFullPointerField(NDRIntField("pulProvType", 0), deferred=True),
        NDRSignedIntField("fDefaultProvider", 0),
        NDRFullPointerField(
            NDRConfFieldListField(
                "ppSymmKeys",
                [],
                NDRFullPointerField(NDRByteField("ppSymmKeys", 0), deferred=True),
                size_is=lambda pkt: pkt.ulSymmKeysSize,
            ),
            deferred=True,
        ),
        NDRIntField("ulSymmKeysSize", None, size_of="ppSymmKeys"),
        NDRFullPointerField(NDRIntField("pulSymmKeysSizeProp", 0), deferred=True),
        NDRByteField("bEncrypted", 0),
        NDRByteField("bAuthenticated", 0),
        NDRShortField("uSenderIDLen", None, size_of="ppSenderID"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "ppSignature",
                [],
                NDRFullPointerField(NDRByteField("ppSignature", 0), deferred=True),
                size_is=lambda pkt: pkt.ulSignatureSize,
            ),
            deferred=True,
        ),
        NDRIntField("ulSignatureSize", None, size_of="ppSignature"),
        NDRFullPointerField(NDRIntField("pulSignatureSizeProp", 0), deferred=True),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppSrcQMID", GUID(), GUID), deferred=True
            ),
            deferred=True,
        ),
        NDRFullPointerField(NDRPacketField("pUow", XACTUOW(), XACTUOW), deferred=True),
        NDRFullPointerField(
            NDRConfVarFieldListField(
                "ppMsgExtension",
                [],
                NDRFullPointerField(
                    NDRVarStrLenField(
                        "ppMsgExtension",
                        "",
                        length_is=lambda pkt: pkt.ulMsgExtensionBufferInBytes,
                    ),
                    deferred=True,
                ),
                size_is=lambda pkt: pkt.ulMsgExtensionBufferInBytes,
                length_is=lambda pkt: pkt.ulMsgExtensionBufferInBytes,
            ),
            deferred=True,
        ),
        NDRIntField("ulMsgExtensionBufferInBytes", None, size_of="ppMsgExtension"),
        NDRFullPointerField(NDRIntField("pMsgExtensionSize", 0), deferred=True),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppConnectorType", GUID(), GUID), deferred=True
            ),
            deferred=True,
        ),
        NDRFullPointerField(NDRIntField("pulBodyType", 0), deferred=True),
        NDRFullPointerField(NDRIntField("pulVersion", 0), deferred=True),
    ]


class R_QMCreateRemoteCursor_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ptb1", CACTransferBufferV1(), CACTransferBufferV1),
        NDRIntField("hQueue", 0),
    ]


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


class VARENUM(IntEnum):
    VT_EMPTY = 0
    VT_NULL = 1
    VT_I2 = 2
    VT_I4 = 3
    VT_BOOL = 11
    VT_VARIANT = 12
    VT_I1 = 16
    VT_UI1 = 17
    VT_UI2 = 18
    VT_UI4 = 19
    VT_I8 = 20
    VT_UI8 = 21
    VT_LPWSTR = 31
    VT_BLOB = 65
    VT_CLSID = 72
    VT_VECTOR = 4096


class LARGE_INTEGER(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRSignedLongField("QuadPart", 0)]


class ULARGE_INTEGER(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRLongField("QuadPart", 0)]


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


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


class CAUI(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16("pElems", "", size_is=lambda pkt: pkt.cElems),
            deferred=True,
        ),
    ]


class CAL(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "pElems",
                [],
                NDRSignedIntField("pElems", 0),
                size_is=lambda pkt: pkt.cElems,
            ),
            deferred=True,
        ),
    ]


class CAUL(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "pElems", [], NDRIntField("pElems", 0), size_is=lambda pkt: pkt.cElems
            ),
            deferred=True,
        ),
    ]


class CAUH(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pElems", [], ULARGE_INTEGER, size_is=lambda pkt: pkt.cElems
            ),
            deferred=True,
        ),
    ]


class CACLSID(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfPacketListField("pElems", [], GUID, size_is=lambda pkt: pkt.cElems),
            deferred=True,
        ),
    ]


class CALPWSTR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cElems", None, size_of="pElems"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "pElems",
                [],
                NDRFullPointerField(
                    NDRConfVarStrNullFieldUtf16("pElems", ""), deferred=True
                ),
                size_is=lambda pkt: pkt.cElems,
            ),
            deferred=True,
        ),
    ]


class tag_inner_PROPVARIANT(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRShortField("vt", 0),
        NDRByteField("wReserved1", 0),
        NDRByteField("wReserved2", 0),
        NDRIntField("wReserved3", 0),
        NDRRecursiveField("_varUnion"),
    ]


class R_QMCreateObjectInternal_Request(NDRPacket):
    fields_desc = [
        NDRIntField("dwObjectType", 0),
        NDRConfVarStrNullFieldUtf16("lpwcsPathName", ""),
        NDRIntField("SDSize", None, size_of="pSecurityDescriptor"),
        NDRConfStrLenField("pSecurityDescriptor", "", size_is=lambda pkt: pkt.SDSize),
        NDRIntField("cp", None, size_of="apVar"),
        NDRConfFieldListField(
            "aProp", [], NDRIntField("", 0), size_is=lambda pkt: pkt.cp
        ),
        NDRConfPacketListField(
            "apVar", [], tag_inner_PROPVARIANT, size_is=lambda pkt: pkt.cp
        ),
    ]


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


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


class R_QMSetObjectSecurityInternal_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pObjectFormat", OBJECT_FORMAT(), OBJECT_FORMAT),
        NDRIntField("SecurityInformation", 0),
        NDRIntField("SDSize", None, size_of="pSecurityDescriptor"),
        NDRConfStrLenField("pSecurityDescriptor", "", size_is=lambda pkt: pkt.SDSize),
    ]


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


class R_QMGetObjectSecurityInternal_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pObjectFormat", OBJECT_FORMAT(), OBJECT_FORMAT),
        NDRIntField("RequestedInformation", 0),
        NDRIntField("nLength", 0),
    ]


class R_QMGetObjectSecurityInternal_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("pSecurityDescriptor", "", size_is=lambda pkt: pkt.nLength),
        NDRIntField("lpnLengthNeeded", 0),
        NDRIntField("status", 0),
    ]


class R_QMDeleteObject_Request(NDRPacket):
    fields_desc = [NDRPacketField("pObjectFormat", OBJECT_FORMAT(), OBJECT_FORMAT)]


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


class R_QMGetObjectProperties_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pObjectFormat", OBJECT_FORMAT(), OBJECT_FORMAT),
        NDRIntField("cp", None, size_of="apVar"),
        NDRConfFieldListField(
            "aProp", [], NDRIntField("", 0), size_is=lambda pkt: pkt.cp
        ),
        NDRConfPacketListField(
            "apVar", [], tag_inner_PROPVARIANT, size_is=lambda pkt: pkt.cp
        ),
    ]


class R_QMGetObjectProperties_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "apVar", [], tag_inner_PROPVARIANT, size_is=lambda pkt: pkt.cp
        ),
        NDRIntField("status", 0),
    ]


class R_QMSetObjectProperties_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pObjectFormat", OBJECT_FORMAT(), OBJECT_FORMAT),
        NDRIntField("cp", None, size_of="apVar"),
        NDRConfFieldListField(
            "aProp", [], NDRIntField("", 0), size_is=lambda pkt: pkt.cp
        ),
        NDRConfPacketListField(
            "apVar", [], tag_inner_PROPVARIANT, size_is=lambda pkt: pkt.cp
        ),
    ]


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


class R_QMObjectPathToObjectFormat_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("lpwcsPathName", ""),
        NDRPacketField("pObjectFormat", OBJECT_FORMAT(), OBJECT_FORMAT),
    ]


class R_QMObjectPathToObjectFormat_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pObjectFormat", OBJECT_FORMAT(), OBJECT_FORMAT),
        NDRIntField("status", 0),
    ]


class R_QMGetTmWhereabouts_Request(NDRPacket):
    fields_desc = [NDRIntField("cbBufSize", 0)]


class R_QMGetTmWhereabouts_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("pbWhereabouts", "", size_is=lambda pkt: pkt.cbBufSize),
        NDRIntField("pcbWhereabouts", 0),
        NDRIntField("status", 0),
    ]


class R_QMEnlistTransaction_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pUow", XACTUOW(), XACTUOW),
        NDRIntField("cbCookie", None, size_of="pbCookie"),
        NDRConfStrLenField("pbCookie", "", size_is=lambda pkt: pkt.cbCookie),
    ]


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


class R_QMEnlistInternalTransaction_Request(NDRPacket):
    fields_desc = [NDRPacketField("pUow", XACTUOW(), XACTUOW)]


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


class R_QMCommitTransaction_Request(NDRPacket):
    fields_desc = [NDRPacketField("phIntXact", NDRContextHandle(), NDRContextHandle)]


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


class R_QMAbortTransaction_Request(NDRPacket):
    fields_desc = [NDRPacketField("phIntXact", NDRContextHandle(), NDRContextHandle)]


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


class rpc_QMOpenQueueInternal_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pQueueFormat", QUEUE_FORMAT(), QUEUE_FORMAT),
        NDRIntField("dwDesiredAccess", 0),
        NDRIntField("dwShareMode", 0),
        NDRIntField("hRemoteQueue", 0),
        NDRFullPointerField(
            NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lplpRemoteQueueName", ""))
        ),
        NDRIntField("dwpQueue", 0),
        NDRPacketField("pLicGuid", GUID(), GUID),
        NDRConfVarStrNullFieldUtf16("lpClientName", ""),
        NDRIntField("dwRemoteProtocol", 0),
        NDRIntField("dwpRemoteContext", 0),
    ]


class rpc_QMOpenQueueInternal_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lplpRemoteQueueName", ""))
        ),
        NDRIntField("pdwQMContext", 0),
        NDRPacketField("phQueue", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class rpc_ACCloseHandle_Request(NDRPacket):
    fields_desc = [NDRPacketField("phQueue", NDRContextHandle(), NDRContextHandle)]


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


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


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


class rpc_ACSetCursorProperties_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hProxy", NDRContextHandle(), NDRContextHandle),
        NDRIntField("hCursor", 0),
        NDRIntField("hRemoteCursor", 0),
    ]


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


class rpc_ACHandleToFormatName_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hQueue", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwFormatNameRPCBufferLen", None, size_of="lpwcsFormatName"),
        NDRConfVarStrLenFieldUtf16(
            "lpwcsFormatName",
            "",
            size_is=lambda pkt: pkt.dwFormatNameRPCBufferLen,
            length_is=lambda pkt: pkt.dwFormatNameRPCBufferLen,
        ),
        NDRIntField("pdwLength", 0),
    ]


class rpc_ACHandleToFormatName_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenFieldUtf16(
            "lpwcsFormatName",
            "",
            size_is=lambda pkt: pkt.dwFormatNameRPCBufferLen,
            length_is=lambda pkt: pkt.dwFormatNameRPCBufferLen,
        ),
        NDRIntField("pdwLength", 0),
        NDRIntField("status", 0),
    ]


class rpc_ACPurgeQueue_Request(NDRPacket):
    fields_desc = [NDRPacketField("hQueue", NDRContextHandle(), NDRContextHandle)]


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


class R_QMQueryQMRegistryInternal_Request(NDRPacket):
    fields_desc = [NDRIntField("dwQueryType", 0)]


class R_QMQueryQMRegistryInternal_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lplpMQISServer", "")),
        NDRIntField("status", 0),
    ]


class R_QMGetRTQMServerPort_Request(NDRPacket):
    fields_desc = [NDRIntField("fIP", 0)]


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


QMCOMM_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    1: DceRpcOp(R_QMGetRemoteQueueName_Request, R_QMGetRemoteQueueName_Response),
    2: DceRpcOp(R_QMOpenRemoteQueue_Request, R_QMOpenRemoteQueue_Response),
    3: DceRpcOp(
        R_QMCloseRemoteQueueContext_Request, R_QMCloseRemoteQueueContext_Response
    ),
    4: DceRpcOp(R_QMCreateRemoteCursor_Request, R_QMCreateRemoteCursor_Response),
    # 5: Opnum5NotUsedOnWire,
    6: DceRpcOp(R_QMCreateObjectInternal_Request, R_QMCreateObjectInternal_Response),
    7: DceRpcOp(
        R_QMSetObjectSecurityInternal_Request, R_QMSetObjectSecurityInternal_Response
    ),
    8: DceRpcOp(
        R_QMGetObjectSecurityInternal_Request, R_QMGetObjectSecurityInternal_Response
    ),
    9: DceRpcOp(R_QMDeleteObject_Request, R_QMDeleteObject_Response),
    10: DceRpcOp(R_QMGetObjectProperties_Request, R_QMGetObjectProperties_Response),
    11: DceRpcOp(R_QMSetObjectProperties_Request, R_QMSetObjectProperties_Response),
    12: DceRpcOp(
        R_QMObjectPathToObjectFormat_Request, R_QMObjectPathToObjectFormat_Response
    ),
    # 13: Opnum13NotUsedOnWire,
    14: DceRpcOp(R_QMGetTmWhereabouts_Request, R_QMGetTmWhereabouts_Response),
    15: DceRpcOp(R_QMEnlistTransaction_Request, R_QMEnlistTransaction_Response),
    16: DceRpcOp(
        R_QMEnlistInternalTransaction_Request, R_QMEnlistInternalTransaction_Response
    ),
    17: DceRpcOp(R_QMCommitTransaction_Request, R_QMCommitTransaction_Response),
    18: DceRpcOp(R_QMAbortTransaction_Request, R_QMAbortTransaction_Response),
    19: DceRpcOp(rpc_QMOpenQueueInternal_Request, rpc_QMOpenQueueInternal_Response),
    20: DceRpcOp(rpc_ACCloseHandle_Request, rpc_ACCloseHandle_Response),
    # 21: Opnum21NotUsedOnWire,
    22: DceRpcOp(rpc_ACCloseCursor_Request, rpc_ACCloseCursor_Response),
    23: DceRpcOp(rpc_ACSetCursorProperties_Request, rpc_ACSetCursorProperties_Response),
    # 24: Opnum24NotUsedOnWire,
    # 25: Opnum25NotUsedOnWire,
    26: DceRpcOp(rpc_ACHandleToFormatName_Request, rpc_ACHandleToFormatName_Response),
    27: DceRpcOp(rpc_ACPurgeQueue_Request, rpc_ACPurgeQueue_Response),
    28: DceRpcOp(
        R_QMQueryQMRegistryInternal_Request, R_QMQueryQMRegistryInternal_Response
    ),
    # 29: Opnum29NotUsedOnWire,
    # 30: Opnum30NotUsedOnWire,
    31: DceRpcOp(R_QMGetRTQMServerPort_Request, R_QMGetRTQMServerPort_Response),
    # 32: Opnum32NotUsedOnWire,
    # 33: Opnum33NotUsedOnWire,
    # 34: Opnum34NotUsedOnWire
}
register_dcerpc_interface(
    name="qmcomm",
    uuid=uuid.UUID("fdb3a030-065f-11d1-bb9b-00a024ea5525"),
    version="1.0",
    opnums=QMCOMM_OPNUMS,
)


class CACTransferBufferV2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("old", CACTransferBufferV1(), CACTransferBufferV1),
        NDRFullPointerField(NDRByteField("pbFirstInXact", 0), deferred=True),
        NDRFullPointerField(NDRByteField("pbLastInXact", 0), deferred=True),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppXactID", OBJECTID(), OBJECTID), deferred=True
            ),
            deferred=True,
        ),
    ]


class QMSendMessageInternalEx_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pQueueFormat", QUEUE_FORMAT(), QUEUE_FORMAT),
        NDRPacketField("ptb", CACTransferBufferV2(), CACTransferBufferV2),
        NDRFullPointerField(NDRPacketField("pMessageID", OBJECTID(), OBJECTID)),
    ]


class QMSendMessageInternalEx_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("pMessageID", OBJECTID(), OBJECTID)),
        NDRIntField("status", 0),
    ]


class rpc_ACSendMessageEx_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hQueue", NDRContextHandle(), NDRContextHandle),
        NDRPacketField("ptb", CACTransferBufferV2(), CACTransferBufferV2),
        NDRFullPointerField(NDRPacketField("pMessageID", OBJECTID(), OBJECTID)),
    ]


class rpc_ACSendMessageEx_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("pMessageID", OBJECTID(), OBJECTID)),
        NDRIntField("status", 0),
    ]


class rpc_ACReceiveMessageEx_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hQMContext", 0),
        NDRPacketField("ptb", CACTransferBufferV2(), CACTransferBufferV2),
    ]


class rpc_ACReceiveMessageEx_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("ptb", CACTransferBufferV2(), CACTransferBufferV2),
        NDRIntField("status", 0),
    ]


class rpc_ACCreateCursorEx_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hQueue", NDRContextHandle(), NDRContextHandle),
        NDRPacketField("pcc", CACCreateRemoteCursor(), CACCreateRemoteCursor),
    ]


class rpc_ACCreateCursorEx_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pcc", CACCreateRemoteCursor(), CACCreateRemoteCursor),
        NDRIntField("status", 0),
    ]


QMCOMM2_OPNUMS = {
    0: DceRpcOp(QMSendMessageInternalEx_Request, QMSendMessageInternalEx_Response),
    1: DceRpcOp(rpc_ACSendMessageEx_Request, rpc_ACSendMessageEx_Response),
    2: DceRpcOp(rpc_ACReceiveMessageEx_Request, rpc_ACReceiveMessageEx_Response),
    3: DceRpcOp(rpc_ACCreateCursorEx_Request, rpc_ACCreateCursorEx_Response),
}
register_dcerpc_interface(
    name="qmcomm2",
    uuid=uuid.UUID("76d12b80-3467-11d3-91ff-0090272f9ea3"),
    version="1.0",
    opnums=QMCOMM2_OPNUMS,
)
