# SPDX-License-Identifier: GPL-2.0-only
# This file is part of Scapy RPC
# See https://scapy.net/ for more information
# Copyright (C) Gabriel Potter

# [ms-adtg] v19.1 (Fri, 30 May 2025)

"""
RPC definitions for the following interfaces:
- IUnknown (v0.0): 00000000-0000-0000-C000-000000000046
- IDataFactory (v0.0): 0EAC4842-8763-11cf-A743-00AA00A3F00D
- IDataFactory2 (v0.0): 070669EB-B52F-11d1-9270-00C04FBBBFB3
- IDataFactory3 (v0.0): 4639DB2A-BFC5-11d2-9318-00C04FBBBFB3
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,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRFullEmbPointerField,
    NDRFullPointerField,
    NDRIEEEDoubleField,
    NDRIEEEFloatField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRRecursiveClass,
    NDRRefEmbPointerField,
    NDRShortField,
    NDRSignedByteField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRSignedShortField,
    NDRUnionField,
    register_com_interface,
    register_dcerpc_interface,
)

IUNKNOWN_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire
}
register_com_interface(
    name="IUnknown",
    uuid=uuid.UUID("00000000-0000-0000-C000-000000000046"),
    opnums=IUNKNOWN_OPNUMS,
)


class FLAGGED_WORD_BLOB(NDRPacket):
    ALIGNMENT = (4, 4)
    DEPORTED_CONFORMANTS = ["asData"]
    fields_desc = [
        NDRIntField("cBytes", 0),
        NDRIntField("clSize", None, size_of="asData"),
        NDRConfStrLenFieldUtf16(
            "asData", "", size_is=lambda pkt: pkt.clSize, conformant_in_struct=True
        ),
    ]


class MInterfacePointer(NDRPacket):
    ALIGNMENT = (4, 4)
    DEPORTED_CONFORMANTS = ["abData"]
    fields_desc = [
        NDRIntField("ulCntData", None, size_of="abData"),
        NDRConfStrLenField(
            "abData", "", size_is=lambda pkt: pkt.ulCntData, conformant_in_struct=True
        ),
    ]


class Query_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrConnection", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrQuery", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("lMarshalOptions", 0),
    ]


class Query_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppRecordset", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class SubmitChanges_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrConnection", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRPacketField("pRecordset", MInterfacePointer(), MInterfacePointer),
    ]


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


class ConvertToString_Request(NDRPacket):
    fields_desc = [NDRPacketField("punkObject", MInterfacePointer(), MInterfacePointer)]


class ConvertToString_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pbstrInline", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
            )
        ),
        NDRIntField("status", 0),
    ]


class VARENUM(IntEnum):
    VT_EMPTY = 0
    VT_NULL = 1
    VT_I2 = 2
    VT_I4 = 3
    VT_R4 = 4
    VT_R8 = 5
    VT_CY = 6
    VT_DATE = 7
    VT_BSTR = 8
    VT_DISPATCH = 9
    VT_ERROR = 10
    VT_BOOL = 11
    VT_VARIANT = 12
    VT_UNKNOWN = 13
    VT_DECIMAL = 14
    VT_I1 = 16
    VT_UI1 = 17
    VT_UI2 = 18
    VT_UI4 = 19
    VT_I8 = 20
    VT_UI8 = 21
    VT_INT = 22
    VT_UINT = 23
    VT_VOID = 24
    VT_HRESULT = 25
    VT_PTR = 26
    VT_SAFEARRAY = 27
    VT_CARRAY = 28
    VT_USERDEFINED = 29
    VT_LPSTR = 30
    VT_LPWSTR = 31
    VT_RECORD = 36
    VT_INT_PTR = 37
    VT_UINT_PTR = 38
    VT_ARRAY = 8192
    VT_BYREF = 16384


class CURRENCY(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRSignedLongField("int64", 0)]


class SF_TYPE(IntEnum):
    SF_ERROR = VARENUM.VT_ERROR
    SF_I1 = VARENUM.VT_I1
    SF_I2 = VARENUM.VT_I2
    SF_I4 = VARENUM.VT_I4
    SF_I8 = VARENUM.VT_I8
    SF_BSTR = VARENUM.VT_BSTR
    SF_UNKNOWN = VARENUM.VT_UNKNOWN
    SF_DISPATCH = VARENUM.VT_DISPATCH
    SF_VARIANT = VARENUM.VT_VARIANT
    SF_RECORD = VARENUM.VT_RECORD
    SF_HAVEIID = VARENUM.VT_UNKNOWN | 32768


class SAFEARR_BSTR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Size", None, size_of="aBstr"),
        NDRRefEmbPointerField(
            NDRConfPacketListField(
                "aBstr", [], FLAGGED_WORD_BLOB, size_is=lambda pkt: pkt.Size, ptr_lvl=1
            )
        ),
    ]


class SAFEARR_UNKNOWN(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Size", None, size_of="apUnknown"),
        NDRRefEmbPointerField(
            NDRConfPacketListField(
                "apUnknown",
                [],
                MInterfacePointer,
                size_is=lambda pkt: pkt.Size,
                ptr_lvl=1,
            )
        ),
    ]


class SAFEARR_DISPATCH(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Size", None, size_of="apDispatch"),
        NDRRefEmbPointerField(
            NDRConfPacketListField(
                "apDispatch",
                [],
                MInterfacePointer,
                size_is=lambda pkt: pkt.Size,
                ptr_lvl=1,
            )
        ),
    ]


class SAFEARR_VARIANT(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Size", None, size_of="aVariant"),
        NDRRefEmbPointerField(
            NDRConfPacketListField(
                "aVariant",
                [],
                NDRRecursiveClass("wireVARIANTStr"),
                size_is=lambda pkt: pkt.Size,
                ptr_lvl=1,
            )
        ),
    ]


class wireBRECORDStr(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("fFlags", 0),
        NDRIntField("clSize", None, size_of="pRecord"),
        NDRFullEmbPointerField(
            NDRPacketField("pRecInfo", MInterfacePointer(), MInterfacePointer)
        ),
        NDRFullEmbPointerField(
            NDRConfStrLenField("pRecord", "", size_is=lambda pkt: pkt.clSize)
        ),
    ]


class SAFEARR_BRECORD(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Size", None, size_of="aRecord"),
        NDRRefEmbPointerField(
            NDRConfPacketListField(
                "aRecord", [], wireBRECORDStr, size_is=lambda pkt: pkt.Size, ptr_lvl=1
            )
        ),
    ]


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


class SAFEARR_HAVEIID(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Size", None, size_of="apUnknown"),
        NDRRefEmbPointerField(
            NDRConfPacketListField(
                "apUnknown",
                [],
                MInterfacePointer,
                size_is=lambda pkt: pkt.Size,
                ptr_lvl=1,
            )
        ),
        NDRPacketField("iid", GUID(), GUID),
    ]


class BYTE_SIZEDARR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("clSize", None, size_of="pData"),
        NDRFullEmbPointerField(
            NDRConfStrLenField("pData", "", size_is=lambda pkt: pkt.clSize)
        ),
    ]


class WORD_SIZEDARR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("clSize", None, size_of="pData"),
        NDRFullEmbPointerField(
            NDRConfStrLenFieldUtf16("pData", "", size_is=lambda pkt: pkt.clSize)
        ),
    ]


class DWORD_SIZEDARR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("clSize", None, size_of="pData"),
        NDRFullEmbPointerField(
            NDRConfFieldListField(
                "pData", [], NDRIntField("", 0), size_is=lambda pkt: pkt.clSize
            )
        ),
    ]


class HYPER_SIZEDARR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("clSize", None, size_of="pData"),
        NDRFullEmbPointerField(
            NDRConfFieldListField(
                "pData", [], NDRSignedLongField("", 0), size_is=lambda pkt: pkt.clSize
            )
        ),
    ]


class SAFEARRAYBOUND(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("cElements", 0), NDRSignedIntField("lLbound", 0)]


class SAFEARRAY(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["rgsabound"]
    fields_desc = [
        NDRShortField("cDims", None, size_of="rgsabound"),
        NDRShortField("fFeatures", 0),
        NDRIntField("cbElements", 0),
        NDRIntField("cLocks", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField("uArrayStructs", SAFEARR_BSTR(), SAFEARR_BSTR),
                    (
                        (lambda pkt: None == SF_TYPE.SF_BSTR),
                        (lambda _, val: val.tag == SF_TYPE.SF_BSTR),
                    ),
                ),
                (
                    NDRPacketField("uArrayStructs", SAFEARR_UNKNOWN(), SAFEARR_UNKNOWN),
                    (
                        (lambda pkt: None == SF_TYPE.SF_UNKNOWN),
                        (lambda _, val: val.tag == SF_TYPE.SF_UNKNOWN),
                    ),
                ),
                (
                    NDRPacketField(
                        "uArrayStructs", SAFEARR_DISPATCH(), SAFEARR_DISPATCH
                    ),
                    (
                        (lambda pkt: None == SF_TYPE.SF_DISPATCH),
                        (lambda _, val: val.tag == SF_TYPE.SF_DISPATCH),
                    ),
                ),
                (
                    NDRPacketField("uArrayStructs", SAFEARR_VARIANT(), SAFEARR_VARIANT),
                    (
                        (lambda pkt: None == SF_TYPE.SF_VARIANT),
                        (lambda _, val: val.tag == SF_TYPE.SF_VARIANT),
                    ),
                ),
                (
                    NDRPacketField("uArrayStructs", SAFEARR_BRECORD(), SAFEARR_BRECORD),
                    (
                        (lambda pkt: None == SF_TYPE.SF_RECORD),
                        (lambda _, val: val.tag == SF_TYPE.SF_RECORD),
                    ),
                ),
                (
                    NDRPacketField("uArrayStructs", SAFEARR_HAVEIID(), SAFEARR_HAVEIID),
                    (
                        (lambda pkt: None == SF_TYPE.SF_HAVEIID),
                        (lambda _, val: val.tag == SF_TYPE.SF_HAVEIID),
                    ),
                ),
                (
                    NDRPacketField("uArrayStructs", BYTE_SIZEDARR(), BYTE_SIZEDARR),
                    (
                        (lambda pkt: None == SF_TYPE.SF_I1),
                        (lambda _, val: val.tag == SF_TYPE.SF_I1),
                    ),
                ),
                (
                    NDRPacketField("uArrayStructs", WORD_SIZEDARR(), WORD_SIZEDARR),
                    (
                        (lambda pkt: None == SF_TYPE.SF_I2),
                        (lambda _, val: val.tag == SF_TYPE.SF_I2),
                    ),
                ),
                (
                    NDRPacketField("uArrayStructs", DWORD_SIZEDARR(), DWORD_SIZEDARR),
                    (
                        (lambda pkt: None == SF_TYPE.SF_I4),
                        (lambda _, val: val.tag == SF_TYPE.SF_I4),
                    ),
                ),
                (
                    NDRPacketField("uArrayStructs", HYPER_SIZEDARR(), HYPER_SIZEDARR),
                    (
                        (lambda pkt: None == SF_TYPE.SF_I8),
                        (lambda _, val: val.tag == SF_TYPE.SF_I8),
                    ),
                ),
            ],
            StrFixedLenField("uArrayStructs", "", length=0),
            align=(4, 8),
            switch_fmt=("I", "I"),
        ),
        NDRConfPacketListField(
            "rgsabound",
            [],
            SAFEARRAYBOUND,
            size_is=lambda pkt: pkt.cDims,
            conformant_in_struct=True,
        ),
    ]


class DECIMAL(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRShortField("wReserved", 0),
        NDRSignedByteField("scale", 0),
        NDRSignedByteField("sign", 0),
        NDRIntField("Hi32", 0),
        NDRLongField("Lo64", 0),
    ]


class wireVARIANTStr(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("clSize", 0),
        NDRIntField("rpcReserved", 0),
        NDRShortField("vt", 0),
        NDRShortField("wReserved1", 0),
        NDRShortField("wReserved2", 0),
        NDRShortField("wReserved3", 0),
        NDRUnionField(
            [
                (
                    NDRSignedLongField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_I8),
                        (lambda _, val: val.tag == VARENUM.VT_I8),
                    ),
                ),
                (
                    NDRSignedIntField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_I4),
                        (lambda _, val: val.tag == VARENUM.VT_I4),
                    ),
                ),
                (
                    NDRSignedByteField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_UI1),
                        (lambda _, val: val.tag == VARENUM.VT_UI1),
                    ),
                ),
                (
                    NDRSignedShortField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_I2),
                        (lambda _, val: val.tag == VARENUM.VT_I2),
                    ),
                ),
                (
                    NDRIEEEFloatField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_R4),
                        (lambda _, val: val.tag == VARENUM.VT_R4),
                    ),
                ),
                (
                    NDRIEEEDoubleField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_R8),
                        (lambda _, val: val.tag == VARENUM.VT_R8),
                    ),
                ),
                (
                    NDRSignedShortField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_BOOL),
                        (lambda _, val: val.tag == VARENUM.VT_BOOL),
                    ),
                ),
                (
                    NDRSignedIntField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_ERROR),
                        (lambda _, val: val.tag == VARENUM.VT_ERROR),
                    ),
                ),
                (
                    NDRPacketField("_varUnion", CURRENCY(), CURRENCY),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_CY),
                        (lambda _, val: val.tag == VARENUM.VT_CY),
                    ),
                ),
                (
                    NDRIEEEDoubleField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_DATE),
                        (lambda _, val: val.tag == VARENUM.VT_DATE),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRPacketField(
                            "_varUnion", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_BSTR),
                        (lambda _, val: val.tag == VARENUM.VT_BSTR),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRPacketField(
                            "_varUnion", MInterfacePointer(), MInterfacePointer
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_UNKNOWN),
                        (lambda _, val: val.tag == VARENUM.VT_UNKNOWN),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRPacketField(
                            "_varUnion", MInterfacePointer(), MInterfacePointer
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_DISPATCH),
                        (lambda _, val: val.tag == VARENUM.VT_DISPATCH),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRFullEmbPointerField(
                            NDRPacketField("_varUnion", SAFEARRAY(), SAFEARRAY)
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_ARRAY),
                        (lambda _, val: val.tag == VARENUM.VT_ARRAY),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRPacketField("_varUnion", wireBRECORDStr(), wireBRECORDStr)
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            in [
                                VARENUM.VT_RECORD,
                                (VARENUM.VT_RECORD | VARENUM.VT_BYREF),
                            ]
                        ),
                        (
                            lambda _, val: val.tag
                            in [
                                VARENUM.VT_RECORD,
                                (VARENUM.VT_RECORD | VARENUM.VT_BYREF),
                            ]
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRSignedByteField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_UI1 | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_UI1 | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRSignedShortField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_I2 | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_I2 | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRSignedIntField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_I4 | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_I4 | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRSignedLongField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_I8 | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_I8 | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRIEEEFloatField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_R4 | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_R4 | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRIEEEDoubleField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_R8 | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_R8 | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRSignedShortField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_BOOL | VARENUM.VT_BYREF)
                        ),
                        (
                            lambda _, val: val.tag
                            == (VARENUM.VT_BOOL | VARENUM.VT_BYREF)
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRSignedIntField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_ERROR | VARENUM.VT_BYREF)
                        ),
                        (
                            lambda _, val: val.tag
                            == (VARENUM.VT_ERROR | VARENUM.VT_BYREF)
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRPacketField("_varUnion", CURRENCY(), CURRENCY)
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_CY | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_CY | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRIEEEDoubleField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_DATE | VARENUM.VT_BYREF)
                        ),
                        (
                            lambda _, val: val.tag
                            == (VARENUM.VT_DATE | VARENUM.VT_BYREF)
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRFullEmbPointerField(
                            NDRPacketField(
                                "_varUnion", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                            )
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_BSTR | VARENUM.VT_BYREF)
                        ),
                        (
                            lambda _, val: val.tag
                            == (VARENUM.VT_BSTR | VARENUM.VT_BYREF)
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRFullEmbPointerField(
                            NDRPacketField(
                                "_varUnion", MInterfacePointer(), MInterfacePointer
                            )
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_UNKNOWN | VARENUM.VT_BYREF)
                        ),
                        (
                            lambda _, val: val.tag
                            == (VARENUM.VT_UNKNOWN | VARENUM.VT_BYREF)
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRFullEmbPointerField(
                            NDRPacketField(
                                "_varUnion", MInterfacePointer(), MInterfacePointer
                            )
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_DISPATCH | VARENUM.VT_BYREF)
                        ),
                        (
                            lambda _, val: val.tag
                            == (VARENUM.VT_DISPATCH | VARENUM.VT_BYREF)
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRFullEmbPointerField(
                            NDRFullEmbPointerField(
                                NDRPacketField("_varUnion", SAFEARRAY(), SAFEARRAY)
                            )
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_ARRAY | VARENUM.VT_BYREF)
                        ),
                        (
                            lambda _, val: val.tag
                            == (VARENUM.VT_ARRAY | VARENUM.VT_BYREF)
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRFullEmbPointerField(
                            NDRPacketField(
                                "_varUnion", None, NDRRecursiveClass("wireVARIANTStr")
                            )
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_VARIANT | VARENUM.VT_BYREF)
                        ),
                        (
                            lambda _, val: val.tag
                            == (VARENUM.VT_VARIANT | VARENUM.VT_BYREF)
                        ),
                    ),
                ),
                (
                    NDRSignedByteField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_I1),
                        (lambda _, val: val.tag == VARENUM.VT_I1),
                    ),
                ),
                (
                    NDRShortField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_UI2),
                        (lambda _, val: val.tag == VARENUM.VT_UI2),
                    ),
                ),
                (
                    NDRIntField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_UI4),
                        (lambda _, val: val.tag == VARENUM.VT_UI4),
                    ),
                ),
                (
                    NDRLongField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_UI8),
                        (lambda _, val: val.tag == VARENUM.VT_UI8),
                    ),
                ),
                (
                    NDRSignedIntField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_INT),
                        (lambda _, val: val.tag == VARENUM.VT_INT),
                    ),
                ),
                (
                    NDRIntField("_varUnion", 0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_UINT),
                        (lambda _, val: val.tag == VARENUM.VT_UINT),
                    ),
                ),
                (
                    NDRPacketField("_varUnion", DECIMAL(), DECIMAL),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_DECIMAL),
                        (lambda _, val: val.tag == VARENUM.VT_DECIMAL),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRSignedByteField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_I1 | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_I1 | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRShortField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_UI2 | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_UI2 | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRIntField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_UI4 | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_UI4 | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRLongField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_UI8 | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_UI8 | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRSignedIntField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_INT | VARENUM.VT_BYREF)
                        ),
                        (lambda _, val: val.tag == (VARENUM.VT_INT | VARENUM.VT_BYREF)),
                    ),
                ),
                (
                    NDRFullEmbPointerField(NDRIntField("_varUnion", 0)),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_UINT | VARENUM.VT_BYREF)
                        ),
                        (
                            lambda _, val: val.tag
                            == (VARENUM.VT_UINT | VARENUM.VT_BYREF)
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRPacketField("_varUnion", DECIMAL(), DECIMAL)
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == (VARENUM.VT_DECIMAL | VARENUM.VT_BYREF)
                        ),
                        (
                            lambda _, val: val.tag
                            == (VARENUM.VT_DECIMAL | VARENUM.VT_BYREF)
                        ),
                    ),
                ),
                (
                    StrFixedLenField("_varUnion", "", length=0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_EMPTY),
                        (lambda _, val: val.tag == VARENUM.VT_EMPTY),
                    ),
                ),
                (
                    StrFixedLenField("_varUnion", "", length=0),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_NULL),
                        (lambda _, val: val.tag == VARENUM.VT_NULL),
                    ),
                ),
            ],
            StrFixedLenField("_varUnion", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "H"),
        ),
    ]


class CreateRecordSet_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("varColumnInfos", wireVARIANTStr(), wireVARIANTStr)
        )
    ]


class CreateRecordSet_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppDispatch", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


IDATAFACTORY_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(Query_Request, Query_Response),
    4: DceRpcOp(SubmitChanges_Request, SubmitChanges_Response),
    5: DceRpcOp(ConvertToString_Request, ConvertToString_Response),
    6: DceRpcOp(CreateRecordSet_Request, CreateRecordSet_Response),
}
register_dcerpc_interface(
    name="IDataFactory",
    uuid=uuid.UUID("0EAC4842-8763-11cf-A743-00AA00A3F00D"),
    version="0.0",
    opnums=IDATAFACTORY_OPNUMS,
)


class Execute21_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ConnectionString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("HandlerString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("QueryString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("lMarshalOptions", 0),
        NDRFullPointerField(
            NDRPacketField("Properties", wireVARIANTStr(), wireVARIANTStr)
        ),
        NDRFullPointerField(
            NDRPacketField("TableId", wireVARIANTStr(), wireVARIANTStr)
        ),
        NDRSignedIntField("lExecuteOptions", 0),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pParameters", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


class Execute21_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pParameters", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRFullPointerField(
            NDRPacketField("ppRecordset", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class Synchronize21_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ConnectionString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("HandlerString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("lSynchronizeOptions", 0),
        NDRFullPointerField(
            NDRPacketField("ppRecordset", MInterfacePointer(), MInterfacePointer)
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pStatusArray", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


class Synchronize21_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppRecordset", MInterfacePointer(), MInterfacePointer)
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pStatusArray", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pResult", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRIntField("status", 0),
    ]


IDATAFACTORY2_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(Query_Request, Query_Response),
    4: DceRpcOp(SubmitChanges_Request, SubmitChanges_Response),
    5: DceRpcOp(ConvertToString_Request, ConvertToString_Response),
    6: DceRpcOp(CreateRecordSet_Request, CreateRecordSet_Response),
    7: DceRpcOp(Execute21_Request, Execute21_Response),
    8: DceRpcOp(Synchronize21_Request, Synchronize21_Response),
}
register_dcerpc_interface(
    name="IDataFactory2",
    uuid=uuid.UUID("070669EB-B52F-11d1-9270-00C04FBBBFB3"),
    version="0.0",
    opnums=IDATAFACTORY2_OPNUMS,
)


class Execute_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ConnectionString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("HandlerString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("QueryString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("lMarshalOptions", 0),
        NDRFullPointerField(
            NDRPacketField("Properties", wireVARIANTStr(), wireVARIANTStr)
        ),
        NDRFullPointerField(
            NDRPacketField("TableId", wireVARIANTStr(), wireVARIANTStr)
        ),
        NDRSignedIntField("lExecuteOptions", 0),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pParameters", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRSignedIntField("lcid", 0),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pInformation", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


class Execute_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pParameters", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pInformation", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRFullPointerField(
            NDRPacketField("ppRecordset", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


class Synchronize_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ConnectionString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("HandlerString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("lSynchronizeOptions", 0),
        NDRFullPointerField(
            NDRPacketField("ppRecordset", MInterfacePointer(), MInterfacePointer)
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pStatusArray", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRSignedIntField("lcid", 0),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pInformation", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


class Synchronize_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppRecordset", MInterfacePointer(), MInterfacePointer)
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pStatusArray", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pInformation", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pResult", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRIntField("status", 0),
    ]


IDATAFACTORY3_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(Query_Request, Query_Response),
    4: DceRpcOp(SubmitChanges_Request, SubmitChanges_Response),
    5: DceRpcOp(ConvertToString_Request, ConvertToString_Response),
    6: DceRpcOp(CreateRecordSet_Request, CreateRecordSet_Response),
    7: DceRpcOp(Execute21_Request, Execute21_Response),
    8: DceRpcOp(Synchronize21_Request, Synchronize21_Response),
    9: DceRpcOp(Execute_Request, Execute_Response),
    10: DceRpcOp(Synchronize_Request, Synchronize_Response),
}
register_dcerpc_interface(
    name="IDataFactory3",
    uuid=uuid.UUID("4639DB2A-BFC5-11d2-9318-00C04FBBBFB3"),
    version="0.0",
    opnums=IDATAFACTORY3_OPNUMS,
)
