### ms-rsp_windowsshutdown.idl
"""
RPC definitions for the following interfaces:
- WindowsShutdown (v1.0): d95afe70-a6d5-4259-822e-2c84da1ddb0d
This file is auto-generated by midl-to-scapy, do not modify.
"""

import uuid


from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfVarStrLenField,
    NDRConfVarStrLenFieldUtf16,
    NDRFullPointerField,
    NDRIntField,
    NDRPacketField,
    NDRShortField,
    register_dcerpc_interface,
)


class PREG_UNICODE_STRING(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRShortField("Length", None, size_of="Buffer", adjust=lambda _, x: (x * 2)),
        NDRShortField(
            "MaximumLength", None, size_of="Buffer", adjust=lambda _, x: (x * 2)
        ),
        NDRFullPointerField(
            NDRConfVarStrLenFieldUtf16(
                "Buffer",
                "",
                size_is=lambda pkt: (pkt.MaximumLength // 2),
                length_is=lambda pkt: (pkt.Length // 2),
            ),
            deferred=True,
        ),
    ]


class WsdrInitiateShutdown_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("lpMessage", PREG_UNICODE_STRING(), PREG_UNICODE_STRING)
        ),
        NDRIntField("dwGracePeriod", 0),
        NDRIntField("dwShudownFlags", 0),
        NDRIntField("dwReason", 0),
        NDRFullPointerField(
            NDRPacketField("lpClientHint", PREG_UNICODE_STRING(), PREG_UNICODE_STRING)
        ),
    ]


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


class WsdrAbortShutdown_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("lpClientHint", PREG_UNICODE_STRING(), PREG_UNICODE_STRING)
        )
    ]


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


WINDOWSSHUTDOWN_OPNUMS = {
    0: DceRpcOp(WsdrInitiateShutdown_Request, WsdrInitiateShutdown_Response),
    1: DceRpcOp(WsdrAbortShutdown_Request, WsdrAbortShutdown_Response),
}
register_dcerpc_interface(
    name="WindowsShutdown",
    uuid=uuid.UUID("d95afe70-a6d5-4259-822e-2c84da1ddb0d"),
    version="1.0",
    opnums=WINDOWSSHUTDOWN_OPNUMS,
)
