# 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-csra] v46.1 (Tue, 13 Jan 2026)

"""
RPC definitions for the following interfaces:
- IUnknown (v0.0): 00000000-0000-0000-C000-000000000046
- ICertAdminD (v0.0): d99e6e71-fc88-11d0-b498-00a0c90312f3
- ICertAdminD2 (v0.0): 7fe0d935-dda6-443f-85d0-1cfb58fe41dd
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,
    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 CERTTRANSBLOB(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cb", None, size_of="pb"),
        NDRFullEmbPointerField(
            NDRConfStrLenField("pb", "", size_is=lambda pkt: pkt.cb)
        ),
    ]


class SetExtension_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("dwRequestId", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszExtensionName", "")),
        NDRIntField("dwType", 0),
        NDRIntField("dwFlags", 0),
        NDRPacketField("pctbValue", CERTTRANSBLOB(), CERTTRANSBLOB),
    ]


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


class SetAttributes_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("dwRequestId", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAttributes", "")),
    ]


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


class ResubmitRequest_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("dwRequestId", 0),
    ]


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


class DenyRequest_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("dwRequestId", 0),
    ]


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


class IsValidCertificate_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pSerialNumber", "")),
    ]


class IsValidCertificate_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("pRevocationReason", 0),
        NDRSignedIntField("pDisposition", 0),
        NDRIntField("status", 0),
    ]


class FILETIME(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwLowDateTime", 0), NDRIntField("dwHighDateTime", 0)]


class PublishCRL_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRPacketField("FileTime", FILETIME(), FILETIME),
    ]


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


class GetCRL_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", ""))
    ]


class GetCRL_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pctbCRL", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class RevokeCertificate_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszSerialNumber", "")),
        NDRIntField("Reason", 0),
        NDRPacketField("FileTime", FILETIME(), FILETIME),
    ]


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


class EnumViewColumn_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("iColumn", 0),
        NDRIntField("cColumn", 0),
    ]


class EnumViewColumn_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcColumn", 0),
        NDRPacketField("pctbColumnInfo", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class GetViewDefaultColumnSet_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("iColumnSetDefault", 0),
    ]


class GetViewDefaultColumnSet_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcColumn", 0),
        NDRPacketField("pctbColumnInfo", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class EnumAttributesOrExtensions_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("RowId", 0),
        NDRIntField("Flags", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszLast", "")),
        NDRIntField("celt", 0),
    ]


class EnumAttributesOrExtensions_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pceltFetched", 0),
        NDRPacketField("pctbOut", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class CERTVIEWRESTRICTION(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ColumnIndex", 0),
        NDRSignedIntField("SeekOperator", 0),
        NDRSignedIntField("SortOrder", 0),
        NDRFullEmbPointerField(
            NDRConfStrLenField("pbValue", "", size_is=lambda pkt: pkt.cbValue)
        ),
        NDRIntField("cbValue", None, size_of="pbValue"),
    ]


class OpenView_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("ccvr", None, size_of="acvr"),
        NDRConfPacketListField(
            "acvr", [], CERTVIEWRESTRICTION, size_is=lambda pkt: pkt.ccvr
        ),
        NDRIntField("ccolOut", None, size_of="acolOut"),
        NDRConfFieldListField(
            "acolOut", [], NDRIntField("", 0), size_is=lambda pkt: pkt.ccolOut
        ),
        NDRIntField("ielt", 0),
        NDRIntField("celt", 0),
    ]


class OpenView_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pceltFetched", 0),
        NDRPacketField("pctbResultRows", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class EnumView_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("ielt", 0),
        NDRIntField("celt", 0),
    ]


class EnumView_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pceltFetched", 0),
        NDRPacketField("pctbResultRows", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class CloseView_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", ""))
    ]


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


class ServerControl_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("dwControlFlags", 0),
    ]


class ServerControl_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pctbOut", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class Ping_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", ""))
    ]


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


class GetServerState_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", ""))
    ]


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


class BackupPrepare_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("grbitJet", 0),
        NDRIntField("dwBackupFlags", 0),
        NDRShortField("pwszBackupAnnotation", 0),
        NDRIntField("dwClientIdentifier", 0),
    ]


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


class BackupEnd_Request(NDRPacket):
    fields_desc = []


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


class BackupGetAttachmentInformation_Request(NDRPacket):
    fields_desc = []


class BackupGetAttachmentInformation_Response(NDRPacket):
    fields_desc = [
        NDRConfFieldListField(
            "ppwszzDBFiles",
            [],
            NDRFullPointerField(NDRShortField("", 0)),
            size_is=lambda pkt: pkt.pcwcDBFiles,
        ),
        NDRSignedIntField("pcwcDBFiles", None, size_of="ppwszzDBFiles"),
        NDRIntField("status", 0),
    ]


class BackupGetBackupLogs_Request(NDRPacket):
    fields_desc = []


class BackupGetBackupLogs_Response(NDRPacket):
    fields_desc = [
        NDRConfFieldListField(
            "ppwszzLogFiles",
            [],
            NDRFullPointerField(NDRShortField("", 0)),
            size_is=lambda pkt: pkt.pcwcLogFiles,
        ),
        NDRSignedIntField("pcwcLogFiles", None, size_of="ppwszzLogFiles"),
        NDRIntField("status", 0),
    ]


class BackupOpenFile_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszPath", ""))]


class BackupOpenFile_Response(NDRPacket):
    fields_desc = [NDRLongField("pliLength", 0), NDRIntField("status", 0)]


class BackupReadFile_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("cbBuffer", 0)]


class BackupReadFile_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("pbBuffer", "", size_is=lambda pkt: pkt.cbBuffer),
        NDRSignedIntField("pcbRead", 0),
        NDRIntField("status", 0),
    ]


class BackupCloseFile_Request(NDRPacket):
    fields_desc = []


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


class BackupTruncateLogs_Request(NDRPacket):
    fields_desc = []


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


class ImportCertificate_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRPacketField("pctbCertificate", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRSignedIntField("dwFlags", 0),
    ]


class ImportCertificate_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pdwRequestId", 0), NDRIntField("status", 0)]


class BackupGetDynamicFiles_Request(NDRPacket):
    fields_desc = []


class BackupGetDynamicFiles_Response(NDRPacket):
    fields_desc = [
        NDRConfFieldListField(
            "ppwszzFiles",
            [],
            NDRFullPointerField(NDRShortField("", 0)),
            size_is=lambda pkt: pkt.pcwcFiles,
        ),
        NDRSignedIntField("pcwcFiles", None, size_of="ppwszzFiles"),
        NDRIntField("status", 0),
    ]


class RestoreGetDatabaseLocations_Request(NDRPacket):
    fields_desc = []


class RestoreGetDatabaseLocations_Response(NDRPacket):
    fields_desc = [
        NDRConfFieldListField(
            "ppwszzDatabaseLocations",
            [],
            NDRFullPointerField(NDRShortField("", 0)),
            size_is=lambda pkt: pkt.pcwcPaths,
        ),
        NDRSignedIntField("pcwcPaths", None, size_of="ppwszzDatabaseLocations"),
        NDRIntField("status", 0),
    ]


ICERTADMIND_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(SetExtension_Request, SetExtension_Response),
    4: DceRpcOp(SetAttributes_Request, SetAttributes_Response),
    5: DceRpcOp(ResubmitRequest_Request, ResubmitRequest_Response),
    6: DceRpcOp(DenyRequest_Request, DenyRequest_Response),
    7: DceRpcOp(IsValidCertificate_Request, IsValidCertificate_Response),
    8: DceRpcOp(PublishCRL_Request, PublishCRL_Response),
    9: DceRpcOp(GetCRL_Request, GetCRL_Response),
    10: DceRpcOp(RevokeCertificate_Request, RevokeCertificate_Response),
    11: DceRpcOp(EnumViewColumn_Request, EnumViewColumn_Response),
    12: DceRpcOp(GetViewDefaultColumnSet_Request, GetViewDefaultColumnSet_Response),
    13: DceRpcOp(
        EnumAttributesOrExtensions_Request, EnumAttributesOrExtensions_Response
    ),
    14: DceRpcOp(OpenView_Request, OpenView_Response),
    15: DceRpcOp(EnumView_Request, EnumView_Response),
    16: DceRpcOp(CloseView_Request, CloseView_Response),
    17: DceRpcOp(ServerControl_Request, ServerControl_Response),
    18: DceRpcOp(Ping_Request, Ping_Response),
    19: DceRpcOp(GetServerState_Request, GetServerState_Response),
    20: DceRpcOp(BackupPrepare_Request, BackupPrepare_Response),
    21: DceRpcOp(BackupEnd_Request, BackupEnd_Response),
    22: DceRpcOp(
        BackupGetAttachmentInformation_Request, BackupGetAttachmentInformation_Response
    ),
    23: DceRpcOp(BackupGetBackupLogs_Request, BackupGetBackupLogs_Response),
    24: DceRpcOp(BackupOpenFile_Request, BackupOpenFile_Response),
    25: DceRpcOp(BackupReadFile_Request, BackupReadFile_Response),
    26: DceRpcOp(BackupCloseFile_Request, BackupCloseFile_Response),
    27: DceRpcOp(BackupTruncateLogs_Request, BackupTruncateLogs_Response),
    28: DceRpcOp(ImportCertificate_Request, ImportCertificate_Response),
    29: DceRpcOp(BackupGetDynamicFiles_Request, BackupGetDynamicFiles_Response),
    30: DceRpcOp(
        RestoreGetDatabaseLocations_Request, RestoreGetDatabaseLocations_Response
    ),
}
register_com_interface(
    name="ICertAdminD",
    uuid=uuid.UUID("d99e6e71-fc88-11d0-b498-00a0c90312f3"),
    opnums=ICERTADMIND_OPNUMS,
)


class PublishCRLs_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRPacketField("FileTime", FILETIME(), FILETIME),
        NDRIntField("Flags", 0),
    ]


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


class GetCAProperty_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRSignedIntField("PropId", 0),
        NDRSignedIntField("PropIndex", 0),
        NDRSignedIntField("PropType", 0),
    ]


class GetCAProperty_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pctbPropertyValue", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class SetCAProperty_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRSignedIntField("PropId", 0),
        NDRSignedIntField("PropIndex", 0),
        NDRSignedIntField("PropType", 0),
        NDRPacketField("pctbPropertyValue", CERTTRANSBLOB(), CERTTRANSBLOB),
    ]


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


class GetCAPropertyInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", ""))
    ]


class GetCAPropertyInfo_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("pcProperty", 0),
        NDRPacketField("pctbPropInfo", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class EnumViewColumnTable_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("iTable", 0),
        NDRIntField("iColumn", 0),
        NDRIntField("cColumn", 0),
    ]


class EnumViewColumnTable_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcColumn", 0),
        NDRPacketField("pctbColumnInfo", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class GetCASecurity_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", ""))
    ]


class GetCASecurity_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pctbSD", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class SetCASecurity_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRPacketField("pctbSD", CERTTRANSBLOB(), CERTTRANSBLOB),
    ]


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


class Ping2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", ""))
    ]


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


class GetArchivedKey_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("dwRequestId", 0),
    ]


class GetArchivedKey_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pctbArchivedKey", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class GetAuditFilter_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", ""))
    ]


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


class SetAuditFilter_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("dwFilter", 0),
    ]


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


class GetOfficerRights_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", ""))
    ]


class GetOfficerRights_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("pfEnabled", 0),
        NDRPacketField("pctbSD", CERTTRANSBLOB(), CERTTRANSBLOB),
        NDRIntField("status", 0),
    ]


class SetOfficerRights_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRSignedIntField("fEnable", 0),
        NDRPacketField("pctbSD", CERTTRANSBLOB(), CERTTRANSBLOB),
    ]


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


class GetConfigEntry_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszNodePath", "")),
        NDRConfVarStrNullFieldUtf16("pwszEntry", ""),
    ]


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


class SetConfigEntry_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszNodePath", "")),
        NDRConfVarStrNullFieldUtf16("pwszEntry", ""),
        NDRFullPointerField(
            NDRPacketField("pVariant", wireVARIANTStr(), wireVARIANTStr)
        ),
    ]


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


class ImportKey_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("dwRequestId", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszCertHash", "")),
        NDRIntField("dwFlags", 0),
        NDRPacketField("pctbKey", CERTTRANSBLOB(), CERTTRANSBLOB),
    ]


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


class GetMyRoles_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", ""))
    ]


class GetMyRoles_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pdwRoles", 0), NDRIntField("status", 0)]


class DeleteRow_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszAuthority", "")),
        NDRIntField("dwFlags", 0),
        NDRPacketField("FileTime", FILETIME(), FILETIME),
        NDRIntField("dwTable", 0),
        NDRIntField("dwRowId", 0),
    ]


class DeleteRow_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pcDeleted", 0), NDRIntField("status", 0)]


ICERTADMIND2_OPNUMS = {  # 0: Opnum0NotUsedOnWire,
    # 1: Opnum1NotUsedOnWire,
    # 2: Opnum2NotUsedOnWire,
    3: DceRpcOp(SetExtension_Request, SetExtension_Response),
    4: DceRpcOp(SetAttributes_Request, SetAttributes_Response),
    5: DceRpcOp(ResubmitRequest_Request, ResubmitRequest_Response),
    6: DceRpcOp(DenyRequest_Request, DenyRequest_Response),
    7: DceRpcOp(IsValidCertificate_Request, IsValidCertificate_Response),
    8: DceRpcOp(PublishCRL_Request, PublishCRL_Response),
    9: DceRpcOp(GetCRL_Request, GetCRL_Response),
    10: DceRpcOp(RevokeCertificate_Request, RevokeCertificate_Response),
    11: DceRpcOp(EnumViewColumn_Request, EnumViewColumn_Response),
    12: DceRpcOp(GetViewDefaultColumnSet_Request, GetViewDefaultColumnSet_Response),
    13: DceRpcOp(
        EnumAttributesOrExtensions_Request, EnumAttributesOrExtensions_Response
    ),
    14: DceRpcOp(OpenView_Request, OpenView_Response),
    15: DceRpcOp(EnumView_Request, EnumView_Response),
    16: DceRpcOp(CloseView_Request, CloseView_Response),
    17: DceRpcOp(ServerControl_Request, ServerControl_Response),
    18: DceRpcOp(Ping_Request, Ping_Response),
    19: DceRpcOp(GetServerState_Request, GetServerState_Response),
    20: DceRpcOp(BackupPrepare_Request, BackupPrepare_Response),
    21: DceRpcOp(BackupEnd_Request, BackupEnd_Response),
    22: DceRpcOp(
        BackupGetAttachmentInformation_Request, BackupGetAttachmentInformation_Response
    ),
    23: DceRpcOp(BackupGetBackupLogs_Request, BackupGetBackupLogs_Response),
    24: DceRpcOp(BackupOpenFile_Request, BackupOpenFile_Response),
    25: DceRpcOp(BackupReadFile_Request, BackupReadFile_Response),
    26: DceRpcOp(BackupCloseFile_Request, BackupCloseFile_Response),
    27: DceRpcOp(BackupTruncateLogs_Request, BackupTruncateLogs_Response),
    28: DceRpcOp(ImportCertificate_Request, ImportCertificate_Response),
    29: DceRpcOp(BackupGetDynamicFiles_Request, BackupGetDynamicFiles_Response),
    30: DceRpcOp(
        RestoreGetDatabaseLocations_Request, RestoreGetDatabaseLocations_Response
    ),
    31: DceRpcOp(PublishCRLs_Request, PublishCRLs_Response),
    32: DceRpcOp(GetCAProperty_Request, GetCAProperty_Response),
    33: DceRpcOp(SetCAProperty_Request, SetCAProperty_Response),
    34: DceRpcOp(GetCAPropertyInfo_Request, GetCAPropertyInfo_Response),
    35: DceRpcOp(EnumViewColumnTable_Request, EnumViewColumnTable_Response),
    36: DceRpcOp(GetCASecurity_Request, GetCASecurity_Response),
    37: DceRpcOp(SetCASecurity_Request, SetCASecurity_Response),
    38: DceRpcOp(Ping2_Request, Ping2_Response),
    39: DceRpcOp(GetArchivedKey_Request, GetArchivedKey_Response),
    40: DceRpcOp(GetAuditFilter_Request, GetAuditFilter_Response),
    41: DceRpcOp(SetAuditFilter_Request, SetAuditFilter_Response),
    42: DceRpcOp(GetOfficerRights_Request, GetOfficerRights_Response),
    43: DceRpcOp(SetOfficerRights_Request, SetOfficerRights_Response),
    44: DceRpcOp(GetConfigEntry_Request, GetConfigEntry_Response),
    45: DceRpcOp(SetConfigEntry_Request, SetConfigEntry_Response),
    46: DceRpcOp(ImportKey_Request, ImportKey_Response),
    47: DceRpcOp(GetMyRoles_Request, GetMyRoles_Response),
    48: DceRpcOp(DeleteRow_Request, DeleteRow_Response),
}
register_com_interface(
    name="ICertAdminD2",
    uuid=uuid.UUID("7fe0d935-dda6-443f-85d0-1cfb58fe41dd"),
    opnums=ICERTADMIND2_OPNUMS,
)
