### ms-frs2.idl
"""
RPC definitions for the following interfaces:
- FrsTransport (v1.0): 897e2e5f-93f3-4376-9c9c-fd2277495c27
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import PacketListField, StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfVarPacketListField,
    NDRConfVarStrLenField,
    NDRContextHandle,
    NDRFullPointerField,
    NDRInt3264EnumField,
    NDRIntField,
    NDRLongField,
    NDRPacketField,
    NDRShortField,
    NDRSignedByteField,
    NDRSignedIntField,
    NDRUnionField,
    NDRVarStrLenField,
    NDRVarStrLenFieldUtf16,
    register_dcerpc_interface,
)


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


class CheckConnectivity_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("replicaSetId", GUID(), GUID),
        NDRPacketField("connectionId", GUID(), GUID),
    ]


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


class EstablishConnection_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("replicaSetId", GUID(), GUID),
        NDRPacketField("connectionId", GUID(), GUID),
        NDRIntField("downstreamProtocolVersion", 0),
        NDRIntField("downstreamFlags", 0),
    ]


class EstablishConnection_Response(NDRPacket):
    fields_desc = [
        NDRIntField("upstreamProtocolVersion", 0),
        NDRIntField("upstreamFlags", 0),
        NDRIntField("status", 0),
    ]


class EstablishSession_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("connectionId", GUID(), GUID),
        NDRPacketField("contentSetId", GUID(), GUID),
    ]


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


class UPDATE_REQUEST_TYPE(IntEnum):
    UPDATE_REQUEST_ALL = 0
    UPDATE_REQUEST_TOMBSTONES = 1
    UPDATE_REQUEST_LIVE = 2


class FRS_VERSION_VECTOR(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("dbGuid", GUID(), GUID),
        NDRLongField("low", 0),
        NDRLongField("high", 0),
    ]


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


class FRS_UPDATE(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRSignedIntField("present", 0),
        NDRSignedIntField("nameConflict", 0),
        NDRIntField("attributes", 0),
        NDRPacketField("fence", FILETIME(), FILETIME),
        NDRPacketField("clock", FILETIME(), FILETIME),
        NDRPacketField("createTime", FILETIME(), FILETIME),
        NDRPacketField("contentSetId", GUID(), GUID),
        StrFixedLenField("hash", "", length=20),
        StrFixedLenField("rdcSimilarity", "", length=16),
        NDRPacketField("uidDbGuid", GUID(), GUID),
        NDRLongField("uidVersion", 0),
        NDRPacketField("gvsnDbGuid", GUID(), GUID),
        NDRLongField("gvsnVersion", 0),
        NDRPacketField("parentDbGuid", GUID(), GUID),
        NDRLongField("parentVersion", 0),
        NDRVarStrLenFieldUtf16("name", ""),
        NDRSignedIntField("flags", 0),
    ]


class UPDATE_STATUS(IntEnum):
    UPDATE_STATUS_DONE = 2
    UPDATE_STATUS_MORE = 3


class RequestUpdates_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("connectionId", GUID(), GUID),
        NDRPacketField("contentSetId", GUID(), GUID),
        NDRIntField("creditsAvailable", 0),
        NDRSignedIntField("hashRequested", 0),
        NDRInt3264EnumField("updateRequestType", 0, UPDATE_REQUEST_TYPE),
        NDRIntField("versionVectorDiffCount", None, size_of="versionVectorDiff"),
        NDRConfPacketListField(
            "versionVectorDiff",
            [],
            FRS_VERSION_VECTOR,
            size_is=lambda pkt: pkt.versionVectorDiffCount,
        ),
    ]


class RequestUpdates_Response(NDRPacket):
    fields_desc = [
        NDRConfVarPacketListField(
            "frsUpdate",
            [],
            FRS_UPDATE,
            size_is=lambda pkt: pkt.creditsAvailable,
            length_is=lambda pkt: pkt.updateCount,
        ),
        NDRIntField("updateCount", None, size_of="frsUpdate"),
        NDRInt3264EnumField("updateStatus", 0, UPDATE_STATUS),
        NDRPacketField("gvsnDbGuid", GUID(), GUID),
        NDRLongField("gvsnVersion", 0),
        NDRIntField("status", 0),
    ]


class VERSION_REQUEST_TYPE(IntEnum):
    REQUEST_NORMAL_SYNC = 0
    REQUEST_SLOW_SYNC = 1
    REQUEST_SUBORDINATE_SYNC = 2


class VERSION_CHANGE_TYPE(IntEnum):
    CHANGE_NOTIFY = 0
    CHANGE_ALL = 2


class RequestVersionVector_Request(NDRPacket):
    fields_desc = [
        NDRIntField("sequenceNumber", 0),
        NDRPacketField("connectionId", GUID(), GUID),
        NDRPacketField("contentSetId", GUID(), GUID),
        NDRInt3264EnumField("requestType", 0, VERSION_REQUEST_TYPE),
        NDRInt3264EnumField("changeType", 0, VERSION_CHANGE_TYPE),
        NDRLongField("vvGeneration", 0),
    ]


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


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 FRS_EPOQUE_VECTOR(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRPacketField("machine", GUID(), GUID),
        NDRPacketField("epoque", SYSTEMTIME(), SYSTEMTIME),
    ]


class FRS_ASYNC_VERSION_VECTOR_RESPONSE(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRLongField("vvGeneration", 0),
        NDRIntField("versionVectorCount", None, size_of="versionVector"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "versionVector",
                [],
                FRS_VERSION_VECTOR,
                size_is=lambda pkt: pkt.versionVectorCount,
            ),
            deferred=True,
        ),
        NDRIntField("epoqueVectorCount", None, size_of="epoqueVector"),
        NDRFullPointerField(
            NDRConfPacketListField(
                "epoqueVector",
                [],
                FRS_EPOQUE_VECTOR,
                size_is=lambda pkt: pkt.epoqueVectorCount,
            ),
            deferred=True,
        ),
    ]


class FRS_ASYNC_RESPONSE_CONTEXT(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRIntField("sequenceNumber", 0),
        NDRIntField("status", 0),
        NDRPacketField(
            "result",
            FRS_ASYNC_VERSION_VECTOR_RESPONSE(),
            FRS_ASYNC_VERSION_VECTOR_RESPONSE,
        ),
    ]


class AsyncPoll_Request(NDRPacket):
    fields_desc = [NDRPacketField("connectionId", GUID(), GUID)]


class AsyncPoll_Response(NDRPacket):
    fields_desc = [
        NDRPacketField(
            "response", FRS_ASYNC_RESPONSE_CONTEXT(), FRS_ASYNC_RESPONSE_CONTEXT
        ),
        NDRIntField("status", 0),
    ]


class RECORDS_STATUS(IntEnum):
    RECORDS_STATUS_DONE = 0
    RECORDS_STATUS_MORE = 1


class RequestRecords_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("connectionId", GUID(), GUID),
        NDRPacketField("contentSetId", GUID(), GUID),
        NDRPacketField("uidDbGuid", GUID(), GUID),
        NDRLongField("uidVersion", 0),
        NDRIntField("maxRecords", 0),
    ]


class RequestRecords_Response(NDRPacket):
    fields_desc = [
        NDRIntField("maxRecords", 0),
        NDRIntField("numRecords", 0),
        NDRIntField("numBytes", None, size_of="compressedRecords"),
        NDRConfStrLenField("compressedRecords", "", size_is=lambda pkt: pkt.numBytes),
        NDRInt3264EnumField("recordsStatus", 0, RECORDS_STATUS),
        NDRIntField("status", 0),
    ]


class FRS_UPDATE_CANCEL_DATA(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [
        NDRPacketField("blockingUpdate", FRS_UPDATE(), FRS_UPDATE),
        NDRPacketField("contentSetId", GUID(), GUID),
        NDRPacketField("gvsnDatabaseId", GUID(), GUID),
        NDRPacketField("uidDatabaseId", GUID(), GUID),
        NDRPacketField("parentDatabaseId", GUID(), GUID),
        NDRLongField("gvsnVersion", 0),
        NDRLongField("uidVersion", 0),
        NDRLongField("parentVersion", 0),
        NDRIntField("cancelType", 0),
        NDRSignedIntField("isUidValid", 0),
        NDRSignedIntField("isParentUidValid", 0),
        NDRSignedIntField("isBlockerValid", 0),
    ]


class UpdateCancel_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("connectionId", GUID(), GUID),
        NDRPacketField("cancelData", FRS_UPDATE_CANCEL_DATA(), FRS_UPDATE_CANCEL_DATA),
    ]


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


class RawGetFileData_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("bufferSize", 0),
    ]


class RawGetFileData_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle),
        NDRConfVarStrLenField(
            "dataBuffer",
            "",
            size_is=lambda pkt: pkt.bufferSize,
            length_is=lambda pkt: pkt.sizeRead,
        ),
        NDRIntField("sizeRead", None, size_of="dataBuffer"),
        NDRSignedIntField("isEndOfFile", 0),
        NDRIntField("status", 0),
    ]


class RdcGetSignatures_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle),
        NDRSignedByteField("level", 0),
        NDRLongField("offset", 0),
        NDRIntField("length", 0),
    ]


class RdcGetSignatures_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "buffer",
            "",
            size_is=lambda pkt: pkt.length,
            length_is=lambda pkt: pkt.sizeRead,
        ),
        NDRIntField("sizeRead", None, size_of="buffer"),
        NDRIntField("status", 0),
    ]


class FRS_RDC_SOURCE_NEED(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRLongField("needOffset", 0), NDRLongField("needSize", 0)]


class RdcPushSourceNeeds_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle),
        NDRConfPacketListField(
            "sourceNeeds", [], FRS_RDC_SOURCE_NEED, size_is=lambda pkt: pkt.needCount
        ),
        NDRIntField("needCount", None, size_of="sourceNeeds"),
    ]


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


class RdcGetFileData_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("bufferSize", 0),
    ]


class RdcGetFileData_Response(NDRPacket):
    fields_desc = [
        NDRConfVarStrLenField(
            "dataBuffer",
            "",
            size_is=lambda pkt: pkt.bufferSize,
            length_is=lambda pkt: pkt.sizeReturned,
        ),
        NDRIntField("sizeReturned", None, size_of="dataBuffer"),
        NDRIntField("status", 0),
    ]


class RdcClose_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle)
    ]


class RdcClose_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle),
        NDRIntField("status", 0),
    ]


class FRS_REQUESTED_STAGING_POLICY(IntEnum):
    SERVER_DEFAULT = 0
    STAGING_REQUIRED = 1
    RESTAGING_REQUIRED = 2


class RDC_FILE_COMPRESSION_TYPES(IntEnum):
    RDC_UNCOMPRESSED = 0
    RDC_XPRESS = 1


class RDC_CHUNKER_ALGORITHM(IntEnum):
    RDC_FILTERGENERIC = 0
    RDC_FILTERMAX = 1
    RDC_FILTERPOINT = 2
    RDC_MAXALGORITHM = 3


class FRS_RDC_PARAMETERS_GENERIC(NDRPacket):
    ALIGNMENT = (2, 2)
    fields_desc = [
        NDRShortField("chunkerType", 0),
        StrFixedLenField("chunkerParameters", "", length=64),
    ]


class FRS_RDC_PARAMETERS_FILTERMAX(NDRPacket):
    ALIGNMENT = (2, 2)
    fields_desc = [NDRShortField("horizonSize", 0), NDRShortField("windowSize", 0)]


class FRS_RDC_PARAMETERS_FILTERPOINT(NDRPacket):
    ALIGNMENT = (2, 2)
    fields_desc = [NDRShortField("minChunkSize", 0), NDRShortField("maxChunkSize", 0)]


class FRS_RDC_PARAMETERS(NDRPacket):
    ALIGNMENT = (2, 4)
    fields_desc = [
        NDRShortField("rdcChunkerAlgorithm", 0),
        NDRUnionField(
            [
                (
                    NDRPacketField(
                        "u", FRS_RDC_PARAMETERS_GENERIC(), FRS_RDC_PARAMETERS_GENERIC
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "rdcChunkerAlgorithm", None)
                            == RDC_CHUNKER_ALGORITHM.RDC_FILTERGENERIC
                        ),
                        (
                            lambda _, val: val.tag
                            == RDC_CHUNKER_ALGORITHM.RDC_FILTERGENERIC
                        ),
                    ),
                ),
                (
                    NDRPacketField(
                        "u",
                        FRS_RDC_PARAMETERS_FILTERMAX(),
                        FRS_RDC_PARAMETERS_FILTERMAX,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "rdcChunkerAlgorithm", None)
                            == RDC_CHUNKER_ALGORITHM.RDC_FILTERMAX
                        ),
                        (lambda _, val: val.tag == RDC_CHUNKER_ALGORITHM.RDC_FILTERMAX),
                    ),
                ),
                (
                    NDRPacketField(
                        "u",
                        FRS_RDC_PARAMETERS_FILTERPOINT(),
                        FRS_RDC_PARAMETERS_FILTERPOINT,
                    ),
                    (
                        (
                            lambda pkt: getattr(pkt, "rdcChunkerAlgorithm", None)
                            == RDC_CHUNKER_ALGORITHM.RDC_FILTERPOINT
                        ),
                        (
                            lambda _, val: val.tag
                            == RDC_CHUNKER_ALGORITHM.RDC_FILTERPOINT
                        ),
                    ),
                ),
            ],
            StrFixedLenField("u", "", length=0),
            align=(2, 4),
            switch_fmt=("H", "H"),
        ),
    ]


class FRS_RDC_FILEINFO(NDRPacket):
    ALIGNMENT = (8, 8)
    DEPORTED_CONFORMANTS = ["rdcFilterParameters"]
    fields_desc = [
        NDRLongField("onDiskFileSize", 0),
        NDRLongField("fileSizeEstimate", 0),
        NDRShortField("rdcVersion", 0),
        NDRShortField("rdcMinimumCompatibleVersion", 0),
        NDRSignedByteField("rdcSignatureLevels", None, size_of="rdcFilterParameters"),
        NDRInt3264EnumField("compressionAlgorithm", 0, RDC_FILE_COMPRESSION_TYPES),
        NDRConfPacketListField(
            "rdcFilterParameters",
            [],
            FRS_RDC_PARAMETERS,
            size_is=lambda pkt: pkt.rdcSignatureLevels,
            conformant_in_struct=True,
        ),
    ]


class InitializeFileTransferAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("connectionId", GUID(), GUID),
        NDRPacketField("frsUpdate", FRS_UPDATE(), FRS_UPDATE),
        NDRSignedIntField("rdcDesired", 0),
        NDRInt3264EnumField("stagingPolicy", 0, FRS_REQUESTED_STAGING_POLICY),
        NDRIntField("bufferSize", 0),
    ]


class InitializeFileTransferAsync_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("frsUpdate", FRS_UPDATE(), FRS_UPDATE),
        NDRInt3264EnumField("stagingPolicy", 0, FRS_REQUESTED_STAGING_POLICY),
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle),
        NDRFullPointerField(
            NDRPacketField("rdcFileInfo", FRS_RDC_FILEINFO(), FRS_RDC_FILEINFO)
        ),
        NDRConfVarStrLenField(
            "dataBuffer",
            "",
            size_is=lambda pkt: pkt.bufferSize,
            length_is=lambda pkt: pkt.sizeRead,
        ),
        NDRIntField("sizeRead", None, size_of="dataBuffer"),
        NDRSignedIntField("isEndOfFile", 0),
        NDRIntField("status", 0),
    ]


class RawGetFileDataAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle)
    ]


class RawGetFileDataAsync_Response(NDRPacket):
    fields_desc = [NDRSignedByteField("bytePipe", 0), NDRIntField("status", 0)]


class RdcGetFileDataAsync_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle)
    ]


class RdcGetFileDataAsync_Response(NDRPacket):
    fields_desc = [NDRSignedByteField("bytePipe", 0), NDRIntField("status", 0)]


class RdcFileDataTransferKeepAlive_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("serverContext", NDRContextHandle(), NDRContextHandle)
    ]


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


FRSTRANSPORT_OPNUMS = {
    0: DceRpcOp(CheckConnectivity_Request, CheckConnectivity_Response),
    1: DceRpcOp(EstablishConnection_Request, EstablishConnection_Response),
    2: DceRpcOp(EstablishSession_Request, EstablishSession_Response),
    3: DceRpcOp(RequestUpdates_Request, RequestUpdates_Response),
    4: DceRpcOp(RequestVersionVector_Request, RequestVersionVector_Response),
    5: DceRpcOp(AsyncPoll_Request, AsyncPoll_Response),
    6: DceRpcOp(RequestRecords_Request, RequestRecords_Response),
    7: DceRpcOp(UpdateCancel_Request, UpdateCancel_Response),
    8: DceRpcOp(RawGetFileData_Request, RawGetFileData_Response),
    9: DceRpcOp(RdcGetSignatures_Request, RdcGetSignatures_Response),
    10: DceRpcOp(RdcPushSourceNeeds_Request, RdcPushSourceNeeds_Response),
    11: DceRpcOp(RdcGetFileData_Request, RdcGetFileData_Response),
    12: DceRpcOp(RdcClose_Request, RdcClose_Response),
    13: DceRpcOp(
        InitializeFileTransferAsync_Request, InitializeFileTransferAsync_Response
    ),
    # 14: Opnum14NotUsedOnWire,
    15: DceRpcOp(RawGetFileDataAsync_Request, RawGetFileDataAsync_Response),
    16: DceRpcOp(RdcGetFileDataAsync_Request, RdcGetFileDataAsync_Response),
    17: DceRpcOp(
        RdcFileDataTransferKeepAlive_Request, RdcFileDataTransferKeepAlive_Response
    ),
}
register_dcerpc_interface(
    name="FrsTransport",
    uuid=uuid.UUID("897e2e5f-93f3-4376-9c9c-fd2277495c27"),
    version="1.0",
    opnums=FRSTRANSPORT_OPNUMS,
)
