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

# [ms-wsrm] v14.2 (Thu, 01 Jun 2017)

"""
RPC definitions for the following interfaces:
- IUnknown (v0.0): 00000000-0000-0000-C000-000000000046
- IDispatch (v0.0): 00020400-0000-0000-C000-000000000046
- IResourceManager (v0.0): C5CEBEE2-9DF5-4CDD-A08C-C2471BC144B4
- IWRMCalendar (v0.0): 481E06CF-AB04-4498-8FFE-124A0A34296D
- IWRMPolicy (v0.0): 59602EB6-57B0-4FD8-AA4B-EBF06971FE15
- IWRMResourceGroup (v0.0): BC681469-9DD9-4BF4-9B3D-709F69EFE431
- IWRMAccounting (v0.0): 4F7CA01C-A9E5-45B6-B142-2332A1339C1D
- IWRMConfig (v0.0): 21546AE8-4DA5-445E-987F-627FEA39C5E8
- IWRMProtocol (v0.0): F31931A9-832D-481C-9503-887A0E6A79F0
- IWRMMachineGroup (v0.0): 943991a5-b3fe-41fa-9696-7f7b656ee34b
- IResourceManager2 (v0.0): 2A3EB639-D134-422d-90D8-AAA1B5216202
- IWRMRemoteSessionMgmt (v0.0): FC910418-55CA-45ef-B264-83D4CE7D30E0
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullEmbPointerField,
    NDRFullPointerField,
    NDRIEEEDoubleField,
    NDRIEEEFloatField,
    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 GetTypeInfoCount_Request(NDRPacket):
    fields_desc = []


class GetTypeInfoCount_Response(NDRPacket):
    fields_desc = [NDRIntField("pctinfo", 0), 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 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),
        NDRConfFieldListField(
            "rgszNames",
            [],
            NDRFullPointerField(NDRConfVarStrNullFieldUtf16("", "")),
            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, 4)
    DEPORTED_CONFORMANTS = ["asData"]
    fields_desc = [
        NDRIntField("cBytes", 0),
        NDRIntField("clSize", None, size_of="asData"),
        NDRConfStrLenFieldUtf16(
            "asData", "", size_is=lambda pkt: pkt.clSize, conformant_in_struct=True
        ),
    ]


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


class DISPPARAMS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullEmbPointerField(
            NDRConfPacketListField(
                "rgvarg", [], wireVARIANTStr, size_is=lambda pkt: pkt.cArgs, ptr_lvl=1
            )
        ),
        NDRFullEmbPointerField(
            NDRConfFieldListField(
                "rgdispidNamedArgs",
                [],
                NDRSignedIntField("", 0),
                size_is=lambda pkt: pkt.cNamedArgs,
            )
        ),
        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),
        NDRFullEmbPointerField(
            NDRPacketField("bstrSource", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullEmbPointerField(
            NDRPacketField("bstrDescription", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullEmbPointerField(
            NDRPacketField("bstrHelpFile", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        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_lvl=1
        ),
    ]


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


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


class RetrieveEventList_Request(NDRPacket):
    fields_desc = []


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


class GetSystemAffinity_Request(NDRPacket):
    fields_desc = []


class GetSystemAffinity_Response(NDRPacket):
    fields_desc = [NDRLongField("pdwSysAffinity", 0), NDRIntField("status", 0)]


class ImportXMLFiles_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPMCXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrPolicyXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrCalendarXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrConditionalXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
    ]


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


class ExportXMLFiles_Request(NDRPacket):
    fields_desc = []


class ExportXMLFiles_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pbstrPMCXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pbstrPolicyXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "pbstrCalendarXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                )
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "pbstrConditionalXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                )
            )
        ),
        NDRIntField("status", 0),
    ]


class RESTORE_MODE(IntEnum):
    RESTORE_LAST_GOOD_STATE = 1
    RESTORE_EMPTY_FILES = 2


class RestoreXMLFiles_Request(NDRPacket):
    fields_desc = [NDRIntEnumField("enumRestore", 0, RESTORE_MODE)]


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


class OBJECT_TYPE(IntEnum):
    OBJECT_SELECTION_CRITERIA = 1
    OBJECT_POLICY = 2
    OBJECT_SCHEDULE = 3


class GetDependencies_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrObjectName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntEnumField("enumObject", 0, OBJECT_TYPE),
    ]


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


class GetServiceList_Request(NDRPacket):
    fields_desc = []


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


class GetIISAppPoolNames_Request(NDRPacket):
    fields_desc = []


class GetIISAppPoolNames_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "pbstrIISAppPoolList", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                )
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "pbstrSystemDirectory", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                )
            )
        ),
        NDRIntField("status", 0),
    ]


class GetServerName_Request(NDRPacket):
    fields_desc = []


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


class GetCurrentMemory_Request(NDRPacket):
    fields_desc = []


class GetCurrentMemory_Response(NDRPacket):
    fields_desc = [NDRLongField("pdwCurrMemory", 0), NDRIntField("status", 0)]


IRESOURCEMANAGER_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    4: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    5: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    6: DceRpcOp(Invoke_Request, Invoke_Response),
    7: DceRpcOp(RetrieveEventList_Request, RetrieveEventList_Response),
    8: DceRpcOp(GetSystemAffinity_Request, GetSystemAffinity_Response),
    9: DceRpcOp(ImportXMLFiles_Request, ImportXMLFiles_Response),
    10: DceRpcOp(ExportXMLFiles_Request, ExportXMLFiles_Response),
    11: DceRpcOp(RestoreXMLFiles_Request, RestoreXMLFiles_Response),
    12: DceRpcOp(GetDependencies_Request, GetDependencies_Response),
    13: DceRpcOp(GetServiceList_Request, GetServiceList_Response),
    14: DceRpcOp(GetIISAppPoolNames_Request, GetIISAppPoolNames_Response),
    15: DceRpcOp(GetServerName_Request, GetServerName_Response),
    16: DceRpcOp(GetCurrentMemory_Request, GetCurrentMemory_Response),
}
register_com_interface(
    name="IResourceManager",
    uuid=uuid.UUID("C5CEBEE2-9DF5-4CDD-A08C-C2471BC144B4"),
    opnums=IRESOURCEMANAGER_OPNUMS,
)


class GetCalendarInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrCalendarName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class CreateCalendar_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrCalendarXML", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("bChangeActivePolicy", 0),
    ]


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


class ModifyCalendar_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrCalendarXML", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("bOverwrite", 0),
        NDRSignedIntField("bChangeActivePolicy", 0),
    ]


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


class DeleteCalendar_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrCalendarName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("bChangeActivePolicy", 0),
    ]


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


class RenameCalendar_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrOldCalendarName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrNewCalendarName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
    ]


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


class ComputeEvents_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("szStartTime", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("szEndTime", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("fMergeEvents", 0),
    ]


class ComputeEvents_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pbstrEvents", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pbstrConflicts", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
            )
        ),
        NDRIntField("status", 0),
    ]


class GetScheduleInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrScheduleName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class CreateSchedule_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrScheduleXML", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class ModifySchedule_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrScheduleXML", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("bOverwrite", 0),
        NDRSignedIntField("bChangeActivePolicy", 0),
    ]


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


class DeleteSchedule_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrScheduleName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class RenameSchedule_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrOldScheduleName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrNewScheduleName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
    ]


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


class MoveBeforeCalendar_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrCalendarName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrRefCalendarName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRSignedIntField("bChangeActivePolicy", 0),
    ]


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


class MoveAfterCalendar_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrCalendarName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrRefCalendarName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRSignedIntField("bChangeActivePolicy", 0),
    ]


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


class GetServerTimeZone_Request(NDRPacket):
    fields_desc = []


class GetServerTimeZone_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pnServerTimeZone", 0), NDRIntField("status", 0)]


IWRMCALENDAR_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    4: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    5: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    6: DceRpcOp(Invoke_Request, Invoke_Response),
    7: DceRpcOp(GetCalendarInfo_Request, GetCalendarInfo_Response),
    8: DceRpcOp(CreateCalendar_Request, CreateCalendar_Response),
    9: DceRpcOp(ModifyCalendar_Request, ModifyCalendar_Response),
    10: DceRpcOp(DeleteCalendar_Request, DeleteCalendar_Response),
    11: DceRpcOp(RenameCalendar_Request, RenameCalendar_Response),
    12: DceRpcOp(ComputeEvents_Request, ComputeEvents_Response),
    13: DceRpcOp(GetScheduleInfo_Request, GetScheduleInfo_Response),
    14: DceRpcOp(CreateSchedule_Request, CreateSchedule_Response),
    15: DceRpcOp(ModifySchedule_Request, ModifySchedule_Response),
    16: DceRpcOp(DeleteSchedule_Request, DeleteSchedule_Response),
    17: DceRpcOp(RenameSchedule_Request, RenameSchedule_Response),
    18: DceRpcOp(MoveBeforeCalendar_Request, MoveBeforeCalendar_Response),
    19: DceRpcOp(MoveAfterCalendar_Request, MoveAfterCalendar_Response),
    20: DceRpcOp(GetServerTimeZone_Request, GetServerTimeZone_Response),
}
register_com_interface(
    name="IWRMCalendar",
    uuid=uuid.UUID("481E06CF-AB04-4498-8FFE-124A0A34296D"),
    opnums=IWRMCALENDAR_OPNUMS,
)


class GetPolicyInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class CreatePolicy_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPolicyInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class ModifyPolicy_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPolicyInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("bOverwrite", 0),
    ]


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


class DeletePolicy_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class RenameAllocationPolicy_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrNewPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrOldPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
    ]


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


class MoveBefore_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrResourceGroupName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrRefResourceGroupName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
    ]


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


class MoveAfter_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrResourceGroupName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrRefResourceGroupName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
    ]


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


class SetCalDefaultPolicyName_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrDefaultPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        )
    ]


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


class GetCalDefaultPolicyName_Request(NDRPacket):
    fields_desc = []


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


class GetProcessList_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class MANAGEMENT_TYPE(IntEnum):
    MANUAL_ACTIVE_POLICY = 1
    CALENDAR_POLICY = 2
    PROFILING = 3


class GetCurrentPolicy_Request(NDRPacket):
    fields_desc = []


class GetCurrentPolicy_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "pbstrCurrentPolicyInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                )
            )
        ),
        NDRIntEnumField("enumManage", 0, MANAGEMENT_TYPE),
        NDRIntField("status", 0),
    ]


class SetCurrentPolicy_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntEnumField("enumManage", 0, MANAGEMENT_TYPE),
    ]


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


class GetCurrentStateAndActivePolicyName_Request(NDRPacket):
    fields_desc = []


class GetCurrentStateAndActivePolicyName_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "pbstrCurrentPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                )
            )
        ),
        NDRIntEnumField("enumManage", 0, MANAGEMENT_TYPE),
        NDRIntField("status", 0),
    ]


class GetConditionalPolicy_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPolicyName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class SetConditionalPolicy_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPolicyInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


IWRMPOLICY_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    4: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    5: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    6: DceRpcOp(Invoke_Request, Invoke_Response),
    7: DceRpcOp(GetPolicyInfo_Request, GetPolicyInfo_Response),
    8: DceRpcOp(CreatePolicy_Request, CreatePolicy_Response),
    9: DceRpcOp(ModifyPolicy_Request, ModifyPolicy_Response),
    10: DceRpcOp(DeletePolicy_Request, DeletePolicy_Response),
    11: DceRpcOp(RenameAllocationPolicy_Request, RenameAllocationPolicy_Response),
    12: DceRpcOp(MoveBefore_Request, MoveBefore_Response),
    13: DceRpcOp(MoveAfter_Request, MoveAfter_Response),
    14: DceRpcOp(SetCalDefaultPolicyName_Request, SetCalDefaultPolicyName_Response),
    15: DceRpcOp(GetCalDefaultPolicyName_Request, GetCalDefaultPolicyName_Response),
    16: DceRpcOp(GetProcessList_Request, GetProcessList_Response),
    17: DceRpcOp(GetCurrentPolicy_Request, GetCurrentPolicy_Response),
    18: DceRpcOp(SetCurrentPolicy_Request, SetCurrentPolicy_Response),
    19: DceRpcOp(
        GetCurrentStateAndActivePolicyName_Request,
        GetCurrentStateAndActivePolicyName_Response,
    ),
    20: DceRpcOp(GetConditionalPolicy_Request, GetConditionalPolicy_Response),
    21: DceRpcOp(SetConditionalPolicy_Request, SetConditionalPolicy_Response),
}
register_com_interface(
    name="IWRMPolicy",
    uuid=uuid.UUID("59602EB6-57B0-4FD8-AA4B-EBF06971FE15"),
    opnums=IWRMPOLICY_OPNUMS,
)


class GetResourceGroupInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrResourceGroupName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        )
    ]


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


class ModifyResourceGroup_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrResourceGroupInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRSignedIntField("bOverwrite", 0),
    ]


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


class CreateResourceGroup_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrResourceGroupInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        )
    ]


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


class DeleteResourceGroup_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrResourceGroupName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        )
    ]


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


class RenameResourceGroup_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrNewResourceGroupName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrOldResourceGroupName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
    ]


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


IWRMRESOURCEGROUP_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    4: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    5: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    6: DceRpcOp(Invoke_Request, Invoke_Response),
    7: DceRpcOp(GetResourceGroupInfo_Request, GetResourceGroupInfo_Response),
    8: DceRpcOp(ModifyResourceGroup_Request, ModifyResourceGroup_Response),
    9: DceRpcOp(CreateResourceGroup_Request, CreateResourceGroup_Response),
    10: DceRpcOp(DeleteResourceGroup_Request, DeleteResourceGroup_Response),
    11: DceRpcOp(RenameResourceGroup_Request, RenameResourceGroup_Response),
}
register_com_interface(
    name="IWRMResourceGroup",
    uuid=uuid.UUID("BC681469-9DD9-4BF4-9B3D-709F69EFE431"),
    opnums=IWRMRESOURCEGROUP_OPNUMS,
)


class CreateAccountingDb_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrServerName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("bWindowsAuth", 0),
        NDRFullPointerField(
            NDRPacketField("bstrUserName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrPasswd", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
    ]


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


class GetAccountingMetadata_Request(NDRPacket):
    fields_desc = []


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


class ExecuteAccountingQuery_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrAccountingQuery", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField("bstrStartingDate", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrEndingDate", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
    ]


class ExecuteAccountingQuery_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pbstrResult", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
            )
        ),
        NDRSignedIntField("pbIsThereMoreData", 0),
        NDRIntField("status", 0),
    ]


class GetRawAccountingData_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrStartingDate", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrEndingDate", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrMachineName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
    ]


class GetRawAccountingData_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pbstrResult", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
            )
        ),
        NDRSignedIntField("pbIsThereMoreData", 0),
        NDRIntField("status", 0),
    ]


class GetNextAccountingDataBatch_Request(NDRPacket):
    fields_desc = []


class GetNextAccountingDataBatch_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pbstrResult", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
            )
        ),
        NDRSignedIntField("pbIsThereMoreData", 0),
        NDRIntField("status", 0),
    ]


class DeleteAccountingData_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrStartingDate", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrEndingDate", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrMachineName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
    ]


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


class DefragmentDB_Request(NDRPacket):
    fields_desc = []


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


class CancelAccountingQuery_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("flag", 0)]


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


class RegisterAccountingClient_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrClientId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class DumpAccountingData_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrAccountingData", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class GetAccountingClients_Request(NDRPacket):
    fields_desc = []


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


class SetAccountingClientStatus_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrClientIds", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class CheckAccountingConnection_Request(NDRPacket):
    fields_desc = []


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


class SetClientPermissions_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrClientId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRSignedIntField("fAddPermissions", 0),
    ]


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


IWRMACCOUNTING_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    4: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    5: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    6: DceRpcOp(Invoke_Request, Invoke_Response),
    7: DceRpcOp(CreateAccountingDb_Request, CreateAccountingDb_Response),
    8: DceRpcOp(GetAccountingMetadata_Request, GetAccountingMetadata_Response),
    9: DceRpcOp(ExecuteAccountingQuery_Request, ExecuteAccountingQuery_Response),
    10: DceRpcOp(GetRawAccountingData_Request, GetRawAccountingData_Response),
    11: DceRpcOp(
        GetNextAccountingDataBatch_Request, GetNextAccountingDataBatch_Response
    ),
    12: DceRpcOp(DeleteAccountingData_Request, DeleteAccountingData_Response),
    13: DceRpcOp(DefragmentDB_Request, DefragmentDB_Response),
    14: DceRpcOp(CancelAccountingQuery_Request, CancelAccountingQuery_Response),
    15: DceRpcOp(RegisterAccountingClient_Request, RegisterAccountingClient_Response),
    16: DceRpcOp(DumpAccountingData_Request, DumpAccountingData_Response),
    17: DceRpcOp(GetAccountingClients_Request, GetAccountingClients_Response),
    18: DceRpcOp(SetAccountingClientStatus_Request, SetAccountingClientStatus_Response),
    19: DceRpcOp(CheckAccountingConnection_Request, CheckAccountingConnection_Response),
    20: DceRpcOp(SetClientPermissions_Request, SetClientPermissions_Response),
}
register_com_interface(
    name="IWRMAccounting",
    uuid=uuid.UUID("4F7CA01C-A9E5-45B6-B142-2332A1339C1D"),
    opnums=IWRMACCOUNTING_OPNUMS,
)


class CONFIGTYPE(IntEnum):
    CONFIGTYPE_ACCOUNTING = 1
    CONFIGTYPE_NOTIFICATION = 2
    CONFIGTYPE_CALENDARING = 3


class GetConfig_Request(NDRPacket):
    fields_desc = [NDRIntEnumField("enumConfigType", 0, CONFIGTYPE)]


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


class SetConfig_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrConfigInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntEnumField("enumConfigType", 0, CONFIGTYPE),
    ]


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


class IsEnabled_Request(NDRPacket):
    fields_desc = [NDRIntEnumField("enumConfigType", 0, CONFIGTYPE)]


class IsEnabled_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pbEnable", 0), NDRIntField("status", 0)]


class EnableDisable_Request(NDRPacket):
    fields_desc = [
        NDRSignedIntField("bEnableDisable", 0),
        NDRIntEnumField("enumConfigType", 0, CONFIGTYPE),
    ]


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


class EXCLUSIONLIST_TYPE(IntEnum):
    SYSTEM_EXCLUSION_LIST = 1
    USER_EXCLUSION_LIST = 2
    DEFAULT_USER_EXCLUSION_LIST = 4


class GetExclusionList_Request(NDRPacket):
    fields_desc = [NDRIntEnumField("enumListType", 0, EXCLUSIONLIST_TYPE)]


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


class SetExclusionList_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrExclusionList", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class WSRMActivate_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("bActivate", 0)]


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


class IsWSRMActivated_Request(NDRPacket):
    fields_desc = []


class IsWSRMActivated_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pbActivated", 0), NDRIntField("status", 0)]


class RestoreExclusionList_Request(NDRPacket):
    fields_desc = []


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


IWRMCONFIG_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    4: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    5: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    6: DceRpcOp(Invoke_Request, Invoke_Response),
    7: DceRpcOp(GetConfig_Request, GetConfig_Response),
    8: DceRpcOp(SetConfig_Request, SetConfig_Response),
    9: DceRpcOp(IsEnabled_Request, IsEnabled_Response),
    10: DceRpcOp(EnableDisable_Request, EnableDisable_Response),
    11: DceRpcOp(GetExclusionList_Request, GetExclusionList_Response),
    12: DceRpcOp(SetExclusionList_Request, SetExclusionList_Response),
    13: DceRpcOp(WSRMActivate_Request, WSRMActivate_Response),
    14: DceRpcOp(IsWSRMActivated_Request, IsWSRMActivated_Response),
    15: DceRpcOp(RestoreExclusionList_Request, RestoreExclusionList_Response),
}
register_com_interface(
    name="IWRMConfig",
    uuid=uuid.UUID("21546AE8-4DA5-445E-987F-627FEA39C5E8"),
    opnums=IWRMCONFIG_OPNUMS,
)


class GetSupportedClient_Request(NDRPacket):
    fields_desc = []


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


IWRMPROTOCOL_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    4: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    5: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    6: DceRpcOp(Invoke_Request, Invoke_Response),
    7: DceRpcOp(GetSupportedClient_Request, GetSupportedClient_Response),
}
register_com_interface(
    name="IWRMProtocol",
    uuid=uuid.UUID("F31931A9-832D-481C-9503-887A0E6A79F0"),
    opnums=IWRMPROTOCOL_OPNUMS,
)


class CreateMachineGroup_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrParentMachineGroupId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrMachineGroupInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
    ]


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


class GetMachineGroupInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrMachineGroupId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class MACHINE_GROUP_MERGE_OPTIONS(IntEnum):
    OVERWRITE_MG_MERGE_OPTION = 1
    OVERRIDE_MG_MERGE_OPTION = 2
    APPEND_MG_MERGE_OPTION = 3
    SMART_MG_MERGE_OPTION = 4


class ModifyMachineGroup_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrMachineGroupId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrMachineGroupInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRIntEnumField("enumMGMergeOptions", 0, MACHINE_GROUP_MERGE_OPTIONS),
    ]


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


class DeleteMachineGroup_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrMachineGroupId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class RenameMachineGroup_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrOldMachineGroupName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrNewMachineGroupName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
    ]


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


class AddMachine_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrParentMachineGroupId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField("bstrMachineInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
    ]


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


class GetMachineInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrMachineId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        )
    ]


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


class ModifyMachineInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrParentMachineGroupId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField("bstrMachineId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrMachineInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
    ]


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


class DeleteMachine_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrParentMachineGroupId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField("bstrMachineId", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
    ]


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


IWRMMACHINEGROUP_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    4: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    5: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    6: DceRpcOp(Invoke_Request, Invoke_Response),
    7: DceRpcOp(CreateMachineGroup_Request, CreateMachineGroup_Response),
    8: DceRpcOp(GetMachineGroupInfo_Request, GetMachineGroupInfo_Response),
    9: DceRpcOp(ModifyMachineGroup_Request, ModifyMachineGroup_Response),
    10: DceRpcOp(DeleteMachineGroup_Request, DeleteMachineGroup_Response),
    11: DceRpcOp(RenameMachineGroup_Request, RenameMachineGroup_Response),
    12: DceRpcOp(AddMachine_Request, AddMachine_Response),
    13: DceRpcOp(GetMachineInfo_Request, GetMachineInfo_Response),
    14: DceRpcOp(ModifyMachineInfo_Request, ModifyMachineInfo_Response),
    15: DceRpcOp(DeleteMachine_Request, DeleteMachine_Response),
}
register_com_interface(
    name="IWRMMachineGroup",
    uuid=uuid.UUID("943991a5-b3fe-41fa-9696-7f7b656ee34b"),
    opnums=IWRMMACHINEGROUP_OPNUMS,
)


class ExportObjects_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrObjectIds", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntEnumField("enumObjectType", 0, OBJECT_TYPE),
    ]


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


class GetImportConflicts_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPMCXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrPolicyXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrCalendarXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrConditionalXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrMachineGroupXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrConfigurationXmls", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
    ]


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


class IMPORT_TYPE(IntEnum):
    OVERWRITE_IMPORT = 1
    IGNORE_EXISTING_IMPORT = 2
    OVERRIDE_EXISTING_IMPORT = 3
    SMART_MERGE_RENAME_EXISTING_IMPORT = 4
    SMART_MERGE_RENAME_IMPORTED_IMPORT = 5


class ImportXml_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrPMCXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrPolicyXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrCalendarXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("bstrConditionalXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrMachineGroupXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "bstrConfigurationXmls", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRIntEnumField("enumImportType", 0, IMPORT_TYPE),
    ]


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


class ExportXml_Request(NDRPacket):
    fields_desc = []


class ExportXml_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pbstrPMCXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("pbstrPolicyXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "pbstrCalendarXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                )
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "pbstrConditionalXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                )
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "pbstrMachineGroupXml", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                )
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "pbstrConfigurationXmls", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
                )
            )
        ),
        NDRIntField("status", 0),
    ]


IRESOURCEMANAGER2_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    4: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    5: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    6: DceRpcOp(Invoke_Request, Invoke_Response),
    7: DceRpcOp(ExportObjects_Request, ExportObjects_Response),
    8: DceRpcOp(GetImportConflicts_Request, GetImportConflicts_Response),
    9: DceRpcOp(ImportXml_Request, ImportXml_Response),
    10: DceRpcOp(ExportXml_Request, ExportXml_Response),
}
register_com_interface(
    name="IResourceManager2",
    uuid=uuid.UUID("2A3EB639-D134-422d-90D8-AAA1B5216202"),
    opnums=IRESOURCEMANAGER2_OPNUMS,
)


class GetRemoteUserCategories_Request(NDRPacket):
    fields_desc = []


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


class SetRemoteUserCategories_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrRemoteUserCategoriesInfo", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        )
    ]


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


class RefreshRemoteSessionWeights_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "bstrTaregetUserSessions", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB
            )
        ),
        NDRSignedIntField("bUpdateAll", 0),
    ]


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


IWRMREMOTESESSIONMGMT_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(GetTypeInfoCount_Request, GetTypeInfoCount_Response),
    4: DceRpcOp(GetTypeInfo_Request, GetTypeInfo_Response),
    5: DceRpcOp(GetIDsOfNames_Request, GetIDsOfNames_Response),
    6: DceRpcOp(Invoke_Request, Invoke_Response),
    7: DceRpcOp(GetRemoteUserCategories_Request, GetRemoteUserCategories_Response),
    8: DceRpcOp(SetRemoteUserCategories_Request, SetRemoteUserCategories_Response),
    9: DceRpcOp(
        RefreshRemoteSessionWeights_Request, RefreshRemoteSessionWeights_Response
    ),
}
register_com_interface(
    name="IWRMRemoteSessionMgmt",
    uuid=uuid.UUID("FC910418-55CA-45ef-B264-83D4CE7D30E0"),
    opnums=IWRMREMOTESESSIONMGMT_OPNUMS,
)
