### ms-wmi.idl
"""
RPC definitions for the following interfaces:
- IWbemClassObject (v0.0): dc12a681-737f-11cf-884d-00aa004b2e24
- IWbemServices (v0.0): 9556dc99-828c-11cf-a37e-00aa003240c7
- IWbemObjectSink (v0.0): 7c857801-7381-11cf-884d-00aa004b2e24
- IEnumWbemClassObject (v0.0): 027947e1-d731-11ce-a357-000000000001
- IWbemCallResult (v0.0): 44aca675-e8fc-11d0-a07c-00c04fb68820
- IWbemContext (v0.0): 44aca674-e8fc-11d0-a07c-00c04fb68820
- IWbemBackupRestore (v0.0): C49E32C7-BC8B-11d2-85D4-00105A1F8304
- IWbemBackupRestoreEx (v0.0): A359DEC5-E813-4834-8A2A-BA7F1D777D76
- IWbemLoginClientID (v0.0): d4781cd6-e5d3-44df-ad94-930efe48a887
- IWbemLevel1Login (v0.0): F309AD18-D86A-11d0-A075-00C04FB68820
- IWbemLoginHelper (v0.0): 541679AB-2E5F-11d3-B34E-00104BCC4B4A
- IWbemQualifierSet (v0.0): None
- IWbemRemoteRefresher (v0.0): F1E9C5B2-F59B-11d2-B362-00105A1F8177
- IWbemRefreshingServices (v0.0): 2C9273E0-1DC3-11d3-B364-00105A1F8177
- IWbemWCOSmartEnum (v0.0): 423EC01E-2E35-11d2-B604-00104B703EFD
- IWbemFetchSmartEnum (v0.0): 1C1C45EE-4395-11d2-B60B-00104B703EFD
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import PacketListField, StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfFieldListField,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRConfVarPacketListField,
    NDRConfVarStrLenField,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRIntEnumField,
    NDRIntField,
    NDRPacketField,
    NDRShortField,
    NDRSignedByteField,
    NDRSignedIntField,
    NDRUnionField,
    register_com_interface,
    register_dcerpc_interface,
)

IWBEMCLASSOBJECT_OPNUMS = {}
register_com_interface(
    name="IWbemClassObject",
    uuid=uuid.UUID("dc12a681-737f-11cf-884d-00aa004b2e24"),
    opnums=IWBEMCLASSOBJECT_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 MInterfacePointer(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["abData"]
    fields_desc = [
        NDRIntField("ulCntData", None, size_of="abData"),
        NDRConfStrLenField(
            "abData", "", size_is=lambda pkt: pkt.ulCntData, conformant_in_struct=True
        ),
    ]


class OpenNamespace_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strNamespace", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "ppWorkingNamespace", MInterfacePointer(), MInterfacePointer
                )
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppResult", MInterfacePointer(), MInterfacePointer)
            )
        ),
    ]


class OpenNamespace_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField(
                    "ppWorkingNamespace", MInterfacePointer(), MInterfacePointer
                )
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppResult", MInterfacePointer(), MInterfacePointer)
            )
        ),
        NDRIntField("status", 0),
    ]


class CancelAsyncCall_Request(NDRPacket):
    fields_desc = [NDRPacketField("pSink", MInterfacePointer(), MInterfacePointer)]


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


class QueryObjectSink_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("lFlags", 0)]


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


class GetObject_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strObjectPath", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppObject", MInterfacePointer(), MInterfacePointer)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppCallResult", MInterfacePointer(), MInterfacePointer)
            )
        ),
    ]


class GetObject_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppObject", MInterfacePointer(), MInterfacePointer)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppCallResult", MInterfacePointer(), MInterfacePointer)
            )
        ),
        NDRIntField("status", 0),
    ]


class GetObjectAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strObjectPath", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pResponseHandler", MInterfacePointer(), MInterfacePointer),
    ]


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


class PutClass_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pObject", MInterfacePointer(), MInterfacePointer),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppCallResult", MInterfacePointer(), MInterfacePointer)
            )
        ),
    ]


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


class PutClassAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pObject", MInterfacePointer(), MInterfacePointer),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pResponseHandler", MInterfacePointer(), MInterfacePointer),
    ]


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


class DeleteClass_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strClass", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppCallResult", MInterfacePointer(), MInterfacePointer)
            )
        ),
    ]


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


class DeleteClassAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strClass", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pResponseHandler", MInterfacePointer(), MInterfacePointer),
    ]


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


class CreateClassEnum_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strSuperclass", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
    ]


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


class CreateClassEnumAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strSuperclass", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pResponseHandler", MInterfacePointer(), MInterfacePointer),
    ]


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


class PutInstance_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pInst", MInterfacePointer(), MInterfacePointer),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppCallResult", MInterfacePointer(), MInterfacePointer)
            )
        ),
    ]


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


class PutInstanceAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pInst", MInterfacePointer(), MInterfacePointer),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pResponseHandler", MInterfacePointer(), MInterfacePointer),
    ]


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


class DeleteInstance_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strObjectPath", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppCallResult", MInterfacePointer(), MInterfacePointer)
            )
        ),
    ]


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


class DeleteInstanceAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strObjectPath", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pResponseHandler", MInterfacePointer(), MInterfacePointer),
    ]


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


class CreateInstanceEnum_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strSuperClass", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
    ]


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


class CreateInstanceEnumAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strSuperClass", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pResponseHandler", MInterfacePointer(), MInterfacePointer),
    ]


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


class ExecQuery_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strQueryLanguage", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("strQuery", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
    ]


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


class ExecQueryAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strQueryLanguage", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("strQuery", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pResponseHandler", MInterfacePointer(), MInterfacePointer),
    ]


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


class ExecNotificationQuery_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strQueryLanguage", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("strQuery", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
    ]


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


class ExecNotificationQueryAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strQueryLanguage", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("strQuery", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pResponseHandler", MInterfacePointer(), MInterfacePointer),
    ]


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


class ExecMethod_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strObjectPath", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("strMethodName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pInParams", MInterfacePointer(), MInterfacePointer),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppOutParams", MInterfacePointer(), MInterfacePointer)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppCallResult", MInterfacePointer(), MInterfacePointer)
            )
        ),
    ]


class ExecMethod_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppOutParams", MInterfacePointer(), MInterfacePointer)
            )
        ),
        NDRFullPointerField(
            NDRFullPointerField(
                NDRPacketField("ppCallResult", MInterfacePointer(), MInterfacePointer)
            )
        ),
        NDRIntField("status", 0),
    ]


class ExecMethodAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("strObjectPath", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("strMethodName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pInParams", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pResponseHandler", MInterfacePointer(), MInterfacePointer),
    ]


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


IWBEMSERVICES_OPNUMS = {
    0: DceRpcOp(OpenNamespace_Request, OpenNamespace_Response),
    1: DceRpcOp(CancelAsyncCall_Request, CancelAsyncCall_Response),
    2: DceRpcOp(QueryObjectSink_Request, QueryObjectSink_Response),
    3: DceRpcOp(GetObject_Request, GetObject_Response),
    4: DceRpcOp(GetObjectAsync_Request, GetObjectAsync_Response),
    5: DceRpcOp(PutClass_Request, PutClass_Response),
    6: DceRpcOp(PutClassAsync_Request, PutClassAsync_Response),
    7: DceRpcOp(DeleteClass_Request, DeleteClass_Response),
    8: DceRpcOp(DeleteClassAsync_Request, DeleteClassAsync_Response),
    9: DceRpcOp(CreateClassEnum_Request, CreateClassEnum_Response),
    10: DceRpcOp(CreateClassEnumAsync_Request, CreateClassEnumAsync_Response),
    11: DceRpcOp(PutInstance_Request, PutInstance_Response),
    12: DceRpcOp(PutInstanceAsync_Request, PutInstanceAsync_Response),
    13: DceRpcOp(DeleteInstance_Request, DeleteInstance_Response),
    14: DceRpcOp(DeleteInstanceAsync_Request, DeleteInstanceAsync_Response),
    15: DceRpcOp(CreateInstanceEnum_Request, CreateInstanceEnum_Response),
    16: DceRpcOp(CreateInstanceEnumAsync_Request, CreateInstanceEnumAsync_Response),
    17: DceRpcOp(ExecQuery_Request, ExecQuery_Response),
    18: DceRpcOp(ExecQueryAsync_Request, ExecQueryAsync_Response),
    19: DceRpcOp(ExecNotificationQuery_Request, ExecNotificationQuery_Response),
    20: DceRpcOp(
        ExecNotificationQueryAsync_Request, ExecNotificationQueryAsync_Response
    ),
    21: DceRpcOp(ExecMethod_Request, ExecMethod_Response),
    22: DceRpcOp(ExecMethodAsync_Request, ExecMethodAsync_Response),
}
register_com_interface(
    name="IWbemServices",
    uuid=uuid.UUID("9556dc99-828c-11cf-a37e-00aa003240c7"),
    opnums=IWBEMSERVICES_OPNUMS,
)


class Indicate_Request(NDRPacket):
    fields_desc = [
        NDRSignedIntField("lObjectCount", None, size_of="apObjArray"),
        NDRConfPacketListField(
            "apObjArray",
            [],
            MInterfacePointer,
            size_is=lambda pkt: pkt.lObjectCount,
            ptr_pack=True,
        ),
    ]


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


class SetStatus_Request(NDRPacket):
    fields_desc = [
        NDRSignedIntField("lFlags", 0),
        NDRSignedIntField("hResult", 0),
        NDRPacketField("strParam", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("pObjParam", MInterfacePointer(), MInterfacePointer),
    ]


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


IWBEMOBJECTSINK_OPNUMS = {
    0: DceRpcOp(Indicate_Request, Indicate_Response),
    1: DceRpcOp(SetStatus_Request, SetStatus_Response),
}
register_com_interface(
    name="IWbemObjectSink",
    uuid=uuid.UUID("7c857801-7381-11cf-884d-00aa004b2e24"),
    opnums=IWBEMOBJECTSINK_OPNUMS,
)


class Reset_Request(NDRPacket):
    fields_desc = []


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


class Next_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("lTimeout", 0), NDRIntField("uCount", 0)]


class Next_Response(NDRPacket):
    fields_desc = [
        NDRConfVarPacketListField(
            "apObjects",
            [],
            MInterfacePointer,
            size_is=lambda pkt: pkt.uCount,
            length_is=lambda pkt: pkt.puReturned,
            ptr_pack=True,
        ),
        NDRIntField("puReturned", None, size_of="apObjects"),
        NDRIntField("status", 0),
    ]


class NextAsync_Request(NDRPacket):
    fields_desc = [
        NDRIntField("uCount", 0),
        NDRPacketField("pSink", MInterfacePointer(), MInterfacePointer),
    ]


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


class Clone_Request(NDRPacket):
    fields_desc = []


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


class Skip_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("lTimeout", 0), NDRIntField("nCount", 0)]


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


IENUMWBEMCLASSOBJECT_OPNUMS = {
    0: DceRpcOp(Reset_Request, Reset_Response),
    1: DceRpcOp(Next_Request, Next_Response),
    2: DceRpcOp(NextAsync_Request, NextAsync_Response),
    3: DceRpcOp(Clone_Request, Clone_Response),
    4: DceRpcOp(Skip_Request, Skip_Response),
}
register_com_interface(
    name="IEnumWbemClassObject",
    uuid=uuid.UUID("027947e1-d731-11ce-a357-000000000001"),
    opnums=IENUMWBEMCLASSOBJECT_OPNUMS,
)


class GetResultObject_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("lTimeout", 0)]


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


class GetResultString_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("lTimeout", 0)]


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


class GetResultServices_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("lTimeout", 0)]


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


class GetCallStatus_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("lTimeout", 0)]


class GetCallStatus_Response(NDRPacket):
    fields_desc = [NDRSignedIntField("plStatus", 0), NDRIntField("status", 0)]


IWBEMCALLRESULT_OPNUMS = {
    0: DceRpcOp(GetResultObject_Request, GetResultObject_Response),
    1: DceRpcOp(GetResultString_Request, GetResultString_Response),
    2: DceRpcOp(GetResultServices_Request, GetResultServices_Response),
    3: DceRpcOp(GetCallStatus_Request, GetCallStatus_Response),
}
register_com_interface(
    name="IWbemCallResult",
    uuid=uuid.UUID("44aca675-e8fc-11d0-a07c-00c04fb68820"),
    opnums=IWBEMCALLRESULT_OPNUMS,
)
IWBEMCONTEXT_OPNUMS = {}
register_com_interface(
    name="IWbemContext",
    uuid=uuid.UUID("44aca674-e8fc-11d0-a07c-00c04fb68820"),
    opnums=IWBEMCONTEXT_OPNUMS,
)


class Backup_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("strBackupToFile", ""),
        NDRSignedIntField("lFlags", 0),
    ]


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


class Restore_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("strRestoreFromFile", ""),
        NDRSignedIntField("lFlags", 0),
    ]


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


IWBEMBACKUPRESTORE_OPNUMS = {
    0: DceRpcOp(Backup_Request, Backup_Response),
    1: DceRpcOp(Restore_Request, Restore_Response),
}
register_com_interface(
    name="IWbemBackupRestore",
    uuid=uuid.UUID("C49E32C7-BC8B-11d2-85D4-00105A1F8304"),
    opnums=IWBEMBACKUPRESTORE_OPNUMS,
)


class Pause_Request(NDRPacket):
    fields_desc = []


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


class Resume_Request(NDRPacket):
    fields_desc = []


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


IWBEMBACKUPRESTOREEX_OPNUMS = {
    0: DceRpcOp(Pause_Request, Pause_Response),
    1: DceRpcOp(Resume_Request, Resume_Response),
}
register_com_interface(
    name="IWbemBackupRestoreEx",
    uuid=uuid.UUID("A359DEC5-E813-4834-8A2A-BA7F1D777D76"),
    opnums=IWBEMBACKUPRESTOREEX_OPNUMS,
)


class SetClientInfo_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("wszClientMachine", "")),
        NDRSignedIntField("lClientProcId", 0),
        NDRSignedIntField("lReserved", 0),
    ]


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


IWBEMLOGINCLIENTID_OPNUMS = {0: DceRpcOp(SetClientInfo_Request, SetClientInfo_Response)}
register_com_interface(
    name="IWbemLoginClientID",
    uuid=uuid.UUID("d4781cd6-e5d3-44df-ad94-930efe48a887"),
    opnums=IWBEMLOGINCLIENTID_OPNUMS,
)


class EstablishPosition_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("reserved1", "")),
        NDRIntField("reserved2", 0),
    ]


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


class RequestChallenge_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("reserved1", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("reserved2", "")),
    ]


class RequestChallenge_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "reserved3", "", size_is=lambda pkt: 16, length_is=lambda pkt: 16
        ),
        NDRIntField("status", 0),
    ]


class WBEMLogin_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("reserved1", "")),
        NDRConfVarStrLenField(
            "reserved2", "", size_is=lambda pkt: 16, length_is=lambda pkt: 16
        ),
        NDRSignedIntField("reserved3", 0),
        NDRPacketField("reserved4", MInterfacePointer(), MInterfacePointer),
    ]


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


class NTLMLogin_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("wszNetworkResource", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("wszPreferredLocale", "")),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pCtx", MInterfacePointer(), MInterfacePointer),
    ]


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


IWBEMLEVEL1LOGIN_OPNUMS = {
    0: DceRpcOp(EstablishPosition_Request, EstablishPosition_Response),
    1: DceRpcOp(RequestChallenge_Request, RequestChallenge_Response),
    2: DceRpcOp(WBEMLogin_Request, WBEMLogin_Response),
    3: DceRpcOp(NTLMLogin_Request, NTLMLogin_Response),
}
register_com_interface(
    name="IWbemLevel1Login",
    uuid=uuid.UUID("F309AD18-D86A-11d0-A075-00C04FB68820"),
    opnums=IWBEMLEVEL1LOGIN_OPNUMS,
)


class SetEvent_Request(NDRPacket):
    fields_desc = [NDRSignedByteField("sEventToSet", 0)]


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


IWBEMLOGINHELPER_OPNUMS = {0: DceRpcOp(SetEvent_Request, SetEvent_Response)}
register_com_interface(
    name="IWbemLoginHelper",
    uuid=uuid.UUID("541679AB-2E5F-11d3-B34E-00104BCC4B4A"),
    opnums=IWBEMLOGINHELPER_OPNUMS,
)


class WBEM_INSTANCE_BLOB_TYPE(IntEnum):
    WBEM_BLOB_TYPE_ALL = 2
    WBEM_BLOB_TYPE_ERROR = 3
    WBEM_BLOB_TYPE_ENUM = 4


class WBEM_REFRESHED_OBJECT(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRSignedIntField("m_lRequestId", 0),
        NDRIntEnumField("m_lBlobType", 0, WBEM_INSTANCE_BLOB_TYPE),
        NDRSignedIntField("m_lBlobLength", None, size_of="m_pbBlob"),
        NDRFullPointerField(
            NDRConfStrLenField("m_pbBlob", "", size_is=lambda pkt: pkt.m_lBlobLength),
            deferred=True,
        ),
    ]


class RemoteRefresh_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("lFlags", 0)]


class RemoteRefresh_Response(NDRPacket):
    fields_desc = [
        NDRSignedIntField("plNumObjects", None, size_of="paObjects"),
        NDRConfPacketListField(
            "paObjects",
            [],
            WBEM_REFRESHED_OBJECT,
            size_is=lambda pkt: pkt.plNumObjects,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


class StopRefreshing_Request(NDRPacket):
    fields_desc = [
        NDRSignedIntField("lNumIds", None, size_of="aplIds"),
        NDRConfFieldListField(
            "aplIds", [], NDRSignedIntField("", 0), size_is=lambda pkt: pkt.lNumIds
        ),
        NDRSignedIntField("lFlags", 0),
    ]


class StopRefreshing_Response(NDRPacket):
    fields_desc = [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 Opnum5NotUsedOnWire_Request(NDRPacket):
    fields_desc = [NDRSignedIntField("lFlags", 0)]


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


IWBEMREMOTEREFRESHER_OPNUMS = {
    0: DceRpcOp(RemoteRefresh_Request, RemoteRefresh_Response),
    1: DceRpcOp(StopRefreshing_Request, StopRefreshing_Response),
    2: DceRpcOp(Opnum5NotUsedOnWire_Request, Opnum5NotUsedOnWire_Response),
}
register_dcerpc_interface(
    name="IWbemRemoteRefresher",
    uuid=uuid.UUID("F1E9C5B2-F59B-11d2-B362-00105A1F8177"),
    version="0.0",
    opnums=IWBEMREMOTEREFRESHER_OPNUMS,
)


class _WBEM_REFRESHER_ID(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullField("m_szMachineName", ""), deferred=True
        ),
        NDRIntField("m_dwProcessId", 0),
        NDRPacketField("m_guidRefresherId", GUID(), GUID),
    ]


class WBEM_REFRESH_TYPE(IntEnum):
    WBEM_REFRESH_TYPE_INVALID = 0
    WBEM_REFRESH_TYPE_REMOTE = 3
    WBEM_REFRESH_TYPE_NON_HIPERF = 6


class _WBEM_REFRESH_INFO_REMOTE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("m_pRefresher", MInterfacePointer(), MInterfacePointer),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRPacketField("m_pTemplate", MInterfacePointer(), MInterfacePointer),
            deferred=True,
        ),
        NDRPacketField("m_Guid", GUID(), GUID),
    ]


class _WBEM_REFRESH_INFO_NON_HIPERF(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("m_wszNamespace", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRPacketField("m_pTemplate", MInterfacePointer(), MInterfacePointer),
            deferred=True,
        ),
    ]


class _WBEM_REFRESH_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRSignedIntField("m_lType", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "m_Info", _WBEM_REFRESH_INFO_REMOTE(), _WBEM_REFRESH_INFO_REMOTE
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_lType", None)
                            == WBEM_REFRESH_TYPE.WBEM_REFRESH_TYPE_REMOTE
                        ),
                        (
                            lambda _, val: val.tag
                            == WBEM_REFRESH_TYPE.WBEM_REFRESH_TYPE_REMOTE
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "m_Info",
                        _WBEM_REFRESH_INFO_NON_HIPERF(),
                        _WBEM_REFRESH_INFO_NON_HIPERF,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_lType", None)
                            == WBEM_REFRESH_TYPE.WBEM_REFRESH_TYPE_NON_HIPERF
                        ),
                        (
                            lambda _, val: val.tag
                            == WBEM_REFRESH_TYPE.WBEM_REFRESH_TYPE_NON_HIPERF
                        ),
                    ),
                ),
                (
                    NDRSignedIntField("m_Info", 0),
                    (
                        (
                            lambda pkt: getattr(pkt, "m_lType", None)
                            == WBEM_REFRESH_TYPE.WBEM_REFRESH_TYPE_INVALID
                        ),
                        (
                            lambda _, val: val.tag
                            == WBEM_REFRESH_TYPE.WBEM_REFRESH_TYPE_INVALID
                        ),
                    ),
                ),
            ],
            StrFixedLenField("m_Info", "", length=0),
            align=(4, 8),
            switch_fmt=("l", "l"),
        ),
        NDRSignedIntField("m_lCancelId", 0),
    ]


class AddObjectToRefresher_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pRefresherId", _WBEM_REFRESHER_ID(), _WBEM_REFRESHER_ID),
        NDRConfVarStrNullFieldUtf16("wszPath", ""),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pContext", MInterfacePointer(), MInterfacePointer),
        NDRIntField("dwClientRefrVersion", 0),
    ]


class AddObjectToRefresher_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pInfo", _WBEM_REFRESH_INFO(), _WBEM_REFRESH_INFO),
        NDRIntField("pdwSvrRefrVersion", 0),
        NDRIntField("status", 0),
    ]


class AddObjectToRefresherByTemplate_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pRefresherId", _WBEM_REFRESHER_ID(), _WBEM_REFRESHER_ID),
        NDRPacketField("pTemplate", MInterfacePointer(), MInterfacePointer),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pContext", MInterfacePointer(), MInterfacePointer),
        NDRIntField("dwClientRefrVersion", 0),
    ]


class AddObjectToRefresherByTemplate_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pInfo", _WBEM_REFRESH_INFO(), _WBEM_REFRESH_INFO),
        NDRIntField("pdwSvrRefrVersion", 0),
        NDRIntField("status", 0),
    ]


class AddEnumToRefresher_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pRefresherId", _WBEM_REFRESHER_ID(), _WBEM_REFRESHER_ID),
        NDRConfVarStrNullFieldUtf16("wszClass", ""),
        NDRSignedIntField("lFlags", 0),
        NDRPacketField("pContext", MInterfacePointer(), MInterfacePointer),
        NDRIntField("dwClientRefrVersion", 0),
    ]


class AddEnumToRefresher_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pInfo", _WBEM_REFRESH_INFO(), _WBEM_REFRESH_INFO),
        NDRIntField("pdwSvrRefrVersion", 0),
        NDRIntField("status", 0),
    ]


class RemoveObjectFromRefresher_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pRefresherId", _WBEM_REFRESHER_ID(), _WBEM_REFRESHER_ID),
        NDRSignedIntField("lId", 0),
        NDRSignedIntField("lFlags", 0),
        NDRIntField("dwClientRefrVersion", 0),
    ]


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


class GetRemoteRefresher_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pRefresherId", _WBEM_REFRESHER_ID(), _WBEM_REFRESHER_ID),
        NDRSignedIntField("lFlags", 0),
        NDRIntField("dwClientRefrVersion", 0),
    ]


class GetRemoteRefresher_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppRemRefresher", MInterfacePointer(), MInterfacePointer)
        ),
        NDRPacketField("pGuid", GUID(), GUID),
        NDRIntField("pdwSvrRefrVersion", 0),
        NDRIntField("status", 0),
    ]


class _WBEM_RECONNECT_INFO(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRSignedIntField("m_lType", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("m_pwcsPath", ""), deferred=True
        ),
    ]


class _WBEM_RECONNECT_RESULTS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRSignedIntField("m_lId", 0), NDRSignedIntField("m_hr", 0)]


class ReconnectRemoteRefresher_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pRefresherId", _WBEM_REFRESHER_ID(), _WBEM_REFRESHER_ID),
        NDRSignedIntField("lFlags", 0),
        NDRSignedIntField("lNumObjects", None, size_of="apReconnectResults"),
        NDRIntField("dwClientRefrVersion", 0),
        NDRConfPacketListField(
            "apReconnectInfo",
            [],
            _WBEM_RECONNECT_INFO,
            size_is=lambda pkt: pkt.lNumObjects,
        ),
        NDRConfPacketListField(
            "apReconnectResults",
            [],
            _WBEM_RECONNECT_RESULTS,
            size_is=lambda pkt: pkt.lNumObjects,
        ),
    ]


class ReconnectRemoteRefresher_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "apReconnectResults",
            [],
            _WBEM_RECONNECT_RESULTS,
            size_is=lambda pkt: pkt.lNumObjects,
        ),
        NDRIntField("pdwSvrRefrVersion", 0),
        NDRIntField("status", 0),
    ]


IWBEMREFRESHINGSERVICES_OPNUMS = {
    0: DceRpcOp(AddObjectToRefresher_Request, AddObjectToRefresher_Response),
    1: DceRpcOp(
        AddObjectToRefresherByTemplate_Request, AddObjectToRefresherByTemplate_Response
    ),
    2: DceRpcOp(AddEnumToRefresher_Request, AddEnumToRefresher_Response),
    3: DceRpcOp(RemoveObjectFromRefresher_Request, RemoveObjectFromRefresher_Response),
    4: DceRpcOp(GetRemoteRefresher_Request, GetRemoteRefresher_Response),
    5: DceRpcOp(ReconnectRemoteRefresher_Request, ReconnectRemoteRefresher_Response),
}
register_dcerpc_interface(
    name="IWbemRefreshingServices",
    uuid=uuid.UUID("2C9273E0-1DC3-11d3-B364-00105A1F8177"),
    version="0.0",
    opnums=IWBEMREFRESHINGSERVICES_OPNUMS,
)


class Next_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("proxyGUID", GUID(), GUID),
        NDRSignedIntField("lTimeout", 0),
        NDRIntField("uCount", 0),
    ]


class Next_Response(NDRPacket):
    fields_desc = [
        NDRIntField("puReturned", 0),
        NDRIntField("pdwBuffSize", None, size_of="pBuffer"),
        NDRConfStrLenField("pBuffer", "", size_is=lambda pkt: pkt.pdwBuffSize),
        NDRIntField("status", 0),
    ]


IWBEMWCOSMARTENUM_OPNUMS = {0: DceRpcOp(Next_Request, Next_Response)}
register_com_interface(
    name="IWbemWCOSmartEnum",
    uuid=uuid.UUID("423EC01E-2E35-11d2-B604-00104B703EFD"),
    opnums=IWBEMWCOSMARTENUM_OPNUMS,
)


class GetSmartEnum_Request(NDRPacket):
    fields_desc = []


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


IWBEMFETCHSMARTENUM_OPNUMS = {0: DceRpcOp(GetSmartEnum_Request, GetSmartEnum_Response)}
register_com_interface(
    name="IWbemFetchSmartEnum",
    uuid=uuid.UUID("1C1C45EE-4395-11d2-B60B-00104B703EFD"),
    opnums=IWBEMFETCHSMARTENUM_OPNUMS,
)
