### ms-rsp_winreg.idl
"""
RPC definitions for the following interfaces:
- winreg (v1.0): 338CD001-2244-31F1-AAAA-900038001003
This file is auto-generated by midl-to-scapy, do not modify.
"""

import uuid


from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRByteField,
    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 BaseInitiateSystemShutdown_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRShortField("ServerName", 0)),
        NDRFullPointerField(
            NDRPacketField("lpMessage", PREG_UNICODE_STRING(), PREG_UNICODE_STRING)
        ),
        NDRIntField("dwTimeout", 0),
        NDRByteField("bForceAppsClosed", 0),
        NDRByteField("bRebootAfterShutdown", 0),
    ]


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


class BaseAbortSystemShutdown_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRShortField("ServerName", 0))]


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


class BaseInitiateSystemShutdownEx_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRShortField("ServerName", 0)),
        NDRFullPointerField(
            NDRPacketField("lpMessage", PREG_UNICODE_STRING(), PREG_UNICODE_STRING)
        ),
        NDRIntField("dwTimeout", 0),
        NDRByteField("bForceAppsClosed", 0),
        NDRByteField("bRebootAfterShutdown", 0),
        NDRIntField("dwReason", 0),
    ]


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


WINREG_OPNUMS = {  # 0: Opnum0NotImplemented,
    # 1: Opnum1NotImplemented,
    # 2: Opnum2NotImplemented,
    # 3: Opnum3NotImplemented,
    # 4: Opnum4NotImplemented,
    # 5: Opnum5NotImplemented,
    # 6: Opnum6NotImplemented,
    # 7: Opnum7NotImplemented,
    # 8: Opnum8NotImplemented,
    # 9: Opnum9NotImplemented,
    # 10: Opnum10NotImplemented,
    # 11: Opnum11NotImplemented,
    # 12: Opnum12NotImplemented,
    # 13: Opnum13NotImplemented,
    # 14: Opnum14NotImplemented,
    # 15: Opnum15NotImplemented,
    # 16: Opnum16NotImplemented,
    # 17: Opnum17NotImplemented,
    # 18: Opnum18NotImplemented,
    # 19: Opnum19NotImplemented,
    # 20: Opnum20NotImplemented,
    # 21: Opnum21NotImplemented,
    # 22: Opnum22NotImplemented,
    # 23: Opnum23NotImplemented,
    24: DceRpcOp(
        BaseInitiateSystemShutdown_Request, BaseInitiateSystemShutdown_Response
    ),
    25: DceRpcOp(BaseAbortSystemShutdown_Request, BaseAbortSystemShutdown_Response),
    # 26: Opnum26NotImplemented,
    # 27: Opnum27NotImplemented,
    # 28: Opnum28NotImplemented,
    # 29: Opnum29NotImplemented,
    30: DceRpcOp(
        BaseInitiateSystemShutdownEx_Request, BaseInitiateSystemShutdownEx_Response
    ),
}
register_dcerpc_interface(
    name="winreg",
    uuid=uuid.UUID("338CD001-2244-31F1-AAAA-900038001003"),
    version="1.0",
    opnums=WINREG_OPNUMS,
)
