### ms-oaut.idl
"""
RPC definitions for the following interfaces:
- IDispatch (v0.0): 00020400-0000-0000-C000-000000000046
- ITypeLib (v0.0): 00020402-0000-0000-C000-000000000046
- ITypeInfo (v0.0): 00020401-0000-0000-C000-000000000046
- IEnumVARIANT (v0.0): 00020404-0000-0000-C000-000000000046
- ITypeComp (v0.0): 00020403-0000-0000-C000-000000000046
- ITypeInfo2 (v0.0): 00020412-0000-0000-C000-000000000046
- ITypeLib2 (v0.0): 00020411-0000-0000-C000-000000000046
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import PacketListField, StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRConfVarFieldListField,
    NDRConfVarPacketListField,
    NDRConfVarStrLenField,
    NDRConfVarStrLenFieldUtf16,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRInt3264Field,
    NDRIntEnumField,
    NDRIntField,
    NDRPacketField,
    NDRRecursiveField,
    NDRRefEmbPointerField,
    NDRShortField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRSignedShortField,
    NDRUnionField,
    register_com_interface,
)


class GetTypeInfoCount_Request(NDRPacket):
    fields_desc = []


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


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


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


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


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


class GetIDsOfNames_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("riid", GUID(), GUID),
        NDRConfVarStrLenFieldUtf16("rgszNames", "", size_is=lambda pkt: pkt.cNames),
        NDRIntField("cNames", None, size_of="rgszNames"),
        NDRIntField("lcid", 0),
    ]


class GetIDsOfNames_Response(NDRPacket):
    fields_desc = [
        NDRConfFieldListField(
            "rgDispId", [], NDRSignedIntField("", 0), size_is=lambda pkt: pkt.cNames
        ),
        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 FLAGGED_WORD_BLOB(NDRPacket):
    ALIGNMENT = (4, 8)
    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 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 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
            ),
            deferred=True,
        ),
    ]


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
            ),
            deferred=True,
        ),
    ]


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
            ),
            deferred=True,
        ),
    ]


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


class DISPPARAMS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfPacketListField(
                "rgvarg",
                [],
                wireVARIANTStr,
                size_is=lambda pkt: pkt.cArgs,
                ptr_pack=True,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfFieldListField(
                "rgdispidNamedArgs",
                [],
                NDRSignedIntField("rgdispidNamedArgs", 0),
                size_is=lambda pkt: pkt.cNamedArgs,
            ),
            deferred=True,
        ),
        NDRIntField("cArgs", None, size_of="rgvarg"),
        NDRIntField("cNamedArgs", None, size_of="rgdispidNamedArgs"),
    ]


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


class Invoke_Request(NDRPacket):
    fields_desc = [
        NDRSignedIntField("dispIdMember", 0),
        NDRPacketField("riid", GUID(), GUID),
        NDRIntField("lcid", 0),
        NDRIntField("dwFlags", 0),
        NDRPacketField("pDispParams", DISPPARAMS(), DISPPARAMS),
        NDRIntField("cVarRef", None, size_of="rgVarRef"),
        NDRConfFieldListField(
            "rgVarRefIdx", [], NDRIntField("", 0), size_is=lambda pkt: pkt.cVarRef
        ),
        NDRConfPacketListField(
            "rgVarRef",
            [],
            wireVARIANTStr,
            size_is=lambda pkt: pkt.cVarRef,
            ptr_pack=True,
        ),
    ]


class Invoke_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pVarResult", wireVARIANTStr(), wireVARIANTStr)
        ),
        NDRPacketField("pExcepInfo", EXCEPINFO(), EXCEPINFO),
        NDRIntField("pArgErr", 0),
        NDRConfPacketListField(
            "rgVarRef",
            [],
            wireVARIANTStr,
            size_is=lambda pkt: pkt.cVarRef,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


IDISPATCH_OPNUMS = {
    0: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    1: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    2: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    3: DceRpcOp(Invoke_Request, Invoke_Response),
}
register_com_interface(
    name="IDispatch",
    uuid=uuid.UUID("00020400-0000-0000-C000-000000000046"),
    opnums=IDISPATCH_OPNUMS,
)


class GetTypeInfoCount_Request(NDRPacket):
    fields_desc = []


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


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


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


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 GetTypeInfoType_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0)]


class GetTypeInfoType_Response(NDRPacket):
    fields_desc = [NDRIntEnumField("pTKind", 0, TYPEKIND), NDRIntField("status", 0)]


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


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


class SYSKIND(IntEnum):
    SYS_WIN32 = 1
    SYS_WIN64 = 3


class LPTLIBATTR(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("guid", GUID(), GUID),
        NDRIntField("lcid", 0),
        NDRIntEnumField("syskind", 0, SYSKIND),
        NDRShortField("wMajorVerNum", 0),
        NDRShortField("wMinorVerNum", 0),
        NDRShortField("wLibFlags", 0),
    ]


class GetLibAttr_Request(NDRPacket):
    fields_desc = []


class GetLibAttr_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("ppTLibAttr", LPTLIBATTR(), LPTLIBATTR)),
        NDRIntField("pReserved", 0),
        NDRIntField("status", 0),
    ]


class GetTypeComp_Request(NDRPacket):
    fields_desc = []


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


class GetDocumentation_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("index", 0), NDRIntField("refPtrFlags", 0)]


class GetDocumentation_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pBstrName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("pBstrDocString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("pdwHelpContext", 0),
        NDRFullPointerField(
            NDRPacketField("pBstrHelpFile", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("status", 0),
    ]


class IsName_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("szNameBuf", ""),
        NDRIntField("lHashVal", 0),
    ]


class IsName_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("pfName", 0),
        NDRFullPointerField(
            NDRPacketField("pBstrNameInLibrary", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("status", 0),
    ]


class FindName_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("szNameBuf", ""),
        NDRIntField("lHashVal", 0),
        NDRShortField("pcFound", 0),
    ]


class FindName_Response(NDRPacket):
    fields_desc = [
        NDRConfVarPacketListField(
            "ppTInfo",
            [],
            MInterfacePointer,
            size_is=lambda pkt: pkt.pcFound,
            length_is=lambda pkt: pkt.pcFound,
            ptr_pack=True,
        ),
        NDRConfVarFieldListField(
            "rgMemId",
            [],
            NDRSignedIntField("", 0),
            size_is=lambda pkt: pkt.pcFound,
            length_is=lambda pkt: pkt.pcFound,
        ),
        NDRShortField("pcFound", None, size_of="rgMemId"),
        NDRFullPointerField(
            NDRPacketField("pBstrNameInLibrary", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("status", 0),
    ]


ITYPELIB_OPNUMS = {
    0: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    1: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    2: DceRpcOp(GetTypeInfoType_Request, GetTypeInfoType_Response),
    3: DceRpcOp(GetTypeInfoOfGuid_Request, GetTypeInfoOfGuid_Response),
    4: DceRpcOp(GetLibAttr_Request, GetLibAttr_Response),
    5: DceRpcOp(GetTypeComp_Request, GetTypeComp_Response),
    6: DceRpcOp(GetDocumentation_Request, GetDocumentation_Response),
    7: DceRpcOp(IsName_Request, IsName_Response),
    8: DceRpcOp(FindName_Request, FindName_Response),
    # 9: Opnum12NotUsedOnWire
}
register_com_interface(
    name="ITypeLib",
    uuid=uuid.UUID("00020402-0000-0000-C000-000000000046"),
    opnums=ITYPELIB_OPNUMS,
)


class TYPEDESC(NDRPacket):
    ALIGNMENT = (2, 2)
    fields_desc = [NDRRecursiveField("_tdUnion"), NDRShortField("vt", 0)]


class LPTYPEATTR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("guid", GUID(), GUID),
        NDRIntField("lcid", 0),
        NDRIntField("dwReserved1", 0),
        NDRIntField("dwReserved2", 0),
        NDRIntField("dwReserved3", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpstrReserved4", ""), deferred=True
        ),
        NDRIntField("cbSizeInstance", 0),
        NDRIntEnumField("typekind", 0, TYPEKIND),
        NDRShortField("cFuncs", 0),
        NDRShortField("cVars", 0),
        NDRShortField("cImplTypes", 0),
        NDRShortField("cbSizeVft", 0),
        NDRShortField("cbAlignment", 0),
        NDRShortField("wTypeFlags", 0),
        NDRShortField("wMajorVerNum", 0),
        NDRShortField("wMinorVerNum", 0),
        NDRPacketField("tdescAlias", TYPEDESC(), TYPEDESC),
        NDRIntField("dwReserved5", 0),
        NDRShortField("wReserved6", 0),
    ]


class GetTypeAttr_Request(NDRPacket):
    fields_desc = []


class GetTypeAttr_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("ppTypeAttr", LPTYPEATTR(), LPTYPEATTR)),
        NDRIntField("pReserved", 0),
        NDRIntField("status", 0),
    ]


class GetTypeComp_Request(NDRPacket):
    fields_desc = []


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


class PARAMDESCEX(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cBytes", 0),
        NDRFullPointerField(
            NDRPacketField("varDefaultValue", wireVARIANTStr(), wireVARIANTStr),
            deferred=True,
        ),
    ]


class PARAMDESC(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pparamdescex", PARAMDESCEX(), PARAMDESCEX), deferred=True
        ),
        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 LPFUNCDESC(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRSignedIntField("memid", 0),
        NDRFullPointerField(
            NDRConfFieldListField(
                "lReserved1",
                [],
                NDRSignedIntField("lReserved1", 0),
                size_is=lambda pkt: pkt.cReserved2,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfPacketListField(
                "lprgelemdescParam", [], ELEMDESC, size_is=lambda pkt: pkt.cParams
            ),
            deferred=True,
        ),
        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 GetFuncDesc_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0)]


class GetFuncDesc_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("ppFuncDesc", LPFUNCDESC(), LPFUNCDESC)),
        NDRIntField("pReserved", 0),
        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 LPVARDESC(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRSignedIntField("memid", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpstrReserved", ""), deferred=True
        ),
        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,
                            ]
                        ),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRFullPointerField(
                            NDRPacketField(
                                "_vdUnion", wireVARIANTStr(), wireVARIANTStr
                            ),
                            deferred=True,
                        ),
                        deferred=True,
                    ),
                    (
                        (
                            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 GetVarDesc_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0)]


class GetVarDesc_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("ppVarDesc", LPVARDESC(), LPVARDESC)),
        NDRIntField("pReserved", 0),
        NDRIntField("status", 0),
    ]


class GetNames_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("memid", 0), NDRIntField("cMaxNames", 0)]


class GetNames_Response(NDRPacket):
    fields_desc = [
        NDRConfVarPacketListField(
            "rgBstrNames",
            [],
            FLAGGED_WORD_BLOB,
            size_is=lambda pkt: pkt.cMaxNames,
            length_is=lambda pkt: pkt.pcNames,
            ptr_pack=True,
        ),
        NDRIntField("pcNames", None, size_of="rgBstrNames"),
        NDRIntField("status", 0),
    ]


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


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


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


class GetImplTypeFlags_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pImplTypeFlags", 0), NDRIntField("status", 0)]


class GetDocumentation_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("memid", 0), NDRIntField("refPtrFlags", 0)]


class GetDocumentation_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pBstrName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("pBstrDocString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("pdwHelpContext", 0),
        NDRFullPointerField(
            NDRPacketField("pBstrHelpFile", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("status", 0),
    ]


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


class GetDllEntry_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pBstrDllName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("pBstrName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRShortField("pwOrdinal", 0),
        NDRIntField("status", 0),
    ]


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


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


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


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


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


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


class GetContainingTypeLib_Request(NDRPacket):
    fields_desc = []


class GetContainingTypeLib_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppTLib", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("pIndex", 0),
        NDRIntField("status", 0),
    ]


ITYPEINFO_OPNUMS = {
    0: DceRpcOp(GetTypeAttr_Request, GetTypeAttr_Response),
    1: DceRpcOp(GetTypeComp_Request, GetTypeComp_Response),
    2: DceRpcOp(GetFuncDesc_Request, GetFuncDesc_Response),
    3: DceRpcOp(GetVarDesc_Request, GetVarDesc_Response),
    4: DceRpcOp(GetNames_Request, GetNames_Response),
    5: DceRpcOp(GetRefTypeOfImplType_Request, GetRefTypeOfImplType_Response),
    6: DceRpcOp(GetImplTypeFlags_Request, GetImplTypeFlags_Response),
    # 7: Opnum10NotUsedOnWire,
    # 8: Opnum11NotUsedOnWire,
    9: DceRpcOp(GetDocumentation_Request, GetDocumentation_Response),
    10: DceRpcOp(GetDllEntry_Request, GetDllEntry_Response),
    11: DceRpcOp(GetRefTypeInfo_Request, GetRefTypeInfo_Response),
    # 12: Opnum15NotUsedOnWire,
    13: DceRpcOp(CreateInstance_Request, CreateInstance_Response),
    14: DceRpcOp(GetMops_Request, GetMops_Response),
    15: DceRpcOp(GetContainingTypeLib_Request, GetContainingTypeLib_Response),
    # 16: Opnum19NotUsedOnWire,
    # 17: Opnum20NotUsedOnWire,
    # 18: Opnum21NotUsedOnWire
}
register_com_interface(
    name="ITypeInfo",
    uuid=uuid.UUID("00020401-0000-0000-C000-000000000046"),
    opnums=ITYPEINFO_OPNUMS,
)


class Next_Request(NDRPacket):
    fields_desc = [NDRIntField("celt", 0)]


class Next_Response(NDRPacket):
    fields_desc = [
        NDRConfVarPacketListField(
            "rgVar",
            [],
            wireVARIANTStr,
            size_is=lambda pkt: pkt.celt,
            length_is=lambda pkt: pkt.pCeltFetched,
            ptr_pack=True,
        ),
        NDRIntField("pCeltFetched", None, size_of="rgVar"),
        NDRIntField("status", 0),
    ]


class Skip_Request(NDRPacket):
    fields_desc = [NDRIntField("celt", 0)]


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


class Reset_Request(NDRPacket):
    fields_desc = []


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


class Clone_Request(NDRPacket):
    fields_desc = []


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


IENUMVARIANT_OPNUMS = {
    0: DceRpcOp(Next_Request, Next_Response),
    1: DceRpcOp(Skip_Request, Skip_Response),
    2: DceRpcOp(Reset_Request, Reset_Response),
    3: DceRpcOp(Clone_Request, Clone_Response),
}
register_com_interface(
    name="IEnumVARIANT",
    uuid=uuid.UUID("00020404-0000-0000-C000-000000000046"),
    opnums=IENUMVARIANT_OPNUMS,
)


class DESCKIND(IntEnum):
    DESCKIND_NONE = 0
    DESCKIND_FUNCDESC = 1
    DESCKIND_VARDESC = 2
    DESCKIND_TYPECOMP = 3
    DESCKIND_IMPLICITAPPOBJ = 4


class Bind_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("szName", ""),
        NDRIntField("lHashVal", 0),
        NDRShortField("wFlags", 0),
    ]


class Bind_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppTInfo", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntEnumField("pDescKind", 0, DESCKIND),
        NDRFullPointerField(NDRPacketField("ppFuncDesc", LPFUNCDESC(), LPFUNCDESC)),
        NDRFullPointerField(NDRPacketField("ppVarDesc", LPVARDESC(), LPVARDESC)),
        NDRFullPointerField(
            NDRPacketField("ppTypeComp", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("pReserved", 0),
        NDRIntField("status", 0),
    ]


class BindType_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("szName", ""),
        NDRIntField("lHashVal", 0),
    ]


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


ITYPECOMP_OPNUMS = {
    0: DceRpcOp(Bind_Request, Bind_Response),
    1: DceRpcOp(BindType_Request, BindType_Response),
}
register_com_interface(
    name="ITypeComp",
    uuid=uuid.UUID("00020403-0000-0000-C000-000000000046"),
    opnums=ITYPECOMP_OPNUMS,
)


class GetTypeKind_Request(NDRPacket):
    fields_desc = []


class GetTypeKind_Response(NDRPacket):
    fields_desc = [NDRIntEnumField("pTypeKind", 0, TYPEKIND), NDRIntField("status", 0)]


class GetTypeFlags_Request(NDRPacket):
    fields_desc = []


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


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


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


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


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


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


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


class GetFuncCustData_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRPacketField("guid", GUID(), GUID)]


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


class GetParamCustData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("indexFunc", 0),
        NDRIntField("indexParam", 0),
        NDRPacketField("guid", GUID(), GUID),
    ]


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


class GetVarCustData_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRPacketField("guid", GUID(), GUID)]


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


class GetImplTypeCustData_Request(NDRPacket):
    fields_desc = [NDRIntField("index", 0), NDRPacketField("guid", GUID(), GUID)]


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


class GetDocumentation2_Request(NDRPacket):
    fields_desc = [
        NDRSignedIntField("memid", 0),
        NDRIntField("lcid", 0),
        NDRIntField("refPtrFlags", 0),
    ]


class GetDocumentation2_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pbstrHelpString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("pdwHelpStringContext", 0),
        NDRFullPointerField(
            NDRPacketField("pbstrHelpStringDll", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("status", 0),
    ]


class CUSTDATAITEM(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("guid", GUID(), GUID),
        NDRFullPointerField(
            NDRPacketField("varValue", wireVARIANTStr(), wireVARIANTStr), deferred=True
        ),
    ]


class CUSTDATA(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cCustData", None, size_of="prgCustData"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "prgCustData", [], CUSTDATAITEM, size_is=lambda pkt: pkt.cCustData
            ),
            deferred=True,
        ),
    ]


class GetAllCustData_Request(NDRPacket):
    fields_desc = []


class GetAllCustData_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pCustData", CUSTDATA(), CUSTDATA),
        NDRIntField("status", 0),
    ]


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


class GetAllFuncCustData_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pCustData", CUSTDATA(), CUSTDATA),
        NDRIntField("status", 0),
    ]


class GetAllParamCustData_Request(NDRPacket):
    fields_desc = [NDRIntField("indexFunc", 0), NDRIntField("indexParam", 0)]


class GetAllParamCustData_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pCustData", CUSTDATA(), CUSTDATA),
        NDRIntField("status", 0),
    ]


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


class GetAllVarCustData_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pCustData", CUSTDATA(), CUSTDATA),
        NDRIntField("status", 0),
    ]


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


class GetAllImplTypeCustData_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pCustData", CUSTDATA(), CUSTDATA),
        NDRIntField("status", 0),
    ]


ITYPEINFO2_OPNUMS = {
    0: DceRpcOp(GetTypeKind_Request, GetTypeKind_Response),
    1: DceRpcOp(GetTypeFlags_Request, GetTypeFlags_Response),
    2: DceRpcOp(GetFuncIndexOfMemId_Request, GetFuncIndexOfMemId_Response),
    3: DceRpcOp(GetVarIndexOfMemId_Request, GetVarIndexOfMemId_Response),
    4: DceRpcOp(GetCustData_Request, GetCustData_Response),
    5: DceRpcOp(GetFuncCustData_Request, GetFuncCustData_Response),
    6: DceRpcOp(GetParamCustData_Request, GetParamCustData_Response),
    7: DceRpcOp(GetVarCustData_Request, GetVarCustData_Response),
    8: DceRpcOp(GetImplTypeCustData_Request, GetImplTypeCustData_Response),
    9: DceRpcOp(GetDocumentation2_Request, GetDocumentation2_Response),
    10: DceRpcOp(GetAllCustData_Request, GetAllCustData_Response),
    11: DceRpcOp(GetAllFuncCustData_Request, GetAllFuncCustData_Response),
    12: DceRpcOp(GetAllParamCustData_Request, GetAllParamCustData_Response),
    13: DceRpcOp(GetAllVarCustData_Request, GetAllVarCustData_Response),
    14: DceRpcOp(GetAllImplTypeCustData_Request, GetAllImplTypeCustData_Response),
}
register_com_interface(
    name="ITypeInfo2",
    uuid=uuid.UUID("00020412-0000-0000-C000-000000000046"),
    opnums=ITYPEINFO2_OPNUMS,
)


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


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


class GetLibStatistics_Request(NDRPacket):
    fields_desc = []


class GetLibStatistics_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcUniqueNames", 0),
        NDRIntField("pcchUniqueNames", 0),
        NDRIntField("status", 0),
    ]


class GetDocumentation2_Request(NDRPacket):
    fields_desc = [
        NDRSignedIntField("index", 0),
        NDRIntField("lcid", 0),
        NDRIntField("refPtrFlags", 0),
    ]


class GetDocumentation2_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pbstrHelpString", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("pdwHelpStringContext", 0),
        NDRFullPointerField(
            NDRPacketField("pbstrHelpStringDll", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("status", 0),
    ]


class GetAllCustData_Request(NDRPacket):
    fields_desc = []


class GetAllCustData_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pCustData", CUSTDATA(), CUSTDATA),
        NDRIntField("status", 0),
    ]


ITYPELIB2_OPNUMS = {
    0: DceRpcOp(GetCustData_Request, GetCustData_Response),
    1: DceRpcOp(GetLibStatistics_Request, GetLibStatistics_Response),
    2: DceRpcOp(GetDocumentation2_Request, GetDocumentation2_Response),
    3: DceRpcOp(GetAllCustData_Request, GetAllCustData_Response),
}
register_com_interface(
    name="ITypeLib2",
    uuid=uuid.UUID("00020411-0000-0000-C000-000000000046"),
    opnums=ITYPELIB2_OPNUMS,
)
