# 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

# oaidl.idl 10.0.10240.0 (29 Jul 2015)

"""
RPC definitions for the following interfaces:
- IUnknown (v0.0): 00000000-0000-0000-C000-000000000046
- ICreateTypeInfo (v0.0): 00020405-0000-0000-C000-000000000046
- ICreateTypeInfo2 (v0.0): 0002040E-0000-0000-C000-000000000046
- ICreateTypeLib (v0.0): 00020406-0000-0000-C000-000000000046
- ICreateTypeLib2 (v0.0): 0002040F-0000-0000-C000-000000000046
- ITypeChangeEvents (v0.0): 00020410-0000-0000-C000-000000000046
- IErrorInfo (v0.0): 1CF2B120-547D-101B-8E65-08002B2BD119
- ICreateErrorInfo (v0.0): 22F03340-547D-101B-8E65-08002B2BD119
- ISupportErrorInfo (v0.0): DF0B3D60-548F-101B-8E65-08002B2BD119
- ITypeFactory (v0.0): 0000002E-0000-0000-C000-000000000046
- ITypeMarshal (v0.0): 0000002D-0000-0000-C000-000000000046
- IRecordInfo (v0.0): 0000002F-0000-0000-C000-000000000046
- IErrorLog (v0.0): 3127CA40-446E-11CE-8135-00AA004BB851
- IPropertyBag (v0.0): 55272A00-42CB-11CE-8135-00AA004BB851
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,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullEmbPointerField,
    NDRFullPointerField,
    NDRIEEEDoubleField,
    NDRIEEEFloatField,
    NDRInt3264EnumField,
    NDRInt3264Field,
    NDRIntEnumField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRRecursiveClass,
    NDRRefEmbPointerField,
    NDRShortField,
    NDRSignedByteField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRSignedShortField,
    NDRUnionField,
    register_com_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 GUID(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Data1", 0),
        NDRShortField("Data2", 0),
        NDRShortField("Data3", 0),
        StrFixedLenField("Data4", "", length=8),
    ]


class SetGuid_Request(NDRPacket):
    fields_desc = [NDRPacketField("guid", GUID(), GUID)]


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


class SetTypeFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("uTypeFlags", 0)]


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


class SetDocString_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("pStrDoc", "")]


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


class SetHelpContext_Request(NDRPacket):
    fields_desc = [NDRIntField("dwHelpContext", 0)]


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


class SetVersion_Request(NDRPacket):
    fields_desc = [NDRShortField("wMajorVerNum", 0), NDRShortField("wMinorVerNum", 0)]


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


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 AddRefTypeInfo_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pTInfo", MInterfacePointer(), MInterfacePointer),
        NDRIntField("phRefType", 0),
    ]


class AddRefTypeInfo_Response(NDRPacket):
    fields_desc = [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 SAFEARRAYBOUND(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("cElements", 0), NDRSignedIntField("lLbound", 0)]


class ARRAYDESC(NDRPacket):
    ALIGNMENT = (2, 2)
    DEPORTED_CONFORMANTS = ["rgbounds"]
    fields_desc = [
        NDRPacketField("tdescElem", None, NDRRecursiveClass("TYPEDESC")),
        NDRShortField("cDims", None, size_of="rgbounds"),
        NDRConfPacketListField(
            "rgbounds",
            [],
            SAFEARRAYBOUND,
            size_is=lambda pkt: pkt.cDims,
            conformant_in_struct=True,
        ),
    ]


class TYPEDESC(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRUnionField(
            [
                (
                    NDRFullEmbPointerField(
                        NDRPacketField("_tdUnion", None, NDRRecursiveClass("TYPEDESC"))
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            in [VARENUM.VT_PTR, VARENUM.VT_SAFEARRAY]
                        ),
                        (
                            lambda _, val: val.tag
                            in [VARENUM.VT_PTR, VARENUM.VT_SAFEARRAY]
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRPacketField("_tdUnion", ARRAYDESC(), ARRAYDESC)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "vt", None) == VARENUM.VT_CARRAY),
                        (lambda _, val: val.tag == VARENUM.VT_CARRAY),
                    ),
                ),
                (
                    NDRIntField("_tdUnion", 0),
                    (
                        (
                            lambda pkt: getattr(pkt, "vt", None)
                            == VARENUM.VT_USERDEFINED
                        ),
                        (lambda _, val: val.tag == VARENUM.VT_USERDEFINED),
                    ),
                ),
            ],
            StrFixedLenField("_tdUnion", "", length=0),
            align=(2, 8),
            switch_fmt=("H", "H"),
        ),
        NDRShortField("vt", 0),
    ]


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(
            NDRConfFieldListField(
                "aBstr",
                [],
                NDRFullEmbPointerField(NDRShortField("", 0)),
                size_is=lambda pkt: pkt.Size,
            )
        ),
    ]


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 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 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),
        NDRByteField("scale", 0),
        NDRByteField("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),
                    ),
                ),
                (
                    NDRByteField("_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(NDRShortField("_varUnion", 0)),
                    (
                        (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(NDRByteField("_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(NDRShortField("_varUnion", 0))
                    ),
                    (
                        (
                            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 PARAMDESCEX(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cBytes", 0),
        NDRFullEmbPointerField(
            NDRPacketField("varDefaultValue", wireVARIANTStr(), wireVARIANTStr)
        ),
    ]


class PARAMDESC(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullEmbPointerField(
            NDRPacketField("pparamdescex", PARAMDESCEX(), PARAMDESCEX)
        ),
        NDRShortField("wParamFlags", 0),
    ]


class ELEMDESC(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("tdesc", TYPEDESC(), TYPEDESC),
        NDRPacketField("paramdesc", PARAMDESC(), PARAMDESC),
    ]


class FUNCKIND(IntEnum):
    FUNC_PUREVIRTUAL = 1
    FUNC_STATIC = 3
    FUNC_DISPATCH = 4


class INVOKEKIND(IntEnum):
    INVOKE_FUNC = 1
    INVOKE_PROPERTYGET = 2
    INVOKE_PROPERTYPUT = 4
    INVOKE_PROPERTYPUTREF = 8


class CALLCONV(IntEnum):
    CC_CDECL = 1
    CC_PASCAL = 2
    CC_STDCALL = 4


class FUNCDESC(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRSignedIntField("memid", 0),
        NDRFullEmbPointerField(
            NDRConfFieldListField(
                "lReserved1",
                [],
                NDRSignedIntField("", 0),
                size_is=lambda pkt: pkt.cReserved2,
            )
        ),
        NDRFullEmbPointerField(
            NDRConfPacketListField(
                "lprgelemdescParam", [], ELEMDESC, size_is=lambda pkt: pkt.cParams
            )
        ),
        NDRIntEnumField("funckind", 0, FUNCKIND),
        NDRIntEnumField("invkind", 0, INVOKEKIND),
        NDRIntEnumField("callconv", 0, CALLCONV),
        NDRSignedShortField("cParams", None, size_of="lprgelemdescParam"),
        NDRSignedShortField("cParamsOpt", 0),
        NDRSignedShortField("oVft", 0),
        NDRSignedShortField("cReserved2", None, size_of="lReserved1"),
        NDRPacketField("elemdescFunc", ELEMDESC(), ELEMDESC),
        NDRShortField("wFuncFlags", 0),
    ]


class AddFuncDesc_Request(NDRPacket):
    fields_desc = [
        NDRIntField("index", 0),
        NDRPacketField("pFuncDesc", FUNCDESC(), FUNCDESC),
    ]


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


class AddImplType_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRIntField("hRefType", 0)]


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


class SetImplTypeFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRSignedIntField("implTypeFlags", 0)]


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


class SetAlignment_Request(NDRPacket):
    fields_desc = [NDRShortField("cbAlignment", 0)]


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


class SetSchema_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("pStrSchema", "")]


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


class VARKIND(IntEnum):
    VAR_PERINSTANCE = 0
    VAR_STATIC = VAR_PERINSTANCE + 1
    VAR_CONST = VAR_STATIC + 1
    VAR_DISPATCH = VAR_CONST + 1


class VARDESC(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRSignedIntField("memid", 0),
        NDRFullEmbPointerField(NDRConfVarStrNullFieldUtf16("lpstrReserved", "")),
        NDRUnionField(
            [
                (
                    NDRIntField("_vdUnion", 0),
                    (
                        (
                            lambda pkt: getattr(pkt, "varkind", None)
                            in [
                                VARKIND.VAR_PERINSTANCE,
                                VARKIND.VAR_DISPATCH,
                                VARKIND.VAR_STATIC,
                            ]
                        ),
                        (
                            lambda _, val: val.tag
                            in [
                                VARKIND.VAR_PERINSTANCE,
                                VARKIND.VAR_DISPATCH,
                                VARKIND.VAR_STATIC,
                            ]
                        ),
                    ),
                ),
                (
                    NDRFullEmbPointerField(
                        NDRFullEmbPointerField(
                            NDRPacketField("_vdUnion", wireVARIANTStr(), wireVARIANTStr)
                        )
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "varkind", None)
                            == VARKIND.VAR_CONST
                        ),
                        (lambda _, val: val.tag == VARKIND.VAR_CONST),
                    ),
                ),
            ],
            StrFixedLenField("_vdUnion", "", length=0),
            align=(4, 8),
            switch_fmt=("I", "I"),
        ),
        NDRPacketField("elemdescVar", ELEMDESC(), ELEMDESC),
        NDRShortField("wVarFlags", 0),
        NDRIntEnumField("varkind", 0, VARKIND),
    ]


class AddVarDesc_Request(NDRPacket):
    fields_desc = [
        NDRIntField("index", 0),
        NDRPacketField("pVarDesc", VARDESC(), VARDESC),
    ]


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


class SetFuncAndParamNames_Request(NDRPacket):
    fields_desc = [
        NDRIntField("index", 0),
        NDRConfFieldListField(
            "rgszNames",
            [],
            NDRFullPointerField(NDRConfVarStrNullFieldUtf16("", "")),
            size_is=lambda pkt: (pkt.cNames & 0xFFFFFFFF),
        ),
        NDRIntField("cNames", 0),
    ]


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


class SetVarName_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRConfVarStrNullFieldUtf16("szName", "")]


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


class SetTypeDescAlias_Request(NDRPacket):
    fields_desc = [NDRPacketField("pTDescAlias", TYPEDESC(), TYPEDESC)]


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


class DefineFuncAsDllEntry_Request(NDRPacket):
    fields_desc = [
        NDRIntField("index", 0),
        NDRConfVarStrNullFieldUtf16("szDllName", ""),
        NDRConfVarStrNullFieldUtf16("szProcName", ""),
    ]


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


class SetFuncDocString_Request(NDRPacket):
    fields_desc = [
        NDRIntField("index", 0),
        NDRConfVarStrNullFieldUtf16("szDocString", ""),
    ]


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


class SetVarDocString_Request(NDRPacket):
    fields_desc = [
        NDRIntField("index", 0),
        NDRConfVarStrNullFieldUtf16("szDocString", ""),
    ]


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


class SetFuncHelpContext_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRIntField("dwHelpContext", 0)]


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


class SetVarHelpContext_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRIntField("dwHelpContext", 0)]


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


class SetMops_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRShortField("bstrMops", 0)]


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


class IDLDESC(NDRPacket):
    ALIGNMENT = (2, 2)
    fields_desc = [NDRInt3264Field("dwReserved", 0), NDRShortField("wIDLFlags", 0)]


class SetTypeIdldesc_Request(NDRPacket):
    fields_desc = [NDRPacketField("pIdlDesc", IDLDESC(), IDLDESC)]


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


class LayOut_Request(NDRPacket):
    fields_desc = []


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


ICREATETYPEINFO_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(SetGuid_Request, SetGuid_Response),
    4: DceRpcOp(SetTypeFlags_Request, SetTypeFlags_Response),
    5: DceRpcOp(SetDocString_Request, SetDocString_Response),
    6: DceRpcOp(SetHelpContext_Request, SetHelpContext_Response),
    7: DceRpcOp(SetVersion_Request, SetVersion_Response),
    8: DceRpcOp(AddRefTypeInfo_Request, AddRefTypeInfo_Response),
    9: DceRpcOp(AddFuncDesc_Request, AddFuncDesc_Response),
    10: DceRpcOp(AddImplType_Request, AddImplType_Response),
    11: DceRpcOp(SetImplTypeFlags_Request, SetImplTypeFlags_Response),
    12: DceRpcOp(SetAlignment_Request, SetAlignment_Response),
    13: DceRpcOp(SetSchema_Request, SetSchema_Response),
    14: DceRpcOp(AddVarDesc_Request, AddVarDesc_Response),
    15: DceRpcOp(SetFuncAndParamNames_Request, SetFuncAndParamNames_Response),
    16: DceRpcOp(SetVarName_Request, SetVarName_Response),
    17: DceRpcOp(SetTypeDescAlias_Request, SetTypeDescAlias_Response),
    18: DceRpcOp(DefineFuncAsDllEntry_Request, DefineFuncAsDllEntry_Response),
    19: DceRpcOp(SetFuncDocString_Request, SetFuncDocString_Response),
    20: DceRpcOp(SetVarDocString_Request, SetVarDocString_Response),
    21: DceRpcOp(SetFuncHelpContext_Request, SetFuncHelpContext_Response),
    22: DceRpcOp(SetVarHelpContext_Request, SetVarHelpContext_Response),
    23: DceRpcOp(SetMops_Request, SetMops_Response),
    24: DceRpcOp(SetTypeIdldesc_Request, SetTypeIdldesc_Response),
    25: DceRpcOp(LayOut_Request, LayOut_Response),
}
register_com_interface(
    name="ICreateTypeInfo",
    uuid=uuid.UUID("00020405-0000-0000-C000-000000000046"),
    opnums=ICREATETYPEINFO_OPNUMS,
)


class DeleteFuncDesc_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0)]


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


class DeleteFuncDescByMemId_Request(NDRPacket):
    fields_desc = [
        NDRSignedIntField("memid", 0),
        NDRIntEnumField("invKind", 0, INVOKEKIND),
    ]


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


class DeleteVarDesc_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0)]


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


class DeleteVarDescByMemId_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("memid", 0)]


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


class DeleteImplType_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0)]


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


class SetCustData_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("guid", GUID(), GUID),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pVarVal", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


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


class SetFuncCustData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("index", 0),
        NDRPacketField("guid", GUID(), GUID),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pVarVal", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


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


class SetParamCustData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("indexFunc", 0),
        NDRIntField("indexParam", 0),
        NDRPacketField("guid", GUID(), GUID),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pVarVal", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


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


class SetVarCustData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("index", 0),
        NDRPacketField("guid", GUID(), GUID),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pVarVal", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


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


class SetImplTypeCustData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("index", 0),
        NDRPacketField("guid", GUID(), GUID),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pVarVal", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


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


class SetHelpStringContext_Request(NDRPacket):
    fields_desc = [NDRIntField("dwHelpStringContext", 0)]


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


class SetFuncHelpStringContext_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRIntField("dwHelpStringContext", 0)]


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


class SetVarHelpStringContext_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRIntField("dwHelpStringContext", 0)]


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


class Invalidate_Request(NDRPacket):
    fields_desc = []


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


class SetName_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("szName", "")]


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


ICREATETYPEINFO2_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(SetGuid_Request, SetGuid_Response),
    4: DceRpcOp(SetTypeFlags_Request, SetTypeFlags_Response),
    5: DceRpcOp(SetDocString_Request, SetDocString_Response),
    6: DceRpcOp(SetHelpContext_Request, SetHelpContext_Response),
    7: DceRpcOp(SetVersion_Request, SetVersion_Response),
    8: DceRpcOp(AddRefTypeInfo_Request, AddRefTypeInfo_Response),
    9: DceRpcOp(AddFuncDesc_Request, AddFuncDesc_Response),
    10: DceRpcOp(AddImplType_Request, AddImplType_Response),
    11: DceRpcOp(SetImplTypeFlags_Request, SetImplTypeFlags_Response),
    12: DceRpcOp(SetAlignment_Request, SetAlignment_Response),
    13: DceRpcOp(SetSchema_Request, SetSchema_Response),
    14: DceRpcOp(AddVarDesc_Request, AddVarDesc_Response),
    15: DceRpcOp(SetFuncAndParamNames_Request, SetFuncAndParamNames_Response),
    16: DceRpcOp(SetVarName_Request, SetVarName_Response),
    17: DceRpcOp(SetTypeDescAlias_Request, SetTypeDescAlias_Response),
    18: DceRpcOp(DefineFuncAsDllEntry_Request, DefineFuncAsDllEntry_Response),
    19: DceRpcOp(SetFuncDocString_Request, SetFuncDocString_Response),
    20: DceRpcOp(SetVarDocString_Request, SetVarDocString_Response),
    21: DceRpcOp(SetFuncHelpContext_Request, SetFuncHelpContext_Response),
    22: DceRpcOp(SetVarHelpContext_Request, SetVarHelpContext_Response),
    23: DceRpcOp(SetMops_Request, SetMops_Response),
    24: DceRpcOp(SetTypeIdldesc_Request, SetTypeIdldesc_Response),
    25: DceRpcOp(LayOut_Request, LayOut_Response),
    26: DceRpcOp(DeleteFuncDesc_Request, DeleteFuncDesc_Response),
    27: DceRpcOp(DeleteFuncDescByMemId_Request, DeleteFuncDescByMemId_Response),
    28: DceRpcOp(DeleteVarDesc_Request, DeleteVarDesc_Response),
    29: DceRpcOp(DeleteVarDescByMemId_Request, DeleteVarDescByMemId_Response),
    30: DceRpcOp(DeleteImplType_Request, DeleteImplType_Response),
    31: DceRpcOp(SetCustData_Request, SetCustData_Response),
    32: DceRpcOp(SetFuncCustData_Request, SetFuncCustData_Response),
    33: DceRpcOp(SetParamCustData_Request, SetParamCustData_Response),
    34: DceRpcOp(SetVarCustData_Request, SetVarCustData_Response),
    35: DceRpcOp(SetImplTypeCustData_Request, SetImplTypeCustData_Response),
    36: DceRpcOp(SetHelpStringContext_Request, SetHelpStringContext_Response),
    37: DceRpcOp(SetFuncHelpStringContext_Request, SetFuncHelpStringContext_Response),
    38: DceRpcOp(SetVarHelpStringContext_Request, SetVarHelpStringContext_Response),
    39: DceRpcOp(Invalidate_Request, Invalidate_Response),
    40: DceRpcOp(SetName_Request, SetName_Response),
}
register_com_interface(
    name="ICreateTypeInfo2",
    uuid=uuid.UUID("0002040E-0000-0000-C000-000000000046"),
    opnums=ICREATETYPEINFO2_OPNUMS,
)


class TYPEKIND(IntEnum):
    TKIND_ENUM = 0
    TKIND_RECORD = 1
    TKIND_MODULE = 2
    TKIND_INTERFACE = 3
    TKIND_DISPATCH = 4
    TKIND_COCLASS = 5
    TKIND_ALIAS = 6
    TKIND_UNION = 7


class CreateTypeInfo_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("szName", ""),
        NDRIntEnumField("tkind", 0, TYPEKIND),
    ]


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


class SetName_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("szName", "")]


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


class SetVersion_Request(NDRPacket):
    fields_desc = [NDRShortField("wMajorVerNum", 0), NDRShortField("wMinorVerNum", 0)]


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


class SetGuid_Request(NDRPacket):
    fields_desc = [NDRPacketField("guid", GUID(), GUID)]


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


class SetDocString_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("szDoc", "")]


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


class SetHelpFileName_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("szHelpFileName", "")]


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


class SetHelpContext_Request(NDRPacket):
    fields_desc = [NDRIntField("dwHelpContext", 0)]


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


class SetLcid_Request(NDRPacket):
    fields_desc = [NDRIntField("lcid", 0)]


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


class SetLibFlags_Request(NDRPacket):
    fields_desc = [NDRIntField("uLibFlags", 0)]


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


class SaveAllChanges_Request(NDRPacket):
    fields_desc = []


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


ICREATETYPELIB_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(CreateTypeInfo_Request, CreateTypeInfo_Response),
    4: DceRpcOp(SetName_Request, SetName_Response),
    5: DceRpcOp(SetVersion_Request, SetVersion_Response),
    6: DceRpcOp(SetGuid_Request, SetGuid_Response),
    7: DceRpcOp(SetDocString_Request, SetDocString_Response),
    8: DceRpcOp(SetHelpFileName_Request, SetHelpFileName_Response),
    9: DceRpcOp(SetHelpContext_Request, SetHelpContext_Response),
    10: DceRpcOp(SetLcid_Request, SetLcid_Response),
    11: DceRpcOp(SetLibFlags_Request, SetLibFlags_Response),
    12: DceRpcOp(SaveAllChanges_Request, SaveAllChanges_Response),
}
register_com_interface(
    name="ICreateTypeLib",
    uuid=uuid.UUID("00020406-0000-0000-C000-000000000046"),
    opnums=ICREATETYPELIB_OPNUMS,
)


class DeleteTypeInfo_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("szName", "")]


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


class SetCustData_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("guid", GUID(), GUID),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pVarVal", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


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


class SetHelpStringContext_Request(NDRPacket):
    fields_desc = [NDRIntField("dwHelpStringContext", 0)]


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


class SetHelpStringDll_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("szFileName", "")]


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


ICREATETYPELIB2_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(CreateTypeInfo_Request, CreateTypeInfo_Response),
    4: DceRpcOp(SetName_Request, SetName_Response),
    5: DceRpcOp(SetVersion_Request, SetVersion_Response),
    6: DceRpcOp(SetGuid_Request, SetGuid_Response),
    7: DceRpcOp(SetDocString_Request, SetDocString_Response),
    8: DceRpcOp(SetHelpFileName_Request, SetHelpFileName_Response),
    9: DceRpcOp(SetHelpContext_Request, SetHelpContext_Response),
    10: DceRpcOp(SetLcid_Request, SetLcid_Response),
    11: DceRpcOp(SetLibFlags_Request, SetLibFlags_Response),
    12: DceRpcOp(SaveAllChanges_Request, SaveAllChanges_Response),
    13: DceRpcOp(DeleteTypeInfo_Request, DeleteTypeInfo_Response),
    14: DceRpcOp(SetCustData_Request, SetCustData_Response),
    15: DceRpcOp(SetHelpStringContext_Request, SetHelpStringContext_Response),
    16: DceRpcOp(SetHelpStringDll_Request, SetHelpStringDll_Response),
}
register_com_interface(
    name="ICreateTypeLib2",
    uuid=uuid.UUID("0002040F-0000-0000-C000-000000000046"),
    opnums=ICREATETYPELIB2_OPNUMS,
)


class CHANGEKIND(IntEnum):
    CHANGEKIND_ADDMEMBER = 1
    CHANGEKIND_DELETEMEMBER = 2
    CHANGEKIND_SETNAMES = 3
    CHANGEKIND_SETDOCUMENTATION = 4
    CHANGEKIND_GENERAL = 5
    CHANGEKIND_INVALIDATE = 6
    CHANGEKIND_CHANGEFAILED = 7
    CHANGEKIND_MAX = 8


class RequestTypeChange_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("changeKind", 0, CHANGEKIND),
        NDRPacketField("pTInfoBefore", MInterfacePointer(), MInterfacePointer),
        NDRConfVarStrNullFieldUtf16("pStrName", ""),
    ]


class RequestTypeChange_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pfCancel", 0), NDRIntField("status", 0)]


class AfterTypeChange_Request(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("changeKind", 0, CHANGEKIND),
        NDRPacketField("pTInfoAfter", MInterfacePointer(), MInterfacePointer),
        NDRConfVarStrNullFieldUtf16("pStrName", ""),
    ]


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


ITYPECHANGEEVENTS_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(RequestTypeChange_Request, RequestTypeChange_Response),
    4: DceRpcOp(AfterTypeChange_Request, AfterTypeChange_Response),
}
register_com_interface(
    name="ITypeChangeEvents",
    uuid=uuid.UUID("00020410-0000-0000-C000-000000000046"),
    opnums=ITYPECHANGEEVENTS_OPNUMS,
)


class GetGUID_Request(NDRPacket):
    fields_desc = []


class GetGUID_Response(NDRPacket):
    fields_desc = [NDRPacketField("pGUID", GUID(), GUID), NDRIntField("status", 0)]


class GetSource_Request(NDRPacket):
    fields_desc = []


class GetSource_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRShortField("pBstrSource", 0)),
        NDRIntField("status", 0),
    ]


class GetDescription_Request(NDRPacket):
    fields_desc = []


class GetDescription_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRShortField("pBstrDescription", 0)),
        NDRIntField("status", 0),
    ]


class GetHelpFile_Request(NDRPacket):
    fields_desc = []


class GetHelpFile_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRShortField("pBstrHelpFile", 0)),
        NDRIntField("status", 0),
    ]


class GetHelpContext_Request(NDRPacket):
    fields_desc = []


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


IERRORINFO_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetGUID_Request, GetGUID_Response),
    4: DceRpcOp(GetSource_Request, GetSource_Response),
    5: DceRpcOp(GetDescription_Request, GetDescription_Response),
    6: DceRpcOp(GetHelpFile_Request, GetHelpFile_Response),
    7: DceRpcOp(GetHelpContext_Request, GetHelpContext_Response),
}
register_com_interface(
    name="IErrorInfo",
    uuid=uuid.UUID("1CF2B120-547D-101B-8E65-08002B2BD119"),
    opnums=IERRORINFO_OPNUMS,
)


class SetGUID_Request(NDRPacket):
    fields_desc = [NDRPacketField("rguid", GUID(), GUID)]


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


class SetSource_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("szSource", "")]


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


class SetDescription_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("szDescription", "")]


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


class SetHelpFile_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("szHelpFile", "")]


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


class SetHelpContext_Request(NDRPacket):
    fields_desc = [NDRIntField("dwHelpContext", 0)]


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


ICREATEERRORINFO_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(SetGUID_Request, SetGUID_Response),
    4: DceRpcOp(SetSource_Request, SetSource_Response),
    5: DceRpcOp(SetDescription_Request, SetDescription_Response),
    6: DceRpcOp(SetHelpFile_Request, SetHelpFile_Response),
    7: DceRpcOp(SetHelpContext_Request, SetHelpContext_Response),
}
register_com_interface(
    name="ICreateErrorInfo",
    uuid=uuid.UUID("22F03340-547D-101B-8E65-08002B2BD119"),
    opnums=ICREATEERRORINFO_OPNUMS,
)


class InterfaceSupportsErrorInfo_Request(NDRPacket):
    fields_desc = [NDRPacketField("riid", GUID(), GUID)]


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


ISUPPORTERRORINFO_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(InterfaceSupportsErrorInfo_Request, InterfaceSupportsErrorInfo_Response)
}
register_com_interface(
    name="ISupportErrorInfo",
    uuid=uuid.UUID("DF0B3D60-548F-101B-8E65-08002B2BD119"),
    opnums=ISUPPORTERRORINFO_OPNUMS,
)


class CreateFromTypeInfo_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pTypeInfo", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("riid", GUID(), GUID),
    ]


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


ITYPEFACTORY_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(CreateFromTypeInfo_Request, CreateFromTypeInfo_Response)
}
register_com_interface(
    name="ITypeFactory",
    uuid=uuid.UUID("0000002E-0000-0000-C000-000000000046"),
    opnums=ITYPEFACTORY_OPNUMS,
)


class Size_Request(NDRPacket):
    fields_desc = [
        StrFixedLenField("pvType", "", length=0),
        NDRIntField("dwDestContext", 0),
        StrFixedLenField("pvDestContext", "", length=0),
    ]


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


class Marshal_Request(NDRPacket):
    fields_desc = [
        StrFixedLenField("pvType", "", length=0),
        NDRIntField("dwDestContext", 0),
        StrFixedLenField("pvDestContext", "", length=0),
        NDRIntField("cbBufferLength", 0),
    ]


class Marshal_Response(NDRPacket):
    fields_desc = [
        NDRByteField("pBuffer", 0),
        NDRIntField("pcbWritten", 0),
        NDRIntField("status", 0),
    ]


class Unmarshal_Request(NDRPacket):
    fields_desc = [
        NDRIntField("dwFlags", 0),
        NDRIntField("cbBufferLength", 0),
        NDRByteField("pBuffer", 0),
    ]


class Unmarshal_Response(NDRPacket):
    fields_desc = [
        StrFixedLenField("pvType", "", length=0),
        NDRIntField("pcbRead", 0),
        NDRIntField("status", 0),
    ]


class Free_Request(NDRPacket):
    fields_desc = [StrFixedLenField("pvType", "", length=0)]


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


ITYPEMARSHAL_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(Size_Request, Size_Response),
    4: DceRpcOp(Marshal_Request, Marshal_Response),
    5: DceRpcOp(Unmarshal_Request, Unmarshal_Response),
    6: DceRpcOp(Free_Request, Free_Response),
}
register_com_interface(
    name="ITypeMarshal",
    uuid=uuid.UUID("0000002D-0000-0000-C000-000000000046"),
    opnums=ITYPEMARSHAL_OPNUMS,
)


class RecordInit_Request(NDRPacket):
    fields_desc = []


class RecordInit_Response(NDRPacket):
    fields_desc = [StrFixedLenField("pvNew", "", length=0), NDRIntField("status", 0)]


class RecordClear_Request(NDRPacket):
    fields_desc = [StrFixedLenField("pvExisting", "", length=0)]


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


class RecordCopy_Request(NDRPacket):
    fields_desc = [StrFixedLenField("pvExisting", "", length=0)]


class RecordCopy_Response(NDRPacket):
    fields_desc = [StrFixedLenField("pvNew", "", length=0), NDRIntField("status", 0)]


class GetGuid_Request(NDRPacket):
    fields_desc = []


class GetGuid_Response(NDRPacket):
    fields_desc = [NDRPacketField("pguid", GUID(), GUID), NDRIntField("status", 0)]


class GetName_Request(NDRPacket):
    fields_desc = []


class GetName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRShortField("pbstrName", 0)),
        NDRIntField("status", 0),
    ]


class GetSize_Request(NDRPacket):
    fields_desc = []


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


class GetTypeInfo_Request(NDRPacket):
    fields_desc = []


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


class GetField_Request(NDRPacket):
    fields_desc = [
        StrFixedLenField("pvData", "", length=0),
        NDRConfVarStrNullFieldUtf16("szFieldName", ""),
    ]


class GetField_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pvarField", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRIntField("status", 0),
    ]


class GetFieldNoCopy_Request(NDRPacket):
    fields_desc = [
        StrFixedLenField("pvData", "", length=0),
        NDRConfVarStrNullFieldUtf16("szFieldName", ""),
    ]


class GetFieldNoCopy_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pvarField", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        StrFixedLenField("ppvDataCArray", "", length=0),
        NDRIntField("status", 0),
    ]


class PutField_Request(NDRPacket):
    fields_desc = [
        NDRIntField("wFlags", 0),
        StrFixedLenField("pvData", "", length=0),
        NDRConfVarStrNullFieldUtf16("szFieldName", ""),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pvarField", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


class PutField_Response(NDRPacket):
    fields_desc = [StrFixedLenField("pvData", "", length=0), NDRIntField("status", 0)]


class PutFieldNoCopy_Request(NDRPacket):
    fields_desc = [
        NDRIntField("wFlags", 0),
        StrFixedLenField("pvData", "", length=0),
        NDRConfVarStrNullFieldUtf16("szFieldName", ""),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pvarField", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


class PutFieldNoCopy_Response(NDRPacket):
    fields_desc = [StrFixedLenField("pvData", "", length=0), NDRIntField("status", 0)]


class GetFieldNames_Request(NDRPacket):
    fields_desc = [NDRIntField("pcNames", 0)]


class GetFieldNames_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcNames", None, size_of="rgBstrNames"),
        NDRConfVarFieldListField(
            "rgBstrNames",
            [],
            NDRFullPointerField(NDRShortField("", 0)),
            size_is=lambda pkt: pkt.pcNames,
            length_is=lambda pkt: pkt.pcNames,
        ),
        NDRIntField("status", 0),
    ]


class IsMatchingType_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pRecordInfo", MInterfacePointer(), MInterfacePointer)
    ]


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


class RecordCreate_Request(NDRPacket):
    fields_desc = []


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


class RecordCreateCopy_Request(NDRPacket):
    fields_desc = [StrFixedLenField("pvSource", "", length=0)]


class RecordCreateCopy_Response(NDRPacket):
    fields_desc = [StrFixedLenField("ppvDest", "", length=0), NDRIntField("status", 0)]


class RecordDestroy_Request(NDRPacket):
    fields_desc = [StrFixedLenField("pvRecord", "", length=0)]


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


IRECORDINFO_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(RecordInit_Request, RecordInit_Response),
    4: DceRpcOp(RecordClear_Request, RecordClear_Response),
    5: DceRpcOp(RecordCopy_Request, RecordCopy_Response),
    6: DceRpcOp(GetGuid_Request, GetGuid_Response),
    7: DceRpcOp(GetName_Request, GetName_Response),
    8: DceRpcOp(GetSize_Request, GetSize_Response),
    9: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    10: DceRpcOp(GetField_Request, GetField_Response),
    11: DceRpcOp(GetFieldNoCopy_Request, GetFieldNoCopy_Response),
    12: DceRpcOp(PutField_Request, PutField_Response),
    13: DceRpcOp(PutFieldNoCopy_Request, PutFieldNoCopy_Response),
    14: DceRpcOp(GetFieldNames_Request, GetFieldNames_Response),
    15: DceRpcOp(IsMatchingType_Request, IsMatchingType_Response),
    16: DceRpcOp(RecordCreate_Request, RecordCreate_Response),
    17: DceRpcOp(RecordCreateCopy_Request, RecordCreateCopy_Response),
    18: DceRpcOp(RecordDestroy_Request, RecordDestroy_Response),
}
register_com_interface(
    name="IRecordInfo",
    uuid=uuid.UUID("0000002F-0000-0000-C000-000000000046"),
    opnums=IRECORDINFO_OPNUMS,
)


class EXCEPINFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRShortField("wCode", 0),
        NDRShortField("wReserved", 0),
        NDRFullEmbPointerField(NDRShortField("bstrSource", 0)),
        NDRFullEmbPointerField(NDRShortField("bstrDescription", 0)),
        NDRFullEmbPointerField(NDRShortField("bstrHelpFile", 0)),
        NDRIntField("dwHelpContext", 0),
        NDRInt3264Field("pvReserved", 0),
        NDRInt3264Field("pfnDeferredFillIn", 0),
        NDRSignedIntField("scode", 0),
    ]


class AddError_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pszPropName", ""),
        NDRPacketField("pExcepInfo", EXCEPINFO(), EXCEPINFO),
    ]


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


IERRORLOG_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(AddError_Request, AddError_Response)
}
register_com_interface(
    name="IErrorLog",
    uuid=uuid.UUID("3127CA40-446E-11CE-8135-00AA004BB851"),
    opnums=IERRORLOG_OPNUMS,
)


class Read_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pszPropName", ""),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pVar", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRFullPointerField(
            NDRPacketField("pErrorLog", MInterfacePointer(), MInterfacePointer)
        ),
    ]


class Read_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pVar", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRIntField("status", 0),
    ]


class RemoteRead_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pszPropName", ""),
        NDRFullPointerField(
            NDRPacketField("pErrorLog", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("varType", 0),
        NDRPacketField("pUnkObj", MInterfacePointer(), MInterfacePointer),
    ]


class RemoteRead_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pVar", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
        NDRIntField("status", 0),
    ]


class Write_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pszPropName", ""),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pVar", wireVARIANTStr(), wireVARIANTStr)
            )
        ),
    ]


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


IPROPERTYBAG_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(Read_Request, Read_Response),
    4: DceRpcOp(RemoteRead_Request, RemoteRead_Response),
    5: DceRpcOp(Write_Request, Write_Response),
}
register_com_interface(
    name="IPropertyBag",
    uuid=uuid.UUID("55272A00-42CB-11CE-8135-00AA004BB851"),
    opnums=IPROPERTYBAG_OPNUMS,
)
