### ms-comt.idl
"""
RPC definitions for the following interfaces:
- IGetTrackingData (v0.0): B60040E0-BCF3-11D1-861D-0080C729264D
- IComTrackingInfoEvents (v0.0): 4E6CDCC9-FB25-4FD5-9CC5-C9F4B6559CEC
- IProcessDump (v0.0): 23C9DD26-2355-4FE2-84DE-F779A238ADBD
This file is auto-generated by midl-to-scapy, do not modify.
"""

import uuid

from scapy.fields import StrFixedLenField, StrFixedLenFieldUtf16
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRFullPointerField,
    NDRIntField,
    NDRPacketField,
    NDRShortField,
    register_com_interface,
)


class ContainerStatistics(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("cCalls", 0),
        NDRIntField("cComponentInstances", 0),
        NDRIntField("cComponents", 0),
        NDRIntField("cCallsPerSecond", 0),
    ]


class ContainerData(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dwLegacyId", 0),
        StrFixedLenFieldUtf16("wszApplicationIdentifier", "", length=40 * 2),
        NDRIntField("dwProcessId", 0),
        NDRPacketField("statistics", ContainerStatistics(), ContainerStatistics),
    ]


class GetContainerData_Request(NDRPacket):
    fields_desc = []


class GetContainerData_Response(NDRPacket):
    fields_desc = [
        NDRIntField("nContainers", None, size_of="aContainerData"),
        NDRConfPacketListField(
            "aContainerData",
            [],
            ContainerData,
            size_is=lambda pkt: pkt.nContainers,
            ptr_pack=True,
        ),
        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 ComponentData(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("clsid", GUID(), GUID),
        NDRIntField("cTotalReferences", 0),
        NDRIntField("cBoundReferences", 0),
        NDRIntField("cPooledInstances", 0),
        NDRIntField("cInstancesInCall", 0),
        NDRIntField("dwResponseTime", 0),
        NDRIntField("cCallsCompleted", 0),
        NDRIntField("cCallsFailed", 0),
    ]


class GetComponentDataByContainer_Request(NDRPacket):
    fields_desc = [NDRIntField("idContainer", 0)]


class GetComponentDataByContainer_Response(NDRPacket):
    fields_desc = [
        NDRIntField("nComponents", None, size_of="aComponentData"),
        NDRConfPacketListField(
            "aComponentData",
            [],
            ComponentData,
            size_is=lambda pkt: pkt.nComponents,
            ptr_pack=True,
        ),
        NDRIntField("status", 0),
    ]


class GetComponentDataByContainerAndCLSID_Request(NDRPacket):
    fields_desc = [NDRIntField("idContainer", 0), NDRPacketField("clsid", GUID(), GUID)]


class GetComponentDataByContainerAndCLSID_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppComponentData", ComponentData(), ComponentData)
        ),
        NDRIntField("status", 0),
    ]


IGETTRACKINGDATA_OPNUMS = {  # 0: Opnum3NotUsedOnWire,
    1: DceRpcOp(GetContainerData_Request, GetContainerData_Response),
    2: DceRpcOp(
        GetComponentDataByContainer_Request, GetComponentDataByContainer_Response
    ),
    3: DceRpcOp(
        GetComponentDataByContainerAndCLSID_Request,
        GetComponentDataByContainerAndCLSID_Response,
    ),
    # 4: Opnum7NotUsedOnWire
}
register_com_interface(
    name="IGetTrackingData",
    uuid=uuid.UUID("B60040E0-BCF3-11D1-861D-0080C729264D"),
    opnums=IGETTRACKINGDATA_OPNUMS,
)


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 OnNewTrackingInfo_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pToplevelCollection", MInterfacePointer(), MInterfacePointer)
    ]


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


ICOMTRACKINGINFOEVENTS_OPNUMS = {
    0: DceRpcOp(OnNewTrackingInfo_Request, OnNewTrackingInfo_Response)
}
register_com_interface(
    name="IComTrackingInfoEvents",
    uuid=uuid.UUID("4E6CDCC9-FB25-4FD5-9CC5-C9F4B6559CEC"),
    opnums=ICOMTRACKINGINFOEVENTS_OPNUMS,
)


class IsSupported_Request(NDRPacket):
    fields_desc = []


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


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 DumpProcess_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("bstrContainerID", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("bstrDirectory", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRIntField("dwMaxFiles", 0),
    ]


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


IPROCESSDUMP_OPNUMS = {
    0: DceRpcOp(IsSupported_Request, IsSupported_Response),
    1: DceRpcOp(DumpProcess_Request, DumpProcess_Response),
}
register_com_interface(
    name="IProcessDump",
    uuid=uuid.UUID("23C9DD26-2355-4FE2-84DE-F779A238ADBD"),
    opnums=IPROCESSDUMP_OPNUMS,
)
