diff --git a/convert_header.py b/convert_header.py new file mode 100644 index 0000000..691eda1 --- /dev/null +++ b/convert_header.py @@ -0,0 +1,413 @@ +import re +from pathlib import Path + +patterns = [ + ( + "replace normal defines", + r"#define\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+([a-zA-Z0-9_]+)[ ]*(\/\/.*)?\n", + r"\1 = \2 \3\n", + 0, + ), + ( + "replace normal defines string", + r'#define\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+("[^"\n]*")[ ]*(\/\/.*)?\n', + r"\1 = \2 \3\n", + 0, + ), + ( + "replace function defines", + r"#define\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+([a-zA-Z0-9_\(\), \|]+)\n", + r"\1 = \2\n", + 0, + ), + ( + "remove empty comments", + r"^[ ]*\/\/\n", + r"", + re.MULTILINE, + ), + ( + "typedef _named struct with var, pointer", + r"\btypedef\s+enum\s+_([a-zA-Z_][a-zA-Z0-9_]*)\s*{([^{}]+)}\s*\1\s*,\s*\*\s*P\1\s*;", + r"class \1(CEnum):\n\2\nP\1 = POINTER(\1)", + 0, + ), + ( + "typedef _named struct with var, pointer, LP", + r"\btypedef\s+enum\s+_([a-zA-Z_][a-zA-Z0-9_]*)\s*{([^{}]+)}\s*\1\s*,\s*\*\s*P\1\s*,\s*\*\s*LP\1\s*;", + r"class \1(CEnum):\n\2\nP\1 = POINTER(\1)\nLP\1 = POINTER(\1)", + 0, + ), + ( + "replace typedef enum with name", + r"\btypedef\s+enum\s+_([a-zA-Z_][a-zA-Z0-9_]*)\s*{([^{}]+)}\s+\1\s*;", + r"class \1(CEnum):\n\2", + 0, + ), + ( + "replace typedef enum without name", + r"\btypedef\s+enum\s*{([^{}]+)}\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*;", + r"class \2(CEnum):\n\1", + 0, + ), + ( + "replace typedef enum without name, with pointer", + r"\btypedef\s+enum\s*{([^{}]+)}\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*\*\s*P\2\s*;", + r"class \2(CEnum):\n\1\nP\2 = POINTER(\2)", + 0, + ), + ( + "replace all comments", + r"[\/]{2,}", + r"#", + 0, + ), + ( + "remove field SAL", + r"\b(_Field_size_\([^()]*\))\s*(.*)", + r"\2 # \1", + 0, + ), + ( + "replace fields: UCHAR Reserved1;", + r"^([ ]+)([a-zA-Z_][a-zA-Z0-9_]*)\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*;", + r'\1("\3", \2),', + re.MULTILINE, + ), + ( + "replace fields: UCHAR Reserved1[12];", + r"^([ ]+)([a-zA-Z_][a-zA-Z0-9_]*)\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*\[([a-zA-Z0-9_]+)\]\s*;", + r'\1("\3", \2 * \4),', + re.MULTILINE, + ), + ( + "replace fields with bits: ULONGLONG MQES : 16;", + r"^([ ]+)([a-zA-Z_][a-zA-Z0-9_]*)\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*:\s*(\d+)\s*;", + r'\1("\3", \2, \4),', + re.MULTILINE, + ), + ( + "replace fields: struct pointer", + r"^([ ]+)struct\s+_([a-zA-Z_][a-zA-Z0-9_]*)\s*\*\s*([a-zA-Z_][a-zA-Z0-9_]*);", + r'\1("\3", POINTER(\2)), # fixme: might be recursive', + re.MULTILINE, + ), + ( + "replace enum fields without assignment", + r"^([ ]+)([a-zA-Z_][a-zA-Z0-9_]*)\s*,[ ]*(#[^\n]*)?$", + r"\1\2 \3", + re.MULTILINE, + ), + ( + "replace enum fields with assignment", + r"^([ ]+)([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s*([a-zA-Z0-9_]+)\s*,[ ]*(#[^\n]*)?$", + r"\1\2 =\3 \4", + re.MULTILINE, + ), + ( + "replace simple typedef var", + r"^typedef\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+([a-zA-Z_][a-zA-Z0-9_]*);", + r"\2 = \1", + re.MULTILINE, + ), + ( + "replace simple typedef double var", # typedef ULONG DEVICE_DATA_MANAGEMENT_SET_ACTION, DEVICE_DSM_ACTION; + r"^typedef\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*([a-zA-Z_][a-zA-Z0-9_]*);", + r"\2 = \1\n\3 = \1", + re.MULTILINE, + ), + ( + "replace simple pointer typedef", + r"^typedef\s+([a-zA-Z_][a-zA-Z0-9_]*)\s+\*([a-zA-Z_][a-zA-Z0-9_]*);", + r"\2 = POINTER(\1)", + re.MULTILINE, + ), + ( + "replace simple struct typedef", + r"^typedef\s+(?:struct\s+)?_?([a-zA-Z_][a-zA-Z0-9_]*)\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*\*\s*P\2;", + r"\2 = \1\nP\2 = POINTER(\1)", + re.MULTILINE, + ), + ( + "remove line continuations", + r"\\\n", + r"", + 0, + ), + ( + "replace multiline comments", + r"\/\*(.*?)\*\/", + r"'''\1'''", + re.DOTALL, + ), + ( + "replace cplusplus", + r"#if defined __cplusplus.*?#endif[^\n]*", + r"", + re.DOTALL, + ), + ( + "replace long literals", + r"\b((?:0x[0-9a-fA-F]{8})|(?:\d+))L", + r"c_long(\1)", + 0, + ), + ( + "replace ulong literals", + r"\b((?:0x[0-9a-fA-F]{8})|(?:\d+))u", + r"c_ulong(\1)", + 0, + ), + ( + "remove struct SAL", + r"\b(_Struct_size_bytes_\([^()]*\))\s*(struct.*)", + r"\2 # \1", + 0, + ), + # ( + # "comment out functions", + # r"((?:[a-zA-Z_][a-zA-Z0-9_]*\s+)+\s*\((?:[^()]*|\((?:[^()]*|\([^()]*\))*\))*\)\s*\{(?:[^{}]*|\{(?:[^{}]*|\{[^{}]*\})*\})*\})", + # r'"""\1"""', + # 0, + # ), +] + + +patternsloop = [ + ( + "typedef _named struct with var, pointer", + r"typedef\s+struct\s+_([a-zA-Z_][a-zA-Z0-9_]*)\s*{((?:[^{}\n]*(?:#[^\n]*)?\n)*)}\s*\1\s*,\s*\*\s*P\1\s*;", + r"class \1(Structure):\n _fields_ = [\2]\nP\1 = POINTER(\1)", + 0, + ), + ( + "typedef _named struct with var, pointer, var, pointer", + r"typedef\s+struct\s+_([a-zA-Z_][a-zA-Z0-9_]*)\s*{((?:[^{}\n]*(?:#[^\n]*)?\n)*)}\s*\1\s*,\s*\*\s*P\1\s*,\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*\*\s*P\3\s*;", + r"class \1(Structure):\n _fields_ = [\2]\nP\1 = POINTER(\1)\n\3 = \1\nP\3 = POINTER(\1)", + 0, + ), + ( + "typedef named struct with var, pointer", + r"typedef\s+struct\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*{((?:[^{}\n]*(?:#[^\n]*)?\n)*)}\s*\1\s*,\s*\*\s*P\1\s*;", + r"class \1(Structure):\n _fields_ = [\2]\nP\1 = POINTER(\1)", + 0, + ), + ( + "typedef _named struct with var, pointer, LP", + r"typedef\s+struct\s+_([a-zA-Z_][a-zA-Z0-9_]*)\s*{([^{}]+)}\s*\1\s*,\s*\*\s*P\1\s*,\s*\*LP\1\s*;", + r"class \1(Structure):\n _fields_ = [\2]\nP\1 = POINTER(\1)\nLP\1 = POINTER(\1)", + 0, + ), + ( + "typedef unnamed struct with var, pointer", + r"typedef\s+struct\s*{([^{}]+)}\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*\*\s*P\2\s*;", + r"class \2(Structure):\n _fields_ = [\1]", + 0, + ), + ( + "typedef _named union with var, pointer", + r"typedef\s+union\s+_([a-zA-Z_][a-zA-Z0-9_]*)\s*{((?:[^{}\n]*(?:#[^\n]*)?\n)*)}\s*\1\s*,\s*\*\s*P\1\s*;", + r"class \1(Union):\n _fields_ = [\2]\nP\1 = POINTER(\1)", + 0, + ), + ( + "typedef unnamed union with var", + r"typedef\s+union\s*{([^{}]+)}\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*;", + r"class \2(Union):\n _fields_ = [\1]", + 0, + ), + ( + "typedef unnamed union with var, pointer", + r"typedef\s+union\s*{([^{}]+)}\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*\*\s*P\2\s*;", + r"class \2(Union):\n _fields_ = [\1]", + 0, + ), + ( + "typedef unnamed union with var, invalid pointer name", + r"typedef\s+union\s*{([^{}]+)}\s+([a-zA-Z_][a-zA-Z0-9_]*)\s*,\s*(\*\s*P[a-zA-Z_][a-zA-Z0-9_]*)\s*;", + r"class \2(Union): # fixme: \3\n _fields_ = [\1]", + 0, + ), + ( + "unnamed union with var", + r"(? Path: + inbasepath = Path("C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/") + outbasepath = Path("D:/OneDrive/Repositories/public-libs/ctypes-windows-sdk-auto/cwinsdk/") + + inpath = inbasepath / relpath + assert inpath.suffix == ".h" + outpath = (outbasepath / relpath).with_suffix(".py") + outpath.parent.mkdir(parents=True, exist_ok=True) + + imports = "\n".join( + f"from {module} import {', '.join(names)}" for module, names in required_imports.get(relpath, []) + ) + + header = f""" +from ctypes import Structure, Union, sizeof, POINTER +from ctypes.wintypes import {", ".join(wintypes)} +from .. import CEnum, make_struct, make_union +{imports} +""" + + with open(inpath, encoding="ascii") as fr: + data = fr.read() + + for name, pattern, repl, flags in patterns: + print(name) + data, num = re.subn(pattern, repl, data, flags=flags) + print(num) + if pause: + write_file(outpath, header, data) + input("continue") + + while True: + total = 0 + for name, pattern, repl, flags in patternsloop: + print(name) + data, num = re.subn(pattern, repl, data, flags=flags) + total += num + if pause: + write_file(outpath, header, data) + input("continue") + + if total == 0: + break + + write_file(outpath, header, data) + + if pause: + input("processing done") + + return outpath + + +def main(args): + header_files = ["shared/ntdddisk.h", "shared/nvme.h"] + header_files = ["shared/ntddstor.h"] + + for relpath in header_files: + print(relpath) + outpath = os.fspath(convert_header(relpath, pause=args.pause_after_each_pattern)) + try: + subprocess.run(["py", "-m", "ruff", "format", outpath], capture_output=True, check=True, encoding="utf-8") + except subprocess.CalledProcessError as e: + print(e.stdout) + print(e.stderr) + print(f"{e.cmd} failed") + return + + for relpath in header_files: + print(relpath) + try: + subprocess.run( + ["py", "-m", "ruff", "check", outpath, "--fix"], capture_output=True, check=True, encoding="utf-8" + ) + except subprocess.CalledProcessError as e: + print(e.stdout) + print(e.stderr) + print(f"{e.cmd} failed") + return + + +if __name__ == "__main__": + import os + import subprocess + from argparse import ArgumentParser + + parser = ArgumentParser() + parser.add_argument("--pause-after-each-pattern", action="store_true") + args = parser.parse_args() + + main(args) diff --git a/cwinsdk/__init__.py b/cwinsdk/__init__.py index 88d5ff2..3155f0e 100644 --- a/cwinsdk/__init__.py +++ b/cwinsdk/__init__.py @@ -1,5 +1,5 @@ import platform -from ctypes import LibraryLoader, Structure, WinDLL, WinError, c_int +from ctypes import LibraryLoader, Structure, Union, WinDLL, WinError, c_int from ctypes.wintypes import HANDLE from typing import Any, Callable, Iterable, Iterator, Tuple @@ -40,10 +40,20 @@ def _value_with_length(values: Iterable) -> Iterator: def _struct2pairs(struct: Structure) -> Iterator[Tuple[str, Any]]: - for name, _ in struct._fields_: + for fieldinfo in struct._fields_: + if len(fieldinfo) == 2: + name, _ = fieldinfo + elif len(fieldinfo) == 3: + name, _, _ = fieldinfo + else: + raise ValueError("too many values to unpack (expected 2 or 3)") + value = getattr(struct, name) if hasattr(value, "_fields_"): + if name in struct._anonymous_: + yield from _struct2pairs(value) + continue value = dict(_struct2pairs(value)) elif hasattr(value, "_length_"): value = list(_value_with_length(value)) @@ -90,3 +100,29 @@ def inner(*args, **kwargs): raise OSError(f"{funcname}() is not available on {platform.platform()}") return inner + + +def make_struct(fields): + anonymous = [] + for name, *_ in fields: + if name in ["u", "DUMMYSTRUCTNAME"]: + anonymous.append(name) + + class _Structure(Structure): + _anonymous_ = anonymous + _fields_ = fields + + return _Structure + + +def make_union(fields): + anonymous = [] + for name, *_ in fields: + if name in ["u", "DUMMYSTRUCTNAME"]: + anonymous.append(name) + + class _Union(Union): + _anonymous_ = anonymous + _fields_ = fields + + return _Union diff --git a/cwinsdk/um/fileapi.py b/cwinsdk/um/fileapi.py index 8ec8857..be8c227 100644 --- a/cwinsdk/um/fileapi.py +++ b/cwinsdk/um/fileapi.py @@ -217,13 +217,19 @@ class STREAM_INFO_LEVELS(CEnum): SetFileApisToANSI.argtypes = [] SetFileApisToANSI.restype = None -GetTempPath2W = windll.kernel32.GetTempPath2W -GetTempPath2W.argtypes = [DWORD, LPWSTR] -GetTempPath2W.restype = DWORD - -GetTempPath2A = windll.kernel32.GetTempPath2A -GetTempPath2A.argtypes = [DWORD, LPSTR] -GetTempPath2A.restype = DWORD +try: # Windows 10 Build 20348 + GetTempPath2W = windll.kernel32.GetTempPath2W + GetTempPath2W.argtypes = [DWORD, LPWSTR] + GetTempPath2W.restype = DWORD +except AttributeError: + pass + +try: # Windows 10 Build 20348 + GetTempPath2A = windll.kernel32.GetTempPath2A + GetTempPath2A.argtypes = [DWORD, LPSTR] + GetTempPath2A.restype = DWORD +except AttributeError: + pass QueryDosDeviceW = windll.kernel32.QueryDosDeviceW QueryDosDeviceW.argtypes = [LPCWSTR, LPWSTR, DWORD] diff --git a/cwinsdk/um/setupapi.py b/cwinsdk/um/setupapi.py index 61b1701..d43426e 100644 --- a/cwinsdk/um/setupapi.py +++ b/cwinsdk/um/setupapi.py @@ -1,5 +1,5 @@ from ctypes import POINTER, Structure -from ctypes.wintypes import BOOL, CHAR, DWORD, HWND, LPVOID, WCHAR +from ctypes.wintypes import BOOL, CHAR, DWORD, HWND, WCHAR from .. import nonzero, validhandle, windll from ..shared.basetsd import ULONG_PTR @@ -37,22 +37,17 @@ class SP_DEVICE_INTERFACE_DETAIL_DATA_A(Structure): ] -class SP_DEVICE_INTERFACE_DETAIL_DATA_W(Structure): - _fields_ = [ - ("cbSize", DWORD), - ("DevicePath", WCHAR * ANYSIZE_ARRAY), - ] - - -def _SP_DEVICE_INTERFACE_DETAIL_DATA_W(size=ANYSIZE_ARRAY): - class SP_DEVICE_INTERFACE_DETAIL_DATA_W(Structure): +def SP_DEVICE_INTERFACE_DETAIL_DATA_W_SIZE(size=ANYSIZE_ARRAY): + class _SP_DEVICE_INTERFACE_DETAIL_DATA_W(Structure): _fields_ = [ ("cbSize", DWORD), ("DevicePath", WCHAR * size), ] - return SP_DEVICE_INTERFACE_DETAIL_DATA_W + return _SP_DEVICE_INTERFACE_DETAIL_DATA_W + +SP_DEVICE_INTERFACE_DETAIL_DATA_W = SP_DEVICE_INTERFACE_DETAIL_DATA_W_SIZE() DIGCF_DEFAULT = 0x00000001 DIGCF_PRESENT = 0x00000002 @@ -123,11 +118,10 @@ class SP_DEVICE_INTERFACE_DETAIL_DATA_W(Structure): SetupDiGetDeviceInterfaceDetailA.errcheck = nonzero SetupDiGetDeviceInterfaceDetailW = windll.setupapi.SetupDiGetDeviceInterfaceDetailW -# SetupDiGetDeviceInterfaceDetailW.argtypes = [HDEVINFO, POINTER(SP_DEVICE_INTERFACE_DATA), POINTER(SP_DEVICE_INTERFACE_DETAIL_DATA_W), DWORD, PDWORD, POINTER(SP_DEVINFO_DATA)] SetupDiGetDeviceInterfaceDetailW.argtypes = [ HDEVINFO, POINTER(SP_DEVICE_INTERFACE_DATA), - LPVOID, + POINTER(SP_DEVICE_INTERFACE_DETAIL_DATA_W), DWORD, PDWORD, POINTER(SP_DEVINFO_DATA), diff --git a/cwinsdk/um/winioctl.py b/cwinsdk/um/winioctl.py index 4e51d61..084a996 100644 --- a/cwinsdk/um/winioctl.py +++ b/cwinsdk/um/winioctl.py @@ -546,20 +546,24 @@ class STORAGE_PROPERTY_ID(CEnum): StorageDeviceMediumProductType = 15 StorageAdapterRpmbProperty = 16 StorageAdapterCryptoProperty = 17 - StorageDeviceIoCapabilityProperty = 18 - StorageAdapterProtocolSpecificProperty = 19 - StorageDeviceProtocolSpecificProperty = 20 - StorageAdapterTemperatureProperty = 21 - StorageDeviceTemperatureProperty = 22 - StorageAdapterPhysicalTopologyProperty = 23 - StorageDevicePhysicalTopologyProperty = 24 - StorageDeviceAttributesProperty = 25 - StorageDeviceManagementStatus = 26 - StorageAdapterSerialNumberProperty = 27 - StorageDeviceLocationProperty = 28 - StorageDeviceNumaProperty = 29 - StorageDeviceZonedDeviceProperty = 30 - StorageDeviceUnsafeShutdownCount = 31 + StorageDeviceIoCapabilityProperty = 48 + StorageAdapterProtocolSpecificProperty = 49 + StorageDeviceProtocolSpecificProperty = 50 + StorageAdapterTemperatureProperty = 51 + StorageDeviceTemperatureProperty = 52 + StorageAdapterPhysicalTopologyProperty = 53 + StorageDevicePhysicalTopologyProperty = 54 + StorageDeviceAttributesProperty = 55 + StorageDeviceManagementStatus = 56 + StorageAdapterSerialNumberProperty = 57 + StorageDeviceLocationProperty = 58 + StorageDeviceNumaProperty = 59 + StorageDeviceZonedDeviceProperty = 60 + StorageDeviceUnsafeShutdownCount = 61 + StorageDeviceEnduranceProperty = 62 + StorageDeviceLedStateProperty = 63 + StorageDeviceSelfEncryptionProperty = 64 + StorageFruIdProperty = 65 class MEDIA_TYPE(CEnum): @@ -597,6 +601,42 @@ class PARTITION_STYLE(CEnum): PARTITION_STYLE_RAW = 2 +class STORAGE_PROTOCOL_NVME_DATA_TYPE(CEnum): + NVMeDataTypeUnknown = 0 + NVMeDataTypeIdentify = 1 + NVMeDataTypeLogPage = 2 + NVMeDataTypeFeature = 3 + NVMeDataTypeLogPageEx = 4 + NVMeDataTypeFeatureEx = 5 + + +class STORAGE_PROTOCOL_TYPE(CEnum): + ProtocolTypeUnknown = 0x00 + ProtocolTypeScsi = 0x01 + ProtocolTypeAta = 0x02 + ProtocolTypeNvme = 0x03 + ProtocolTypeSd = 0x04 + ProtocolTypeUfs = 0x05 + ProtocolTypeProprietary = 0x7E + ProtocolTypeMaxReserved = 0x7F + + +class STORAGE_PROTOCOL_ATA_DATA_TYPE(CEnum): + AtaDataTypeUnknown = 0 + AtaDataTypeIdentify = 1 # Retrieved by command - IDENTIFY DEVICE + AtaDataTypeLogPage = 2 # Retrieved by command - READ LOG EXT + + +class STORAGE_PROTOCOL_UFS_DATA_TYPE(CEnum): + UfsDataTypeUnknown = 0 + UfsDataTypeQueryDescriptor = 1 # Retrieved by command - QUERY UPIU + UfsDataTypeQueryAttribute = 2 # Retrieved by command - QUERY UPIU + UfsDataTypeQueryFlag = 3 # Retrieved by command - QUERY UPIU + UfsDataTypeQueryDmeAttribute = 4 # Retrieved by command - QUERY UPIU + UfsDataTypeQueryDmePeerAttribute = 5 # Retrieved by command - QUERY UPIU + UfsDataTypeMax = 6 + + class VERIFY_INFORMATION(Structure): _fields_ = [ ("StartingOffset", LARGE_INTEGER), @@ -645,31 +685,50 @@ class STORAGE_READ_CAPACITY(Structure): ] -class STORAGE_PROPERTY_QUERY(Structure): - # no pack - _fields_ = [ - ("PropertyId", STORAGE_PROPERTY_ID), - ("QueryType", STORAGE_QUERY_TYPE), - ("AdditionalParameters", BYTE * 1), - ] +def STORAGE_PROPERTY_QUERY_SIZE(size=1): + class _STORAGE_PROPERTY_QUERY(Structure): + # no pack + _fields_ = [ + ("PropertyId", STORAGE_PROPERTY_ID), + ("QueryType", STORAGE_QUERY_TYPE), + ("AdditionalParameters", BYTE * size), + ] + + return _STORAGE_PROPERTY_QUERY + +STORAGE_PROPERTY_QUERY = STORAGE_PROPERTY_QUERY_SIZE() + + +def STORAGE_DEVICE_DESCRIPTOR_SIZE(size=1): + class _STORAGE_DEVICE_DESCRIPTOR(Structure): + # no pack + _fields_ = [ + ("Version", DWORD), + ("Size", DWORD), + ("DeviceType", BYTE), + ("DeviceTypeModifier", BYTE), + ("RemovableMedia", BOOLEAN), + ("CommandQueueing", BOOLEAN), + ("VendorIdOffset", DWORD), + ("ProductIdOffset", DWORD), + ("ProductRevisionOffset", DWORD), + ("SerialNumberOffset", DWORD), + ("BusType", STORAGE_BUS_TYPE), + ("RawPropertiesLength", DWORD), + ("RawDeviceProperties", BYTE * size), + ] -class STORAGE_DEVICE_DESCRIPTOR(Structure): - # no pack + return _STORAGE_DEVICE_DESCRIPTOR + + +STORAGE_DEVICE_DESCRIPTOR = STORAGE_DEVICE_DESCRIPTOR_SIZE() + + +class STORAGE_DESCRIPTOR_HEADER(Structure): _fields_ = [ ("Version", DWORD), ("Size", DWORD), - ("DeviceType", BYTE), - ("DeviceTypeModifier", BYTE), - ("RemovableMedia", BOOLEAN), - ("CommandQueueing", BOOLEAN), - ("VendorIdOffset", DWORD), - ("ProductIdOffset", DWORD), - ("ProductRevisionOffset", DWORD), - ("SerialNumberOffset", DWORD), - ("BusType", STORAGE_BUS_TYPE), - ("RawPropertiesLength", DWORD), - ("RawDeviceProperties", BYTE * 1), ] @@ -832,7 +891,7 @@ class DRIVE_LAYOUT_INFORMATION_EX_DUMMYUNIONNAME(Union): ] -def DRIVE_LAYOUT_INFORMATION_EX(size=1): +def DRIVE_LAYOUT_INFORMATION_EX_SIZE(size=1): class _DRIVE_LAYOUT_INFORMATION_EX(Structure): _anonymous_ = ("u",) _fields_ = [ @@ -845,6 +904,9 @@ class _DRIVE_LAYOUT_INFORMATION_EX(Structure): return _DRIVE_LAYOUT_INFORMATION_EX +DRIVE_LAYOUT_INFORMATION_EX = DRIVE_LAYOUT_INFORMATION_EX_SIZE() + + class STORAGE_DEVICE_NUMBER(Structure): _fields_ = [ ("DeviceType", DEVICE_TYPE), @@ -853,4 +915,27 @@ class STORAGE_DEVICE_NUMBER(Structure): ] +class STORAGE_PROTOCOL_SPECIFIC_DATA(Structure): + _fields_ = [ + ("ProtocolType", STORAGE_PROTOCOL_TYPE), + ("DataType", DWORD), + ("ProtocolDataRequestValue", DWORD), + ("ProtocolDataRequestSubValue", DWORD), + ("ProtocolDataOffset", DWORD), + ("ProtocolDataLength", DWORD), + ("FixedProtocolReturnData", DWORD), + ("ProtocolDataRequestSubValue2", DWORD), + ("ProtocolDataRequestSubValue3", DWORD), + ("ProtocolDataRequestSubValue4", DWORD), + ] + + +class STORAGE_PROTOCOL_DATA_DESCRIPTOR(Structure): + _fields_ = [ + ("Version", DWORD), + ("Size", DWORD), + ("ProtocolSpecificData", STORAGE_PROTOCOL_SPECIFIC_DATA), + ] + + GUID_DEVINTERFACE_DISK = GUID(0x53F56307, 0xB6BF, 0x11D0, (0x94, 0xF2, 0x00, 0xA0, 0xC9, 0x1E, 0xFB, 0x8B)) diff --git a/setup.py b/setup.py index d462cd5..02b4309 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( author="Dobatymo", name="ctypes-windows-sdk", - version="0.0.12", + version="0.0.13", url="https://github.com/Dobatymo/ctypes-windows-sdk", description="Ctypes port of Windows SDK", long_description=long_description,