### ms-imsa.idl
"""
RPC definitions for the following interfaces:
- IMSAdminBaseW (v0.0): 70B51430-B6CA-11d0-B9B9-00A0C922E750
- IMSAdminBase2W (v0.0): 8298d101-f992-43b7-8eca-5052d885b995
- IMSAdminBase3W (v0.0): f612954d-3b0b-4c56-9563-227b7be624b4
- IWamAdmin (v0.0): 29822AB7-F302-11D0-9953-00C04FD919C1
- IWamAdmin2 (v0.0): 29822AB8-F302-11D0-9953-00C04FD919C1
- IIISApplicationAdmin (v0.0): 7C4E1804-E342-483D-A43E-A850CFCC8D18
- IIISCertObj (v0.0): BD0C73BC-805B-4043-9C30-9A28D64DD7D2
This file is auto-generated by midl-to-scapy, do not modify.
"""

from enum import IntEnum
import uuid

from scapy.fields import StrFixedLenField
from scapy.layers.dcerpc import (
    NDRPacket,
    DceRpcOp,
    NDRConfPacketListField,
    NDRConfStrLenField,
    NDRConfStrLenFieldUtf16,
    NDRConfVarStrLenField,
    NDRConfVarStrNullField,
    NDRConfVarStrNullFieldUtf16,
    NDRFullPointerField,
    NDRIntField,
    NDRPacketField,
    NDRRecursiveField,
    NDRRefEmbPointerField,
    NDRShortField,
    NDRSignedByteField,
    NDRSignedIntField,
    NDRSignedLongField,
    NDRSignedShortField,
    register_com_interface,
    register_dcerpc_interface,
)


class AddKey_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
    ]


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


class DeleteKey_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
    ]


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


class DeleteChildKeys_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
    ]


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


class EnumKeys_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRIntField("dwMDEnumObjectIndex", 0),
    ]


class EnumKeys_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenFieldUtf16(
            "pszMDName", "", size_is=lambda pkt: pkt.ADMINDATA_MAX_NAME_LEN
        ),
        NDRIntField("status", 0),
    ]


class CopyKey_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDSourceHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDSourcePath", "")),
        NDRIntField("hMDDestHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDDestPath", "")),
        NDRSignedIntField("bMDOverwriteFlag", 0),
        NDRSignedIntField("bMDCopyFlag", 0),
    ]


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


class RenameKey_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDNewName", "")),
    ]


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


class METADATA_RECORD(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("dwMDIdentifier", 0),
        NDRIntField("dwMDAttributes", 0),
        NDRIntField("dwMDUserType", 0),
        NDRIntField("dwMDDataType", 0),
        NDRIntField("dwMDDataLen", None, size_of="pbMDData"),
        NDRFullPointerField(
            NDRConfStrLenField("pbMDData", "", size_is=lambda pkt: pkt.dwMDDataLen),
            deferred=True,
        ),
        NDRIntField("dwMDDataTag", 0),
    ]


class R_SetData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRPacketField("pmdrMDData", METADATA_RECORD(), METADATA_RECORD),
    ]


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


class IIS_CRYPTO_BLOB(NDRPacket):
    ALIGNMENT = (4, 4)
    DEPORTED_CONFORMANTS = ["BlobData"]
    fields_desc = [
        NDRIntField("BlobSignature", 0),
        NDRIntField("BlobDataLength", None, size_of="BlobData"),
        NDRConfStrLenField(
            "BlobData",
            "",
            size_is=lambda pkt: pkt.BlobDataLength,
            conformant_in_struct=True,
        ),
    ]


class R_GetData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRPacketField("pmdrMDData", METADATA_RECORD(), METADATA_RECORD),
    ]


class R_GetData_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pmdrMDData", METADATA_RECORD(), METADATA_RECORD),
        NDRIntField("pdwMDRequiredDataLen", 0),
        NDRFullPointerField(
            NDRPacketField("ppDataBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB)
        ),
        NDRIntField("status", 0),
    ]


class DeleteData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRIntField("dwMDIdentifier", 0),
        NDRIntField("dwMDDataType", 0),
    ]


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


class R_EnumData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRPacketField("pmdrMDData", METADATA_RECORD(), METADATA_RECORD),
        NDRIntField("dwMDEnumDataIndex", 0),
    ]


class R_EnumData_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pmdrMDData", METADATA_RECORD(), METADATA_RECORD),
        NDRIntField("pdwMDRequiredDataLen", 0),
        NDRFullPointerField(
            NDRPacketField("ppDataBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB)
        ),
        NDRIntField("status", 0),
    ]


class R_GetAllData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRIntField("dwMDAttributes", 0),
        NDRIntField("dwMDUserType", 0),
        NDRIntField("dwMDDataType", 0),
        NDRIntField("dwMDBufferSize", 0),
    ]


class R_GetAllData_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pdwMDNumDataEntries", 0),
        NDRIntField("pdwMDDataSetNumber", 0),
        NDRIntField("pdwMDRequiredBufferSize", 0),
        NDRFullPointerField(
            NDRPacketField("ppDataBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB)
        ),
        NDRIntField("status", 0),
    ]


class DeleteAllData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRIntField("dwMDUserType", 0),
        NDRIntField("dwMDDataType", 0),
    ]


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


class CopyData_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDSourceHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDSourcePath", "")),
        NDRIntField("hMDDestHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDDestPath", "")),
        NDRIntField("dwMDAttributes", 0),
        NDRIntField("dwMDUserType", 0),
        NDRIntField("dwMDDataType", 0),
        NDRSignedIntField("bMDCopyFlag", 0),
    ]


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


class GetDataPaths_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRIntField("dwMDIdentifier", 0),
        NDRIntField("dwMDDataType", 0),
        NDRIntField("dwMDBufferSize", 0),
    ]


class GetDataPaths_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenFieldUtf16(
            "pszBuffer", "", size_is=lambda pkt: pkt.dwMDBufferSize
        ),
        NDRIntField("pdwMDRequiredBufferSize", 0),
        NDRIntField("status", 0),
    ]


class OpenKey_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRIntField("dwMDAccessRequested", 0),
        NDRIntField("dwMDTimeOut", 0),
    ]


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


class CloseKey_Request(NDRPacket):
    fields_desc = [NDRIntField("hMDHandle", 0)]


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


class ChangePermissions_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRIntField("dwMDTimeOut", 0),
        NDRIntField("dwMDAccessRequested", 0),
    ]


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


class SaveData_Request(NDRPacket):
    fields_desc = []


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


class METADATA_HANDLE_INFO(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("dwMDPermissions", 0),
        NDRIntField("dwMDSystemChangeNumber", 0),
    ]


class GetHandleInfo_Request(NDRPacket):
    fields_desc = [NDRIntField("hMDHandle", 0)]


class GetHandleInfo_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pmdhiInfo", METADATA_HANDLE_INFO(), METADATA_HANDLE_INFO),
        NDRIntField("status", 0),
    ]


class GetSystemChangeNumber_Request(NDRPacket):
    fields_desc = []


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


class GetDataSetNumber_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
    ]


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


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


class SetLastChangeTime_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRPacketField("pftMDLastChangeTime", PFILETIME(), PFILETIME),
        NDRSignedIntField("bLocalTime", 0),
    ]


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


class GetLastChangeTime_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRSignedIntField("bLocalTime", 0),
    ]


class GetLastChangeTime_Response(NDRPacket):
    fields_desc = [
        NDRPacketField("pftMDLastChangeTime", PFILETIME(), PFILETIME),
        NDRIntField("status", 0),
    ]


class R_KeyExchangePhase1_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "pClientKeyExchangeKeyBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "pClientSignatureKeyBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB
            )
        ),
    ]


class R_KeyExchangePhase1_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField(
                "ppServerKeyExchangeKeyBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField(
                "ppServerSignatureKeyBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB
            )
        ),
        NDRFullPointerField(
            NDRPacketField("ppServerSessionKeyBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB)
        ),
        NDRIntField("status", 0),
    ]


class R_KeyExchangePhase2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("pClientSessionKeyBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB)
        ),
        NDRFullPointerField(
            NDRPacketField("pClientHashBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB)
        ),
    ]


class R_KeyExchangePhase2_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("ppServerHashBlob", IIS_CRYPTO_BLOB(), IIS_CRYPTO_BLOB)
        ),
        NDRIntField("status", 0),
    ]


class Backup_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDBackupName", "")),
        NDRIntField("dwMDVersion", 0),
        NDRIntField("dwMDFlags", 0),
    ]


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


class Restore_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDBackupName", "")),
        NDRIntField("dwMDVersion", 0),
        NDRIntField("dwMDFlags", 0),
    ]


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


class EnumBackups_Request(NDRPacket):
    fields_desc = [
        NDRConfStrLenFieldUtf16(
            "pszMDBackupName", "", size_is=lambda pkt: pkt.MD_BACKUP_MAX_LEN
        ),
        NDRIntField("dwMDEnumIndex", 0),
    ]


class EnumBackups_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenFieldUtf16(
            "pszMDBackupName", "", size_is=lambda pkt: pkt.MD_BACKUP_MAX_LEN
        ),
        NDRIntField("pdwMDVersion", 0),
        NDRPacketField("pftMDBackupTime", PFILETIME(), PFILETIME),
        NDRIntField("status", 0),
    ]


class DeleteBackup_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDBackupName", "")),
        NDRIntField("dwMDVersion", 0),
    ]


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


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 UnmarshalInterface_Request(NDRPacket):
    fields_desc = []


class UnmarshalInterface_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("piadmbwInterface", MInterfacePointer(), MInterfacePointer)
        ),
        NDRIntField("status", 0),
    ]


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


class R_GetServerGuid_Request(NDRPacket):
    fields_desc = []


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


IMSADMINBASEW_OPNUMS = {
    0: DceRpcOp(AddKey_Request, AddKey_Response),
    1: DceRpcOp(DeleteKey_Request, DeleteKey_Response),
    2: DceRpcOp(DeleteChildKeys_Request, DeleteChildKeys_Response),
    3: DceRpcOp(EnumKeys_Request, EnumKeys_Response),
    4: DceRpcOp(CopyKey_Request, CopyKey_Response),
    5: DceRpcOp(RenameKey_Request, RenameKey_Response),
    6: DceRpcOp(R_SetData_Request, R_SetData_Response),
    7: DceRpcOp(R_GetData_Request, R_GetData_Response),
    8: DceRpcOp(DeleteData_Request, DeleteData_Response),
    9: DceRpcOp(R_EnumData_Request, R_EnumData_Response),
    10: DceRpcOp(R_GetAllData_Request, R_GetAllData_Response),
    11: DceRpcOp(DeleteAllData_Request, DeleteAllData_Response),
    12: DceRpcOp(CopyData_Request, CopyData_Response),
    13: DceRpcOp(GetDataPaths_Request, GetDataPaths_Response),
    14: DceRpcOp(OpenKey_Request, OpenKey_Response),
    15: DceRpcOp(CloseKey_Request, CloseKey_Response),
    16: DceRpcOp(ChangePermissions_Request, ChangePermissions_Response),
    17: DceRpcOp(SaveData_Request, SaveData_Response),
    18: DceRpcOp(GetHandleInfo_Request, GetHandleInfo_Response),
    19: DceRpcOp(GetSystemChangeNumber_Request, GetSystemChangeNumber_Response),
    20: DceRpcOp(GetDataSetNumber_Request, GetDataSetNumber_Response),
    21: DceRpcOp(SetLastChangeTime_Request, SetLastChangeTime_Response),
    22: DceRpcOp(GetLastChangeTime_Request, GetLastChangeTime_Response),
    23: DceRpcOp(R_KeyExchangePhase1_Request, R_KeyExchangePhase1_Response),
    24: DceRpcOp(R_KeyExchangePhase2_Request, R_KeyExchangePhase2_Response),
    25: DceRpcOp(Backup_Request, Backup_Response),
    26: DceRpcOp(Restore_Request, Restore_Response),
    27: DceRpcOp(EnumBackups_Request, EnumBackups_Response),
    28: DceRpcOp(DeleteBackup_Request, DeleteBackup_Response),
    29: DceRpcOp(UnmarshalInterface_Request, UnmarshalInterface_Response),
    30: DceRpcOp(R_GetServerGuid_Request, R_GetServerGuid_Response),
}
register_com_interface(
    name="IMSAdminBaseW",
    uuid=uuid.UUID("70B51430-B6CA-11d0-B9B9-00A0C922E750"),
    opnums=IMSADMINBASEW_OPNUMS,
)


class BackupWithPasswd_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDBackupName", "")),
        NDRIntField("dwMDVersion", 0),
        NDRIntField("dwMDFlags", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszPasswd", "")),
    ]


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


class RestoreWithPasswd_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDBackupName", "")),
        NDRIntField("dwMDVersion", 0),
        NDRIntField("dwMDFlags", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszPasswd", "")),
    ]


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


class Export_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszPasswd", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszFileName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszSourcePath", "")),
        NDRIntField("dwMDFlags", 0),
    ]


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


class Import_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszPasswd", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszFileName", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszSourcePath", "")),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszDestPath", "")),
        NDRIntField("dwMDFlags", 0),
    ]


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


class RestoreHistory_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDHistoryLocation", "")),
        NDRIntField("dwMDMajorVersion", 0),
        NDRIntField("dwMDMinorVersion", 0),
        NDRIntField("dwMDFlags", 0),
    ]


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


class EnumHistory_Request(NDRPacket):
    fields_desc = [
        NDRConfStrLenFieldUtf16(
            "pszMDHistoryLocation", "", size_is=lambda pkt: pkt.MD_BACKUP_MAX_LEN
        ),
        NDRIntField("dwMDEnumIndex", 0),
    ]


class EnumHistory_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenFieldUtf16(
            "pszMDHistoryLocation", "", size_is=lambda pkt: pkt.MD_BACKUP_MAX_LEN
        ),
        NDRIntField("pdwMDMajorVersion", 0),
        NDRIntField("pdwMDMinorVersion", 0),
        NDRPacketField("pftMDHistoryTime", PFILETIME(), PFILETIME),
        NDRIntField("status", 0),
    ]


IMSADMINBASE2W_OPNUMS = {
    0: DceRpcOp(BackupWithPasswd_Request, BackupWithPasswd_Response),
    1: DceRpcOp(RestoreWithPasswd_Request, RestoreWithPasswd_Response),
    2: DceRpcOp(Export_Request, Export_Response),
    3: DceRpcOp(Import_Request, Import_Response),
    4: DceRpcOp(RestoreHistory_Request, RestoreHistory_Response),
    5: DceRpcOp(EnumHistory_Request, EnumHistory_Response),
}
register_com_interface(
    name="IMSAdminBase2W",
    uuid=uuid.UUID("8298d101-f992-43b7-8eca-5052d885b995"),
    opnums=IMSADMINBASE2W_OPNUMS,
)


class GetChildPaths_Request(NDRPacket):
    fields_desc = [
        NDRIntField("hMDHandle", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("pszMDPath", "")),
        NDRIntField("cchMDBufferSize", None, size_of="pszBuffer"),
        NDRConfStrLenFieldUtf16(
            "pszBuffer", "", size_is=lambda pkt: pkt.cchMDBufferSize
        ),
        NDRFullPointerField(NDRIntField("pcchMDRequiredBufferSize", 0)),
    ]


class GetChildPaths_Response(NDRPacket):
    fields_desc = [
        NDRConfStrLenFieldUtf16(
            "pszBuffer", "", size_is=lambda pkt: pkt.cchMDBufferSize
        ),
        NDRFullPointerField(NDRIntField("pcchMDRequiredBufferSize", 0)),
        NDRIntField("status", 0),
    ]


IMSADMINBASE3W_OPNUMS = {0: DceRpcOp(GetChildPaths_Request, GetChildPaths_Response)}
register_com_interface(
    name="IMSAdminBase3W",
    uuid=uuid.UUID("f612954d-3b0b-4c56-9563-227b7be624b4"),
    opnums=IMSADMINBASE3W_OPNUMS,
)


class AppCreate_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szMDPath", "")),
        NDRSignedIntField("fInProc", 0),
    ]


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


class AppDelete_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szMDPath", "")),
        NDRSignedIntField("fRecursive", 0),
    ]


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


class AppUnLoad_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szMDPath", "")),
        NDRSignedIntField("fRecursive", 0),
    ]


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


class AppGetStatus_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szMDPath", ""))]


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


class AppDeleteRecoverable_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szMDPath", "")),
        NDRSignedIntField("fRecursive", 0),
    ]


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


class AppRecover_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szMDPath", "")),
        NDRSignedIntField("fRecursive", 0),
    ]


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


IWAMADMIN_OPNUMS = {
    0: DceRpcOp(AppCreate_Request, AppCreate_Response),
    1: DceRpcOp(AppDelete_Request, AppDelete_Response),
    2: DceRpcOp(AppUnLoad_Request, AppUnLoad_Response),
    3: DceRpcOp(AppGetStatus_Request, AppGetStatus_Response),
    4: DceRpcOp(AppDeleteRecoverable_Request, AppDeleteRecoverable_Response),
    5: DceRpcOp(AppRecover_Request, AppRecover_Response),
}
register_dcerpc_interface(
    name="IWamAdmin",
    uuid=uuid.UUID("29822AB7-F302-11D0-9953-00C04FD919C1"),
    version="0.0",
    opnums=IWAMADMIN_OPNUMS,
)


class AppCreate2_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szMDPath", "")),
        NDRIntField("dwAppMode", 0),
    ]


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


IWAMADMIN2_OPNUMS = {0: DceRpcOp(AppCreate2_Request, AppCreate2_Response)}
register_dcerpc_interface(
    name="IWamAdmin2",
    uuid=uuid.UUID("29822AB8-F302-11D0-9953-00C04FD919C1"),
    version="0.0",
    opnums=IWAMADMIN2_OPNUMS,
)


class CreateApplication_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szMDPath", "")),
        NDRIntField("dwAppMode", 0),
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szAppPoolId", "")),
        NDRSignedIntField("fCreatePool", 0),
    ]


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


class DeleteApplication_Request(NDRPacket):
    fields_desc = [
        NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szMDPath", "")),
        NDRSignedIntField("fRecursive", 0),
    ]


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


class CreateApplicationPool_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szPool", ""))]


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


class DeleteApplicationPool_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szPool", ""))]


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


class FLAGGED_WORD_BLOB(NDRPacket):
    ALIGNMENT = (4, 8)
    DEPORTED_CONFORMANTS = ["asData"]
    fields_desc = [
        NDRIntField("cBytes", 0),
        NDRIntField("clSize", None, size_of="asData"),
        NDRConfStrLenFieldUtf16(
            "asData", "", size_is=lambda pkt: pkt.clSize, conformant_in_struct=True
        ),
    ]


class EnumerateApplicationsInPool_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szPool", ""))]


class EnumerateApplicationsInPool_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("bstrBuffer", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)
        ),
        NDRIntField("status", 0),
    ]


class RecycleApplicationPool_Request(NDRPacket):
    fields_desc = [NDRFullPointerField(NDRConfVarStrNullFieldUtf16("szPool", ""))]


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


class GetProcessMode_Request(NDRPacket):
    fields_desc = []


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


IIISAPPLICATIONADMIN_OPNUMS = {
    0: DceRpcOp(CreateApplication_Request, CreateApplication_Response),
    1: DceRpcOp(DeleteApplication_Request, DeleteApplication_Response),
    2: DceRpcOp(CreateApplicationPool_Request, CreateApplicationPool_Response),
    3: DceRpcOp(DeleteApplicationPool_Request, DeleteApplicationPool_Response),
    4: DceRpcOp(
        EnumerateApplicationsInPool_Request, EnumerateApplicationsInPool_Response
    ),
    5: DceRpcOp(RecycleApplicationPool_Request, RecycleApplicationPool_Response),
    6: DceRpcOp(GetProcessMode_Request, GetProcessMode_Response),
}
register_dcerpc_interface(
    name="IIISApplicationAdmin",
    uuid=uuid.UUID("7C4E1804-E342-483D-A43E-A850CFCC8D18"),
    version="0.0",
    opnums=IIISAPPLICATIONADMIN_OPNUMS,
)


class put_Opnum7NotUsedOnWire_Request(NDRPacket):
    fields_desc = []


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


class put_Opnum8NotUsedOnWire_Request(NDRPacket):
    fields_desc = []


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


class put_Opnum9NotUsedOnWire_Request(NDRPacket):
    fields_desc = []


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


class put_InstanceName_Request(NDRPacket):
    fields_desc = [NDRPacketField("newVal", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB)]


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


class IsInstalledRemote_Request(NDRPacket):
    fields_desc = []


class IsInstalledRemote_Response(NDRPacket):
    fields_desc = [NDRSignedShortField("retval", 0), NDRIntField("status", 0)]


class IsExportableRemote_Request(NDRPacket):
    fields_desc = []


class IsExportableRemote_Response(NDRPacket):
    fields_desc = [NDRSignedShortField("retval", 0), NDRIntField("status", 0)]


class VARENUM(IntEnum):
    VT_EMPTY = 0
    VT_NULL = 1
    VT_I2 = 2
    VT_I4 = 3
    VT_R4 = 4
    VT_R8 = 5
    VT_CY = 6
    VT_DATE = 7
    VT_BSTR = 8
    VT_DISPATCH = 9
    VT_ERROR = 10
    VT_BOOL = 11
    VT_VARIANT = 12
    VT_UNKNOWN = 13
    VT_DECIMAL = 14
    VT_I1 = 16
    VT_UI1 = 17
    VT_UI2 = 18
    VT_UI4 = 19
    VT_I8 = 20
    VT_UI8 = 21
    VT_INT = 22
    VT_UINT = 23
    VT_VOID = 24
    VT_HRESULT = 25
    VT_PTR = 26
    VT_SAFEARRAY = 27
    VT_CARRAY = 28
    VT_USERDEFINED = 29
    VT_LPSTR = 30
    VT_LPWSTR = 31
    VT_RECORD = 36
    VT_INT_PTR = 37
    VT_UINT_PTR = 38
    VT_ARRAY = 8192
    VT_BYREF = 16384


class CURRENCY(NDRPacket):
    ALIGNMENT = (8, 8)
    fields_desc = [NDRSignedLongField("int64", 0)]


class VARENUM(IntEnum):
    VT_EMPTY = 0
    VT_NULL = 1
    VT_I2 = 2
    VT_I4 = 3
    VT_R4 = 4
    VT_R8 = 5
    VT_CY = 6
    VT_DATE = 7
    VT_BSTR = 8
    VT_DISPATCH = 9
    VT_ERROR = 10
    VT_BOOL = 11
    VT_VARIANT = 12
    VT_UNKNOWN = 13
    VT_DECIMAL = 14
    VT_I1 = 16
    VT_UI1 = 17
    VT_UI2 = 18
    VT_UI4 = 19
    VT_I8 = 20
    VT_UI8 = 21
    VT_INT = 22
    VT_UINT = 23
    VT_VOID = 24
    VT_HRESULT = 25
    VT_PTR = 26
    VT_SAFEARRAY = 27
    VT_CARRAY = 28
    VT_USERDEFINED = 29
    VT_LPSTR = 30
    VT_LPWSTR = 31
    VT_RECORD = 36
    VT_INT_PTR = 37
    VT_UINT_PTR = 38
    VT_ARRAY = 8192
    VT_BYREF = 16384


class SF_TYPE(IntEnum):
    SF_ERROR = VARENUM.VT_ERROR
    SF_I1 = VARENUM.VT_I1
    SF_I2 = VARENUM.VT_I2
    SF_I4 = VARENUM.VT_I4
    SF_I8 = VARENUM.VT_I8
    SF_BSTR = VARENUM.VT_BSTR
    SF_UNKNOWN = VARENUM.VT_UNKNOWN
    SF_DISPATCH = VARENUM.VT_DISPATCH
    SF_VARIANT = VARENUM.VT_VARIANT
    SF_RECORD = VARENUM.VT_RECORD
    SF_HAVEIID = VARENUM.VT_UNKNOWN | 32768


class SAFEARR_BSTR(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Size", None, size_of="aBstr"),
        NDRRefEmbPointerField(
            NDRConfPacketListField(
                "aBstr", [], FLAGGED_WORD_BLOB, size_is=lambda pkt: pkt.Size
            ),
            deferred=True,
        ),
    ]


class SAFEARR_UNKNOWN(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Size", None, size_of="apUnknown"),
        NDRRefEmbPointerField(
            NDRConfPacketListField(
                "apUnknown", [], MInterfacePointer, size_is=lambda pkt: pkt.Size
            ),
            deferred=True,
        ),
    ]


class SAFEARR_DISPATCH(NDRPacket):
    ALIGNMENT = (4, 8)
    fields_desc = [
        NDRIntField("Size", None, size_of="apDispatch"),
        NDRRefEmbPointerField(
            NDRConfPacketListField(
                "apDispatch", [], MInterfacePointer, size_is=lambda pkt: pkt.Size
            ),
            deferred=True,
        ),
    ]


class wireVARIANTStr(NDRPacket):
    ALIGNMENT = (4, 4)
    fields_desc = [
        NDRIntField("clSize", 0),
        NDRIntField("rpcReserved", 0),
        NDRShortField("vt", 0),
        NDRShortField("wReserved1", 0),
        NDRShortField("wReserved2", 0),
        NDRShortField("wReserved3", 0),
        NDRRecursiveField("_varUnion"),
    ]


class GetCertInfoRemote_Request(NDRPacket):
    fields_desc = []


class GetCertInfoRemote_Response(NDRPacket):
    fields_desc = [
        NDRFullPointerField(
            NDRPacketField("BinaryVariant", wireVARIANTStr(), wireVARIANTStr)
        ),
        NDRIntField("status", 0),
    ]


class ImportFromBlob_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("InstanceName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("Password", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedShortField("bInstallToMetabase", 0),
        NDRSignedShortField("bAllowExport", 0),
        NDRSignedShortField("bOverWriteExisting", 0),
        NDRIntField("cbSize", None, size_of="pBlobBinary"),
        NDRConfVarStrLenField("pBlobBinary", "", size_is=lambda pkt: pkt.cbSize),
    ]


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


class ImportFromBlobGetHash_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("InstanceName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("Password", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedShortField("bInstallToMetabase", 0),
        NDRSignedShortField("bAllowExport", 0),
        NDRSignedShortField("bOverWriteExisting", 0),
        NDRIntField("cbSize", None, size_of="pBlobBinary"),
        NDRConfVarStrLenField("pBlobBinary", "", size_is=lambda pkt: pkt.cbSize),
    ]


class ImportFromBlobGetHash_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcbCertHashSize", 0),
        NDRFullPointerField(NDRSignedByteField("pCertHash", 0)),
        NDRIntField("status", 0),
    ]


class ExportToBlob_Request(NDRPacket):
    fields_desc = [
        NDRPacketField("InstanceName", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRPacketField("Password", FLAGGED_WORD_BLOB(), FLAGGED_WORD_BLOB),
        NDRSignedShortField("bPrivateKey", 0),
        NDRSignedShortField("bCertChain", 0),
        NDRIntField("pcbSize", 0),
        NDRFullPointerField(NDRConfVarStrNullField("pBlobBinary", "")),
    ]


class ExportToBlob_Response(NDRPacket):
    fields_desc = [
        NDRIntField("pcbSize", 0),
        NDRFullPointerField(NDRConfVarStrNullField("pBlobBinary", "")),
        NDRIntField("status", 0),
    ]


IIISCERTOBJ_OPNUMS = {
    0: DceRpcOp(put_Opnum7NotUsedOnWire_Request, put_Opnum7NotUsedOnWire_Response),
    1: DceRpcOp(put_Opnum8NotUsedOnWire_Request, put_Opnum8NotUsedOnWire_Response),
    2: DceRpcOp(put_Opnum9NotUsedOnWire_Request, put_Opnum9NotUsedOnWire_Response),
    3: DceRpcOp(put_InstanceName_Request, put_InstanceName_Response),
    # 4: Opnum11NotUsedOnWire,
    5: DceRpcOp(IsInstalledRemote_Request, IsInstalledRemote_Response),
    # 6: Opnum13NotUsedOnWire,
    7: DceRpcOp(IsExportableRemote_Request, IsExportableRemote_Response),
    # 8: Opnum15NotUsedOnWire,
    9: DceRpcOp(GetCertInfoRemote_Request, GetCertInfoRemote_Response),
    # 10: Opnum17NotUsedOnWire,
    # 11: Opnum18NotUsedOnWire,
    # 12: Opnum19NotUsedOnWire,
    # 13: Opnum20NotUsedOnWire,
    # 14: Opnum21NotUsedOnWire,
    15: DceRpcOp(ImportFromBlob_Request, ImportFromBlob_Response),
    16: DceRpcOp(ImportFromBlobGetHash_Request, ImportFromBlobGetHash_Response),
    # 17: Opnum24NotUsedOnWire,
    18: DceRpcOp(ExportToBlob_Request, ExportToBlob_Response),
}
register_com_interface(
    name="IIISCertObj",
    uuid=uuid.UUID("BD0C73BC-805B-4043-9C30-9A28D64DD7D2"),
    opnums=IIISCERTOBJ_OPNUMS,
)
