### ms-dltm.idl
"""
RPC definitions for the following interfaces:
- trksvr (v1.0): 4da1c422-943d-11d1-acae-00c04fc2aa3f
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import StrFixedLenField, StrFixedLenFieldUtf16
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfPacketListField,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRIntEnumField,
    NDRIntField,
    NDRPacketField,
    NDRShortField,
    NDRSignedIntField,
    NDRSignedShortField,
    NDRUnionField,
    register_dcerpc_interface,
)


class TRKSVR_MESSAGE_TYPE(IntEnum):
    old_SEARCH = 1
    MOVE_NOTIFICATION = 1
    REFRESH = 2
    SYNC_VOLUMES = 3
    DELETE_NOTIFY = 4
    STATISTICS = 5
    SEARCH = 6
    WKS_CONFIG = 7
    WKS_VOLUME_REFRESH = 8


class TRKSVR_MESSAGE_PRIORITY(IntEnum):
    PRI_0 = 0
    PRI_1 = 1
    PRI_2 = 2
    PRI_3 = 3
    PRI_4 = 4
    PRI_5 = 5
    PRI_6 = 6
    PRI_7 = 7
    PRI_8 = 8
    PRI_9 = 9


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


class CVolumeId(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRPacketField("_volume", GUID(), GUID)]


class CObjId(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRPacketField("_object", GUID(), GUID)]


class CDomainRelativeObjId(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("_volume", CVolumeId(), CVolumeId),
        NDRPacketField("_object", CObjId(), CObjId),
    ]


class old_TRK_FILE_TRACKING_INFORMATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        StrFixedLenFieldUtf16("tszFilePath", "", length=257 * 2),
        NDRPacketField("droidBirth", CDomainRelativeObjId(), CDomainRelativeObjId),
        NDRPacketField("droidLast", CDomainRelativeObjId(), CDomainRelativeObjId),
        NDRSignedIntField("hr", 0),
    ]


class old_TRKSVR_CALL_SEARCH(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cSearch", None, size_of="pSearches"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pSearches",
                [],
                old_TRK_FILE_TRACKING_INFORMATION,
                size_is=lambda pkt: pkt.cSearch,
            ),
            deferred=True,
        ),
    ]


class TRKSVR_CALL_MOVE_NOTIFICATION(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cNotifications", None, size_of="rgdroidNew"),
        NDRIntField("cProcessed", 0),
        NDRSignedIntField("seq", 0),
        NDRSignedIntField("fForceSeqNumber", 0),
        NDRFullPointerField(
            NDRPacketField("pvolid", CVolumeId(), CVolumeId), deferred=True
        ),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rgobjidCurrent", [], CObjId, size_is=lambda pkt: pkt.cNotifications
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rgdroidBirth",
                [],
                CDomainRelativeObjId,
                size_is=lambda pkt: pkt.cNotifications,
            ),
            deferred=True,
        ),
        NDRFullPointerField(
            NDRConfPacketListField(
                "rgdroidNew",
                [],
                CDomainRelativeObjId,
                size_is=lambda pkt: pkt.cNotifications,
            ),
            deferred=True,
        ),
    ]


class TRKSVR_CALL_REFRESH(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cSources", None, size_of="adroidBirth"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "adroidBirth",
                [],
                CDomainRelativeObjId,
                size_is=lambda pkt: pkt.cSources,
            ),
            deferred=True,
        ),
        NDRIntField("cVolumes", None, size_of="avolid"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "avolid", [], CVolumeId, size_is=lambda pkt: pkt.cVolumes
            ),
            deferred=True,
        ),
    ]


class TRKSVR_SYNC_TYPE(IntEnum):
    CREATE_VOLUME = 0
    QUERY_VOLUME = 1
    CLAIM_VOLUME = 2
    FIND_VOLUME = 3
    TEST_VOLUME = 4
    DELETE_VOLUME = 5


class CVolumeSecret(NDRPacket):
    fields_desc = [StrFixedLenField("_abSecret", "", length=8)]


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


class CMachineId(NDRPacket):
    fields_desc = [StrFixedLenField("_szMachine", "", length=16)]


class TRKSVR_SYNC_VOLUME(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRSignedIntField("hr", 0),
        NDRIntEnumField("SyncType", 0, TRKSVR_SYNC_TYPE),
        NDRPacketField("volume", CVolumeId(), CVolumeId),
        NDRPacketField("secret", CVolumeSecret(), CVolumeSecret),
        NDRPacketField("secretOld", CVolumeSecret(), CVolumeSecret),
        NDRSignedIntField("seq", 0),
        NDRPacketField("ftLastRefresh", FILETIME(), FILETIME),
        NDRPacketField("machine", CMachineId(), CMachineId),
    ]


class TRKSVR_CALL_SYNC_VOLUMES(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cVolumes", None, size_of="pVolumes"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pVolumes", [], TRKSVR_SYNC_VOLUME, size_is=lambda pkt: pkt.cVolumes
            ),
            deferred=True,
        ),
    ]


class TRKSVR_CALL_DELETE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cdroidBirth", None, size_of="adroidBirth"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "adroidBirth",
                [],
                CDomainRelativeObjId,
                size_is=lambda pkt: pkt.cdroidBirth,
            ),
            deferred=True,
        ),
        NDRIntField("cVolumes", None, size_of="pVolumes"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pVolumes", [], CVolumeId, size_is=lambda pkt: pkt.cVolumes
            ),
            deferred=True,
        ),
    ]


class Version_TRKSVR_STATISTICS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dwMajor", 0),
        NDRIntField("dwMinor", 0),
        NDRIntField("dwBuildNumber", 0),
    ]


class TRKSVR_STATISTICS(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("cSyncVolumeRequests", 0),
        NDRIntField("cSyncVolumeErrors", 0),
        NDRIntField("cSyncVolumeThreads", 0),
        NDRIntField("cCreateVolumeRequests", 0),
        NDRIntField("cCreateVolumeErrors", 0),
        NDRIntField("cClaimVolumeRequests", 0),
        NDRIntField("cClaimVolumeErrors", 0),
        NDRIntField("cQueryVolumeRequests", 0),
        NDRIntField("cQueryVolumeErrors", 0),
        NDRIntField("cFindVolumeRequests", 0),
        NDRIntField("cFindVolumeErrors", 0),
        NDRIntField("cTestVolumeRequests", 0),
        NDRIntField("cTestVolumeErrors", 0),
        NDRIntField("cSearchRequests", 0),
        NDRIntField("cSearchErrors", 0),
        NDRIntField("cSearchThreads", 0),
        NDRIntField("cMoveNotifyRequests", 0),
        NDRIntField("cMoveNotifyErrors", 0),
        NDRIntField("cMoveNotifyThreads", 0),
        NDRIntField("cRefreshRequests", 0),
        NDRIntField("cRefreshErrors", 0),
        NDRIntField("cRefreshThreads", 0),
        NDRIntField("cDeleteNotifyRequests", 0),
        NDRIntField("cDeleteNotifyErrors", 0),
        NDRIntField("cDeleteNotifyThreads", 0),
        NDRIntField("ulGCIterationPeriod", 0),
        NDRPacketField("ftLastSuccessfulRequest", FILETIME(), FILETIME),
        NDRSignedIntField("hrLastError", 0),
        NDRIntField("dwMoveLimit", 0),
        NDRSignedIntField("lRefreshCounter", 0),
        NDRIntField("dwCachedVolumeTableCount", 0),
        NDRIntField("dwCachedMoveTableCount", 0),
        NDRPacketField("ftCachedLastUpdated", FILETIME(), FILETIME),
        NDRSignedIntField("fIsDesignatedDc", 0),
        NDRPacketField("ftNextGC", FILETIME(), FILETIME),
        NDRPacketField("ftServiceStart", FILETIME(), FILETIME),
        NDRIntField("cMaxRPCThreads", 0),
        NDRIntField("cAvailableRPCThreads", 0),
        NDRIntField("cLowestAvailableRPCThreads", 0),
        NDRIntField("cNumThreadPoolThreads", 0),
        NDRIntField("cMostThreadPoolThreads", 0),
        NDRSignedShortField("cEntriesToGC", 0),
        NDRSignedShortField("cEntriesGCed", 0),
        NDRSignedShortField("cMaxDsWriteEvents", 0),
        NDRSignedShortField("cCurrentFailedWrites", 0),
        NDRPacketField(
            "Version_TRKSVR_STATISTICS",
            Version_TRKSVR_STATISTICS(),
            Version_TRKSVR_STATISTICS,
        ),
    ]


class TRK_FILE_TRACKING_INFORMATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("droidBirth", CDomainRelativeObjId(), CDomainRelativeObjId),
        NDRPacketField("droidLast", CDomainRelativeObjId(), CDomainRelativeObjId),
        NDRPacketField("mcidLast", CMachineId(), CMachineId),
        NDRSignedIntField("hr", 0),
    ]


class TRKSVR_CALL_SEARCH(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("cSearch", None, size_of="pSearches"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "pSearches",
                [],
                TRK_FILE_TRACKING_INFORMATION,
                size_is=lambda pkt: pkt.cSearch,
            ),
            deferred=True,
        ),
    ]


class TRKWKS_CONFIG(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [NDRIntField("dwParameter", 0), NDRIntField("dwNewValue", 0)]


class TRKSVR_MESSAGE_UNION(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntEnumField("MessageType", 0, TRKSVR_MESSAGE_TYPE),
        NDRIntEnumField("Priority", 0, TRKSVR_MESSAGE_PRIORITY),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "value", old_TRKSVR_CALL_SEARCH(), old_TRKSVR_CALL_SEARCH
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "MessageType", None)
                            == TRKSVR_MESSAGE_TYPE.old_SEARCH
                        ),
                        (lambda _, val: val.tag == TRKSVR_MESSAGE_TYPE.old_SEARCH),
                    ),
                ),
                (
                    NDRPacketField(
                        "value",
                        TRKSVR_CALL_MOVE_NOTIFICATION(),
                        TRKSVR_CALL_MOVE_NOTIFICATION,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "MessageType", None)
                            == TRKSVR_MESSAGE_TYPE.MOVE_NOTIFICATION
                        ),
                        (
                            lambda _, val: val.tag
                            == TRKSVR_MESSAGE_TYPE.MOVE_NOTIFICATION
                        ),
                    ),
                ),
                (
                    NDRPacketField("value", TRKSVR_CALL_REFRESH(), TRKSVR_CALL_REFRESH),
                    (
                        (
                            lambda pkt: getattr(pkt, "MessageType", None)
                            == TRKSVR_MESSAGE_TYPE.REFRESH
                        ),
                        (lambda _, val: val.tag == TRKSVR_MESSAGE_TYPE.REFRESH),
                    ),
                ),
                (
                    NDRPacketField(
                        "value", TRKSVR_CALL_SYNC_VOLUMES(), TRKSVR_CALL_SYNC_VOLUMES
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "MessageType", None)
                            == TRKSVR_MESSAGE_TYPE.SYNC_VOLUMES
                        ),
                        (lambda _, val: val.tag == TRKSVR_MESSAGE_TYPE.SYNC_VOLUMES),
                    ),
                ),
                (
                    NDRPacketField("value", TRKSVR_CALL_DELETE(), TRKSVR_CALL_DELETE),
                    (
                        (
                            lambda pkt: getattr(pkt, "MessageType", None)
                            == TRKSVR_MESSAGE_TYPE.DELETE_NOTIFY
                        ),
                        (lambda _, val: val.tag == TRKSVR_MESSAGE_TYPE.DELETE_NOTIFY),
                    ),
                ),
                (
                    NDRPacketField("value", TRKSVR_STATISTICS(), TRKSVR_STATISTICS),
                    (
                        (
                            lambda pkt: getattr(pkt, "MessageType", None)
                            == TRKSVR_MESSAGE_TYPE.STATISTICS
                        ),
                        (lambda _, val: val.tag == TRKSVR_MESSAGE_TYPE.STATISTICS),
                    ),
                ),
                (
                    NDRPacketField("value", TRKSVR_CALL_SEARCH(), TRKSVR_CALL_SEARCH),
                    (
                        (
                            lambda pkt: getattr(pkt, "MessageType", None)
                            == TRKSVR_MESSAGE_TYPE.SEARCH
                        ),
                        (lambda _, val: val.tag == TRKSVR_MESSAGE_TYPE.SEARCH),
                    ),
                ),
                (
                    NDRPacketField("value", TRKWKS_CONFIG(), TRKWKS_CONFIG),
                    (
                        (
                            lambda pkt: getattr(pkt, "MessageType", None)
                            == TRKSVR_MESSAGE_TYPE.WKS_CONFIG
                        ),
                        (lambda _, val: val.tag == TRKSVR_MESSAGE_TYPE.WKS_CONFIG),
                    ),
                ),
                (
                    NDRIntField("value", 0),
                    (
                        (
                            lambda pkt: getattr(pkt, "MessageType", None)
                            == TRKSVR_MESSAGE_TYPE.WKS_VOLUME_REFRESH
                        ),
                        (
                            lambda _, val: val.tag
                            == TRKSVR_MESSAGE_TYPE.WKS_VOLUME_REFRESH
                        ),
                    ),
                ),
            ],
            StrFixedLenField("value", "", length=0),
            align=(4, 8),
            switch_fmt=("I", "I"),
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("ptszMachineID", ""), deferred=True
        ),
    ]


class LnkSvrMessage_Request(NDRPacket):
    fields_desc = [NDRPacketField("pMsg", TRKSVR_MESSAGE_UNION(), TRKSVR_MESSAGE_UNION)]


class LnkSvrMessage_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pMsg", TRKSVR_MESSAGE_UNION(), TRKSVR_MESSAGE_UNION),
        NDRIntField("status", 0),
    ]


class LnkSvrMessageCallback_Request(NDRPacket):
    fields_desc = [NDRPacketField("pMsg", TRKSVR_MESSAGE_UNION(), TRKSVR_MESSAGE_UNION)]


class LnkSvrMessageCallback_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pMsg", TRKSVR_MESSAGE_UNION(), TRKSVR_MESSAGE_UNION),
        NDRIntField("status", 0),
    ]


TRKSVR_OPNUMS = {
    0: DceRpcOp(LnkSvrMessage_Request, LnkSvrMessage_Response),
    1: DceRpcOp(LnkSvrMessageCallback_Request, LnkSvrMessageCallback_Response),
}
register_dcerpc_interface(
    name="trksvr",
    uuid=uuid.UUID("4da1c422-943d-11d1-acae-00c04fc2aa3f"),
    version="1.0",
    opnums=TRKSVR_OPNUMS,
)
