### ms-rsmp.idl
"""
RPC definitions for the following interfaces:
- IUnknown (v0.0): 00000000-0000-0000-C000-000000000046
- INtmsLibraryControl1 (v0.0): 4e934f30-341a-11d1-8fb1-00a024cb6019
- INtmsMediaServices1 (v0.0): d02e4be0-3419-11d1-8fb1-00a024cb6019
- INtmsObjectInfo1 (v0.0): 69ab7050-3059-11d1-8faf-00a024cb6019
- INtmsObjectManagement1 (v0.0): b057dc50-3059-11d1-8faf-00a024cb6019
- INtmsSession1 (v0.0): None
- IClientSink (v0.0): 879C8BBE-41B0-11d1-BE11-00C04FB6BF70
- INtmsLibraryControl2 (v0.0): DB90832F-6910-4d46-9F5E-9FD6BFA73903
- INtmsObjectManagement2 (v0.0): 895A2C86-270D-489d-A6C0-DC2A9B35280E
- INtmsObjectManagement3 (v0.0): 3BBED8D9-2C9A-4b21-8936-ACB2F995BE6C
- IRobustNtmsMediaServices1 (v0.0): 7D07F313-A53F-459a-BB12-012C15B1846E
- IMessenger (v0.0): 081E7188-C080-4FF3-9238-29F66D6CABFD
- INtmsNotifySink (v0.0): BB39332C-BFEE-4380-AD8A-BADC8AFF5BB6
This file is auto-generated by midl-to-scapy, do not modify.
"""

import uuid

from scapy.fields import PacketListField, StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfVarPacketListField,
    NDRConfVarStrLenField,
    NDRConfVarStrLenFieldUtf16,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRInt3264Field,
    NDRIntField,
    NDRPacketField,
    NDRShortField,
    NDRSignedByteField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRUnionField,
    NDRVarStrLenField,
    NDRVarStrLenFieldUtf16,
    register_com_interface,
)


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


class QueryInterface_Request(NDRPacket):
    fields_desc = [NDRPacketField("riid", GUID(), GUID)]


class QueryInterface_Response(NDRPacket):
    fields_desc = [
        StrFixedLenField("ppvObject", "", length=0),
        NDRIntField("status", 0),
    ]


class AddRef_Request(NDRPacket):
    fields_desc = []


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


class Release_Request(NDRPacket):
    fields_desc = []


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


IUNKNOWN_OPNUMS = {
    0: DceRpcOp(QueryInterface_Request, QueryInterface_Response),
    1: DceRpcOp(AddRef_Request, AddRef_Response),
    2: DceRpcOp(Release_Request, Release_Response),
}
register_com_interface(
    name="IUnknown",
    uuid=uuid.UUID("00000000-0000-0000-C000-000000000046"),
    opnums=IUNKNOWN_OPNUMS,
)


class EjectNtmsMedia_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("lpMediaId", GUID(), GUID)),
        NDRPacketField("lpEjectOperation", GUID(), GUID),
        NDRIntField("dwAction", 0),
    ]


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


class InjectNtmsMedia_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpLibraryId", GUID(), GUID),
        NDRPacketField("lpInjectOperation", GUID(), GUID),
        NDRIntField("dwAction", 0),
    ]


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


class AccessNtmsLibraryDoor_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpLibraryId", GUID(), GUID),
        NDRIntField("dwAction", 0),
    ]


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


class CleanNtmsDrive_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpDriveId", GUID(), GUID)]


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


class DismountNtmsDrive_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpDriveId", GUID(), GUID)]


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


class InventoryNtmsLibrary_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpLibraryId", GUID(), GUID),
        NDRIntField("dwAction", 0),
    ]


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


class INtmsLibraryControl1_LocalOnlyOpnum09_Request(NDRPacket):
    fields_desc = []


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


class CancelNtmsLibraryRequest_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpRequestId", GUID(), GUID)]


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


class ReserveNtmsCleanerSlot_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpLibrary", GUID(), GUID),
        NDRPacketField("lpSlot", GUID(), GUID),
    ]


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


class ReleaseNtmsCleanerSlot_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpLibrary", GUID(), GUID)]


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


class InjectNtmsCleaner_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpLibrary", GUID(), GUID),
        NDRPacketField("lpInjectOperation", GUID(), GUID),
        NDRIntField("dwNumberOfCleansLeft", 0),
        NDRIntField("dwAction", 0),
    ]


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


class EjectNtmsCleaner_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpLibrary", GUID(), GUID),
        NDRPacketField("lpEjectOperation", GUID(), GUID),
        NDRIntField("dwAction", 0),
    ]


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


class DeleteNtmsLibrary_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpLibraryId", GUID(), GUID)]


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


class DeleteNtmsDrive_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpDriveId", GUID(), GUID)]


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


class GetNtmsRequestOrder_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpRequestId", GUID(), GUID)]


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


class SetNtmsRequestOrder_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpRequestId", GUID(), GUID),
        NDRIntField("dwOrderNumber", 0),
    ]


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


class DeleteNtmsRequests_Request(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "lpRequestId", [GUID()], GUID, size_is=lambda pkt: pkt.dwCount
        ),
        NDRIntField("dwType", 0),
        NDRIntField("dwCount", None, size_of="lpRequestId"),
    ]


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


class BeginNtmsDeviceChangeDetection_Request(NDRPacket):
    fields_desc = []


class BeginNtmsDeviceChangeDetection_Response(NDRPacket):
    fields_desc = [NDRInt3264Field("lpDetectHandle", 0), NDRIntField("status", 0)]


class SetNtmsDeviceChangeDetection_Request(NDRPacket):
    fields_desc = [
        NDRInt3264Field("DetectHandle", 0),
        NDRConfPacketListField(
            "lpObjectId", [GUID()], GUID, size_is=lambda pkt: pkt.dwCount
        ),
        NDRIntField("dwType", 0),
        NDRIntField("dwCount", None, size_of="lpObjectId"),
    ]


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


class EndNtmsDeviceChangeDetection_Request(NDRPacket):
    fields_desc = [NDRInt3264Field("DetectHandle", 0)]


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


INTMSLIBRARYCONTROL1_OPNUMS = {
    0: DceRpcOp(EjectNtmsMedia_Request, EjectNtmsMedia_Response),
    1: DceRpcOp(InjectNtmsMedia_Request, InjectNtmsMedia_Response),
    2: DceRpcOp(AccessNtmsLibraryDoor_Request, AccessNtmsLibraryDoor_Response),
    3: DceRpcOp(CleanNtmsDrive_Request, CleanNtmsDrive_Response),
    4: DceRpcOp(DismountNtmsDrive_Request, DismountNtmsDrive_Response),
    5: DceRpcOp(InventoryNtmsLibrary_Request, InventoryNtmsLibrary_Response),
    6: DceRpcOp(
        INtmsLibraryControl1_LocalOnlyOpnum09_Request,
        INtmsLibraryControl1_LocalOnlyOpnum09_Response,
    ),
    7: DceRpcOp(CancelNtmsLibraryRequest_Request, CancelNtmsLibraryRequest_Response),
    8: DceRpcOp(ReserveNtmsCleanerSlot_Request, ReserveNtmsCleanerSlot_Response),
    9: DceRpcOp(ReleaseNtmsCleanerSlot_Request, ReleaseNtmsCleanerSlot_Response),
    10: DceRpcOp(InjectNtmsCleaner_Request, InjectNtmsCleaner_Response),
    11: DceRpcOp(EjectNtmsCleaner_Request, EjectNtmsCleaner_Response),
    12: DceRpcOp(DeleteNtmsLibrary_Request, DeleteNtmsLibrary_Response),
    13: DceRpcOp(DeleteNtmsDrive_Request, DeleteNtmsDrive_Response),
    14: DceRpcOp(GetNtmsRequestOrder_Request, GetNtmsRequestOrder_Response),
    15: DceRpcOp(SetNtmsRequestOrder_Request, SetNtmsRequestOrder_Response),
    16: DceRpcOp(DeleteNtmsRequests_Request, DeleteNtmsRequests_Response),
    17: DceRpcOp(
        BeginNtmsDeviceChangeDetection_Request, BeginNtmsDeviceChangeDetection_Response
    ),
    18: DceRpcOp(
        SetNtmsDeviceChangeDetection_Request, SetNtmsDeviceChangeDetection_Response
    ),
    19: DceRpcOp(
        EndNtmsDeviceChangeDetection_Request, EndNtmsDeviceChangeDetection_Response
    ),
}
register_com_interface(
    name="INtmsLibraryControl1",
    uuid=uuid.UUID("4e934f30-341a-11d1-8fb1-00a024cb6019"),
    opnums=INTMSLIBRARYCONTROL1_OPNUMS,
)


class LPNTMS_ASYNC_IO(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("OperationId", GUID(), GUID),
        NDRPacketField("EventId", GUID(), GUID),
        NDRIntField("dwOperationType", 0),
        NDRIntField("dwResult", 0),
        NDRIntField("dwAsyncState", 0),
        NDRInt3264Field("hEvent", 0),
        NDRSignedIntField("bOnStateChange", 0),
    ]


class LPNTMS_MOUNT_INFORMATION(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwSize", 0),
        NDRFullPointerField(
            NDRPacketField("lpReserved", LPNTMS_ASYNC_IO(), LPNTMS_ASYNC_IO),
            deferred=True,
        ),
    ]


class MountNtmsMedia_Request(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "lpMediaId", [GUID()], GUID, size_is=lambda pkt: pkt.dwCount
        ),
        NDRConfPacketListField(
            "lpDriveId", [GUID()], GUID, size_is=lambda pkt: pkt.dwCount
        ),
        NDRIntField("dwCount", None, size_of="lpDriveId"),
        NDRIntField("dwOptions", 0),
        NDRSignedIntField("dwPriority", 0),
        NDRIntField("dwTimeout", 0),
        NDRPacketField(
            "lpMountInformation", LPNTMS_MOUNT_INFORMATION(), LPNTMS_MOUNT_INFORMATION
        ),
    ]


class MountNtmsMedia_Response(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "lpDriveId", [GUID()], GUID, size_is=lambda pkt: pkt.dwCount
        ),
        NDRPacketField(
            "lpMountInformation", LPNTMS_MOUNT_INFORMATION(), LPNTMS_MOUNT_INFORMATION
        ),
        NDRIntField("status", 0),
    ]


class DismountNtmsMedia_Request(NDRPacket):
    fields_desc = [
        NDRConfPacketListField(
            "lpMediaId", [GUID()], GUID, size_is=lambda pkt: pkt.dwCount
        ),
        NDRIntField("dwCount", None, size_of="lpMediaId"),
        NDRIntField("dwOptions", 0),
    ]


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


class LPNTMS_ALLOCATION_INFORMATION(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwSize", 0),
        NDRFullPointerField(NDRSignedByteField("lpReserved", 0), deferred=True),
        NDRPacketField("AllocatedFrom", GUID(), GUID),
    ]


class AllocateNtmsMedia_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpMediaPool", GUID(), GUID),
        NDRFullPointerField(NDRPacketField("lpPartition", GUID(), GUID)),
        NDRPacketField("lpMediaId", GUID(), GUID),
        NDRIntField("dwOptions", 0),
        NDRIntField("dwTimeout", 0),
        NDRPacketField(
            "lpAllocateInformation",
            LPNTMS_ALLOCATION_INFORMATION(),
            LPNTMS_ALLOCATION_INFORMATION,
        ),
    ]


class AllocateNtmsMedia_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("lpMediaId", GUID(), GUID),
        NDRPacketField(
            "lpAllocateInformation",
            LPNTMS_ALLOCATION_INFORMATION(),
            LPNTMS_ALLOCATION_INFORMATION,
        ),
        NDRIntField("status", 0),
    ]


class DeallocateNtmsMedia_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpMediaId", GUID(), GUID),
        NDRIntField("dwOptions", 0),
    ]


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


class SwapNtmsMedia_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpMediaId1", GUID(), GUID),
        NDRPacketField("lpMediaId2", GUID(), GUID),
    ]


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


class DecommissionNtmsMedia_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpMediaId", GUID(), GUID)]


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


class SetNtmsMediaComplete_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpMediaId", GUID(), GUID)]


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


class DeleteNtmsMedia_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpMediaId", GUID(), GUID)]


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


class LPSECURITY_ATTRIBUTES_NTMS(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("nLength", 0),
        NDRFullPointerField(
            NDRConfStrLenField(
                "lpSecurityDescriptor", "", size_is=lambda pkt: pkt.nDescriptorLength
            ),
            deferred=True,
        ),
        NDRSignedIntField("bInheritHandle", 0),
        NDRIntField("nDescriptorLength", None, size_of="lpSecurityDescriptor"),
    ]


class CreateNtmsMediaPoolA_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullField("lpPoolName", ""),
        NDRFullPointerField(NDRPacketField("lpMediaType", GUID(), GUID)),
        NDRIntField("dwOptions", 0),
        NDRFullPointerField(
            NDRPacketField(
                "lpSecurityAttributes",
                LPSECURITY_ATTRIBUTES_NTMS(),
                LPSECURITY_ATTRIBUTES_NTMS,
            )
        ),
    ]


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


class CreateNtmsMediaPoolW_Request(NDRPacket):
    fields_desc = [
        NDRConfVarStrNullFieldUtf16("lpPoolName", ""),
        NDRFullPointerField(NDRPacketField("lpMediaType", GUID(), GUID)),
        NDRIntField("dwOptions", 0),
        NDRFullPointerField(
            NDRPacketField(
                "lpSecurityAttributes",
                LPSECURITY_ATTRIBUTES_NTMS(),
                LPSECURITY_ATTRIBUTES_NTMS,
            )
        ),
    ]


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


class GetNtmsMediaPoolNameA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpPoolId", GUID(), GUID),
        NDRIntField("lpdwNameSizeBuf", 0),
    ]


class GetNtmsMediaPoolNameA_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "lpBufName",
            "",
            size_is=lambda pkt: pkt.lpdwNameSizeBuf,
            length_is=lambda pkt: pkt.lpdwNameSizeBuf,
        ),
        NDRIntField("lpdwNameSize", 0),
        NDRIntField("status", 0),
    ]


class GetNtmsMediaPoolNameW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpPoolId", GUID(), GUID),
        NDRIntField("lpdwNameSizeBuf", 0),
    ]


class GetNtmsMediaPoolNameW_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenFieldUtf16(
            "lpBufName",
            "",
            size_is=lambda pkt: pkt.lpdwNameSizeBuf,
            length_is=lambda pkt: pkt.lpdwNameSizeBuf,
        ),
        NDRIntField("lpdwNameSize", 0),
        NDRIntField("status", 0),
    ]


class MoveToNtmsMediaPool_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpMediaId", GUID(), GUID),
        NDRPacketField("lpPoolId", GUID(), GUID),
    ]


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


class DeleteNtmsMediaPool_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpPoolId", GUID(), GUID)]


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


class AddNtmsMediaType_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpMediaTypeId", GUID(), GUID),
        NDRPacketField("lpLibId", GUID(), GUID),
    ]


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


class DeleteNtmsMediaType_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpMediaTypeId", GUID(), GUID),
        NDRPacketField("lpLibId", GUID(), GUID),
    ]


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


class ChangeNtmsMediaType_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpMediaId", GUID(), GUID),
        NDRPacketField("lpPoolId", GUID(), GUID),
    ]


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


INTMSMEDIASERVICES1_OPNUMS = {
    0: DceRpcOp(MountNtmsMedia_Request, MountNtmsMedia_Response),
    1: DceRpcOp(DismountNtmsMedia_Request, DismountNtmsMedia_Response),
    # 2: Opnum5NotUsedOnWire,
    3: DceRpcOp(AllocateNtmsMedia_Request, AllocateNtmsMedia_Response),
    4: DceRpcOp(DeallocateNtmsMedia_Request, DeallocateNtmsMedia_Response),
    5: DceRpcOp(SwapNtmsMedia_Request, SwapNtmsMedia_Response),
    6: DceRpcOp(DecommissionNtmsMedia_Request, DecommissionNtmsMedia_Response),
    7: DceRpcOp(SetNtmsMediaComplete_Request, SetNtmsMediaComplete_Response),
    8: DceRpcOp(DeleteNtmsMedia_Request, DeleteNtmsMedia_Response),
    9: DceRpcOp(CreateNtmsMediaPoolA_Request, CreateNtmsMediaPoolA_Response),
    10: DceRpcOp(CreateNtmsMediaPoolW_Request, CreateNtmsMediaPoolW_Response),
    11: DceRpcOp(GetNtmsMediaPoolNameA_Request, GetNtmsMediaPoolNameA_Response),
    12: DceRpcOp(GetNtmsMediaPoolNameW_Request, GetNtmsMediaPoolNameW_Response),
    13: DceRpcOp(MoveToNtmsMediaPool_Request, MoveToNtmsMediaPool_Response),
    14: DceRpcOp(DeleteNtmsMediaPool_Request, DeleteNtmsMediaPool_Response),
    15: DceRpcOp(AddNtmsMediaType_Request, AddNtmsMediaType_Response),
    16: DceRpcOp(DeleteNtmsMediaType_Request, DeleteNtmsMediaType_Response),
    17: DceRpcOp(ChangeNtmsMediaType_Request, ChangeNtmsMediaType_Response),
}
register_com_interface(
    name="INtmsMediaServices1",
    uuid=uuid.UUID("d02e4be0-3419-11d1-8fb1-00a024cb6019"),
    opnums=INTMSMEDIASERVICES1_OPNUMS,
)


class SYSTEMTIME(NDRPacket):
    ALIGNMENT = (2, 2)
    fields_desc = [
        NDRShortField("wYear", 0),
        NDRShortField("wMonth", 0),
        NDRShortField("wDayOfWeek", 0),
        NDRShortField("wDay", 0),
        NDRShortField("wHour", 0),
        NDRShortField("wMinute", 0),
        NDRShortField("wSecond", 0),
        NDRShortField("wMilliseconds", 0),
    ]


class NTMS_LIBRARYINFORMATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("LibraryType", 0),
        NDRPacketField("CleanerSlot", GUID(), GUID),
        NDRPacketField("CleanerSlotDefault", GUID(), GUID),
        NDRSignedIntField("LibrarySupportsDriveCleaning", 0),
        NDRSignedIntField("BarCodeReaderInstalled", 0),
        NDRIntField("InventoryMethod", 0),
        NDRIntField("dwCleanerUsesRemaining", 0),
        NDRIntField("FirstDriveNumber", 0),
        NDRIntField("dwNumberOfDrives", 0),
        NDRIntField("FirstSlotNumber", 0),
        NDRIntField("dwNumberOfSlots", 0),
        NDRIntField("FirstDoorNumber", 0),
        NDRIntField("dwNumberOfDoors", 0),
        NDRIntField("FirstPortNumber", 0),
        NDRIntField("dwNumberOfPorts", 0),
        NDRIntField("FirstChangerNumber", 0),
        NDRIntField("dwNumberOfChangers", 0),
        NDRIntField("dwNumberOfMedia", 0),
        NDRIntField("dwNumberOfMediaTypes", 0),
        NDRIntField("dwNumberOfLibRequests", 0),
        NDRPacketField("Reserved", GUID(), GUID),
        NDRSignedIntField("AutoRecovery", 0),
        NDRIntField("dwFlags", 0),
    ]


class NTMS_DRIVEINFORMATIONA(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Number", 0),
        NDRIntField("State", 0),
        NDRPacketField("DriveType", GUID(), GUID),
        StrFixedLenField("szDeviceName", "", length=64),
        StrFixedLenField("szSerialNumber", "", length=32),
        StrFixedLenField("szRevision", "", length=32),
        NDRShortField("ScsiPort", 0),
        NDRShortField("ScsiBus", 0),
        NDRShortField("ScsiTarget", 0),
        NDRShortField("ScsiLun", 0),
        NDRIntField("dwMountCount", 0),
        NDRPacketField("LastCleanedTs", SYSTEMTIME(), SYSTEMTIME),
        NDRPacketField("SavedPartitionId", GUID(), GUID),
        NDRPacketField("Library", GUID(), GUID),
        NDRPacketField("Reserved", GUID(), GUID),
        NDRIntField("dwDeferDismountDelay", 0),
    ]


class NTMS_DRIVETYPEINFORMATIONA(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        StrFixedLenField("szVendor", "", length=128),
        StrFixedLenField("szProduct", "", length=128),
        NDRIntField("NumberOfHeads", 0),
        NDRIntField("DeviceType", 0),
    ]


class NTMS_CHANGERINFORMATIONA(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Number", 0),
        NDRPacketField("ChangerType", GUID(), GUID),
        StrFixedLenField("szSerialNumber", "", length=32),
        StrFixedLenField("szRevision", "", length=32),
        StrFixedLenField("szDeviceName", "", length=64),
        NDRShortField("ScsiPort", 0),
        NDRShortField("ScsiBus", 0),
        NDRShortField("ScsiTarget", 0),
        NDRShortField("ScsiLun", 0),
        NDRPacketField("Library", GUID(), GUID),
    ]


class NTMS_CHANGERTYPEINFORMATIONA(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        StrFixedLenField("szVendor", "", length=128),
        StrFixedLenField("szProduct", "", length=128),
        NDRIntField("DeviceType", 0),
    ]


class NTMS_STORAGESLOTINFORMATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Number", 0),
        NDRIntField("State", 0),
        NDRPacketField("Library", GUID(), GUID),
    ]


class NTMS_IEDOORINFORMATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Number", 0),
        NDRIntField("State", 0),
        NDRShortField("MaxOpenSecs", 0),
        NDRPacketField("Library", GUID(), GUID),
    ]


class NTMS_IEPORTINFORMATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Number", 0),
        NDRIntField("Content", 0),
        NDRIntField("Position", 0),
        NDRShortField("MaxExtendSecs", 0),
        NDRPacketField("Library", GUID(), GUID),
    ]


class NTMS_PMIDINFORMATIONA(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("CurrentLibrary", GUID(), GUID),
        NDRPacketField("MediaPool", GUID(), GUID),
        NDRPacketField("Location", GUID(), GUID),
        NDRIntField("LocationType", 0),
        NDRPacketField("MediaType", GUID(), GUID),
        NDRPacketField("HomeSlot", GUID(), GUID),
        StrFixedLenField("szBarCode", "", length=64),
        NDRIntField("BarCodeState", 0),
        StrFixedLenField("szSequenceNumber", "", length=32),
        NDRIntField("MediaState", 0),
        NDRIntField("dwNumberOfPartitions", 0),
        NDRIntField("dwMediaTypeCode", 0),
        NDRIntField("dwDensityCode", 0),
        NDRPacketField("MountedPartition", GUID(), GUID),
    ]


class NTMS_LMIDINFORMATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("MediaPool", GUID(), GUID),
        NDRIntField("dwNumberOfPartitions", 0),
    ]


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


class NTMS_PARTITIONINFORMATIONA(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("PhysicalMedia", GUID(), GUID),
        NDRPacketField("LogicalMedia", GUID(), GUID),
        NDRIntField("State", 0),
        NDRShortField("Side", 0),
        NDRIntField("dwOmidLabelIdLength", 0),
        StrFixedLenField("OmidLabelId", "", length=255),
        StrFixedLenField("szOmidLabelType", "", length=64),
        StrFixedLenField("szOmidLabelInfo", "", length=256),
        NDRIntField("dwMountCount", 0),
        NDRIntField("dwAllocateCount", 0),
        NDRPacketField("Capacity", LARGE_INTEGER(), LARGE_INTEGER),
    ]


class NTMS_MEDIAPOOLINFORMATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("PoolType", 0),
        NDRPacketField("MediaType", GUID(), GUID),
        NDRPacketField("Parent", GUID(), GUID),
        NDRIntField("AllocationPolicy", 0),
        NDRIntField("DeallocationPolicy", 0),
        NDRIntField("dwMaxAllocates", 0),
        NDRIntField("dwNumberOfPhysicalMedia", 0),
        NDRIntField("dwNumberOfLogicalMedia", 0),
        NDRIntField("dwNumberOfMediaPools", 0),
    ]


class NTMS_MEDIATYPEINFORMATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("MediaType", 0),
        NDRIntField("NumberOfSides", 0),
        NDRIntField("ReadWriteCharacteristics", 0),
        NDRIntField("DeviceType", 0),
    ]


class NTMS_LIBREQUESTINFORMATIONA(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("OperationCode", 0),
        NDRIntField("OperationOption", 0),
        NDRIntField("State", 0),
        NDRPacketField("PartitionId", GUID(), GUID),
        NDRPacketField("DriveId", GUID(), GUID),
        NDRPacketField("PhysMediaId", GUID(), GUID),
        NDRPacketField("Library", GUID(), GUID),
        NDRPacketField("SlotId", GUID(), GUID),
        NDRPacketField("TimeQueued", SYSTEMTIME(), SYSTEMTIME),
        NDRPacketField("TimeCompleted", SYSTEMTIME(), SYSTEMTIME),
        StrFixedLenField("szApplication", "", length=64),
        StrFixedLenField("szUser", "", length=64),
        StrFixedLenField("szComputer", "", length=64),
        NDRIntField("dwErrorCode", 0),
        NDRPacketField("WorkItemId", GUID(), GUID),
        NDRIntField("dwPriority", 0),
    ]


class NTMS_OPREQUESTINFORMATIONA(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Request", 0),
        NDRPacketField("Submitted", SYSTEMTIME(), SYSTEMTIME),
        NDRIntField("State", 0),
        StrFixedLenField("szMessage", "", length=256),
        NDRIntField("Arg1Type", 0),
        NDRPacketField("Arg1", GUID(), GUID),
        NDRIntField("Arg2Type", 0),
        NDRPacketField("Arg2", GUID(), GUID),
        StrFixedLenField("szApplication", "", length=64),
        StrFixedLenField("szUser", "", length=64),
        StrFixedLenField("szComputer", "", length=64),
    ]


class NTMS_COMPUTERINFORMATION(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dwLibRequestPurgeTime", 0),
        NDRIntField("dwOpRequestPurgeTime", 0),
        NDRIntField("dwLibRequestFlags", 0),
        NDRIntField("dwOpRequestFlags", 0),
        NDRIntField("dwMediaPoolPolicy", 0),
    ]


class LPNTMS_OBJECTINFORMATIONA(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("dwSize", 0),
        NDRIntField("dwType", 0),
        NDRPacketField("Created", SYSTEMTIME(), SYSTEMTIME),
        NDRPacketField("Modified", SYSTEMTIME(), SYSTEMTIME),
        NDRPacketField("ObjectGuid", GUID(), GUID),
        NDRSignedIntField("Enabled", 0),
        NDRIntField("dwOperationalState", 0),
        StrFixedLenField("szName", "", length=64),
        StrFixedLenField("szDescription", "", length=127),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "Info", NTMS_DRIVEINFORMATIONA(), NTMS_DRIVEINFORMATIONA
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_DRIVE
                        ),
                        (lambda _, val: val.tag == NTMS_LIBRARYINFORMATION.NTMS_DRIVE),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_DRIVETYPEINFORMATIONA(), NTMS_DRIVETYPEINFORMATIONA
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_DRIVE_TYPE
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_DRIVE_TYPE
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_LIBRARYINFORMATION(), NTMS_LIBRARYINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_LIBRARY
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_LIBRARY
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_CHANGERINFORMATIONA(), NTMS_CHANGERINFORMATIONA
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_CHANGER
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_CHANGER
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info",
                        NTMS_CHANGERTYPEINFORMATIONA(),
                        NTMS_CHANGERTYPEINFORMATIONA,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_CHANGER_TYPE
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_CHANGER_TYPE
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info",
                        NTMS_STORAGESLOTINFORMATION(),
                        NTMS_STORAGESLOTINFORMATION,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_STORAGESLOT
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_STORAGESLOT
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_IEDOORINFORMATION(), NTMS_IEDOORINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_IEDOOR
                        ),
                        (lambda _, val: val.tag == NTMS_LIBRARYINFORMATION.NTMS_IEDOOR),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_IEPORTINFORMATION(), NTMS_IEPORTINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_IEPORT
                        ),
                        (lambda _, val: val.tag == NTMS_LIBRARYINFORMATION.NTMS_IEPORT),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_PMIDINFORMATIONA(), NTMS_PMIDINFORMATIONA
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_PHYSICAL_MEDIA
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_PHYSICAL_MEDIA
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_LMIDINFORMATION(), NTMS_LMIDINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_LOGICAL_MEDIA
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_LOGICAL_MEDIA
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_PARTITIONINFORMATIONA(), NTMS_PARTITIONINFORMATIONA
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_PARTITION
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_PARTITION
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_MEDIAPOOLINFORMATION(), NTMS_MEDIAPOOLINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_MEDIA_POOL
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_MEDIA_POOL
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_MEDIATYPEINFORMATION(), NTMS_MEDIATYPEINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_MEDIA_TYPE
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_MEDIA_TYPE
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info",
                        NTMS_LIBREQUESTINFORMATIONA(),
                        NTMS_LIBREQUESTINFORMATIONA,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_LIBREQUEST
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_LIBREQUEST
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_OPREQUESTINFORMATIONA(), NTMS_OPREQUESTINFORMATIONA
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_OPREQUEST
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_OPREQUEST
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_COMPUTERINFORMATION(), NTMS_COMPUTERINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_COMPUTER
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_COMPUTER
                        ),
                    ),
                ),
            ],
            StrFixedLenField("Info", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class GetNtmsServerObjectInformationA_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("lpObjectId", GUID(), GUID)),
        NDRIntField("dwType", 0),
        NDRIntField("dwSize", 0),
    ]


class GetNtmsServerObjectInformationA_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "lpInfo", LPNTMS_OBJECTINFORMATIONA(), LPNTMS_OBJECTINFORMATIONA
        ),
        NDRIntField("status", 0),
    ]


class NTMS_DRIVEINFORMATIONW(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Number", 0),
        NDRIntField("State", 0),
        NDRPacketField("DriveType", GUID(), GUID),
        NDRVarStrLenFieldUtf16("szDeviceName", ""),
        NDRVarStrLenFieldUtf16("szSerialNumber", ""),
        NDRVarStrLenFieldUtf16("szRevision", ""),
        NDRShortField("ScsiPort", 0),
        NDRShortField("ScsiBus", 0),
        NDRShortField("ScsiTarget", 0),
        NDRShortField("ScsiLun", 0),
        NDRIntField("dwMountCount", 0),
        NDRPacketField("LastCleanedTs", SYSTEMTIME(), SYSTEMTIME),
        NDRPacketField("SavedPartitionId", GUID(), GUID),
        NDRPacketField("Library", GUID(), GUID),
        NDRPacketField("Reserved", GUID(), GUID),
        NDRIntField("dwDeferDismountDelay", 0),
    ]


class NTMS_DRIVETYPEINFORMATIONW(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRVarStrLenFieldUtf16("szVendor", ""),
        NDRVarStrLenFieldUtf16("szProduct", ""),
        NDRIntField("NumberOfHeads", 0),
        NDRIntField("DeviceType", 0),
    ]


class NTMS_CHANGERINFORMATIONW(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Number", 0),
        NDRPacketField("ChangerType", GUID(), GUID),
        NDRVarStrLenFieldUtf16("szSerialNumber", ""),
        NDRVarStrLenFieldUtf16("szRevision", ""),
        NDRVarStrLenFieldUtf16("szDeviceName", ""),
        NDRShortField("ScsiPort", 0),
        NDRShortField("ScsiBus", 0),
        NDRShortField("ScsiTarget", 0),
        NDRShortField("ScsiLun", 0),
        NDRPacketField("Library", GUID(), GUID),
    ]


class NTMS_CHANGERTYPEINFORMATIONW(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRVarStrLenFieldUtf16("szVendor", ""),
        NDRVarStrLenFieldUtf16("szProduct", ""),
        NDRIntField("DeviceType", 0),
    ]


class NTMS_PMIDINFORMATIONW(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("CurrentLibrary", GUID(), GUID),
        NDRPacketField("MediaPool", GUID(), GUID),
        NDRPacketField("Location", GUID(), GUID),
        NDRIntField("LocationType", 0),
        NDRPacketField("MediaType", GUID(), GUID),
        NDRPacketField("HomeSlot", GUID(), GUID),
        NDRVarStrLenFieldUtf16("szBarCode", ""),
        NDRIntField("BarCodeState", 0),
        NDRVarStrLenFieldUtf16("szSequenceNumber", ""),
        NDRIntField("MediaState", 0),
        NDRIntField("dwNumberOfPartitions", 0),
        NDRIntField("dwMediaTypeCode", 0),
        NDRIntField("dwDensityCode", 0),
        NDRPacketField("MountedPartition", GUID(), GUID),
    ]


class NTMS_PARTITIONINFORMATIONW(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("PhysicalMedia", GUID(), GUID),
        NDRPacketField("LogicalMedia", GUID(), GUID),
        NDRIntField("State", 0),
        NDRShortField("Side", 0),
        NDRIntField("dwOmidLabelIdLength", 0),
        StrFixedLenField("OmidLabelId", "", length=255),
        NDRVarStrLenFieldUtf16("szOmidLabelType", ""),
        NDRVarStrLenFieldUtf16("szOmidLabelInfo", ""),
        NDRIntField("dwMountCount", 0),
        NDRIntField("dwAllocateCount", 0),
        NDRPacketField("Capacity", LARGE_INTEGER(), LARGE_INTEGER),
    ]


class NTMS_LIBREQUESTINFORMATIONW(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("OperationCode", 0),
        NDRIntField("OperationOption", 0),
        NDRIntField("State", 0),
        NDRPacketField("PartitionId", GUID(), GUID),
        NDRPacketField("DriveId", GUID(), GUID),
        NDRPacketField("PhysMediaId", GUID(), GUID),
        NDRPacketField("Library", GUID(), GUID),
        NDRPacketField("SlotId", GUID(), GUID),
        NDRPacketField("TimeQueued", SYSTEMTIME(), SYSTEMTIME),
        NDRPacketField("TimeCompleted", SYSTEMTIME(), SYSTEMTIME),
        NDRVarStrLenFieldUtf16("szApplication", ""),
        NDRVarStrLenFieldUtf16("szUser", ""),
        NDRVarStrLenFieldUtf16("szComputer", ""),
        NDRIntField("dwErrorCode", 0),
        NDRPacketField("WorkItemId", GUID(), GUID),
        NDRIntField("dwPriority", 0),
    ]


class NTMS_OPREQUESTINFORMATIONW(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("Request", 0),
        NDRPacketField("Submitted", SYSTEMTIME(), SYSTEMTIME),
        NDRIntField("State", 0),
        NDRVarStrLenFieldUtf16("szMessage", ""),
        NDRIntField("Arg1Type", 0),
        NDRPacketField("Arg1", GUID(), GUID),
        NDRIntField("Arg2Type", 0),
        NDRPacketField("Arg2", GUID(), GUID),
        NDRVarStrLenFieldUtf16("szApplication", ""),
        NDRVarStrLenFieldUtf16("szUser", ""),
        NDRVarStrLenFieldUtf16("szComputer", ""),
    ]


class LPNTMS_OBJECTINFORMATIONW(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("dwSize", 0),
        NDRIntField("dwType", 0),
        NDRPacketField("Created", SYSTEMTIME(), SYSTEMTIME),
        NDRPacketField("Modified", SYSTEMTIME(), SYSTEMTIME),
        NDRPacketField("ObjectGuid", GUID(), GUID),
        NDRSignedIntField("Enabled", 0),
        NDRIntField("dwOperationalState", 0),
        NDRVarStrLenFieldUtf16("szName", ""),
        NDRVarStrLenFieldUtf16("szDescription", ""),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "Info", NTMS_DRIVEINFORMATIONW(), NTMS_DRIVEINFORMATIONW
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_DRIVE
                        ),
                        (lambda _, val: val.tag == NTMS_LIBRARYINFORMATION.NTMS_DRIVE),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_DRIVETYPEINFORMATIONW(), NTMS_DRIVETYPEINFORMATIONW
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_DRIVE_TYPE
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_DRIVE_TYPE
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_LIBRARYINFORMATION(), NTMS_LIBRARYINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_LIBRARY
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_LIBRARY
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_CHANGERINFORMATIONW(), NTMS_CHANGERINFORMATIONW
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_CHANGER
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_CHANGER
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info",
                        NTMS_CHANGERTYPEINFORMATIONW(),
                        NTMS_CHANGERTYPEINFORMATIONW,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_CHANGER_TYPE
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_CHANGER_TYPE
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info",
                        NTMS_STORAGESLOTINFORMATION(),
                        NTMS_STORAGESLOTINFORMATION,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_STORAGESLOT
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_STORAGESLOT
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_IEDOORINFORMATION(), NTMS_IEDOORINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_IEDOOR
                        ),
                        (lambda _, val: val.tag == NTMS_LIBRARYINFORMATION.NTMS_IEDOOR),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_IEPORTINFORMATION(), NTMS_IEPORTINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_IEPORT
                        ),
                        (lambda _, val: val.tag == NTMS_LIBRARYINFORMATION.NTMS_IEPORT),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_PMIDINFORMATIONW(), NTMS_PMIDINFORMATIONW
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_PHYSICAL_MEDIA
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_PHYSICAL_MEDIA
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_LMIDINFORMATION(), NTMS_LMIDINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_LOGICAL_MEDIA
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_LOGICAL_MEDIA
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_PARTITIONINFORMATIONW(), NTMS_PARTITIONINFORMATIONW
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_PARTITION
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_PARTITION
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_MEDIAPOOLINFORMATION(), NTMS_MEDIAPOOLINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_MEDIA_POOL
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_MEDIA_POOL
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_MEDIATYPEINFORMATION(), NTMS_MEDIATYPEINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_MEDIA_TYPE
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_MEDIA_TYPE
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info",
                        NTMS_LIBREQUESTINFORMATIONW(),
                        NTMS_LIBREQUESTINFORMATIONW,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_LIBREQUEST
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_LIBREQUEST
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_OPREQUESTINFORMATIONW(), NTMS_OPREQUESTINFORMATIONW
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_OPREQUEST
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_OPREQUEST
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "Info", NTMS_COMPUTERINFORMATION(), NTMS_COMPUTERINFORMATION
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "dwType", None)
                            == NTMS_LIBRARYINFORMATION.NTMS_COMPUTER
                        ),
                        (
                            lambda _, val: val.tag
                            == NTMS_LIBRARYINFORMATION.NTMS_COMPUTER
                        ),
                    ),
                ),
            ],
            StrFixedLenField("Info", "", length=0),
            align=(4, 8),
            switch_fmt=("L", "L"),
        ),
    ]


class GetNtmsServerObjectInformationW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRIntField("dwType", 0),
        NDRIntField("dwSize", 0),
    ]


class GetNtmsServerObjectInformationW_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "lpInfo", LPNTMS_OBJECTINFORMATIONW(), LPNTMS_OBJECTINFORMATIONW
        ),
        NDRIntField("status", 0),
    ]


class SetNtmsObjectInformationA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRPacketField(
            "lpInfo", LPNTMS_OBJECTINFORMATIONA(), LPNTMS_OBJECTINFORMATIONA
        ),
    ]


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


class SetNtmsObjectInformationW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRPacketField(
            "lpInfo", LPNTMS_OBJECTINFORMATIONW(), LPNTMS_OBJECTINFORMATIONW
        ),
    ]


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


class CreateNtmsMediaA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "lpMedia", LPNTMS_OBJECTINFORMATIONA(), LPNTMS_OBJECTINFORMATIONA
        ),
        NDRConfVarPacketListField(
            "lpList",
            [LPNTMS_OBJECTINFORMATIONA()],
            LPNTMS_OBJECTINFORMATIONA,
            size_is=lambda pkt: pkt.lpdwListBufferSize,
            length_is=lambda pkt: pkt.dwListCount,
        ),
        NDRIntField("lpdwListBufferSize", None, size_of="lpList"),
        NDRIntField("dwListCount", None, size_of="lpList"),
        NDRIntField("dwOptions", 0),
    ]


class CreateNtmsMediaA_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "lpMedia", LPNTMS_OBJECTINFORMATIONA(), LPNTMS_OBJECTINFORMATIONA
        ),
        NDRConfVarPacketListField(
            "lpList",
            [LPNTMS_OBJECTINFORMATIONA()],
            LPNTMS_OBJECTINFORMATIONA,
            size_is=lambda pkt: pkt.lpdwListBufferSize,
            length_is=lambda pkt: pkt.dwListCount,
        ),
        NDRIntField("status", 0),
    ]


class CreateNtmsMediaW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "lpMedia", LPNTMS_OBJECTINFORMATIONW(), LPNTMS_OBJECTINFORMATIONW
        ),
        NDRConfVarPacketListField(
            "lpList",
            [LPNTMS_OBJECTINFORMATIONW()],
            LPNTMS_OBJECTINFORMATIONW,
            size_is=lambda pkt: pkt.lpdwListBufferSize,
            length_is=lambda pkt: pkt.dwListCount,
        ),
        NDRIntField("lpdwListBufferSize", None, size_of="lpList"),
        NDRIntField("dwListCount", None, size_of="lpList"),
        NDRIntField("dwOptions", 0),
    ]


class CreateNtmsMediaW_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "lpMedia", LPNTMS_OBJECTINFORMATIONW(), LPNTMS_OBJECTINFORMATIONW
        ),
        NDRConfVarPacketListField(
            "lpList",
            [LPNTMS_OBJECTINFORMATIONW()],
            LPNTMS_OBJECTINFORMATIONW,
            size_is=lambda pkt: pkt.lpdwListBufferSize,
            length_is=lambda pkt: pkt.dwListCount,
        ),
        NDRIntField("status", 0),
    ]


INTMSOBJECTINFO1_OPNUMS = {
    0: DceRpcOp(
        GetNtmsServerObjectInformationA_Request,
        GetNtmsServerObjectInformationA_Response,
    ),
    1: DceRpcOp(
        GetNtmsServerObjectInformationW_Request,
        GetNtmsServerObjectInformationW_Response,
    ),
    2: DceRpcOp(SetNtmsObjectInformationA_Request, SetNtmsObjectInformationA_Response),
    3: DceRpcOp(SetNtmsObjectInformationW_Request, SetNtmsObjectInformationW_Response),
    4: DceRpcOp(CreateNtmsMediaA_Request, CreateNtmsMediaA_Response),
    5: DceRpcOp(CreateNtmsMediaW_Request, CreateNtmsMediaW_Response),
}
register_com_interface(
    name="INtmsObjectInfo1",
    uuid=uuid.UUID("69ab7050-3059-11d1-8faf-00a024cb6019"),
    opnums=INTMSOBJECTINFO1_OPNUMS,
)


class GetNtmsObjectSecurity_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRIntField("dwType", 0),
        NDRIntField("SecurityInformation", 0),
        NDRIntField("nLength", 0),
    ]


class GetNtmsObjectSecurity_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenField("lpSecurityDescriptor", "", size_is=lambda pkt: pkt.nLength),
        NDRIntField("lpnLengthNeeded", 0),
        NDRIntField("status", 0),
    ]


class SetNtmsObjectSecurity_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRIntField("dwType", 0),
        NDRIntField("SecurityInformation", 0),
        NDRConfStrLenField("lpSecurityDescriptor", "", size_is=lambda pkt: pkt.nLength),
        NDRIntField("nLength", None, size_of="lpSecurityDescriptor"),
    ]


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


class GetNtmsObjectAttributeA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRIntField("dwType", 0),
        NDRSignedByteField("lpAttributeName", 0),
        NDRIntField("lpdwAttributeBufferSize", 0),
    ]


class GetNtmsObjectAttributeA_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "lpAttributeData",
            "",
            size_is=lambda pkt: pkt.lpdwAttributeBufferSize,
            length_is=lambda pkt: pkt.lpAttributeSize,
        ),
        NDRIntField("lpAttributeSize", None, size_of="lpAttributeData"),
        NDRIntField("status", 0),
    ]


class GetNtmsObjectAttributeW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRIntField("dwType", 0),
        NDRConfVarStrNullFieldUtf16("lpAttributeName", ""),
        NDRIntField("lpdwAttributeBufferSize", 0),
    ]


class GetNtmsObjectAttributeW_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "lpAttributeData",
            "",
            size_is=lambda pkt: pkt.lpdwAttributeBufferSize,
            length_is=lambda pkt: pkt.lpAttributeSize,
        ),
        NDRIntField("lpAttributeSize", None, size_of="lpAttributeData"),
        NDRIntField("status", 0),
    ]


class SetNtmsObjectAttributeA_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRIntField("dwType", 0),
        NDRSignedByteField("lpAttributeName", 0),
        NDRConfStrLenField(
            "lpAttributeData", "", size_is=lambda pkt: pkt.AttributeSize
        ),
        NDRIntField("AttributeSize", None, size_of="lpAttributeData"),
    ]


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


class SetNtmsObjectAttributeW_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRIntField("dwType", 0),
        NDRConfVarStrNullFieldUtf16("lpAttributeName", ""),
        NDRConfStrLenField(
            "lpAttributeData", "", size_is=lambda pkt: pkt.AttributeSize
        ),
        NDRIntField("AttributeSize", None, size_of="lpAttributeData"),
    ]


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


class EnumerateNtmsObject_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("lpContainerId", GUID(), GUID)),
        NDRIntField("lpdwListBufferSize", 0),
        NDRIntField("dwType", 0),
        NDRIntField("dwOptions", 0),
    ]


class EnumerateNtmsObject_Response(NDRPacket):
    fields_desc = [
        NDRConfVarPacketListField(
            "lpList",
            [GUID()],
            GUID,
            size_is=lambda pkt: pkt.lpdwListBufferSize,
            length_is=lambda pkt: pkt.lpdwListBufferSize,
        ),
        NDRIntField("lpdwListSize", 0),
        NDRIntField("status", 0),
    ]


class DisableNtmsObject_Request(NDRPacket):
    fields_desc = [NDRIntField("dwType", 0), NDRPacketField("lpObjectId", GUID(), GUID)]


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


class EnableNtmsObject_Request(NDRPacket):
    fields_desc = [NDRIntField("dwType", 0), NDRPacketField("lpObjectId", GUID(), GUID)]


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


INTMSOBJECTMANAGEMENT1_OPNUMS = {
    0: DceRpcOp(GetNtmsObjectSecurity_Request, GetNtmsObjectSecurity_Response),
    1: DceRpcOp(SetNtmsObjectSecurity_Request, SetNtmsObjectSecurity_Response),
    2: DceRpcOp(GetNtmsObjectAttributeA_Request, GetNtmsObjectAttributeA_Response),
    3: DceRpcOp(GetNtmsObjectAttributeW_Request, GetNtmsObjectAttributeW_Response),
    4: DceRpcOp(SetNtmsObjectAttributeA_Request, SetNtmsObjectAttributeA_Response),
    5: DceRpcOp(SetNtmsObjectAttributeW_Request, SetNtmsObjectAttributeW_Response),
    6: DceRpcOp(EnumerateNtmsObject_Request, EnumerateNtmsObject_Response),
    7: DceRpcOp(DisableNtmsObject_Request, DisableNtmsObject_Response),
    8: DceRpcOp(EnableNtmsObject_Request, EnableNtmsObject_Response),
}
register_com_interface(
    name="INtmsObjectManagement1",
    uuid=uuid.UUID("b057dc50-3059-11d1-8faf-00a024cb6019"),
    opnums=INTMSOBJECTMANAGEMENT1_OPNUMS,
)


class OnNotify_Request(NDRPacket):
    fields_desc = [
        NDRIntField("dwType", 0),
        NDRIntField("dwOperation", 0),
        NDRPacketField("lpIdentifier", GUID(), GUID),
    ]


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


ICLIENTSINK_OPNUMS = {0: DceRpcOp(OnNotify_Request, OnNotify_Response)}
register_com_interface(
    name="IClientSink",
    uuid=uuid.UUID("879C8BBE-41B0-11d1-BE11-00C04FB6BF70"),
    opnums=ICLIENTSINK_OPNUMS,
)


class IdentifyNtmsSlot_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpSlotId", GUID(), GUID), NDRIntField("dwOption", 0)]


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


INTMSLIBRARYCONTROL2_OPNUMS = {
    0: DceRpcOp(IdentifyNtmsSlot_Request, IdentifyNtmsSlot_Response)
}
register_com_interface(
    name="INtmsLibraryControl2",
    uuid=uuid.UUID("DB90832F-6910-4d46-9F5E-9FD6BFA73903"),
    opnums=INTMSLIBRARYCONTROL2_OPNUMS,
)


class EnumerateNtmsObjectR_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("lpContainerId", GUID(), GUID)),
        NDRIntField("lpdwListBufferSize", 0),
        NDRIntField("dwType", 0),
        NDRIntField("dwOptions", 0),
    ]


class EnumerateNtmsObjectR_Response(NDRPacket):
    fields_desc = [
        NDRConfVarPacketListField(
            "lpList",
            [GUID()],
            GUID,
            size_is=lambda pkt: pkt.lpdwListBufferSize,
            length_is=lambda pkt: pkt.lpdwListSize,
        ),
        NDRIntField("lpdwListSize", None, size_of="lpList"),
        NDRIntField("lpdwOutputSize", 0),
        NDRIntField("status", 0),
    ]


class GetNtmsUIOptionsA_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("lpObjectId", GUID(), GUID)),
        NDRIntField("dwType", 0),
        NDRIntField("lpdwBufSize", 0),
    ]


class GetNtmsUIOptionsA_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "lpszDestination",
            "",
            size_is=lambda pkt: pkt.lpdwBufSize,
            length_is=lambda pkt: pkt.lpdwDataSize,
        ),
        NDRIntField("lpdwDataSize", None, size_of="lpszDestination"),
        NDRIntField("lpdwOutSize", 0),
        NDRIntField("status", 0),
    ]


class GetNtmsUIOptionsW_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("lpObjectId", GUID(), GUID)),
        NDRIntField("dwType", 0),
        NDRIntField("lpdwBufSize", 0),
    ]


class GetNtmsUIOptionsW_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenFieldUtf16(
            "lpszDestination",
            "",
            size_is=lambda pkt: pkt.lpdwBufSize,
            length_is=lambda pkt: pkt.lpdwDataSize,
        ),
        NDRIntField("lpdwDataSize", None, size_of="lpszDestination"),
        NDRIntField("lpdwOutSize", 0),
        NDRIntField("status", 0),
    ]


class SetNtmsUIOptionsA_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("lpObjectId", GUID(), GUID)),
        NDRIntField("dwType", 0),
        NDRIntField("dwOperation", 0),
        NDRConfVarStrNullField("lpszDestination", ""),
    ]


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


class SetNtmsUIOptionsW_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRPacketField("lpObjectId", GUID(), GUID)),
        NDRIntField("dwType", 0),
        NDRIntField("dwOperation", 0),
        NDRConfVarStrNullFieldUtf16("lpszDestination", ""),
    ]


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


INTMSOBJECTMANAGEMENT2_OPNUMS = {
    0: DceRpcOp(EnumerateNtmsObjectR_Request, EnumerateNtmsObjectR_Response),
    1: DceRpcOp(GetNtmsUIOptionsA_Request, GetNtmsUIOptionsA_Response),
    2: DceRpcOp(GetNtmsUIOptionsW_Request, GetNtmsUIOptionsW_Response),
    3: DceRpcOp(SetNtmsUIOptionsA_Request, SetNtmsUIOptionsA_Response),
    4: DceRpcOp(SetNtmsUIOptionsW_Request, SetNtmsUIOptionsW_Response),
}
register_com_interface(
    name="INtmsObjectManagement2",
    uuid=uuid.UUID("895A2C86-270D-489d-A6C0-DC2A9B35280E"),
    opnums=INTMSOBJECTMANAGEMENT2_OPNUMS,
)


class GetNtmsObjectAttributeAR_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRIntField("dwType", 0),
        NDRSignedByteField("lpAttributeName", 0),
        NDRIntField("lpdwAttributeBufferSize", 0),
    ]


class GetNtmsObjectAttributeAR_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "lpAttributeData",
            "",
            size_is=lambda pkt: pkt.lpdwAttributeBufferSize,
            length_is=lambda pkt: pkt.lpAttributeSize,
        ),
        NDRIntField("lpAttributeSize", None, size_of="lpAttributeData"),
        NDRIntField("lpActualAttributeSize", 0),
        NDRIntField("status", 0),
    ]


class GetNtmsObjectAttributeWR_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpObjectId", GUID(), GUID),
        NDRIntField("dwType", 0),
        NDRConfVarStrNullFieldUtf16("lpAttributeName", ""),
        NDRIntField("lpdwAttributeBufferSize", 0),
    ]


class GetNtmsObjectAttributeWR_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "lpAttributeData",
            "",
            size_is=lambda pkt: pkt.lpdwAttributeBufferSize,
            length_is=lambda pkt: pkt.lpAttributeSize,
        ),
        NDRIntField("lpAttributeSize", None, size_of="lpAttributeData"),
        NDRIntField("lpActualAttributeSize", 0),
        NDRIntField("status", 0),
    ]


INTMSOBJECTMANAGEMENT3_OPNUMS = {
    0: DceRpcOp(GetNtmsObjectAttributeAR_Request, GetNtmsObjectAttributeAR_Response),
    1: DceRpcOp(GetNtmsObjectAttributeWR_Request, GetNtmsObjectAttributeWR_Response),
}
register_com_interface(
    name="INtmsObjectManagement3",
    uuid=uuid.UUID("3BBED8D9-2C9A-4b21-8936-ACB2F995BE6C"),
    opnums=INTMSOBJECTMANAGEMENT3_OPNUMS,
)


class GetNtmsMediaPoolNameAR_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpPoolId", GUID(), GUID),
        NDRIntField("lpdwNameSizeBuf", 0),
    ]


class GetNtmsMediaPoolNameAR_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "lpBufName",
            "",
            size_is=lambda pkt: pkt.lpdwNameSizeBuf,
            length_is=lambda pkt: pkt.lpdwNameSize,
        ),
        NDRIntField("lpdwNameSize", None, size_of="lpBufName"),
        NDRIntField("lpdwOutputSize", 0),
        NDRIntField("status", 0),
    ]


class GetNtmsMediaPoolNameWR_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("lpPoolId", GUID(), GUID),
        NDRIntField("lpdwNameSizeBuf", 0),
    ]


class GetNtmsMediaPoolNameWR_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenFieldUtf16(
            "lpBufName",
            "",
            size_is=lambda pkt: pkt.lpdwNameSizeBuf,
            length_is=lambda pkt: pkt.lpdwNameSize,
        ),
        NDRIntField("lpdwNameSize", None, size_of="lpBufName"),
        NDRIntField("lpdwOutputSize", 0),
        NDRIntField("status", 0),
    ]


IROBUSTNTMSMEDIASERVICES1_OPNUMS = {
    0: DceRpcOp(GetNtmsMediaPoolNameAR_Request, GetNtmsMediaPoolNameAR_Response),
    1: DceRpcOp(GetNtmsMediaPoolNameWR_Request, GetNtmsMediaPoolNameWR_Response),
}
register_com_interface(
    name="IRobustNtmsMediaServices1",
    uuid=uuid.UUID("7D07F313-A53F-459a-BB12-012C15B1846E"),
    opnums=IROBUSTNTMSMEDIASERVICES1_OPNUMS,
)


class LPRSM_MESSAGE(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("lpguidOperation", GUID(), GUID), deferred=True
        ),
        NDRIntField("dwNtmsType", 0),
        NDRIntField("dwState", 0),
        NDRIntField("dwFlags", 0),
        NDRIntField("dwPriority", 0),
        NDRIntField("dwErrorCode", 0),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszComputerName", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszApplication", ""), deferred=True
        ),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("lpszUser", ""), deferred=True),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszTimeSubmitted", ""), deferred=True
        ),
        NDRFullPointerField(
            NDRConfVarStrNullFieldUtf16("lpszMessage", ""), deferred=True
        ),
    ]


class SendMessage_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("lpRsmMessage", LPRSM_MESSAGE(), LPRSM_MESSAGE)
        )
    ]


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


class RecallMessage_Request(NDRPacket):
    fields_desc = [NDRPacketField("lpGuid", GUID(), GUID)]


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


IMESSENGER_OPNUMS = {
    0: DceRpcOp(SendMessage_Request, SendMessage_Response),
    1: DceRpcOp(RecallMessage_Request, RecallMessage_Response),
}
register_com_interface(
    name="IMessenger",
    uuid=uuid.UUID("081E7188-C080-4FF3-9238-29F66D6CABFD"),
    opnums=IMESSENGER_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 ConnectCallback_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("pUnkCP", MInterfacePointer(), MInterfacePointer),
        NDRPacketField("pUnkSink", MInterfacePointer(), MInterfacePointer),
    ]


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


class OnNotify_Request(NDRPacket):
    fields_desc = [
        NDRIntField("dwType", 0),
        NDRIntField("dwOperation", 0),
        NDRPacketField("lpIdentifier", GUID(), GUID),
    ]


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


class ReleaseCallback_Request(NDRPacket):
    fields_desc = []


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


INTMSNOTIFYSINK_OPNUMS = {
    0: DceRpcOp(ConnectCallback_Request, ConnectCallback_Response),
    1: DceRpcOp(OnNotify_Request, OnNotify_Response),
    2: DceRpcOp(ReleaseCallback_Request, ReleaseCallback_Response),
}
register_com_interface(
    name="INtmsNotifySink",
    uuid=uuid.UUID("BB39332C-BFEE-4380-AD8A-BADC8AFF5BB6"),
    opnums=INTMSNOTIFYSINK_OPNUMS,
)
