### ms-coma.idl
"""
RPC definitions for the following interfaces:
- ICatalogSession (v0.0): 182C40FA-32E4-11D0-818B-00A0C9231C29
- ICatalog64BitSupport (v0.0): 1D118904-94B3-4A64-9FA6-ED432666A7B9
- ICatalogTableInfo (v0.0): A8927A41-D3CE-11D1-8472-006008B0E5CA
- ICatalogTableRead (v0.0): 0E3D6630-B46B-11D1-9D2D-006008B0E5CA
- ICatalogTableWrite (v0.0): 0E3D6631-B46B-11D1-9D2D-006008B0E5CA
- IRegister (v0.0): 8DB2180E-BD29-11D1-8B7E-00C04FD7A924
- IRegister2 (v0.0): 971668DC-C3FE-4EA1-9643-0C7230F494A1
- IImport (v0.0): C2BE6970-DF9E-11D1-8B87-00C04FD7A924
- IImport2 (v0.0): 1F7B1697-ECB2-4CBB-8A0E-75C427F4A6F0
- IExport (v0.0): CFADAC84-E12C-11D1-B34C-00C04F990D54
- IExport2 (v0.0): F131EA3E-B7BE-480E-A60D-51CB2785779E
- IAlternateLaunch (v0.0): 7F43B400-1A0E-4D57-BBC9-6B0C65F7A889
- ICatalogUtils (v0.0): 456129E2-1078-11D2-B0F9-00805FC73204
- ICatalogUtils2 (v0.0): C726744E-5735-4F08-8286-C510EE638FB6
- ICapabilitySupport (v0.0): 47CDE9A1-0BF6-11D2-8016-00C04FB9988E
- IContainerControl (v0.0): 3F3B1B86-DBBE-11D1-9DA6-00805F85CFE3
- IContainerControl2 (v0.0): 6C935649-30A6-4211-8687-C4C83E5FE1C7
- IReplicationUtil (v0.0): 98315903-7BE5-11D2-ADC1-00A02463D6E7
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRConfVarStrLenField,
    NDRConfVarStrLenFieldUtf16,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRIEEEFloatField,
    NDRInt3264EnumField,
    NDRIntField,
    NDRPacketField,
    NDRShortField,
    NDRSignedIntField,
    NDRSignedShortField,
    register_com_interface,
)


class InitializeSession_Request(NDRPacket):
    fields_desc = [
        NDRIEEEFloatField("flVerLower", 0),
        NDRIEEEFloatField("flVerUpper", 0),
        NDRSignedIntField("reserved", 0),
    ]


class InitializeSession_Response(NDRPacket):
    fields_desc = [NDRIEEEFloatField("pflVerSession", 0), NDRIntField("status", 0)]


class GetServerInformation_Request(NDRPacket):
    fields_desc = []


class GetServerInformation_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("plReserved1", 0),
        NDRSignedIntField("plReserved2", 0),
        NDRSignedIntField("plReserved3", 0),
        NDRSignedIntField("plMultiplePartitionSupport", 0),
        NDRSignedIntField("plReserved4", 0),
        NDRSignedIntField("plReserved5", 0),
        NDRIntField("status", 0),
    ]


ICATALOGSESSION_OPNUMS = {  # 0: Opnum3NotUsedOnWire,
    # 1: Opnum4NotUsedOnWire,
    # 2: Opnum5NotUsedOnWire,
    # 3: Opnum6NotUsedOnWire,
    4: DceRpcOp(InitializeSession_Request, InitializeSession_Response),
    5: DceRpcOp(GetServerInformation_Request, GetServerInformation_Response),
}
register_com_interface(
    name="ICatalogSession",
    uuid=uuid.UUID("182C40FA-32E4-11D0-818B-00A0C9231C29"),
    opnums=ICATALOGSESSION_OPNUMS,
)


class SupportsMultipleBitness_Request(NDRPacket):
    fields_desc = []


class SupportsMultipleBitness_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("pbSupportsMultipleBitness", 0),
        NDRIntField("status", 0),
    ]


class Initialize64BitQueryCellSupport_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("bClientSupports64BitQueryCells", 0)]


class Initialize64BitQueryCellSupport_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("pbServerSupports64BitQueryCells", 0),
        NDRIntField("status", 0),
    ]


ICATALOG64BITSUPPORT_OPNUMS = {
    0: DceRpcOp(SupportsMultipleBitness_Request, SupportsMultipleBitness_Response),
    1: DceRpcOp(
        Initialize64BitQueryCellSupport_Request,
        Initialize64BitQueryCellSupport_Response,
    ),
}
register_com_interface(
    name="ICatalog64BitSupport",
    uuid=uuid.UUID("1D118904-94B3-4A64-9FA6-ED432666A7B9"),
    opnums=ICATALOG64BITSUPPORT_OPNUMS,
)


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


class PropertyMeta(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dataType", 0),
        NDRIntField("cbSize", 0),
        NDRIntField("flags", 0),
    ]


class GetClientTableInfo_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pCatalogIdentifier", GUID(), GUID),
        NDRPacketField("pTableIdentifier", GUID(), GUID),
        NDRIntField("tableFlags", 0),
        NDRConfStrLenField(
            "pQueryCellArray", "", size_is=lambda pkt: pkt.cbQueryCellArray
        ),
        NDRIntField("cbQueryCellArray", None, size_of="pQueryCellArray"),
        NDRConfStrLenField(
            "pQueryComparison", "", size_is=lambda pkt: pkt.cbQueryComparison
        ),
        NDRIntField("cbQueryComparison", None, size_of="pQueryComparison"),
        NDRIntField("eQueryFormat", 0),
    ]


class GetClientTableInfo_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pRequiredFixedGuid", GUID(), GUID),
        NDRConfStrLenField("ppReserved1", "", size_is=lambda pkt: pkt.pcbReserved1),
        NDRIntField("pcbReserved1", None, size_of="ppReserved1"),
        NDRConfPacketListField(
            "ppAuxiliaryGuid",
            [],
            GUID,
            size_is=lambda pkt: pkt.pcAuxiliaryGuid,
            ptr_pack=True,
        ),
        NDRIntField("pcAuxiliaryGuid", None, size_of="ppAuxiliaryGuid"),
        NDRConfPacketListField(
            "ppPropertyMeta",
            [],
            PropertyMeta,
            size_is=lambda pkt: pkt.pcProperties,
            ptr_pack=True,
        ),
        NDRIntField("pcProperties", None, size_of="ppPropertyMeta"),
        NDRPacketField("piid", GUID(), GUID),
        StrFixedLenField("pItf", "", length=0),
        NDRConfStrLenField("ppReserved2", "", size_is=lambda pkt: pkt.pcbReserved2),
        NDRIntField("pcbReserved2", None, size_of="ppReserved2"),
        NDRIntField("status", 0),
    ]


ICATALOGTABLEINFO_OPNUMS = {
    0: DceRpcOp(GetClientTableInfo_Request, GetClientTableInfo_Response)
}
register_com_interface(
    name="ICatalogTableInfo",
    uuid=uuid.UUID("A8927A41-D3CE-11D1-8472-006008B0E5CA"),
    opnums=ICATALOGTABLEINFO_OPNUMS,
)


class ReadTable_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pCatalogIdentifier", GUID(), GUID),
        NDRPacketField("pTableIdentifier", GUID(), GUID),
        NDRIntField("tableFlags", 0),
        NDRConfStrLenField(
            "pQueryCellArray", "", size_is=lambda pkt: pkt.cbQueryCellArray
        ),
        NDRIntField("cbQueryCellArray", None, size_of="pQueryCellArray"),
        NDRConfStrLenField(
            "pQueryComparison", "", size_is=lambda pkt: pkt.cbQueryComparison
        ),
        NDRIntField("cbQueryComparison", None, size_of="pQueryComparison"),
        NDRIntField("eQueryFormat", 0),
    ]


class ReadTable_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField(
            "ppTableDataFixed", "", size_is=lambda pkt: pkt.pcbTableDataFixed
        ),
        NDRIntField("pcbTableDataFixed", None, size_of="ppTableDataFixed"),
        NDRConfStrLenField(
            "ppTableDataVariable", "", size_is=lambda pkt: pkt.pcbTableDataVariable
        ),
        NDRIntField("pcbTableDataVariable", None, size_of="ppTableDataVariable"),
        NDRConfStrLenField(
            "ppTableDetailedErrors", "", size_is=lambda pkt: pkt.pcbTableDetailedErrors
        ),
        NDRIntField("pcbTableDetailedErrors", None, size_of="ppTableDetailedErrors"),
        NDRConfStrLenField("ppReserved1", "", size_is=lambda pkt: pkt.pcbReserved1),
        NDRIntField("pcbReserved1", None, size_of="ppReserved1"),
        NDRConfStrLenField("ppReserved2", "", size_is=lambda pkt: pkt.pcbReserved2),
        NDRIntField("pcbReserved2", None, size_of="ppReserved2"),
        NDRIntField("status", 0),
    ]


ICATALOGTABLEREAD_OPNUMS = {0: DceRpcOp(ReadTable_Request, ReadTable_Response)}
register_com_interface(
    name="ICatalogTableRead",
    uuid=uuid.UUID("0E3D6630-B46B-11D1-9D2D-006008B0E5CA"),
    opnums=ICATALOGTABLEREAD_OPNUMS,
)


class WriteTable_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pCatalogIdentifier", GUID(), GUID),
        NDRPacketField("pTableIdentifier", GUID(), GUID),
        NDRIntField("tableFlags", 0),
        NDRConfStrLenField(
            "pQueryCellArray", "", size_is=lambda pkt: pkt.cbQueryCellArray
        ),
        NDRIntField("cbQueryCellArray", None, size_of="pQueryCellArray"),
        NDRConfStrLenField(
            "pQueryComparison", "", size_is=lambda pkt: pkt.cbQueryComparison
        ),
        NDRIntField("cbQueryComparison", None, size_of="pQueryComparison"),
        NDRIntField("eQueryFormat", 0),
        NDRConfStrLenField(
            "pTableDataFixedWrite", "", size_is=lambda pkt: pkt.cbTableDataFixedWrite
        ),
        NDRIntField("cbTableDataFixedWrite", None, size_of="pTableDataFixedWrite"),
        NDRConfStrLenField(
            "pTableDataVariable", "", size_is=lambda pkt: pkt.cbTableDataVariable
        ),
        NDRIntField("cbTableDataVariable", None, size_of="pTableDataVariable"),
        NDRConfStrLenField("pReserved1", "", size_is=lambda pkt: pkt.cbReserved1),
        NDRIntField("cbReserved1", None, size_of="pReserved1"),
        NDRConfStrLenField("pReserved2", "", size_is=lambda pkt: pkt.cbReserved2),
        NDRIntField("cbReserved2", None, size_of="pReserved2"),
        NDRConfStrLenField("pReserved3", "", size_is=lambda pkt: pkt.cbReserved3),
        NDRIntField("cbReserved3", None, size_of="pReserved3"),
    ]


class WriteTable_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField(
            "ppTableDetailedErrors", "", size_is=lambda pkt: pkt.pcbTableDetailedErrors
        ),
        NDRIntField("pcbTableDetailedErrors", None, size_of="ppTableDetailedErrors"),
        NDRIntField("status", 0),
    ]


ICATALOGTABLEWRITE_OPNUMS = {0: DceRpcOp(WriteTable_Request, WriteTable_Response)}
register_com_interface(
    name="ICatalogTableWrite",
    uuid=uuid.UUID("0E3D6631-B46B-11D1-9D2D-006008B0E5CA"),
    opnums=ICATALOGTABLEWRITE_OPNUMS,
)


class RegisterModule_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ConglomerationIdentifier", GUID(), GUID),
        NDRConfVarStrLenFieldUtf16("ppModules", "", size_is=lambda pkt: pkt.cModules),
        NDRIntField("cModules", None, size_of="ppModules"),
        NDRIntField("dwFlags", 0),
        NDRConfPacketListField(
            "pRequestedCLSIDs", [], GUID, size_is=lambda pkt: pkt.cRequested
        ),
        NDRIntField("cRequested", None, size_of="pRequestedCLSIDs"),
    ]


class RegisterModule_Response(NDRPacket):
    fields_desc = [
        NDRConfFieldListField(
            "ppModuleFlags",
            [],
            NDRIntField("", 0),
            size_is=lambda pkt: pkt.cModules,
            ptr_pack=True,
        ),
        NDRIntField("pcResults", None, size_of="ppResultHRs"),
        NDRConfPacketListField(
            "ppResultCLSIDs", [], GUID, size_is=lambda pkt: pkt.pcResults, ptr_pack=True
        ),
        NDRConfVarStrLenFieldUtf16(
            "ppResultNames", "", size_is=lambda pkt: pkt.pcResults
        ),
        NDRConfFieldListField(
            "ppResultFlags",
            [],
            NDRIntField("", 0),
            size_is=lambda pkt: pkt.pcResults,
            ptr_pack=True,
        ),
        NDRConfFieldListField(
            "ppResultHRs",
            [],
            NDRSignedIntField("", 0),
            size_is=lambda pkt: pkt.pcResults,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


IREGISTER_OPNUMS = {
    0: DceRpcOp(RegisterModule_Request, RegisterModule_Response),
    # 1: Opnum4NotUsedOnWire
}
register_com_interface(
    name="IRegister",
    uuid=uuid.UUID("8DB2180E-BD29-11D1-8B7E-00C04FD7A924"),
    opnums=IREGISTER_OPNUMS,
)


class eComponentType(IntEnum):
    eCT_UNKNOWN = 0
    eCT_32BIT = 1
    eCT_64BIT = 2
    eCT_NATIVE = 4096


class CreateFullConfiguration_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pwszConglomerationIdOrName", ""),
        NDRConfVarStrNullFieldUtf16("pwszCLSIDOrProgId", ""),
        NDRInt3264EnumField("ctComponentType", 0, eComponentType),
    ]


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


class CreateLegacyConfiguration_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pwszConglomerationIdOrName", ""),
        NDRConfVarStrNullFieldUtf16("pwszCLSIDOrProgId", ""),
        NDRInt3264EnumField("ctComponentType", 0, eComponentType),
    ]


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


class PromoteLegacyConfiguration_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pwszConglomerationIdOrName", ""),
        NDRConfVarStrNullFieldUtf16("pwszCLSIDOrProgId", ""),
        NDRInt3264EnumField("ctComponentType", 0, eComponentType),
    ]


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


class RegisterModule2_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ConglomerationIdentifier", GUID(), GUID),
        NDRPacketField("PartitionIdentifier", GUID(), GUID),
        NDRConfVarStrLenFieldUtf16("ppModules", "", size_is=lambda pkt: pkt.cModules),
        NDRIntField("cModules", None, size_of="ppModules"),
        NDRIntField("dwFlags", 0),
        NDRConfPacketListField(
            "pRequestedCLSIDs", [], GUID, size_is=lambda pkt: pkt.cRequested
        ),
        NDRIntField("cRequested", None, size_of="pRequestedCLSIDs"),
    ]


class RegisterModule2_Response(NDRPacket):
    fields_desc = [
        NDRConfFieldListField(
            "ppModuleFlags",
            [],
            NDRIntField("", 0),
            size_is=lambda pkt: pkt.cModules,
            ptr_pack=True,
        ),
        NDRIntField("pcResults", None, size_of="ppResultHRs"),
        NDRConfPacketListField(
            "ppResultCLSIDs", [], GUID, size_is=lambda pkt: pkt.pcResults, ptr_pack=True
        ),
        NDRConfVarStrLenFieldUtf16(
            "ppResultNames", "", size_is=lambda pkt: pkt.pcResults
        ),
        NDRConfFieldListField(
            "ppResultFlags",
            [],
            NDRIntField("", 0),
            size_is=lambda pkt: pkt.pcResults,
            ptr_pack=True,
        ),
        NDRConfFieldListField(
            "ppResultHRs",
            [],
            NDRSignedIntField("", 0),
            size_is=lambda pkt: pkt.pcResults,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


IREGISTER2_OPNUMS = {
    0: DceRpcOp(CreateFullConfiguration_Request, CreateFullConfiguration_Response),
    1: DceRpcOp(CreateLegacyConfiguration_Request, CreateLegacyConfiguration_Response),
    2: DceRpcOp(
        PromoteLegacyConfiguration_Request, PromoteLegacyConfiguration_Response
    ),
    # 3: Opnum6NotUsedOnWire,
    # 4: Opnum7NotUsedOnWire,
    5: DceRpcOp(RegisterModule2_Request, RegisterModule2_Response),
    # 6: Opnum9NotUsedOnWire
}
register_com_interface(
    name="IRegister2",
    uuid=uuid.UUID("971668DC-C3FE-4EA1-9643-0C7230F494A1"),
    opnums=IREGISTER2_OPNUMS,
)


class ImportFromFile_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszModuleDestination", "")),
        NDRConfVarStrNullFieldUtf16("pwszInstallerPackage", ""),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszUser", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszPassword", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszRemoteServerName", "")),
        NDRIntField("dwFlags", 0),
        NDRPacketField("reserved1", GUID(), GUID),
        NDRIntField("reserved2", 0),
    ]


class ImportFromFile_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcModules", None, size_of="ppModules"),
        NDRConfFieldListField(
            "ppModuleFlags",
            [],
            NDRIntField("", 0),
            size_is=lambda pkt: pkt.pcModules,
            ptr_pack=True,
        ),
        NDRConfVarStrLenFieldUtf16("ppModules", "", size_is=lambda pkt: pkt.pcModules),
        NDRIntField("pcComponents", None, size_of="ppResultHRs"),
        NDRConfPacketListField(
            "ppResultCLSIDs",
            [],
            GUID,
            size_is=lambda pkt: pkt.pcComponents,
            ptr_pack=True,
        ),
        NDRConfVarStrLenFieldUtf16(
            "ppResultNames", "", size_is=lambda pkt: pkt.pcComponents
        ),
        NDRConfFieldListField(
            "ppResultFlags",
            [],
            NDRIntField("", 0),
            size_is=lambda pkt: pkt.pcComponents,
            ptr_pack=True,
        ),
        NDRConfFieldListField(
            "ppResultHRs",
            [],
            NDRSignedIntField("", 0),
            size_is=lambda pkt: pkt.pcComponents,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


class QueryFile_Request(NDRPacket):
    fields_desc = [NDRConfVarStrNullFieldUtf16("pwszInstallerPackage", "")]


class QueryFile_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwConglomerations", None, size_of="ppDescriptions"),
        NDRConfVarStrLenFieldUtf16(
            "ppNames", "", size_is=lambda pkt: pkt.pdwConglomerations
        ),
        NDRConfVarStrLenFieldUtf16(
            "ppDescriptions", "", size_is=lambda pkt: pkt.pdwConglomerations
        ),
        NDRIntField("pdwUsers", 0),
        NDRIntField("pdwIsProxy", 0),
        NDRIntField("pcModules", None, size_of="ppModules"),
        NDRConfVarStrLenFieldUtf16("ppModules", "", size_is=lambda pkt: pkt.pcModules),
        NDRIntField("status", 0),
    ]


IIMPORT_OPNUMS = {
    0: DceRpcOp(ImportFromFile_Request, ImportFromFile_Response),
    1: DceRpcOp(QueryFile_Request, QueryFile_Response),
    # 2: Opnum5NotUsedOnWire,
    # 3: Opnum6NotUsedOnWire
}
register_com_interface(
    name="IImport",
    uuid=uuid.UUID("C2BE6970-DF9E-11D1-8B87-00C04FD7A924"),
    opnums=IIMPORT_OPNUMS,
)


class SetPartition_Request(NDRPacket):
    fields_desc = [NDRPacketField("pPartitionIdentifier", GUID(), GUID)]


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


IIMPORT2_OPNUMS = {
    0: DceRpcOp(SetPartition_Request, SetPartition_Response),
    # 1: Opnum4NotUsedOnWire,
    # 2: Opnum5NotUsedOnWire
}
register_com_interface(
    name="IImport2",
    uuid=uuid.UUID("1F7B1697-ECB2-4CBB-8A0E-75C427F4A6F0"),
    opnums=IIMPORT2_OPNUMS,
)


class ExportConglomeration_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pConglomerationIdentifier", GUID(), GUID),
        NDRShortField("pwszInstallerPackage", 0),
        NDRShortField("pwszReserved", 0),
        NDRIntField("dwFlags", 0),
    ]


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


IEXPORT_OPNUMS = {
    0: DceRpcOp(ExportConglomeration_Request, ExportConglomeration_Response),
    # 1: Opnum4NotUsedOnWire,
    # 2: Opnum5NotUsedOnWire,
    # 3: Opnum6NotUsedOnWire
}
register_com_interface(
    name="IExport",
    uuid=uuid.UUID("CFADAC84-E12C-11D1-B34C-00C04F990D54"),
    opnums=IEXPORT_OPNUMS,
)


class ExportPartition_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pPartitionIdentifier", GUID(), GUID),
        NDRShortField("pwszInstallerPackage", 0),
        NDRShortField("pwszReserved", 0),
        NDRIntField("dwFlags", 0),
    ]


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


IEXPORT2_OPNUMS = {0: DceRpcOp(ExportPartition_Request, ExportPartition_Response)}
register_com_interface(
    name="IExport2",
    uuid=uuid.UUID("F131EA3E-B7BE-480E-A60D-51CB2785779E"),
    opnums=IEXPORT2_OPNUMS,
)


class FLAGGED_WORD_BLOB(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["asData"]
    fields_desc = [
        NDRIntField("cBytes", 0),
        NDRIntField("clSize", None, size_of="asData"),
        NDRConfStrLenFieldUtf16(
            "asData", "", size_is=lambda pkt: pkt.clSize, conformant_in_struct=True
        ),
    ]


class CreateConfiguration_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ConglomerationIdentifier", GUID(), GUID),
        NDRPacketField("bstrConfigurationName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRIntField("dwStartType", 0),
        NDRIntField("dwErrorControl", 0),
        NDRPacketField("bstrDependencies", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("bstrRunAs", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("bstrPassword", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedShortField("bDesktopOk", 0),
    ]


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


class DeleteConfiguration_Request(NDRPacket):
    fields_desc = [NDRPacketField("ConglomerationIdentifier", GUID(), GUID)]


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


IALTERNATELAUNCH_OPNUMS = {
    0: DceRpcOp(CreateConfiguration_Request, CreateConfiguration_Response),
    1: DceRpcOp(DeleteConfiguration_Request, DeleteConfiguration_Response),
}
register_com_interface(
    name="IAlternateLaunch",
    uuid=uuid.UUID("7F43B400-1A0E-4D57-BBC9-6B0C65F7A889"),
    opnums=IALTERNATELAUNCH_OPNUMS,
)


class ValidateUser_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszPrincipalName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pwszPassword", "")),
    ]


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


class WaitForEndWrites_Request(NDRPacket):
    fields_desc = []


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


class GetEventClassesForIID_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("wszIID", ""))]


class GetEventClassesForIID_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcClasses", None, size_of="pawszDescriptions"),
        NDRConfVarStrLenFieldUtf16(
            "pawszCLSIDs", "", size_is=lambda pkt: pkt.pcClasses
        ),
        NDRConfVarStrLenFieldUtf16(
            "pawszProgIDs", "", size_is=lambda pkt: pkt.pcClasses
        ),
        NDRConfVarStrLenFieldUtf16(
            "pawszDescriptions", "", size_is=lambda pkt: pkt.pcClasses
        ),
        NDRIntField("status", 0),
    ]


ICATALOGUTILS_OPNUMS = {
    0: DceRpcOp(ValidateUser_Request, ValidateUser_Response),
    1: DceRpcOp(WaitForEndWrites_Request, WaitForEndWrites_Response),
    2: DceRpcOp(GetEventClassesForIID_Request, GetEventClassesForIID_Response),
}
register_com_interface(
    name="ICatalogUtils",
    uuid=uuid.UUID("456129E2-1078-11D2-B0F9-00805FC73204"),
    opnums=ICATALOGUTILS_OPNUMS,
)


class CopyConglomerations_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pwszSourcePartition", ""),
        NDRConfVarStrNullFieldUtf16("pwszDestPartition", ""),
        NDRIntField("cConglomerations", None, size_of="ppwszConglomerationNamesOrIds"),
        NDRConfVarStrLenFieldUtf16(
            "ppwszConglomerationNamesOrIds",
            "",
            size_is=lambda pkt: pkt.cConglomerations,
        ),
    ]


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


class CopyComponentConfiguration_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pwszSourceConglomeration", ""),
        NDRConfVarStrNullFieldUtf16("pwszComponent", ""),
        NDRConfVarStrNullFieldUtf16("pwszDestConglomeration", ""),
    ]


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


class AliasComponent_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pwszSourceConglomeration", ""),
        NDRConfVarStrNullFieldUtf16("pwszComponent", ""),
        NDRConfVarStrNullFieldUtf16("pwszDestConglomeration", ""),
        NDRPacketField("pNewCLSID", GUID(), GUID),
        NDRConfVarStrNullFieldUtf16("pwszNewProgID", ""),
    ]


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


class MoveComponentConfiguration_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("pwszSourceConglomeration", ""),
        NDRConfVarStrNullFieldUtf16("pwszComponent", ""),
        NDRConfVarStrNullFieldUtf16("pwszDestinationConglomeration", ""),
    ]


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


class GetEventClassesForIID2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("wszIID", "")),
        NDRPacketField("PartitionId", GUID(), GUID),
    ]


class GetEventClassesForIID2_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcClasses", None, size_of="padwIsPrivate"),
        NDRConfVarStrLenFieldUtf16(
            "pawszCLSIDs", "", size_is=lambda pkt: pkt.pcClasses
        ),
        NDRConfVarStrLenFieldUtf16(
            "pawszProgIDs", "", size_is=lambda pkt: pkt.pcClasses
        ),
        NDRConfVarStrLenFieldUtf16(
            "pawszDescriptions", "", size_is=lambda pkt: pkt.pcClasses
        ),
        NDRConfVarStrLenFieldUtf16(
            "pawszConglomerationIDs", "", size_is=lambda pkt: pkt.pcClasses
        ),
        NDRConfFieldListField(
            "padwIsPrivate",
            [],
            NDRIntField("", 0),
            size_is=lambda pkt: pkt.pcClasses,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


class IsSafeToDelete_Request(NDRPacket):
    fields_desc = [NDRPacketField("bstrFile", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)]


class IsSafeToDelete_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("pInUse", 0), NDRIntField("status", 0)]


class FlushPartitionCache_Request(NDRPacket):
    fields_desc = []


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


class SRPLevelInfo(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwSRPLevel", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("wszFriendlyName", ""), deferred=True
        ),
    ]


class EnumerateSRPLevels_Request(NDRPacket):
    fields_desc = [NDRIntField("Locale", 0)]


class EnumerateSRPLevels_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("cLevels", None, size_of="aSRPLevels"),
        NDRConfPacketListField(
            "aSRPLevels",
            [],
            SRPLevelInfo,
            size_is=lambda pkt: pkt.cLevels,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


class GetComponentVersions_Request(NDRPacket):
    fields_desc = [NDRShortField("pwszClsidOrProgId", 0)]


class GetComponentVersions_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwVersions", None, size_of="ppBitness"),
        NDRConfPacketListField(
            "ppPartitionIDs",
            [],
            GUID,
            size_is=lambda pkt: pkt.pdwVersions,
            ptr_pack=True,
        ),
        NDRConfPacketListField(
            "ppConglomerationIDs",
            [],
            GUID,
            size_is=lambda pkt: pkt.pdwVersions,
            ptr_pack=True,
        ),
        NDRConfFieldListField(
            "ppIsPrivate",
            [],
            NDRSignedIntField("", 0),
            size_is=lambda pkt: pkt.pdwVersions,
            ptr_pack=True,
        ),
        NDRConfFieldListField(
            "ppBitness",
            [],
            NDRSignedIntField("", 0),
            size_is=lambda pkt: pkt.pdwVersions,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


ICATALOGUTILS2_OPNUMS = {
    0: DceRpcOp(CopyConglomerations_Request, CopyConglomerations_Response),
    1: DceRpcOp(
        CopyComponentConfiguration_Request, CopyComponentConfiguration_Response
    ),
    2: DceRpcOp(AliasComponent_Request, AliasComponent_Response),
    3: DceRpcOp(
        MoveComponentConfiguration_Request, MoveComponentConfiguration_Response
    ),
    4: DceRpcOp(GetEventClassesForIID2_Request, GetEventClassesForIID2_Response),
    5: DceRpcOp(IsSafeToDelete_Request, IsSafeToDelete_Response),
    6: DceRpcOp(FlushPartitionCache_Request, FlushPartitionCache_Response),
    7: DceRpcOp(EnumerateSRPLevels_Request, EnumerateSRPLevels_Response),
    8: DceRpcOp(GetComponentVersions_Request, GetComponentVersions_Response),
}
register_com_interface(
    name="ICatalogUtils2",
    uuid=uuid.UUID("C726744E-5735-4F08-8286-C510EE638FB6"),
    opnums=ICATALOGUTILS2_OPNUMS,
)


class CatSrvServices(IntEnum):
    css_lb = 1


class Start_Request(NDRPacket):
    fields_desc = [NDRInt3264EnumField("i_css", 0, CatSrvServices)]


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


class Stop_Request(NDRPacket):
    fields_desc = [NDRInt3264EnumField("i_css", 0, CatSrvServices)]


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


class IsInstalled_Request(NDRPacket):
    fields_desc = [NDRInt3264EnumField("i_css", 0, CatSrvServices)]


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


class CatSrvServiceState(IntEnum):
    css_serviceStopped = 0
    css_serviceStartPending = 1
    css_serviceStopPending = 2
    css_serviceRunning = 3
    css_serviceContinuePending = 4
    css_servicePausePending = 5
    css_servicePaused = 6
    css_serviceUnknownState = 7


class IsRunning_Request(NDRPacket):
    fields_desc = [NDRInt3264EnumField("i_css", 0, CatSrvServices)]


class IsRunning_Response(NDRPacket):
    fields_desc = [
        NDRInt3264EnumField("pulStates", 0, CatSrvServiceState),
        NDRIntField("status", 0),
    ]


ICAPABILITYSUPPORT_OPNUMS = {
    0: DceRpcOp(Start_Request, Start_Response),
    1: DceRpcOp(Stop_Request, Stop_Response),
    # 2: Opnum5NotUsedOnWire,
    # 3: Opnum6NotUsedOnWire,
    4: DceRpcOp(IsInstalled_Request, IsInstalled_Response),
    5: DceRpcOp(IsRunning_Request, IsRunning_Response),
    # 6: Opnum9NotUsedOnWire
}
register_com_interface(
    name="ICapabilitySupport",
    uuid=uuid.UUID("47CDE9A1-0BF6-11D2-8016-00C04FB9988E"),
    opnums=ICAPABILITYSUPPORT_OPNUMS,
)


class CreateContainer_Request(NDRPacket):
    fields_desc = [NDRPacketField("pConglomerationIdentifier", GUID(), GUID)]


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


class ShutdownContainers_Request(NDRPacket):
    fields_desc = [NDRPacketField("pConglomerationIdentifier", GUID(), GUID)]


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


class RefreshComponents_Request(NDRPacket):
    fields_desc = []


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


ICONTAINERCONTROL_OPNUMS = {
    0: DceRpcOp(CreateContainer_Request, CreateContainer_Response),
    1: DceRpcOp(ShutdownContainers_Request, ShutdownContainers_Response),
    2: DceRpcOp(RefreshComponents_Request, RefreshComponents_Response),
}
register_com_interface(
    name="IContainerControl",
    uuid=uuid.UUID("3F3B1B86-DBBE-11D1-9DA6-00805F85CFE3"),
    opnums=ICONTAINERCONTROL_OPNUMS,
)


class ShutdownContainer_Request(NDRPacket):
    fields_desc = [NDRPacketField("ContainerIdentifier", GUID(), GUID)]


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


class PauseContainer_Request(NDRPacket):
    fields_desc = [NDRPacketField("ContainerIdentifier", GUID(), GUID)]


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


class ResumeContainer_Request(NDRPacket):
    fields_desc = [NDRPacketField("ContainerIdentifier", GUID(), GUID)]


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


class IsContainerPaused_Request(NDRPacket):
    fields_desc = [NDRPacketField("ContainerIdentifier", GUID(), GUID)]


class IsContainerPaused_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("bPaused", 0), NDRIntField("status", 0)]


class InstanceContainer(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("ConglomerationID", GUID(), GUID),
        NDRPacketField("PartitionID", GUID(), GUID),
        NDRPacketField("ContainerID", GUID(), GUID),
        NDRIntField("dwProcessID", 0),
        NDRSignedIntField("bPaused", 0),
        NDRSignedIntField("bRecycled", 0),
    ]


class GetRunningContainers_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("PartitionId", GUID(), GUID),
        NDRPacketField("ConglomerationId", GUID(), GUID),
    ]


class GetRunningContainers_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwNumContainers", None, size_of="ppContainers"),
        NDRConfPacketListField(
            "ppContainers",
            [],
            InstanceContainer,
            size_is=lambda pkt: pkt.pdwNumContainers,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


class GetContainerIDFromProcessID_Request(NDRPacket):
    fields_desc = [NDRIntField("dwPID", 0)]


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


class RecycleContainer_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("ContainerIdentifier", GUID(), GUID),
        NDRSignedIntField("lReasonCode", 0),
    ]


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


class GetContainerIDFromConglomerationID_Request(NDRPacket):
    fields_desc = [NDRPacketField("ConglomerationIdentifier", GUID(), GUID)]


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


ICONTAINERCONTROL2_OPNUMS = {
    0: DceRpcOp(ShutdownContainer_Request, ShutdownContainer_Response),
    1: DceRpcOp(PauseContainer_Request, PauseContainer_Response),
    2: DceRpcOp(ResumeContainer_Request, ResumeContainer_Response),
    3: DceRpcOp(IsContainerPaused_Request, IsContainerPaused_Response),
    4: DceRpcOp(GetRunningContainers_Request, GetRunningContainers_Response),
    5: DceRpcOp(
        GetContainerIDFromProcessID_Request, GetContainerIDFromProcessID_Response
    ),
    6: DceRpcOp(RecycleContainer_Request, RecycleContainer_Response),
    7: DceRpcOp(
        GetContainerIDFromConglomerationID_Request,
        GetContainerIDFromConglomerationID_Response,
    ),
}
register_com_interface(
    name="IContainerControl2",
    uuid=uuid.UUID("6C935649-30A6-4211-8687-C4C83E5FE1C7"),
    opnums=ICONTAINERCONTROL2_OPNUMS,
)


class CreateShare_Request(NDRPacket):
    fields_desc = [NDRShortField("pwszShareName", 0), NDRShortField("pwszPath", 0)]


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


class CreateEmptyDir_Request(NDRPacket):
    fields_desc = [NDRShortField("pwszPath", 0)]


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


class RemoveShare_Request(NDRPacket):
    fields_desc = [NDRShortField("pwszShareName", 0)]


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


class BeginReplicationAsTarget_Request(NDRPacket):
    fields_desc = [NDRShortField("pwszBaseReplicationDir", 0)]


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


class QueryConglomerationPassword_Request(NDRPacket):
    fields_desc = [NDRPacketField("ConglomerationId", GUID(), GUID)]


class QueryConglomerationPassword_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("ppvPassword", "", size_is=lambda pkt: pkt.pcbPassword),
        NDRIntField("pcbPassword", None, size_of="ppvPassword"),
        NDRIntField("status", 0),
    ]


class CreateReplicationDir_Request(NDRPacket):
    fields_desc = []


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


IREPLICATIONUTIL_OPNUMS = {
    0: DceRpcOp(CreateShare_Request, CreateShare_Response),
    1: DceRpcOp(CreateEmptyDir_Request, CreateEmptyDir_Response),
    2: DceRpcOp(RemoveShare_Request, RemoveShare_Response),
    3: DceRpcOp(BeginReplicationAsTarget_Request, BeginReplicationAsTarget_Response),
    4: DceRpcOp(
        QueryConglomerationPassword_Request, QueryConglomerationPassword_Response
    ),
    5: DceRpcOp(CreateReplicationDir_Request, CreateReplicationDir_Response),
}
register_com_interface(
    name="IReplicationUtil",
    uuid=uuid.UUID("98315903-7BE5-11D2-ADC1-00A02463D6E7"),
    opnums=IREPLICATIONUTIL_OPNUMS,
)
