### ms-drsr.idl
"""
RPC definitions for the following interfaces:
- drsuapi (v4.0): e3514235-4b06-11d1-ab04-00c04fc2dcd2
- dsaop (v1.0): 7c44d7d4-31d5-424c-bd5e-2b3e1f323d22
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRByteField,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRConfVarStrLenField,
    NDRConfVarStrLenFieldUtf16,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRContextHandle,
    NDRFullPointerField,
    NDRInt3264EnumField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRRecursiveField,
    NDRRefEmbPointerField,
    NDRShortField,
    NDRSignedByteField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRUnionField,
    register_dcerpc_interface,
)


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


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


class IDL_DRSBind_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("puuidClientDsa", UUID(), UUID)),
        NDRFullPointerField(
            NDRPacketField("pextClient", DRS_EXTENSIONS(), DRS_EXTENSIONS)
        ),
    ]


class IDL_DRSBind_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppextServer", DRS_EXTENSIONS(), DRS_EXTENSIONS)
        ),
        NDRPacketField("phDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class IDL_DRSUnbind_Request(NDRPacket):
    fields_desc = [NDRPacketField("phDrs", NDRContextHandle(), NDRContextHandle)]


class IDL_DRSUnbind_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("phDrs", NDRContextHandle(), NDRContextHandle),
        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 NT4SID(NDRPacket):
    fields_desc = [StrFixedLenField("Data", "", length=28)]


class DSNAME(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["StringName"]
    fields_desc = [
        NDRIntField("structLen", 0),
        NDRIntField("SidLen", 0),
        NDRPacketField("Guid", GUID(), GUID),
        NDRPacketField("Sid", NT4SID(), NT4SID),
        NDRIntField("NameLen", None, size_of="StringName", adjust=lambda _, x: (x - 1)),
        NDRConfStrLenFieldUtf16(
            "StringName",
            "",
            size_is=lambda pkt: (pkt.NameLen + 1),
            conformant_in_struct=True,
        ),
    ]


class DRS_MSG_REPSYNC_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("uuidDsaSrc", UUID(), UUID),
        NDRFullPointerField(NDRConfVarStrNullField("pszDsaSrc", ""), deferred=True),
        NDRIntField("ulOptions", 0),
    ]


class VAR_SIZE_BUFFER_WITH_VERSION(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgbBuffer"]
    fields_desc = [
        NDRIntField("ulVersion", 0),
        NDRIntField("cbByteBuffer", None, size_of="rgbBuffer"),
        NDRLongField("ullPadding", 0),
        NDRConfStrLenField(
            "rgbBuffer",
            "",
            size_is=lambda pkt: pkt.cbByteBuffer,
            conformant_in_struct=True,
        ),
    ]


class DRS_MSG_REPSYNC_V2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("uuidDsaSrc", UUID(), UUID),
        NDRFullPointerField(NDRConfVarStrNullField("pszDsaSrc", ""), deferred=True),
        NDRIntField("ulOptions", 0),
        NDRPacketField("correlationID", GUID(), GUID),
        NDRFullPointerField(
            NDRPacketField(
                "pReservedBuffer",
                VAR_SIZE_BUFFER_WITH_VERSION(),
                VAR_SIZE_BUFFER_WITH_VERSION,
            ),
            deferred=True,
        ),
    ]


class IDL_DRSReplicaSync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgSync", DRS_MSG_REPSYNC_V1(), DRS_MSG_REPSYNC_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgSync", DRS_MSG_REPSYNC_V2(), DRS_MSG_REPSYNC_V2
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
            ],
            StrFixedLenField("pmsgSync", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


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


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


class USN_VECTOR(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRSignedLongField("usnHighObjUpdate", 0),
        NDRSignedLongField("usnReserved", 0),
        NDRSignedLongField("usnHighPropUpdate", 0),
    ]


class UPTODATE_CURSOR_V1(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidDsa", UUID(), UUID),
        NDRSignedLongField("usnHighPropUpdate", 0),
    ]


class UPTODATE_VECTOR_V1_EXT(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgCursors"]
    fields_desc = [
        NDRIntField("dwVersion", 0),
        NDRIntField("dwReserved1", 0),
        NDRIntField("cNumCursors", None, size_of="rgCursors"),
        NDRIntField("dwReserved2", 0),
        NDRConfPacketListField(
            "rgCursors",
            [],
            UPTODATE_CURSOR_V1,
            size_is=lambda pkt: pkt.cNumCursors,
            conformant_in_struct=True,
        ),
    ]


class PARTIAL_ATTR_VECTOR_V1_EXT(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["rgPartialAttr"]
    fields_desc = [
        NDRIntField("dwVersion", 0),
        NDRIntField("dwReserved1", 0),
        NDRIntField("cAttrs", None, size_of="rgPartialAttr"),
        NDRConfFieldListField(
            "rgPartialAttr",
            [],
            NDRIntField("", 0),
            size_is=lambda pkt: pkt.cAttrs,
            conformant_in_struct=True,
        ),
    ]


class OID_t(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("length", None, size_of="elements"),
        NDRFullPointerField(
            NDRConfStrLenField("elements", "", size_is=lambda pkt: pkt.length),
            deferred=True,
        ),
    ]


class PrefixTableEntry(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [NDRIntField("ndx", 0), NDRPacketField("prefix", OID_t(), OID_t)]


class SCHEMA_PREFIX_TABLE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("PrefixCount", None, size_of="pPrefixEntry"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pPrefixEntry",
                [],
                PrefixTableEntry,
                size_is=lambda pkt: pkt.PrefixCount,
            ),
            deferred=True,
        ),
    ]


class DRS_MSG_GETCHGREQ_V3(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidDsaObjDest", UUID(), UUID),
        NDRPacketField("uuidInvocIdSrc", UUID(), UUID),
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("usnvecFrom", USN_VECTOR(), USN_VECTOR),
        NDRFullPointerField(
            NDRPacketField(
                "pUpToDateVecDestV1", UPTODATE_VECTOR_V1_EXT(), UPTODATE_VECTOR_V1_EXT
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField(
                "pPartialAttrVecDestV1",
                PARTIAL_ATTR_VECTOR_V1_EXT(),
                PARTIAL_ATTR_VECTOR_V1_EXT,
            ),
            deferred=True,
        ),
        NDRPacketField("PrefixTableDest", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
        NDRIntField("ulFlags", 0),
        NDRIntField("cMaxObjects", 0),
        NDRIntField("cMaxBytes", 0),
        NDRIntField("ulExtendedOp", 0),
    ]


class DRS_MSG_GETCHGREQ_V4(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidTransportObj", UUID(), UUID),
        NDRRefEmbPointerField(
            NDRPacketField("pmtxReturnAddress", MTX_ADDR(), MTX_ADDR), deferred=True
        ),
        NDRPacketField("V3", DRS_MSG_GETCHGREQ_V3(), DRS_MSG_GETCHGREQ_V3),
    ]


class ULARGE_INTEGER(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRLongField("QuadPart", 0)]


class DRS_MSG_GETCHGREQ_V5(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidDsaObjDest", UUID(), UUID),
        NDRPacketField("uuidInvocIdSrc", UUID(), UUID),
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("usnvecFrom", USN_VECTOR(), USN_VECTOR),
        NDRFullPointerField(
            NDRPacketField(
                "pUpToDateVecDestV1", UPTODATE_VECTOR_V1_EXT(), UPTODATE_VECTOR_V1_EXT
            ),
            deferred=True,
        ),
        NDRIntField("ulFlags", 0),
        NDRIntField("cMaxObjects", 0),
        NDRIntField("cMaxBytes", 0),
        NDRIntField("ulExtendedOp", 0),
        NDRPacketField("liFsmoInfo", ULARGE_INTEGER(), ULARGE_INTEGER),
    ]


class DRS_MSG_GETCHGREQ_V7(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidTransportObj", UUID(), UUID),
        NDRRefEmbPointerField(
            NDRPacketField("pmtxReturnAddress", MTX_ADDR(), MTX_ADDR), deferred=True
        ),
        NDRPacketField("V3", DRS_MSG_GETCHGREQ_V3(), DRS_MSG_GETCHGREQ_V3),
        NDRFullPointerField(
            NDRPacketField(
                "pPartialAttrSet",
                PARTIAL_ATTR_VECTOR_V1_EXT(),
                PARTIAL_ATTR_VECTOR_V1_EXT,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField(
                "pPartialAttrSetEx",
                PARTIAL_ATTR_VECTOR_V1_EXT(),
                PARTIAL_ATTR_VECTOR_V1_EXT,
            ),
            deferred=True,
        ),
        NDRPacketField("PrefixTableDest", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
    ]


class DRS_MSG_GETCHGREQ_V8(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidDsaObjDest", UUID(), UUID),
        NDRPacketField("uuidInvocIdSrc", UUID(), UUID),
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("usnvecFrom", USN_VECTOR(), USN_VECTOR),
        NDRFullPointerField(
            NDRPacketField(
                "pUpToDateVecDest", UPTODATE_VECTOR_V1_EXT(), UPTODATE_VECTOR_V1_EXT
            ),
            deferred=True,
        ),
        NDRIntField("ulFlags", 0),
        NDRIntField("cMaxObjects", 0),
        NDRIntField("cMaxBytes", 0),
        NDRIntField("ulExtendedOp", 0),
        NDRPacketField("liFsmoInfo", ULARGE_INTEGER(), ULARGE_INTEGER),
        NDRFullPointerField(
            NDRPacketField(
                "pPartialAttrSet",
                PARTIAL_ATTR_VECTOR_V1_EXT(),
                PARTIAL_ATTR_VECTOR_V1_EXT,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField(
                "pPartialAttrSetEx",
                PARTIAL_ATTR_VECTOR_V1_EXT(),
                PARTIAL_ATTR_VECTOR_V1_EXT,
            ),
            deferred=True,
        ),
        NDRPacketField("PrefixTableDest", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
    ]


class DRS_MSG_GETCHGREQ_V10(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidDsaObjDest", UUID(), UUID),
        NDRPacketField("uuidInvocIdSrc", UUID(), UUID),
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("usnvecFrom", USN_VECTOR(), USN_VECTOR),
        NDRFullPointerField(
            NDRPacketField(
                "pUpToDateVecDest", UPTODATE_VECTOR_V1_EXT(), UPTODATE_VECTOR_V1_EXT
            ),
            deferred=True,
        ),
        NDRIntField("ulFlags", 0),
        NDRIntField("cMaxObjects", 0),
        NDRIntField("cMaxBytes", 0),
        NDRIntField("ulExtendedOp", 0),
        NDRPacketField("liFsmoInfo", ULARGE_INTEGER(), ULARGE_INTEGER),
        NDRFullPointerField(
            NDRPacketField(
                "pPartialAttrSet",
                PARTIAL_ATTR_VECTOR_V1_EXT(),
                PARTIAL_ATTR_VECTOR_V1_EXT,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField(
                "pPartialAttrSetEx",
                PARTIAL_ATTR_VECTOR_V1_EXT(),
                PARTIAL_ATTR_VECTOR_V1_EXT,
            ),
            deferred=True,
        ),
        NDRPacketField("PrefixTableDest", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
        NDRIntField("ulMoreFlags", 0),
    ]


class DRS_MSG_GETCHGREQ_V11(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidDsaObjDest", UUID(), UUID),
        NDRPacketField("uuidInvocIdSrc", UUID(), UUID),
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("usnvecFrom", USN_VECTOR(), USN_VECTOR),
        NDRFullPointerField(
            NDRPacketField(
                "pUpToDateVecDest", UPTODATE_VECTOR_V1_EXT(), UPTODATE_VECTOR_V1_EXT
            ),
            deferred=True,
        ),
        NDRIntField("ulFlags", 0),
        NDRIntField("cMaxObjects", 0),
        NDRIntField("cMaxBytes", 0),
        NDRIntField("ulExtendedOp", 0),
        NDRPacketField("liFsmoInfo", ULARGE_INTEGER(), ULARGE_INTEGER),
        NDRFullPointerField(
            NDRPacketField(
                "pPartialAttrSet",
                PARTIAL_ATTR_VECTOR_V1_EXT(),
                PARTIAL_ATTR_VECTOR_V1_EXT,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField(
                "pPartialAttrSetEx",
                PARTIAL_ATTR_VECTOR_V1_EXT(),
                PARTIAL_ATTR_VECTOR_V1_EXT,
            ),
            deferred=True,
        ),
        NDRPacketField("PrefixTableDest", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
        NDRIntField("ulMoreFlags", 0),
        NDRPacketField("correlationID", GUID(), GUID),
        NDRFullPointerField(
            NDRPacketField(
                "pReservedBuffer",
                VAR_SIZE_BUFFER_WITH_VERSION(),
                VAR_SIZE_BUFFER_WITH_VERSION,
            ),
            deferred=True,
        ),
    ]


class ATTRVAL(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("valLen", None, size_of="pVal"),
        NDRFullPointerField(
            NDRConfStrLenField("pVal", "", size_is=lambda pkt: pkt.valLen),
            deferred=True,
        ),
    ]


class ATTRVALBLOCK(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("valCount", None, size_of="pAVal"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pAVal", [], ATTRVAL, size_is=lambda pkt: pkt.valCount
            ),
            deferred=True,
        ),
    ]


class ATTR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("attrTyp", 0),
        NDRPacketField("AttrVal", ATTRVALBLOCK(), ATTRVALBLOCK),
    ]


class ATTRBLOCK(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("attrCount", None, size_of="pAttr"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pAttr", [], ATTR, size_is=lambda pkt: pkt.attrCount
            ),
            deferred=True,
        ),
    ]


class ENTINF(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRPacketField("pName", DSNAME(), DSNAME), deferred=True),
        NDRIntField("ulFlags", 0),
        NDRPacketField("AttrBlock", ATTRBLOCK(), ATTRBLOCK),
    ]


class PROPERTY_META_DATA_EXT(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("dwVersion", 0),
        NDRSignedLongField("timeChanged", 0),
        NDRPacketField("uuidDsaOriginating", UUID(), UUID),
        NDRSignedLongField("usnOriginating", 0),
    ]


class PROPERTY_META_DATA_EXT_VECTOR(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgMetaData"]
    fields_desc = [
        NDRIntField("cNumProps", None, size_of="rgMetaData"),
        NDRConfPacketListField(
            "rgMetaData",
            [],
            PROPERTY_META_DATA_EXT,
            size_is=lambda pkt: pkt.cNumProps,
            conformant_in_struct=True,
        ),
    ]


class REPLENTINFLIST(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRecursiveField("pNextEntInf"),
        NDRPacketField("Entinf", ENTINF(), ENTINF),
        NDRSignedIntField("fIsNCPrefix", 0),
        NDRFullPointerField(NDRPacketField("pParentGuid", UUID(), UUID), deferred=True),
        NDRFullPointerField(
            NDRPacketField(
                "pMetaDataExt",
                PROPERTY_META_DATA_EXT_VECTOR(),
                PROPERTY_META_DATA_EXT_VECTOR,
            ),
            deferred=True,
        ),
    ]


class DRS_MSG_GETCHGREPLY_V1(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidDsaObjSrc", UUID(), UUID),
        NDRPacketField("uuidInvocIdSrc", UUID(), UUID),
        NDRFullPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("usnvecFrom", USN_VECTOR(), USN_VECTOR),
        NDRPacketField("usnvecTo", USN_VECTOR(), USN_VECTOR),
        NDRFullPointerField(
            NDRPacketField(
                "pUpToDateVecSrcV1", UPTODATE_VECTOR_V1_EXT(), UPTODATE_VECTOR_V1_EXT
            ),
            deferred=True,
        ),
        NDRPacketField("PrefixTableSrc", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
        NDRIntField("ulExtendedRet", 0),
        NDRIntField("cNumObjects", 0),
        NDRIntField("cNumBytes", 0),
        NDRFullPointerField(
            NDRPacketField("pObjects", REPLENTINFLIST(), REPLENTINFLIST), deferred=True
        ),
        NDRSignedIntField("fMoreData", 0),
    ]


class DRS_COMPRESSED_BLOB(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cbUncompressedSize", 0),
        NDRIntField("cbCompressedSize", None, size_of="pbCompressedData"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "pbCompressedData", "", size_is=lambda pkt: pkt.cbCompressedSize
            ),
            deferred=True,
        ),
    ]


class DRS_MSG_GETCHGREPLY_V2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("CompressedV1", DRS_COMPRESSED_BLOB(), DRS_COMPRESSED_BLOB)
    ]


class UPTODATE_CURSOR_V2(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidDsa", UUID(), UUID),
        NDRSignedLongField("usnHighPropUpdate", 0),
        NDRSignedLongField("timeLastSyncSuccess", 0),
    ]


class UPTODATE_VECTOR_V2_EXT(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgCursors"]
    fields_desc = [
        NDRIntField("dwVersion", 0),
        NDRIntField("dwReserved1", 0),
        NDRIntField("cNumCursors", None, size_of="rgCursors"),
        NDRIntField("dwReserved2", 0),
        NDRConfPacketListField(
            "rgCursors",
            [],
            UPTODATE_CURSOR_V2,
            size_is=lambda pkt: pkt.cNumCursors,
            conformant_in_struct=True,
        ),
    ]


class VALUE_META_DATA_EXT_V1(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRSignedLongField("timeCreated", 0),
        NDRPacketField("MetaData", PROPERTY_META_DATA_EXT(), PROPERTY_META_DATA_EXT),
    ]


class REPLVALINF_V1(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRFullPointerField(NDRPacketField("pObject", DSNAME(), DSNAME), deferred=True),
        NDRIntField("attrTyp", 0),
        NDRPacketField("Aval", ATTRVAL(), ATTRVAL),
        NDRSignedIntField("fIsPresent", 0),
        NDRPacketField("MetaData", VALUE_META_DATA_EXT_V1(), VALUE_META_DATA_EXT_V1),
    ]


class DRS_MSG_GETCHGREPLY_V6(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidDsaObjSrc", UUID(), UUID),
        NDRPacketField("uuidInvocIdSrc", UUID(), UUID),
        NDRFullPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("usnvecFrom", USN_VECTOR(), USN_VECTOR),
        NDRPacketField("usnvecTo", USN_VECTOR(), USN_VECTOR),
        NDRFullPointerField(
            NDRPacketField(
                "pUpToDateVecSrc", UPTODATE_VECTOR_V2_EXT(), UPTODATE_VECTOR_V2_EXT
            ),
            deferred=True,
        ),
        NDRPacketField("PrefixTableSrc", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
        NDRIntField("ulExtendedRet", 0),
        NDRIntField("cNumObjects", 0),
        NDRIntField("cNumBytes", 0),
        NDRFullPointerField(
            NDRPacketField("pObjects", REPLENTINFLIST(), REPLENTINFLIST), deferred=True
        ),
        NDRSignedIntField("fMoreData", 0),
        NDRIntField("cNumNcSizeObjects", 0),
        NDRIntField("cNumNcSizeValues", 0),
        NDRIntField("cNumValues", None, size_of="rgValues"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rgValues", [], REPLVALINF_V1, size_is=lambda pkt: pkt.cNumValues
            ),
            deferred=True,
        ),
        NDRIntField("dwDRSError", 0),
    ]


class DRS_COMP_ALG_TYPE(IntEnum):
    DRS_COMP_ALG_NONE = 0
    DRS_COMP_ALG_UNUSED = 1
    DRS_COMP_ALG_MSZIP = 2
    DRS_COMP_ALG_WIN2K3 = 3


class DRS_MSG_GETCHGREPLY_V7(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwCompressedVersion", 0),
        NDRInt3264EnumField("CompressionAlg", 0, DRS_COMP_ALG_TYPE),
        NDRPacketField("CompressedAny", DRS_COMPRESSED_BLOB(), DRS_COMPRESSED_BLOB),
    ]


class VALUE_META_DATA_EXT_V3(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRSignedLongField("timeCreated", 0),
        NDRPacketField("MetaData", PROPERTY_META_DATA_EXT(), PROPERTY_META_DATA_EXT),
        NDRIntField("unused1", 0),
        NDRIntField("unused2", 0),
        NDRIntField("unused3", 0),
        NDRSignedLongField("timeExpired", 0),
    ]


class REPLVALINF_V3(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRFullPointerField(NDRPacketField("pObject", DSNAME(), DSNAME), deferred=True),
        NDRIntField("attrTyp", 0),
        NDRPacketField("Aval", ATTRVAL(), ATTRVAL),
        NDRSignedIntField("fIsPresent", 0),
        NDRPacketField("MetaData", VALUE_META_DATA_EXT_V3(), VALUE_META_DATA_EXT_V3),
    ]


class DRS_MSG_GETCHGREPLY_V9(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidDsaObjSrc", UUID(), UUID),
        NDRPacketField("uuidInvocIdSrc", UUID(), UUID),
        NDRFullPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("usnvecFrom", USN_VECTOR(), USN_VECTOR),
        NDRPacketField("usnvecTo", USN_VECTOR(), USN_VECTOR),
        NDRFullPointerField(
            NDRPacketField(
                "pUpToDateVecSrc", UPTODATE_VECTOR_V2_EXT(), UPTODATE_VECTOR_V2_EXT
            ),
            deferred=True,
        ),
        NDRPacketField("PrefixTableSrc", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
        NDRIntField("ulExtendedRet", 0),
        NDRIntField("cNumObjects", 0),
        NDRIntField("cNumBytes", 0),
        NDRFullPointerField(
            NDRPacketField("pObjects", REPLENTINFLIST(), REPLENTINFLIST), deferred=True
        ),
        NDRSignedIntField("fMoreData", 0),
        NDRIntField("cNumNcSizeObjects", 0),
        NDRIntField("cNumNcSizeValues", 0),
        NDRIntField("cNumValues", None, size_of="rgValues"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rgValues", [], REPLVALINF_V3, size_is=lambda pkt: pkt.cNumValues
            ),
            deferred=True,
        ),
        NDRIntField("dwDRSError", 0),
    ]


class IDL_DRSGetNCChanges_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_GETCHGREQ_V4(), DRS_MSG_GETCHGREQ_V4
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 4),
                        (lambda _, val: val.tag == 4),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_GETCHGREQ_V5(), DRS_MSG_GETCHGREQ_V5
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 5),
                        (lambda _, val: val.tag == 5),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_GETCHGREQ_V7(), DRS_MSG_GETCHGREQ_V7
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 7),
                        (lambda _, val: val.tag == 7),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_GETCHGREQ_V8(), DRS_MSG_GETCHGREQ_V8
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 8),
                        (lambda _, val: val.tag == 8),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_GETCHGREQ_V10(), DRS_MSG_GETCHGREQ_V10
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 10),
                        (lambda _, val: val.tag == 10),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_GETCHGREQ_V11(), DRS_MSG_GETCHGREQ_V11
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 11),
                        (lambda _, val: val.tag == 11),
                    ),
                ),
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSGetNCChanges_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_GETCHGREPLY_V1(), DRS_MSG_GETCHGREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_GETCHGREPLY_V2(), DRS_MSG_GETCHGREPLY_V2
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_GETCHGREPLY_V6(), DRS_MSG_GETCHGREPLY_V6
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 6),
                        (lambda _, val: val.tag == 6),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_GETCHGREPLY_V7(), DRS_MSG_GETCHGREPLY_V7
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 7),
                        (lambda _, val: val.tag == 7),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_GETCHGREPLY_V9(), DRS_MSG_GETCHGREPLY_V9
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 9),
                        (lambda _, val: val.tag == 9),
                    ),
                ),
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_UPDREFS_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRRefEmbPointerField(NDRConfVarStrNullField("pszDsaDest", ""), deferred=True),
        NDRPacketField("uuidDsaObjDest", UUID(), UUID),
        NDRIntField("ulOptions", 0),
    ]


class DRS_MSG_UPDREFS_V2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRRefEmbPointerField(NDRConfVarStrNullField("pszDsaDest", ""), deferred=True),
        NDRPacketField("uuidDsaObjDest", UUID(), UUID),
        NDRIntField("ulOptions", 0),
        NDRPacketField("correlationID", GUID(), GUID),
        NDRFullPointerField(
            NDRPacketField(
                "pReservedBuffer",
                VAR_SIZE_BUFFER_WITH_VERSION(),
                VAR_SIZE_BUFFER_WITH_VERSION,
            ),
            deferred=True,
        ),
    ]


class IDL_DRSUpdateRefs_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgUpdRefs", DRS_MSG_UPDREFS_V1(), DRS_MSG_UPDREFS_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgUpdRefs", DRS_MSG_UPDREFS_V2(), DRS_MSG_UPDREFS_V2
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
            ],
            StrFixedLenField("pmsgUpdRefs", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


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


class REPLTIMES(NDRPacket):
    fields_desc = [StrFixedLenField("rgTimes", "", length=84)]


class DRS_MSG_REPADD_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRRefEmbPointerField(NDRConfVarStrNullField("pszDsaSrc", ""), deferred=True),
        NDRPacketField("rtSchedule", REPLTIMES(), REPLTIMES),
        NDRIntField("ulOptions", 0),
    ]


class DRS_MSG_REPADD_V2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRFullPointerField(
            NDRPacketField("pSourceDsaDN", DSNAME(), DSNAME), deferred=True
        ),
        NDRFullPointerField(
            NDRPacketField("pTransportDN", DSNAME(), DSNAME), deferred=True
        ),
        NDRRefEmbPointerField(
            NDRConfVarStrNullField("pszSourceDsaAddress", ""), deferred=True
        ),
        NDRPacketField("rtSchedule", REPLTIMES(), REPLTIMES),
        NDRIntField("ulOptions", 0),
    ]


class DRS_MSG_REPADD_V3(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRFullPointerField(
            NDRPacketField("pSourceDsaDN", DSNAME(), DSNAME), deferred=True
        ),
        NDRFullPointerField(
            NDRPacketField("pTransportDN", DSNAME(), DSNAME), deferred=True
        ),
        NDRRefEmbPointerField(
            NDRConfVarStrNullField("pszSourceDsaAddress", ""), deferred=True
        ),
        NDRPacketField("rtSchedule", REPLTIMES(), REPLTIMES),
        NDRIntField("ulOptions", 0),
        NDRPacketField("correlationID", GUID(), GUID),
        NDRFullPointerField(
            NDRPacketField(
                "pReservedBuffer",
                VAR_SIZE_BUFFER_WITH_VERSION(),
                VAR_SIZE_BUFFER_WITH_VERSION,
            ),
            deferred=True,
        ),
    ]


class IDL_DRSReplicaAdd_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField("pmsgAdd", DRS_MSG_REPADD_V1(), DRS_MSG_REPADD_V1),
                    (
                        (lambda pkt: getattr(pkt, "dwVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRPacketField("pmsgAdd", DRS_MSG_REPADD_V2(), DRS_MSG_REPADD_V2),
                    (
                        (lambda pkt: getattr(pkt, "dwVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRPacketField("pmsgAdd", DRS_MSG_REPADD_V3(), DRS_MSG_REPADD_V3),
                    (
                        (lambda pkt: getattr(pkt, "dwVersion", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
            ],
            StrFixedLenField("pmsgAdd", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


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


class DRS_MSG_REPDEL_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullField("pszDsaSrc", ""), deferred=True),
        NDRIntField("ulOptions", 0),
    ]


class IDL_DRSReplicaDel_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField("pmsgDel", DRS_MSG_REPDEL_V1(), DRS_MSG_REPDEL_V1),
                    (
                        (lambda pkt: getattr(pkt, "dwVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgDel", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


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


class DRS_MSG_REPMOD_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("uuidSourceDRA", UUID(), UUID),
        NDRFullPointerField(NDRConfVarStrNullField("pszSourceDRA", ""), deferred=True),
        NDRPacketField("rtSchedule", REPLTIMES(), REPLTIMES),
        NDRIntField("ulReplicaFlags", 0),
        NDRIntField("ulModifyFields", 0),
        NDRIntField("ulOptions", 0),
    ]


class IDL_DRSReplicaModify_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField("pmsgMod", DRS_MSG_REPMOD_V1(), DRS_MSG_REPMOD_V1),
                    (
                        (lambda pkt: getattr(pkt, "dwVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgMod", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


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


class DRS_MSG_VERIFYREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwFlags", 0),
        NDRIntField("cNames", None, size_of="rpNames"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rpNames", [], DSNAME, size_is=lambda pkt: pkt.cNames, ptr_pack=True
            ),
            deferred=True,
        ),
        NDRPacketField("RequiredAttrs", ATTRBLOCK(), ATTRBLOCK),
        NDRPacketField("PrefixTable", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
    ]


class DRS_MSG_VERIFYREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("error", 0),
        NDRIntField("cNames", None, size_of="rpEntInf"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rpEntInf", [], ENTINF, size_is=lambda pkt: pkt.cNames
            ),
            deferred=True,
        ),
        NDRPacketField("PrefixTable", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
    ]


class IDL_DRSVerifyNames_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_VERIFYREQ_V1(), DRS_MSG_VERIFYREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSVerifyNames_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_VERIFYREPLY_V1(), DRS_MSG_VERIFYREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class REVERSE_MEMBERSHIP_OPERATION_TYPE(IntEnum):
    RevMembGetGroupsForUser = 1
    RevMembGetAliasMembership = 2
    RevMembGetAccountGroups = 3
    RevMembGetResourceGroups = 4
    RevMembGetUniversalGroups = 5
    GroupMembersTransitive = 6
    RevMembGlobalGroupsNonTransitive = 7


class DRS_MSG_REVMEMB_REQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cDsNames", None, size_of="ppDsNames"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "ppDsNames", [], DSNAME, size_is=lambda pkt: pkt.cDsNames, ptr_pack=True
            ),
            deferred=True,
        ),
        NDRIntField("dwFlags", 0),
        NDRInt3264EnumField("OperationType", 0, REVERSE_MEMBERSHIP_OPERATION_TYPE),
        NDRFullPointerField(
            NDRPacketField("pLimitingDomain", DSNAME(), DSNAME), deferred=True
        ),
    ]


class DRS_MSG_REVMEMB_REPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("errCode", 0),
        NDRIntField("cDsNames", None, size_of="pAttributes"),
        NDRIntField("cSidHistory", None, size_of="ppSidHistory"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "ppDsNames", [], DSNAME, size_is=lambda pkt: pkt.cDsNames, ptr_pack=True
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfFieldListField(
                "pAttributes",
                [],
                NDRIntField("pAttributes", 0),
                size_is=lambda pkt: pkt.cDsNames,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfPacketListField(
                "ppSidHistory",
                [],
                NT4SID,
                size_is=lambda pkt: pkt.cSidHistory,
                ptr_pack=True,
            ),
            deferred=True,
        ),
    ]


class IDL_DRSGetMemberships_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_REVMEMB_REQ_V1(), DRS_MSG_REVMEMB_REQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSGetMemberships_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_REVMEMB_REPLY_V1(), DRS_MSG_REVMEMB_REPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_MOVEREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRSignedByteField("pSourceDSA", 0), deferred=True),
        NDRFullPointerField(NDRPacketField("pObject", ENTINF(), ENTINF), deferred=True),
        NDRFullPointerField(NDRPacketField("pParentUUID", UUID(), UUID), deferred=True),
        NDRPacketField("PrefixTable", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
        NDRIntField("ulFlags", 0),
    ]


class DRS_SecBuffer(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cbBuffer", None, size_of="pvBuffer"),
        NDRIntField("BufferType", 0),
        NDRFullPointerField(
            NDRConfStrLenField("pvBuffer", "", size_is=lambda pkt: pkt.cbBuffer),
            deferred=True,
        ),
    ]


class DRS_SecBufferDesc(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("ulVersion", 0),
        NDRIntField("cBuffers", None, size_of="Buffers"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Buffers", [], DRS_SecBuffer, size_is=lambda pkt: pkt.cBuffers
            ),
            deferred=True,
        ),
    ]


class DRS_MSG_MOVEREQ_V2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRPacketField("pSrcDSA", DSNAME(), DSNAME), deferred=True),
        NDRFullPointerField(
            NDRPacketField("pSrcObject", ENTINF(), ENTINF), deferred=True
        ),
        NDRFullPointerField(
            NDRPacketField("pDstName", DSNAME(), DSNAME), deferred=True
        ),
        NDRFullPointerField(
            NDRPacketField("pExpectedTargetNC", DSNAME(), DSNAME), deferred=True
        ),
        NDRFullPointerField(
            NDRPacketField("pClientCreds", DRS_SecBufferDesc(), DRS_SecBufferDesc),
            deferred=True,
        ),
        NDRPacketField("PrefixTable", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
        NDRIntField("ulFlags", 0),
    ]


class DRS_MSG_MOVEREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppResult", ENTINF(), ENTINF), deferred=True
            ),
            deferred=True,
        ),
        NDRPacketField("PrefixTable", SCHEMA_PREFIX_TABLE(), SCHEMA_PREFIX_TABLE),
        NDRFullPointerField(NDRIntField("pError", 0), deferred=True),
    ]


class DRS_MSG_MOVEREPLY_V2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("win32Error", 0),
        NDRFullPointerField(
            NDRPacketField("pAddedName", DSNAME(), DSNAME), deferred=True
        ),
    ]


class IDL_DRSInterDomainMove_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField("pmsgIn", DRS_MSG_MOVEREQ_V1(), DRS_MSG_MOVEREQ_V1),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRPacketField("pmsgIn", DRS_MSG_MOVEREQ_V2(), DRS_MSG_MOVEREQ_V2),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSInterDomainMove_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_MOVEREPLY_V1(), DRS_MSG_MOVEREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_MOVEREPLY_V2(), DRS_MSG_MOVEREPLY_V2
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_NT4_CHGLOG_REQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwFlags", 0),
        NDRIntField("PreferredMaximumLength", 0),
        NDRIntField("cbRestart", None, size_of="pRestart"),
        NDRFullPointerField(
            NDRConfStrLenField("pRestart", "", size_is=lambda pkt: pkt.cbRestart),
            deferred=True,
        ),
    ]


class LARGE_INTEGER(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRSignedLongField("QuadPart", 0)]


class NT4_REPLICATION_STATE(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("SamSerialNumber", LARGE_INTEGER(), LARGE_INTEGER),
        NDRPacketField("SamCreationTime", LARGE_INTEGER(), LARGE_INTEGER),
        NDRPacketField("BuiltinSerialNumber", LARGE_INTEGER(), LARGE_INTEGER),
        NDRPacketField("BuiltinCreationTime", LARGE_INTEGER(), LARGE_INTEGER),
        NDRPacketField("LsaSerialNumber", LARGE_INTEGER(), LARGE_INTEGER),
        NDRPacketField("LsaCreationTime", LARGE_INTEGER(), LARGE_INTEGER),
    ]


class DRS_MSG_NT4_CHGLOG_REPLY_V1(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("cbRestart", None, size_of="pRestart"),
        NDRIntField("cbLog", None, size_of="pLog"),
        NDRPacketField(
            "ReplicationState", NT4_REPLICATION_STATE(), NT4_REPLICATION_STATE
        ),
        NDRIntField("ActualNtStatus", 0),
        NDRFullPointerField(
            NDRConfStrLenField("pRestart", "", size_is=lambda pkt: pkt.cbRestart),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfStrLenField("pLog", "", size_is=lambda pkt: pkt.cbLog), deferred=True
        ),
    ]


class IDL_DRSGetNT4ChangeLog_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_NT4_CHGLOG_REQ_V1(), DRS_MSG_NT4_CHGLOG_REQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSGetNT4ChangeLog_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DRS_MSG_NT4_CHGLOG_REPLY_V1(),
                        DRS_MSG_NT4_CHGLOG_REPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_CRACKREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("CodePage", 0),
        NDRIntField("LocaleId", 0),
        NDRIntField("dwFlags", 0),
        NDRIntField("formatOffered", 0),
        NDRIntField("formatDesired", 0),
        NDRIntField("cNames", None, size_of="rpNames"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "rpNames",
                [],
                NDRFullPointerField(
                    NDRConfVarStrNullFieldUtf16("rpNames", ""), deferred=True
                ),
                size_is=lambda pkt: pkt.cNames,
            ),
            deferred=True,
        ),
    ]


class PDS_NAME_RESULT_ITEMW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("status", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pDomain", ""), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pName", ""), deferred=True),
    ]


class DS_NAME_RESULTW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cItems", None, size_of="rItems"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rItems",
                [PDS_NAME_RESULT_ITEMW()],
                PDS_NAME_RESULT_ITEMW,
                size_is=lambda pkt: pkt.cItems,
            ),
            deferred=True,
        ),
    ]


class DRS_MSG_CRACKREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pResult", DS_NAME_RESULTW(), DS_NAME_RESULTW), deferred=True
        )
    ]


class IDL_DRSCrackNames_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_CRACKREQ_V1(), DRS_MSG_CRACKREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSCrackNames_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_CRACKREPLY_V1(), DRS_MSG_CRACKREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_SPNREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("operation", 0),
        NDRIntField("flags", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszAccount", ""), deferred=True
        ),
        NDRIntField("cSPN", None, size_of="rpwszSPN"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "rpwszSPN",
                [],
                NDRFullPointerField(
                    NDRConfVarStrNullFieldUtf16("rpwszSPN", ""), deferred=True
                ),
                size_is=lambda pkt: pkt.cSPN,
            ),
            deferred=True,
        ),
    ]


class DRS_MSG_SPNREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("retVal", 0)]


class IDL_DRSWriteSPN_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField("pmsgIn", DRS_MSG_SPNREQ_V1(), DRS_MSG_SPNREQ_V1),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSWriteSPN_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_SPNREPLY_V1(), DRS_MSG_SPNREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_RMSVRREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("ServerDN", ""), deferred=True),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DomainDN", ""), deferred=True),
        NDRSignedIntField("fCommit", 0),
    ]


class DRS_MSG_RMSVRREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRSignedIntField("fLastDcInDomain", 0)]


class IDL_DRSRemoveDsServer_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_RMSVRREQ_V1(), DRS_MSG_RMSVRREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSRemoveDsServer_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_RMSVRREPLY_V1(), DRS_MSG_RMSVRREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_RMDMNREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("DomainDN", ""), deferred=True)
    ]


class DRS_MSG_RMDMNREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("Reserved", 0)]


class IDL_DRSRemoveDsDomain_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_RMDMNREQ_V1(), DRS_MSG_RMDMNREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSRemoveDsDomain_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_RMDMNREPLY_V1(), DRS_MSG_RMDMNREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_DCINFOREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("Domain", ""), deferred=True),
        NDRIntField("InfoLevel", 0),
    ]


class DS_DOMAIN_CONTROLLER_INFO_1W(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("NetbiosName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DnsHostName", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("SiteName", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("ComputerObjectName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("ServerObjectName", ""), deferred=True
        ),
        NDRSignedIntField("fIsPdc", 0),
        NDRSignedIntField("fDsEnabled", 0),
    ]


class DRS_MSG_DCINFOREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cItems", None, size_of="rItems"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rItems",
                [],
                DS_DOMAIN_CONTROLLER_INFO_1W,
                size_is=lambda pkt: pkt.cItems,
            ),
            deferred=True,
        ),
    ]


class DS_DOMAIN_CONTROLLER_INFO_2W(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("NetbiosName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DnsHostName", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("SiteName", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("SiteObjectName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("ComputerObjectName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("ServerObjectName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("NtdsDsaObjectName", ""), deferred=True
        ),
        NDRSignedIntField("fIsPdc", 0),
        NDRSignedIntField("fDsEnabled", 0),
        NDRSignedIntField("fIsGc", 0),
        NDRPacketField("SiteObjectGuid", GUID(), GUID),
        NDRPacketField("ComputerObjectGuid", GUID(), GUID),
        NDRPacketField("ServerObjectGuid", GUID(), GUID),
        NDRPacketField("NtdsDsaObjectGuid", GUID(), GUID),
    ]


class DRS_MSG_DCINFOREPLY_V2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cItems", None, size_of="rItems"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rItems",
                [],
                DS_DOMAIN_CONTROLLER_INFO_2W,
                size_is=lambda pkt: pkt.cItems,
            ),
            deferred=True,
        ),
    ]


class DS_DOMAIN_CONTROLLER_INFO_3W(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("NetbiosName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DnsHostName", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("SiteName", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("SiteObjectName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("ComputerObjectName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("ServerObjectName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("NtdsDsaObjectName", ""), deferred=True
        ),
        NDRSignedIntField("fIsPdc", 0),
        NDRSignedIntField("fDsEnabled", 0),
        NDRSignedIntField("fIsGc", 0),
        NDRSignedIntField("fIsRodc", 0),
        NDRPacketField("SiteObjectGuid", GUID(), GUID),
        NDRPacketField("ComputerObjectGuid", GUID(), GUID),
        NDRPacketField("ServerObjectGuid", GUID(), GUID),
        NDRPacketField("NtdsDsaObjectGuid", GUID(), GUID),
    ]


class DRS_MSG_DCINFOREPLY_V3(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cItems", None, size_of="rItems"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rItems",
                [],
                DS_DOMAIN_CONTROLLER_INFO_3W,
                size_is=lambda pkt: pkt.cItems,
            ),
            deferred=True,
        ),
    ]


class DS_DOMAIN_CONTROLLER_INFO_FFFFFFFFW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("IPAddress", 0),
        NDRIntField("NotificationCount", 0),
        NDRIntField("secTimeConnected", 0),
        NDRIntField("Flags", 0),
        NDRIntField("TotalRequests", 0),
        NDRIntField("Reserved1", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("UserName", ""), deferred=True),
    ]


class DRS_MSG_DCINFOREPLY_VFFFFFFFF(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cItems", None, size_of="rItems"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rItems",
                [],
                DS_DOMAIN_CONTROLLER_INFO_FFFFFFFFW,
                size_is=lambda pkt: pkt.cItems,
            ),
            deferred=True,
        ),
    ]


class IDL_DRSDomainControllerInfo_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_DCINFOREQ_V1(), DRS_MSG_DCINFOREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSDomainControllerInfo_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_DCINFOREPLY_V1(), DRS_MSG_DCINFOREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_DCINFOREPLY_V2(), DRS_MSG_DCINFOREPLY_V2
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_DCINFOREPLY_V3(), DRS_MSG_DCINFOREPLY_V3
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgOut",
                        DRS_MSG_DCINFOREPLY_VFFFFFFFF(),
                        DRS_MSG_DCINFOREPLY_VFFFFFFFF,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 4294967295),
                        (lambda _, val: val.tag == 4294967295),
                    ),
                ),
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_ADDENTRYREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(
            NDRPacketField("pObject", DSNAME(), DSNAME), deferred=True
        ),
        NDRPacketField("AttrBlock", ATTRBLOCK(), ATTRBLOCK),
    ]


class ENTINFLIST(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRecursiveField("pNextEntInf"),
        NDRPacketField("Entinf", ENTINF(), ENTINF),
    ]


class DRS_MSG_ADDENTRYREQ_V2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [NDRPacketField("EntInfList", ENTINFLIST(), ENTINFLIST)]


class DRS_MSG_ADDENTRYREQ_V3(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("EntInfList", ENTINFLIST(), ENTINFLIST),
        NDRFullPointerField(
            NDRPacketField("pClientCreds", DRS_SecBufferDesc(), DRS_SecBufferDesc),
            deferred=True,
        ),
    ]


class DRS_MSG_ADDENTRYREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("Guid", GUID(), GUID),
        NDRPacketField("Sid", NT4SID(), NT4SID),
        NDRIntField("errCode", 0),
        NDRIntField("dsid", 0),
        NDRIntField("extendedErr", 0),
        NDRIntField("extendedData", 0),
        NDRShortField("problem", 0),
    ]


class ADDENTRY_REPLY_INFO(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("objGuid", GUID(), GUID),
        NDRPacketField("objSid", NT4SID(), NT4SID),
    ]


class DRS_MSG_ADDENTRYREPLY_V2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pErrorObject", DSNAME(), DSNAME), deferred=True
        ),
        NDRIntField("errCode", 0),
        NDRIntField("dsid", 0),
        NDRIntField("extendedErr", 0),
        NDRIntField("extendedData", 0),
        NDRShortField("problem", 0),
        NDRIntField("cObjectsAdded", None, size_of="infoList"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "infoList",
                [],
                ADDENTRY_REPLY_INFO,
                size_is=lambda pkt: pkt.cObjectsAdded,
            ),
            deferred=True,
        ),
    ]


class INTFORMPROB_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dsid", 0),
        NDRIntField("extendedErr", 0),
        NDRIntField("extendedData", 0),
        NDRShortField("problem", 0),
        NDRIntField("type", 0),
        NDRSignedIntField("valReturned", 0),
        NDRPacketField("Val", ATTRVAL(), ATTRVAL),
    ]


class PROBLEMLIST_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRecursiveField("pNextProblem"),
        NDRPacketField("intprob", INTFORMPROB_DRS_WIRE_V1(), INTFORMPROB_DRS_WIRE_V1),
    ]


class ATRERR_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRPacketField("pObject", DSNAME(), DSNAME), deferred=True),
        NDRIntField("count", 0),
        NDRPacketField(
            "FirstProblem", PROBLEMLIST_DRS_WIRE_V1(), PROBLEMLIST_DRS_WIRE_V1
        ),
    ]


class NAMERR_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dsid", 0),
        NDRIntField("extendedErr", 0),
        NDRIntField("extendedData", 0),
        NDRShortField("problem", 0),
        NDRFullPointerField(
            NDRPacketField("pMatched", DSNAME(), DSNAME), deferred=True
        ),
    ]


class NAMERESOP_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (2, 2)
    fields_desc = [
        NDRByteField("nameRes", 0),
        NDRByteField("unusedPad", 0),
        NDRShortField("nextRDN", 0),
    ]


class RPC_UNICODE_STRING(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRShortField("Length", None, size_of="Buffer", adjust=lambda _, x: (x * 2)),
        NDRShortField(
            "MaximumLength", None, size_of="Buffer", adjust=lambda _, x: (x * 2)
        ),
        NDRFullPointerField(
            NDRConfVarStrLenFieldUtf16(
                "Buffer",
                "",
                size_is=lambda pkt: (pkt.MaximumLength // 2),
                length_is=lambda pkt: (pkt.Length // 2),
            ),
            deferred=True,
        ),
    ]


class DSA_ADDRESS_LIST_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRecursiveField("pNextAddress"),
        NDRFullPointerField(
            NDRPacketField("pAddress", RPC_UNICODE_STRING(), RPC_UNICODE_STRING),
            deferred=True,
        ),
    ]


class CONTREF_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRPacketField("pTarget", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("OpState", NAMERESOP_DRS_WIRE_V1(), NAMERESOP_DRS_WIRE_V1),
        NDRShortField("aliasRDN", 0),
        NDRShortField("RDNsInternal", 0),
        NDRShortField("refType", 0),
        NDRShortField("count", 0),
        NDRFullPointerField(
            NDRPacketField(
                "pDAL", DSA_ADDRESS_LIST_DRS_WIRE_V1(), DSA_ADDRESS_LIST_DRS_WIRE_V1
            ),
            deferred=True,
        ),
        NDRRecursiveField("pNextContRef"),
        NDRSignedIntField("bNewChoice", 0),
        NDRByteField("choice", 0),
    ]


class REFERR_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dsid", 0),
        NDRIntField("extendedErr", 0),
        NDRIntField("extendedData", 0),
        NDRPacketField("Refer", CONTREF_DRS_WIRE_V1(), CONTREF_DRS_WIRE_V1),
    ]


class SECERR_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dsid", 0),
        NDRIntField("extendedErr", 0),
        NDRIntField("extendedData", 0),
        NDRShortField("problem", 0),
    ]


class SVCERR_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dsid", 0),
        NDRIntField("extendedErr", 0),
        NDRIntField("extendedData", 0),
        NDRShortField("problem", 0),
    ]


class UPDERR_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dsid", 0),
        NDRIntField("extendedErr", 0),
        NDRIntField("extendedData", 0),
        NDRShortField("problem", 0),
    ]


class SYSERR_DRS_WIRE_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dsid", 0),
        NDRIntField("extendedErr", 0),
        NDRIntField("extendedData", 0),
        NDRShortField("problem", 0),
    ]


class DRS_ERROR_DATA_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwRepError", 0),
        NDRIntField("errCode", 0),
        NDRFullPointerField(
            NDRUnionField(
                [
                    (
                        NDRPacketField(
                            "pErrInfo", ATRERR_DRS_WIRE_V1(), ATRERR_DRS_WIRE_V1
                        ),
                        (
                            (lambda pkt: getattr(pkt, "errCode", None) == 1),
                            (lambda _, val: val.tag == 1),
                        ),
                    ),
                    (
                        NDRPacketField(
                            "pErrInfo", NAMERR_DRS_WIRE_V1(), NAMERR_DRS_WIRE_V1
                        ),
                        (
                            (lambda pkt: getattr(pkt, "errCode", None) == 2),
                            (lambda _, val: val.tag == 2),
                        ),
                    ),
                    (
                        NDRPacketField(
                            "pErrInfo", REFERR_DRS_WIRE_V1(), REFERR_DRS_WIRE_V1
                        ),
                        (
                            (lambda pkt: getattr(pkt, "errCode", None) == 3),
                            (lambda _, val: val.tag == 3),
                        ),
                    ),
                    (
                        NDRPacketField(
                            "pErrInfo", SECERR_DRS_WIRE_V1(), SECERR_DRS_WIRE_V1
                        ),
                        (
                            (lambda pkt: getattr(pkt, "errCode", None) == 4),
                            (lambda _, val: val.tag == 4),
                        ),
                    ),
                    (
                        NDRPacketField(
                            "pErrInfo", SVCERR_DRS_WIRE_V1(), SVCERR_DRS_WIRE_V1
                        ),
                        (
                            (lambda pkt: getattr(pkt, "errCode", None) == 5),
                            (lambda _, val: val.tag == 5),
                        ),
                    ),
                    (
                        NDRPacketField(
                            "pErrInfo", UPDERR_DRS_WIRE_V1(), UPDERR_DRS_WIRE_V1
                        ),
                        (
                            (lambda pkt: getattr(pkt, "errCode", None) == 6),
                            (lambda _, val: val.tag == 6),
                        ),
                    ),
                    (
                        NDRPacketField(
                            "pErrInfo", SYSERR_DRS_WIRE_V1(), SYSERR_DRS_WIRE_V1
                        ),
                        (
                            (lambda pkt: getattr(pkt, "errCode", None) == 7),
                            (lambda _, val: val.tag == 7),
                        ),
                    ),
                ],
                StrFixedLenField("pErrInfo", "", length=0),
                align=(4, 8),
                switch_fmt=("L", "L"),
            ),
            deferred=True,
        ),
    ]


class DRS_MSG_ADDENTRYREPLY_V3(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pdsErrObject", DSNAME(), DSNAME), deferred=True
        ),
        NDRIntField("dwErrVer", 0),
        NDRFullPointerField(
            NDRUnionField(
                [
                    (
                        NDRPacketField(
                            "pErrData", DRS_ERROR_DATA_V1(), DRS_ERROR_DATA_V1
                        ),
                        (
                            (lambda pkt: getattr(pkt, "dwErrVer", None) == 1),
                            (lambda _, val: val.tag == 1),
                        ),
                    )
                ],
                StrFixedLenField("pErrData", "", length=0),
                align=(4, 8),
                switch_fmt=("L", "L"),
            ),
            deferred=True,
        ),
        NDRIntField("cObjectsAdded", None, size_of="infoList"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "infoList",
                [],
                ADDENTRY_REPLY_INFO,
                size_is=lambda pkt: pkt.cObjectsAdded,
            ),
            deferred=True,
        ),
    ]


class IDL_DRSAddEntry_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_ADDENTRYREQ_V1(), DRS_MSG_ADDENTRYREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_ADDENTRYREQ_V2(), DRS_MSG_ADDENTRYREQ_V2
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_ADDENTRYREQ_V3(), DRS_MSG_ADDENTRYREQ_V3
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSAddEntry_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_ADDENTRYREPLY_V1(), DRS_MSG_ADDENTRYREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_ADDENTRYREPLY_V2(), DRS_MSG_ADDENTRYREPLY_V2
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_ADDENTRYREPLY_V3(), DRS_MSG_ADDENTRYREPLY_V3
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_KCC_EXECUTE_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwTaskID", 0), NDRIntField("dwFlags", 0)]


class IDL_DRSExecuteKCC_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_KCC_EXECUTE_V1(), DRS_MSG_KCC_EXECUTE_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
    ]


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


class DRS_MSG_GETREPLINFO_REQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("InfoType", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszObjectDN", ""), deferred=True
        ),
        NDRPacketField("uuidSourceDsaObjGuid", UUID(), UUID),
    ]


class DRS_MSG_GETREPLINFO_REQ_V2(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("InfoType", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszObjectDN", ""), deferred=True
        ),
        NDRPacketField("uuidSourceDsaObjGuid", UUID(), UUID),
        NDRIntField("ulFlags", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszAttributeName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszValueDN", ""), deferred=True
        ),
        NDRIntField("dwEnumerationContext", 0),
    ]


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


class DS_REPL_NEIGHBORW(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszNamingContext", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszSourceDsaDN", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszSourceDsaAddress", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszAsyncIntersiteTransportDN", ""),
            deferred=True,
        ),
        NDRIntField("dwReplicaFlags", 0),
        NDRIntField("dwReserved", 0),
        NDRPacketField("uuidNamingContextObjGuid", UUID(), UUID),
        NDRPacketField("uuidSourceDsaObjGuid", UUID(), UUID),
        NDRPacketField("uuidSourceDsaInvocationID", UUID(), UUID),
        NDRPacketField("uuidAsyncIntersiteTransportObjGuid", UUID(), UUID),
        NDRSignedLongField("usnLastObjChangeSynced", 0),
        NDRSignedLongField("usnAttributeFilter", 0),
        NDRPacketField("ftimeLastSyncSuccess", FILETIME(), FILETIME),
        NDRPacketField("ftimeLastSyncAttempt", FILETIME(), FILETIME),
        NDRIntField("dwLastSyncResult", 0),
        NDRIntField("cNumConsecutiveSyncFailures", 0),
    ]


class DS_REPL_NEIGHBORSW(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgNeighbor"]
    fields_desc = [
        NDRIntField("cNumNeighbors", None, size_of="rgNeighbor"),
        NDRIntField("dwReserved", 0),
        NDRConfPacketListField(
            "rgNeighbor",
            [],
            DS_REPL_NEIGHBORW,
            size_is=lambda pkt: pkt.cNumNeighbors,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_CURSOR(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidSourceDsaInvocationID", UUID(), UUID),
        NDRSignedLongField("usnAttributeFilter", 0),
    ]


class DS_REPL_CURSORS(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgCursor"]
    fields_desc = [
        NDRIntField("cNumCursors", None, size_of="rgCursor"),
        NDRIntField("dwReserved", 0),
        NDRConfPacketListField(
            "rgCursor",
            [],
            DS_REPL_CURSOR,
            size_is=lambda pkt: pkt.cNumCursors,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_ATTR_META_DATA(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszAttributeName", ""), deferred=True
        ),
        NDRIntField("dwVersion", 0),
        NDRPacketField("ftimeLastOriginatingChange", FILETIME(), FILETIME),
        NDRPacketField("uuidLastOriginatingDsaInvocationID", UUID(), UUID),
        NDRSignedLongField("usnOriginatingChange", 0),
        NDRSignedLongField("usnLocalChange", 0),
    ]


class DS_REPL_OBJ_META_DATA(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgMetaData"]
    fields_desc = [
        NDRIntField("cNumEntries", None, size_of="rgMetaData"),
        NDRIntField("dwReserved", 0),
        NDRConfPacketListField(
            "rgMetaData",
            [],
            DS_REPL_ATTR_META_DATA,
            size_is=lambda pkt: pkt.cNumEntries,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_KCC_DSA_FAILUREW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszDsaDN", ""), deferred=True),
        NDRPacketField("uuidDsaObjGuid", UUID(), UUID),
        NDRPacketField("ftimeFirstFailure", FILETIME(), FILETIME),
        NDRIntField("cNumFailures", 0),
        NDRIntField("dwLastResult", 0),
    ]


class DS_REPL_KCC_DSA_FAILURESW(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["rgDsaFailure"]
    fields_desc = [
        NDRIntField("cNumEntries", None, size_of="rgDsaFailure"),
        NDRIntField("dwReserved", 0),
        NDRConfPacketListField(
            "rgDsaFailure",
            [],
            DS_REPL_KCC_DSA_FAILUREW,
            size_is=lambda pkt: pkt.cNumEntries,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_OP_TYPE(IntEnum):
    DS_REPL_OP_TYPE_SYNC = 0
    DS_REPL_OP_TYPE_ADD = 1
    DS_REPL_OP_TYPE_DELETE = 2
    DS_REPL_OP_TYPE_MODIFY = 3
    DS_REPL_OP_TYPE_UPDATE_REFS = 4


class DS_REPL_OPW(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("ftimeEnqueued", FILETIME(), FILETIME),
        NDRIntField("ulSerialNumber", 0),
        NDRIntField("ulPriority", 0),
        NDRInt3264EnumField("OpType", 0, DS_REPL_OP_TYPE),
        NDRIntField("ulOptions", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszNamingContext", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszDsaDN", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszDsaAddress", ""), deferred=True
        ),
        NDRPacketField("uuidNamingContextObjGuid", UUID(), UUID),
        NDRPacketField("uuidDsaObjGuid", UUID(), UUID),
    ]


class DS_REPL_PENDING_OPSW(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["rgPendingOp"]
    fields_desc = [
        NDRPacketField("ftimeCurrentOpStarted", FILETIME(), FILETIME),
        NDRIntField("cNumPendingOps", None, size_of="rgPendingOp"),
        NDRConfPacketListField(
            "rgPendingOp",
            [],
            DS_REPL_OPW,
            size_is=lambda pkt: pkt.cNumPendingOps,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_VALUE_META_DATA(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszAttributeName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszObjectDn", ""), deferred=True
        ),
        NDRIntField("cbData", None, size_of="pbData"),
        NDRFullPointerField(
            NDRConfStrLenField("pbData", "", size_is=lambda pkt: pkt.cbData),
            deferred=True,
        ),
        NDRPacketField("ftimeDeleted", FILETIME(), FILETIME),
        NDRPacketField("ftimeCreated", FILETIME(), FILETIME),
        NDRIntField("dwVersion", 0),
        NDRPacketField("ftimeLastOriginatingChange", FILETIME(), FILETIME),
        NDRPacketField("uuidLastOriginatingDsaInvocationID", UUID(), UUID),
        NDRSignedLongField("usnOriginatingChange", 0),
        NDRSignedLongField("usnLocalChange", 0),
    ]


class DS_REPL_ATTR_VALUE_META_DATA(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgMetaData"]
    fields_desc = [
        NDRIntField("cNumEntries", None, size_of="rgMetaData"),
        NDRIntField("dwEnumerationContext", 0),
        NDRConfPacketListField(
            "rgMetaData",
            [],
            DS_REPL_VALUE_META_DATA,
            size_is=lambda pkt: pkt.cNumEntries,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_CURSOR_2(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidSourceDsaInvocationID", UUID(), UUID),
        NDRSignedLongField("usnAttributeFilter", 0),
        NDRPacketField("ftimeLastSyncSuccess", FILETIME(), FILETIME),
    ]


class DS_REPL_CURSORS_2(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgCursor"]
    fields_desc = [
        NDRIntField("cNumCursors", None, size_of="rgCursor"),
        NDRIntField("dwEnumerationContext", 0),
        NDRConfPacketListField(
            "rgCursor",
            [],
            DS_REPL_CURSOR_2,
            size_is=lambda pkt: pkt.cNumCursors,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_CURSOR_3W(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("uuidSourceDsaInvocationID", UUID(), UUID),
        NDRSignedLongField("usnAttributeFilter", 0),
        NDRPacketField("ftimeLastSyncSuccess", FILETIME(), FILETIME),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszSourceDsaDN", ""), deferred=True
        ),
    ]


class DS_REPL_CURSORS_3W(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgCursor"]
    fields_desc = [
        NDRIntField("cNumCursors", None, size_of="rgCursor"),
        NDRIntField("dwEnumerationContext", 0),
        NDRConfPacketListField(
            "rgCursor",
            [],
            DS_REPL_CURSOR_3W,
            size_is=lambda pkt: pkt.cNumCursors,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_ATTR_META_DATA_2(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszAttributeName", ""), deferred=True
        ),
        NDRIntField("dwVersion", 0),
        NDRPacketField("ftimeLastOriginatingChange", FILETIME(), FILETIME),
        NDRPacketField("uuidLastOriginatingDsaInvocationID", UUID(), UUID),
        NDRSignedLongField("usnOriginatingChange", 0),
        NDRSignedLongField("usnLocalChange", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszLastOriginatingDsaDN", ""), deferred=True
        ),
    ]


class DS_REPL_OBJ_META_DATA_2(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgMetaData"]
    fields_desc = [
        NDRIntField("cNumEntries", None, size_of="rgMetaData"),
        NDRIntField("dwReserved", 0),
        NDRConfPacketListField(
            "rgMetaData",
            [],
            DS_REPL_ATTR_META_DATA_2,
            size_is=lambda pkt: pkt.cNumEntries,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_VALUE_META_DATA_2(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszAttributeName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszObjectDn", ""), deferred=True
        ),
        NDRIntField("cbData", None, size_of="pbData"),
        NDRFullPointerField(
            NDRConfStrLenField("pbData", "", size_is=lambda pkt: pkt.cbData),
            deferred=True,
        ),
        NDRPacketField("ftimeDeleted", FILETIME(), FILETIME),
        NDRPacketField("ftimeCreated", FILETIME(), FILETIME),
        NDRIntField("dwVersion", 0),
        NDRPacketField("ftimeLastOriginatingChange", FILETIME(), FILETIME),
        NDRPacketField("uuidLastOriginatingDsaInvocationID", UUID(), UUID),
        NDRSignedLongField("usnOriginatingChange", 0),
        NDRSignedLongField("usnLocalChange", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszLastOriginatingDsaDN", ""), deferred=True
        ),
    ]


class DS_REPL_ATTR_VALUE_META_DATA_2(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgMetaData"]
    fields_desc = [
        NDRIntField("cNumEntries", None, size_of="rgMetaData"),
        NDRIntField("dwEnumerationContext", 0),
        NDRConfPacketListField(
            "rgMetaData",
            [],
            DS_REPL_VALUE_META_DATA_2,
            size_is=lambda pkt: pkt.cNumEntries,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_SERVER_OUTGOING_CALL(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pszServerName", ""), deferred=True
        ),
        NDRSignedIntField("fIsHandleBound", 0),
        NDRSignedIntField("fIsHandleFromCache", 0),
        NDRSignedIntField("fIsHandleInCache", 0),
        NDRIntField("dwThreadId", 0),
        NDRIntField("dwBindingTimeoutMins", 0),
        NDRSignedLongField("dstimeCreated", 0),
        NDRIntField("dwCallType", 0),
    ]


class DS_REPL_SERVER_OUTGOING_CALLS(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgCall"]
    fields_desc = [
        NDRIntField("cNumCalls", None, size_of="rgCall"),
        NDRIntField("dwReserved", 0),
        NDRConfPacketListField(
            "rgCall",
            [],
            DS_REPL_SERVER_OUTGOING_CALL,
            size_is=lambda pkt: pkt.cNumCalls,
            conformant_in_struct=True,
        ),
    ]


class DS_REPL_CLIENT_CONTEXT(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRLongField("hCtx", 0),
        NDRSignedIntField("lReferenceCount", 0),
        NDRSignedIntField("fIsBound", 0),
        NDRPacketField("uuidClient", UUID(), UUID),
        NDRSignedLongField("timeLastUsed", 0),
        NDRIntField("IPAddr", 0),
        NDRSignedIntField("pid", 0),
    ]


class DS_REPL_CLIENT_CONTEXTS(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rgContext"]
    fields_desc = [
        NDRIntField("cNumContexts", None, size_of="rgContext"),
        NDRIntField("dwReserved", 0),
        NDRConfPacketListField(
            "rgContext",
            [],
            DS_REPL_CLIENT_CONTEXT,
            size_is=lambda pkt: pkt.cNumContexts,
            conformant_in_struct=True,
        ),
    ]


class IDL_DRSGetReplInfo_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn",
                        DRS_MSG_GETREPLINFO_REQ_V1(),
                        DRS_MSG_GETREPLINFO_REQ_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRPacketField(
                        "pmsgIn",
                        DRS_MSG_GETREPLINFO_REQ_V2(),
                        DRS_MSG_GETREPLINFO_REQ_V2,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSGetReplInfo_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut", DS_REPL_NEIGHBORSW(), DS_REPL_NEIGHBORSW
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 0),
                        (lambda _, val: val.tag == 0),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField("pmsgOut", DS_REPL_CURSORS(), DS_REPL_CURSORS)
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut", DS_REPL_OBJ_META_DATA(), DS_REPL_OBJ_META_DATA
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 2),
                        (lambda _, val: val.tag == 2),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut",
                            DS_REPL_KCC_DSA_FAILURESW(),
                            DS_REPL_KCC_DSA_FAILURESW,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 3),
                        (lambda _, val: val.tag == 3),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut",
                            DS_REPL_KCC_DSA_FAILURESW(),
                            DS_REPL_KCC_DSA_FAILURESW,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 4),
                        (lambda _, val: val.tag == 4),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut", DS_REPL_PENDING_OPSW(), DS_REPL_PENDING_OPSW
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 5),
                        (lambda _, val: val.tag == 5),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut",
                            DS_REPL_ATTR_VALUE_META_DATA(),
                            DS_REPL_ATTR_VALUE_META_DATA,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 6),
                        (lambda _, val: val.tag == 6),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut", DS_REPL_CURSORS_2(), DS_REPL_CURSORS_2
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 7),
                        (lambda _, val: val.tag == 7),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut", DS_REPL_CURSORS_3W(), DS_REPL_CURSORS_3W
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 8),
                        (lambda _, val: val.tag == 8),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut",
                            DS_REPL_OBJ_META_DATA_2(),
                            DS_REPL_OBJ_META_DATA_2,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 9),
                        (lambda _, val: val.tag == 9),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut",
                            DS_REPL_ATTR_VALUE_META_DATA_2(),
                            DS_REPL_ATTR_VALUE_META_DATA_2,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 10),
                        (lambda _, val: val.tag == 10),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut",
                            DS_REPL_SERVER_OUTGOING_CALLS(),
                            DS_REPL_SERVER_OUTGOING_CALLS,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 4294967290),
                        (lambda _, val: val.tag == 4294967290),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut", UPTODATE_VECTOR_V1_EXT(), UPTODATE_VECTOR_V1_EXT
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 4294967291),
                        (lambda _, val: val.tag == 4294967291),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut",
                            DS_REPL_CLIENT_CONTEXTS(),
                            DS_REPL_CLIENT_CONTEXTS,
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 4294967292),
                        (lambda _, val: val.tag == 4294967292),
                    ),
                ),
                (
                    NDRFullPointerField(
                        NDRPacketField(
                            "pmsgOut", DS_REPL_NEIGHBORSW(), DS_REPL_NEIGHBORSW
                        )
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 4294967294),
                        (lambda _, val: val.tag == 4294967294),
                    ),
                ),
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_ADDSIDREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Flags", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("SrcDomain", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("SrcPrincipal", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("SrcDomainController", ""), deferred=True
        ),
        NDRIntField("SrcCredsUserLength", None, size_of="SrcCredsUser"),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16(
                "SrcCredsUser", "", size_is=lambda pkt: pkt.SrcCredsUserLength
            ),
            deferred=True,
        ),
        NDRIntField("SrcCredsDomainLength", None, size_of="SrcCredsDomain"),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16(
                "SrcCredsDomain", "", size_is=lambda pkt: pkt.SrcCredsDomainLength
            ),
            deferred=True,
        ),
        NDRIntField("SrcCredsPasswordLength", None, size_of="SrcCredsPassword"),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16(
                "SrcCredsPassword", "", size_is=lambda pkt: pkt.SrcCredsPasswordLength
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DstDomain", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("DstPrincipal", ""), deferred=True
        ),
    ]


class DRS_MSG_ADDSIDREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwWin32Error", 0)]


class IDL_DRSAddSidHistory_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_ADDSIDREQ_V1(), DRS_MSG_ADDSIDREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSAddSidHistory_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_ADDSIDREPLY_V1(), DRS_MSG_ADDSIDREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_GETMEMBERSHIPS2_REQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Count", None, size_of="Requests"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Requests", [], DRS_MSG_REVMEMB_REQ_V1, size_is=lambda pkt: pkt.Count
            ),
            deferred=True,
        ),
    ]


class DRS_MSG_GETMEMBERSHIPS2_REPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Count", None, size_of="Replies"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "Replies", [], DRS_MSG_REVMEMB_REPLY_V1, size_is=lambda pkt: pkt.Count
            ),
            deferred=True,
        ),
    ]


class IDL_DRSGetMemberships2_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn",
                        DRS_MSG_GETMEMBERSHIPS2_REQ_V1(),
                        DRS_MSG_GETMEMBERSHIPS2_REQ_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSGetMemberships2_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DRS_MSG_GETMEMBERSHIPS2_REPLY_V1(),
                        DRS_MSG_GETMEMBERSHIPS2_REPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_REPVERIFYOBJ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRPacketField("uuidDsaSrc", UUID(), UUID),
        NDRIntField("ulOptions", 0),
    ]


class IDL_DRSReplicaVerifyObjects_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgVerify", DRS_MSG_REPVERIFYOBJ_V1(), DRS_MSG_REPVERIFYOBJ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgVerify", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


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


class DRS_MSG_EXISTREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRPacketField("guidStart", UUID(), UUID),
        NDRIntField("cGuids", 0),
        NDRFullPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
        NDRFullPointerField(
            NDRPacketField(
                "pUpToDateVecCommonV1", UPTODATE_VECTOR_V1_EXT(), UPTODATE_VECTOR_V1_EXT
            ),
            deferred=True,
        ),
        StrFixedLenField("Md5Digest", "", length=16),
    ]


class DRS_MSG_EXISTREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwStatusFlags", 0),
        NDRIntField("cNumGuids", None, size_of="rgGuids"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rgGuids", [], UUID, size_is=lambda pkt: pkt.cNumGuids
            ),
            deferred=True,
        ),
    ]


class IDL_DRSGetObjectExistence_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_EXISTREQ_V1(), DRS_MSG_EXISTREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSGetObjectExistence_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut", DRS_MSG_EXISTREPLY_V1(), DRS_MSG_EXISTREPLY_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_QUERYSITESREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszFromSite", ""), deferred=True
        ),
        NDRIntField("cToSites", None, size_of="rgszToSites"),
        NDRFullPointerField(
            NDRConfFieldListField(
                "rgszToSites",
                [],
                NDRFullPointerField(
                    NDRConfVarStrNullFieldUtf16("rgszToSites", ""), deferred=True
                ),
                size_is=lambda pkt: pkt.cToSites,
            ),
            deferred=True,
        ),
        NDRIntField("dwFlags", 0),
    ]


class DRS_MSG_QUERYSITESREPLYELEMENT_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwErrorCode", 0), NDRIntField("dwCost", 0)]


class DRS_MSG_QUERYSITESREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cToSites", None, size_of="rgCostInfo"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rgCostInfo",
                [],
                DRS_MSG_QUERYSITESREPLYELEMENT_V1,
                size_is=lambda pkt: pkt.cToSites,
            ),
            deferred=True,
        ),
        NDRIntField("dwFlags", 0),
    ]


class IDL_DRSQuerySitesByCost_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_QUERYSITESREQ_V1(), DRS_MSG_QUERYSITESREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSQuerySitesByCost_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DRS_MSG_QUERYSITESREPLY_V1(),
                        DRS_MSG_QUERYSITESREPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_INIT_DEMOTIONREQ_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwReserved", 0)]


class DRS_MSG_INIT_DEMOTIONREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwOpError", 0)]


class IDL_DRSInitDemotion_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn",
                        DRS_MSG_INIT_DEMOTIONREQ_V1(),
                        DRS_MSG_INIT_DEMOTIONREQ_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSInitDemotion_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DRS_MSG_INIT_DEMOTIONREPLY_V1(),
                        DRS_MSG_INIT_DEMOTIONREPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_REPLICA_DEMOTIONREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwFlags", 0),
        NDRPacketField("uuidHelperDest", UUID(), UUID),
        NDRRefEmbPointerField(NDRPacketField("pNC", DSNAME(), DSNAME), deferred=True),
    ]


class DRS_MSG_REPLICA_DEMOTIONREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwOpError", 0)]


class IDL_DRSReplicaDemotion_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn",
                        DRS_MSG_REPLICA_DEMOTIONREQ_V1(),
                        DRS_MSG_REPLICA_DEMOTIONREQ_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSReplicaDemotion_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DRS_MSG_REPLICA_DEMOTIONREPLY_V1(),
                        DRS_MSG_REPLICA_DEMOTIONREPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_FINISH_DEMOTIONREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwOperations", 0),
        NDRPacketField("uuidHelperDest", UUID(), UUID),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("szScriptBase", ""), deferred=True
        ),
    ]


class DRS_MSG_FINISH_DEMOTIONREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dwOperationsDone", 0),
        NDRIntField("dwOpFailed", 0),
        NDRIntField("dwOpError", 0),
    ]


class IDL_DRSFinishDemotion_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn",
                        DRS_MSG_FINISH_DEMOTIONREQ_V1(),
                        DRS_MSG_FINISH_DEMOTIONREQ_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSFinishDemotion_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DRS_MSG_FINISH_DEMOTIONREPLY_V1(),
                        DRS_MSG_FINISH_DEMOTIONREPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_ADDCLONEDCREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszCloneDCName", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszSite", ""), deferred=True),
    ]


class DRS_MSG_ADDCLONEDCREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszCloneDCName", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszSite", ""), deferred=True),
        NDRIntField("cPasswordLength", None, size_of="pwsNewDCAccountPassword"),
        NDRFullPointerField(
            NDRConfStrLenFieldUtf16(
                "pwsNewDCAccountPassword", "", size_is=lambda pkt: pkt.cPasswordLength
            ),
            deferred=True,
        ),
    ]


class IDL_DRSAddCloneDC_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_ADDCLONEDCREQ_V1(), DRS_MSG_ADDCLONEDCREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSAddCloneDC_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DRS_MSG_ADDCLONEDCREPLY_V1(),
                        DRS_MSG_ADDCLONEDCREPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_WRITENGCKEYREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszAccount", ""), deferred=True
        ),
        NDRIntField("cNgcKey", None, size_of="pNgcKey"),
        NDRFullPointerField(
            NDRConfStrLenField("pNgcKey", "", size_is=lambda pkt: pkt.cNgcKey),
            deferred=True,
        ),
    ]


class DRS_MSG_WRITENGCKEYREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("retVal", 0)]


class IDL_DRSWriteNgcKey_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_WRITENGCKEYREQ_V1(), DRS_MSG_WRITENGCKEYREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSWriteNgcKey_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DRS_MSG_WRITENGCKEYREPLY_V1(),
                        DRS_MSG_WRITENGCKEYREPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DRS_MSG_READNGCKEYREQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwszAccount", ""), deferred=True
        )
    ]


class DRS_MSG_READNGCKEYREPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("retVal", 0),
        NDRIntField("cNgcKey", None, size_of="pNgcKey"),
        NDRFullPointerField(
            NDRConfStrLenField("pNgcKey", "", size_is=lambda pkt: pkt.cNgcKey),
            deferred=True,
        ),
    ]


class IDL_DRSReadNgcKey_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("hDrs", NDRContextHandle(), NDRContextHandle),
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn", DRS_MSG_READNGCKEYREQ_V1(), DRS_MSG_READNGCKEYREQ_V1
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DRSReadNgcKey_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DRS_MSG_READNGCKEYREPLY_V1(),
                        DRS_MSG_READNGCKEYREPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


DRSUAPI_OPNUMS = {
    0: DceRpcOp(IDL_DRSBind_Request, IDL_DRSBind_Response),
    1: DceRpcOp(IDL_DRSUnbind_Request, IDL_DRSUnbind_Response),
    2: DceRpcOp(IDL_DRSReplicaSync_Request, IDL_DRSReplicaSync_Response),
    3: DceRpcOp(IDL_DRSGetNCChanges_Request, IDL_DRSGetNCChanges_Response),
    4: DceRpcOp(IDL_DRSUpdateRefs_Request, IDL_DRSUpdateRefs_Response),
    5: DceRpcOp(IDL_DRSReplicaAdd_Request, IDL_DRSReplicaAdd_Response),
    6: DceRpcOp(IDL_DRSReplicaDel_Request, IDL_DRSReplicaDel_Response),
    7: DceRpcOp(IDL_DRSReplicaModify_Request, IDL_DRSReplicaModify_Response),
    8: DceRpcOp(IDL_DRSVerifyNames_Request, IDL_DRSVerifyNames_Response),
    9: DceRpcOp(IDL_DRSGetMemberships_Request, IDL_DRSGetMemberships_Response),
    10: DceRpcOp(IDL_DRSInterDomainMove_Request, IDL_DRSInterDomainMove_Response),
    11: DceRpcOp(IDL_DRSGetNT4ChangeLog_Request, IDL_DRSGetNT4ChangeLog_Response),
    12: DceRpcOp(IDL_DRSCrackNames_Request, IDL_DRSCrackNames_Response),
    13: DceRpcOp(IDL_DRSWriteSPN_Request, IDL_DRSWriteSPN_Response),
    14: DceRpcOp(IDL_DRSRemoveDsServer_Request, IDL_DRSRemoveDsServer_Response),
    15: DceRpcOp(IDL_DRSRemoveDsDomain_Request, IDL_DRSRemoveDsDomain_Response),
    16: DceRpcOp(
        IDL_DRSDomainControllerInfo_Request, IDL_DRSDomainControllerInfo_Response
    ),
    17: DceRpcOp(IDL_DRSAddEntry_Request, IDL_DRSAddEntry_Response),
    18: DceRpcOp(IDL_DRSExecuteKCC_Request, IDL_DRSExecuteKCC_Response),
    19: DceRpcOp(IDL_DRSGetReplInfo_Request, IDL_DRSGetReplInfo_Response),
    20: DceRpcOp(IDL_DRSAddSidHistory_Request, IDL_DRSAddSidHistory_Response),
    21: DceRpcOp(IDL_DRSGetMemberships2_Request, IDL_DRSGetMemberships2_Response),
    22: DceRpcOp(
        IDL_DRSReplicaVerifyObjects_Request, IDL_DRSReplicaVerifyObjects_Response
    ),
    23: DceRpcOp(IDL_DRSGetObjectExistence_Request, IDL_DRSGetObjectExistence_Response),
    24: DceRpcOp(IDL_DRSQuerySitesByCost_Request, IDL_DRSQuerySitesByCost_Response),
    25: DceRpcOp(IDL_DRSInitDemotion_Request, IDL_DRSInitDemotion_Response),
    26: DceRpcOp(IDL_DRSReplicaDemotion_Request, IDL_DRSReplicaDemotion_Response),
    27: DceRpcOp(IDL_DRSFinishDemotion_Request, IDL_DRSFinishDemotion_Response),
    28: DceRpcOp(IDL_DRSAddCloneDC_Request, IDL_DRSAddCloneDC_Response),
    29: DceRpcOp(IDL_DRSWriteNgcKey_Request, IDL_DRSWriteNgcKey_Response),
    30: DceRpcOp(IDL_DRSReadNgcKey_Request, IDL_DRSReadNgcKey_Response),
}
register_dcerpc_interface(
    name="drsuapi",
    uuid=uuid.UUID("e3514235-4b06-11d1-ab04-00c04fc2dcd2"),
    version="4.0",
    opnums=DRSUAPI_OPNUMS,
)


class DSA_MSG_PREPARE_SCRIPT_REQ_V1(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("Reserved", 0)]


class DSA_MSG_PREPARE_SCRIPT_REPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwOperationStatus", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwErrMessage", ""), deferred=True
        ),
        NDRIntField("cbPassword", None, size_of="pbPassword"),
        NDRFullPointerField(
            NDRConfStrLenField("pbPassword", "", size_is=lambda pkt: pkt.cbPassword),
            deferred=True,
        ),
        NDRIntField("cbHashBody", None, size_of="pbHashBody"),
        NDRFullPointerField(
            NDRConfStrLenField("pbHashBody", "", size_is=lambda pkt: pkt.cbHashBody),
            deferred=True,
        ),
        NDRIntField("cbHashSignature", None, size_of="pbHashSignature"),
        NDRFullPointerField(
            NDRConfStrLenField(
                "pbHashSignature", "", size_is=lambda pkt: pkt.cbHashSignature
            ),
            deferred=True,
        ),
    ]


class IDL_DSAPrepareScript_Request(NDRPacket):
    fields_desc = [
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn",
                        DSA_MSG_PREPARE_SCRIPT_REQ_V1(),
                        DSA_MSG_PREPARE_SCRIPT_REQ_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 4),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DSAPrepareScript_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DSA_MSG_PREPARE_SCRIPT_REPLY_V1(),
                        DSA_MSG_PREPARE_SCRIPT_REPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


class DSA_MSG_EXECUTE_SCRIPT_REQ_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Flags", 0),
        NDRIntField("cbPassword", None, size_of="pbPassword"),
        NDRFullPointerField(
            NDRConfStrLenField("pbPassword", "", size_is=lambda pkt: pkt.cbPassword),
            deferred=True,
        ),
    ]


class DSA_MSG_EXECUTE_SCRIPT_REPLY_V1(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwOperationStatus", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("pwErrMessage", ""), deferred=True
        ),
    ]


class IDL_DSAExecuteScript_Request(NDRPacket):
    fields_desc = [
        NDRIntField("dwInVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgIn",
                        DSA_MSG_EXECUTE_SCRIPT_REQ_V1(),
                        DSA_MSG_EXECUTE_SCRIPT_REQ_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "dwInVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgIn", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class IDL_DSAExecuteScript_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwOutVersion", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "pmsgOut",
                        DSA_MSG_EXECUTE_SCRIPT_REPLY_V1(),
                        DSA_MSG_EXECUTE_SCRIPT_REPLY_V1,
                    ),
                    (
                        (lambda pkt: getattr(pkt, "pdwOutVersion", None) == 1),
                        (lambda _, val: val.tag == 1),
                    ),
                )
            ],
            StrFixedLenField("pmsgOut", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
        NDRIntField("status", 0),
    ]


DSAOP_OPNUMS = {
    0: DceRpcOp(IDL_DSAPrepareScript_Request, IDL_DSAPrepareScript_Response),
    1: DceRpcOp(IDL_DSAExecuteScript_Request, IDL_DSAExecuteScript_Response),
}
register_dcerpc_interface(
    name="dsaop",
    uuid=uuid.UUID("7c44d7d4-31d5-424c-bd5e-2b3e1f323d22"),
    version="1.0",
    opnums=DSAOP_OPNUMS,
)
