Skip to content

Commit

Permalink
v0.0.12
Browse files Browse the repository at this point in the history
add um.memoryapi
add um.setupapi
finally fix packages in setup.py
  • Loading branch information
Dobatymo committed May 9, 2024
1 parent 2f25239 commit b4136db
Show file tree
Hide file tree
Showing 14 changed files with 849 additions and 154 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -18,21 +18,21 @@ repos:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.12.0
rev: v2.13.0
hooks:
- id: pretty-format-yaml
args: [--autofix]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: 1.7.0
rev: 1.8.0
hooks:
- id: pyproject-fmt
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.3.0
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
Expand Down
10 changes: 9 additions & 1 deletion cwinsdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@


class CEnum(c_int):
pass
def __hash__(self):
return hash(self.value)

def __eq__(self, other):
if isinstance(other, int):
return self.value == other
elif isinstance(other, CEnum):
return self.value == other.value
return NotImplemented


class WinApiError(OSError):
Expand Down
79 changes: 79 additions & 0 deletions cwinsdk/shared/diskguid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from .guiddef import GUID

PARTITION_BASIC_DATA_GUID = GUID(
0xEBD0A0A2, 0xB9E5, 0x4433, (0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7)
) # Basic data partition
PARTITION_BSP_GUID = GUID(0x57434F53, 0x4DF9, 0x45B9, (0x8E, 0x9E, 0x23, 0x70, 0xF0, 0x06, 0x45, 0x7C)) # BSP partition
PARTITION_CLUSTER_GUID = GUID(
0xDB97DBA9, 0x0840, 0x4BAE, (0x97, 0xF0, 0xFF, 0xB9, 0xA3, 0x27, 0xC7, 0xE1)
) # Cluster metadata partition
PARTITION_DPP_GUID = GUID(0x57434F53, 0x94CB, 0x43F0, (0xA5, 0x33, 0xD7, 0x3C, 0x10, 0xCF, 0xA5, 0x7D)) # DPP partition
PARTITION_ENTRY_UNUSED_GUID = GUID(
0x00000000, 0x0000, 0x0000, (0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
) # Entry unused
PARTITION_LDM_DATA_GUID = GUID(
0xAF9B60A0, 0x1431, 0x4F62, (0xBC, 0x68, 0x33, 0x11, 0x71, 0x4A, 0x69, 0xAD)
) # Logical Disk Manager data partition
PARTITION_LDM_METADATA_GUID = GUID(
0x5808C8AA, 0x7E8F, 0x42E0, (0x85, 0xD2, 0xE1, 0xE9, 0x04, 0x34, 0xCF, 0xB3)
) # Logical Disk Manager metadata partition
PARTITION_LEGACY_BL_GUID = GUID(
0x424CA0E2, 0x7CB2, 0x4FB9, (0x81, 0x43, 0xC5, 0x2A, 0x99, 0x39, 0x8B, 0xC6)
) # Legacy boot loader partition
PARTITION_LEGACY_BL_GUID_BACKUP = GUID(
0x424C3E6C, 0xD79F, 0x49CB, (0x93, 0x5D, 0x36, 0xD7, 0x14, 0x67, 0xA2, 0x88)
) # Legacy boot loader backup partition
PARTITION_MAIN_OS_GUID = GUID(
0x57434F53, 0x8F45, 0x405E, (0x8A, 0x23, 0x18, 0x6D, 0x8A, 0x43, 0x30, 0xD3)
) # Main OS partition
PARTITION_MSFT_RECOVERY_GUID = GUID(
0xDE94BBA4, 0x06D1, 0x4D40, (0xA1, 0x6A, 0xBF, 0xD5, 0x01, 0x79, 0xD6, 0xAC)
) # Microsoft recovery partition
PARTITION_MSFT_RESERVED_GUID = GUID(
0xE3C9E316, 0x0B5C, 0x4DB8, (0x81, 0x7D, 0xF9, 0x2D, 0xF0, 0x02, 0x15, 0xAE)
) # Microsoft reserved space
PARTITION_MSFT_SNAPSHOT_GUID = GUID(
0xCADDEBF1, 0x4400, 0x4DE8, (0xB1, 0x03, 0x12, 0x11, 0x7D, 0xCF, 0x3C, 0xCF)
) # Microsoft shadow copy partition
PARTITION_OS_DATA_GUID = GUID(
0x57434F53, 0x23F2, 0x44D5, (0xA8, 0x30, 0x67, 0xBB, 0xDA, 0xA6, 0x09, 0xF9)
) # OS data partition
PARTITION_PATCH_GUID = GUID(
0x8967A686, 0x96AA, 0x6AA8, (0x95, 0x89, 0xA8, 0x42, 0x56, 0x54, 0x10, 0x90)
) # Patch partition
PARTITION_PRE_INSTALLED_GUID = GUID(
0x57434F53, 0x7FE0, 0x4196, (0x9B, 0x42, 0x42, 0x7B, 0x51, 0x64, 0x34, 0x84)
) # PreInstalled partition
PARTITION_SBL_CACHE_SSD_GUID = GUID(
0xEEFF8352, 0xDD2A, 0x44DB, (0xAE, 0x83, 0xBE, 0xE1, 0xCF, 0x74, 0x81, 0xDC)
) # Storage Bus Layer Cache partition
PARTITION_SBL_CACHE_SSD_RESERVED_GUID = GUID(
0xDCC0C7C1, 0x55AD, 0x4F17, (0x9D, 0x43, 0x4B, 0xC7, 0x76, 0xE0, 0x11, 0x7E)
) # Storage Bus Layer Cache partition
PARTITION_SBL_CACHE_HDD_GUID = GUID(
0x03AAA829, 0xEBFC, 0x4E7E, (0xAA, 0xC9, 0xC4, 0xD7, 0x6C, 0x63, 0xB2, 0x4B)
) # Storage Bus Layer Cache partition
PARTITION_SERVICING_FILES_GUID = GUID(
0x57434F53, 0x432E, 0x4014, (0xAE, 0x4C, 0x8D, 0xEA, 0xA9, 0xC0, 0x00, 0x6A)
) # Servicing files partition
PARTITION_SERVICING_METADATA_GUID = GUID(
0x57434F53, 0xC691, 0x4A05, (0xBB, 0x4E, 0x70, 0x3D, 0xAF, 0xD2, 0x29, 0xCE)
) # Servicing metadata partition
PARTITION_SERVICING_RESERVE_GUID = GUID(
0x57434F53, 0x4B81, 0x460B, (0xA3, 0x19, 0xFF, 0xB6, 0xFE, 0x13, 0x6D, 0x14)
) # Servicing reserve partition
PARTITION_SERVICING_STAGING_ROOT_GUID = GUID(
0x57434F53, 0xE84D, 0x4E84, (0xAA, 0xF3, 0xEC, 0xBB, 0xBD, 0x04, 0xB9, 0xDF)
) # Servicing staging root partition
PARTITION_SPACES_GUID = GUID(
0xE75CAF8F, 0xF680, 0x4CEE, (0xAF, 0xA3, 0xB0, 0x01, 0xE5, 0x6E, 0xFC, 0x2D)
) # Storage Spaces protective partition
PARTITION_SPACES_DATA_GUID = GUID(
0xE7ADDCB4, 0xDC34, 0x4539, (0x9A, 0x76, 0xEB, 0xBD, 0x07, 0xBE, 0x6F, 0x7E)
) # Storage Spaces protective partition
PARTITION_SYSTEM_GUID = GUID(
0xC12A7328, 0xF81F, 0x11D2, (0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B)
) # EFI system partition
PARTITION_WINDOWS_SYSTEM_GUID = GUID(
0x57434F53, 0xE3E3, 0x4631, (0xA5, 0xC5, 0x26, 0xD2, 0x24, 0x38, 0x73, 0xAA)
) # Windows system partition
11 changes: 11 additions & 0 deletions cwinsdk/shared/guiddef.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ class GUID(Structure):
("Data4", c_ubyte * 8),
]

def __str__(self) -> str:
return f"{self.Data1:08x}-{self.Data2:04x}-{self.Data3:04x}-{bytes(self.Data4)[:2].hex().zfill(4)}-{bytes(self.Data4)[2:].hex().zfill(12)}"

def __eq__(self, other) -> bool:
if isinstance(other, GUID):
return memoryview(self).cast("B") == memoryview(other).cast("B")
return NotImplemented

def __hash__(self):
return hash(bytes(self))


IID = GUID
LPIID = POINTER(IID)
Expand Down
4 changes: 4 additions & 0 deletions cwinsdk/shared/ntdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
LPWSTR = POINTER(WCHAR)
PWSTR = POINTER(WCHAR)


PVOID = c_void_p
POINTER_64 = c_void_p
PVOID64 = c_void_p
Expand All @@ -46,6 +47,9 @@
HRESULT = LONG
NTSTATUS = LONG

PCSTR = POINTER(CHAR) # const
PSTR = POINTER(CHAR)


class STRING(Structure):
_fields_ = [
Expand Down
64 changes: 62 additions & 2 deletions cwinsdk/um/WinBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
WORD,
)

from .. import CEnum, windll
from .. import CEnum, nonzero, validhandle, windll
from ..km.wdm import SECURITY_IMPERSONATION_LEVEL
from ..shared.basetsd import SIZE_T, ULONG64
from ..shared.guiddef import GUID
from ..shared.minwindef import ATOM
from ..shared.minwindef import ATOM, PDWORD
from ..shared.ntdef import CHAR, ULONGLONG
from .minwinbase import FILE_INFO_BY_HANDLE_CLASS, LPSECURITY_ATTRIBUTES
from .winnt import (
Expand All @@ -31,6 +31,7 @@
FILE_SUPPORTS_ENCRYPTION,
FILE_UNICODE_ON_DISK,
FILE_VOLUME_IS_COMPRESSED,
LPCH,
LUID,
MAXLONG,
STATUS_ABANDONED_WAIT_0,
Expand Down Expand Up @@ -722,3 +723,62 @@ class FILE_ID_DESCRIPTOR(Structure):
ReOpenFile = windll.kernel32.ReOpenFile
ReOpenFile.argtypes = [HANDLE, DWORD, DWORD, DWORD]
ReOpenFile.restype = HANDLE

FindFirstVolumeA = windll.kernel32.FindFirstVolumeA
FindFirstVolumeA.argtypes = [LPSTR, DWORD]
FindFirstVolumeA.restype = HANDLE
FindFirstVolumeA.errcheck = validhandle

FindNextVolumeA = windll.kernel32.FindNextVolumeA
FindNextVolumeA.argtypes = [HANDLE, LPSTR, DWORD]
FindNextVolumeA.restype = BOOL
FindNextVolumeA.errcheck = nonzero

FindFirstVolumeMountPointA = windll.kernel32.FindFirstVolumeMountPointA
FindFirstVolumeMountPointA.argtypes = [LPCSTR, LPSTR, DWORD]
FindFirstVolumeMountPointA.restype = HANDLE
FindFirstVolumeMountPointA.errcheck = validhandle

FindFirstVolumeMountPointW = windll.kernel32.FindFirstVolumeMountPointW
FindFirstVolumeMountPointW.argtypes = [LPCWSTR, LPWSTR, DWORD]
FindFirstVolumeMountPointW.restype = HANDLE
FindFirstVolumeMountPointW.errcheck = validhandle

FindNextVolumeMountPointA = windll.kernel32.FindNextVolumeMountPointA
FindNextVolumeMountPointA.argtypes = [HANDLE, LPSTR, DWORD]
FindNextVolumeMountPointA.restype = BOOL
FindNextVolumeMountPointA.errcheck = nonzero

FindNextVolumeMountPointW = windll.kernel32.FindNextVolumeMountPointW
FindNextVolumeMountPointW.argtypes = [HANDLE, LPWSTR, DWORD]
FindNextVolumeMountPointW.restype = BOOL
FindNextVolumeMountPointA.errcheck = nonzero

FindVolumeMountPointClose = windll.kernel32.FindVolumeMountPointClose
FindVolumeMountPointClose.argtypes = [HANDLE]
FindVolumeMountPointClose.restype = BOOL
FindVolumeMountPointClose.errcheck = nonzero

SetVolumeMountPointA = windll.kernel32.SetVolumeMountPointA
SetVolumeMountPointA.argtypes = [LPCSTR, LPCSTR]
SetVolumeMountPointA.restype = BOOL

SetVolumeMountPointW = windll.kernel32.SetVolumeMountPointW
SetVolumeMountPointW.argtypes = [LPCWSTR, LPCWSTR]
SetVolumeMountPointW.restype = BOOL

DeleteVolumeMountPointA = windll.kernel32.DeleteVolumeMountPointA
DeleteVolumeMountPointA.argtypes = [LPCSTR]
DeleteVolumeMountPointA.restype = BOOL

GetVolumeNameForVolumeMountPointA = windll.kernel32.GetVolumeNameForVolumeMountPointA
GetVolumeNameForVolumeMountPointA.argtypes = [LPCSTR, LPSTR, DWORD]
GetVolumeNameForVolumeMountPointA.restype = BOOL

GetVolumePathNameA = windll.kernel32.GetVolumePathNameA
GetVolumePathNameA.argtypes = [LPCSTR, LPSTR, DWORD]
GetVolumePathNameA.restype = BOOL

GetVolumePathNamesForVolumeNameA = windll.kernel32.GetVolumePathNamesForVolumeNameA
GetVolumePathNamesForVolumeNameA.argtypes = [LPCSTR, LPCH, DWORD, PDWORD]
GetVolumePathNamesForVolumeNameA.restype = BOOL
100 changes: 96 additions & 4 deletions cwinsdk/um/fileapi.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from ctypes import POINTER, Structure
from ctypes.wintypes import BOOL, DWORD, HANDLE, LONG, LPCSTR, LPCWSTR, LPSTR, LPVOID, LPWSTR, UINT, ULARGE_INTEGER

from .. import nonzero, validhandle, windll
from ..shared.minwindef import FILETIME
from ..shared.ntdef import ULONGLONG
from .minwinbase import GET_FILEEX_INFO_LEVELS, LPOVERLAPPED, LPSECURITY_ATTRIBUTES
from .. import CEnum, nonzero, validhandle, windll
from ..shared.minwindef import FILETIME, PDWORD
from ..shared.ntdef import LPWCH, PWSTR, ULONGLONG
from .minwinbase import FILE_INFO_BY_HANDLE_CLASS, GET_FILEEX_INFO_LEVELS, LPOVERLAPPED, LPSECURITY_ATTRIBUTES

CREATE_NEW = 1
CREATE_ALWAYS = 2
Expand Down Expand Up @@ -50,6 +50,11 @@ class DISK_SPACE_INFORMATION(Structure):
]


class STREAM_INFO_LEVELS(CEnum):
FindStreamInfoStandard = 0
FindStreamInfoMaxInfoLevel = 1


# functions

AreFileApisANSI = windll.kernel32.AreFileApisANSI
Expand Down Expand Up @@ -118,6 +123,11 @@ class DISK_SPACE_INFORMATION(Structure):
GetFileInformationByHandle.restype = BOOL
GetFileInformationByHandle.errcheck = nonzero

SetFileInformationByHandle = windll.kernel32.SetFileInformationByHandle
SetFileInformationByHandle.argtypes = [HANDLE, FILE_INFO_BY_HANDLE_CLASS, LPVOID, DWORD]
SetFileInformationByHandle.restype = BOOL
SetFileInformationByHandle.errcheck = nonzero

GetFileType = windll.kernel32.GetFileType
GetFileType.argtypes = [HANDLE]
GetFileType.restype = DWORD
Expand Down Expand Up @@ -157,3 +167,85 @@ class DISK_SPACE_INFORMATION(Structure):
GetFinalPathNameByHandleW = windll.kernel32.GetFinalPathNameByHandleW
GetFinalPathNameByHandleW.argtypes = [HANDLE, LPWSTR, DWORD, DWORD]
GetFinalPathNameByHandleW.restype = DWORD

GetLogicalDrives = windll.kernel32.GetLogicalDrives
GetLogicalDrives.argtypes = []
GetLogicalDrives.restype = DWORD

GetLogicalDriveStringsW = windll.kernel32.GetLogicalDriveStringsW
GetLogicalDriveStringsW.argtypes = [DWORD, LPWSTR]
GetLogicalDriveStringsW.restype = DWORD
GetLogicalDriveStringsW.errcheck = nonzero

FindFirstStreamW = windll.kernel32.FindFirstStreamW
FindFirstStreamW.argtypes = [LPCWSTR, STREAM_INFO_LEVELS, LPVOID, DWORD]
FindFirstStreamW.restype = HANDLE
FindFirstStreamW.errcheck = validhandle

FindNextStreamW = windll.kernel32.FindNextStreamW
FindNextStreamW.argtypes = [HANDLE, LPVOID]
FindNextStreamW.restype = BOOL
FindNextStreamW.errcheck = nonzero

GetTempPathA = windll.kernel32.GetTempPathA
GetTempPathA.argtypes = [DWORD, LPSTR]
GetTempPathA.restype = DWORD

FindFirstFileNameW = windll.kernel32.FindFirstFileNameW
FindFirstFileNameW.argtypes = [LPCWSTR, DWORD, POINTER(DWORD), PWSTR]
FindFirstFileNameW.restype = HANDLE
FindFirstFileNameW.errcheck = validhandle

FindNextFileNameW = windll.kernel32.FindNextFileNameW
FindNextFileNameW.argtypes = [HANDLE, POINTER(DWORD), PWSTR]
FindNextFileNameW.restype = BOOL
FindNextFileNameW.errcheck = nonzero

GetVolumeInformationA = windll.kernel32.GetVolumeInformationA
GetVolumeInformationA.argtypes = [LPCSTR, LPSTR, DWORD, POINTER(DWORD), POINTER(DWORD), POINTER(DWORD), LPSTR, DWORD]
GetVolumeInformationA.restype = BOOL

GetTempFileNameA = windll.kernel32.GetTempFileNameA
GetTempFileNameA.argtypes = [LPCSTR, LPCSTR, UINT, LPSTR]
GetTempFileNameA.restype = UINT

SetFileApisToOEM = windll.kernel32.SetFileApisToOEM
SetFileApisToOEM.argtypes = []
SetFileApisToOEM.restype = None

SetFileApisToANSI = windll.kernel32.SetFileApisToANSI
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

QueryDosDeviceW = windll.kernel32.QueryDosDeviceW
QueryDosDeviceW.argtypes = [LPCWSTR, LPWSTR, DWORD]
QueryDosDeviceW.restype = DWORD
QueryDosDeviceW.errcheck = nonzero

FindFirstVolumeW = windll.kernel32.FindFirstVolumeW
FindFirstVolumeW.argtypes = [LPWSTR, DWORD]
FindFirstVolumeW.restype = HANDLE
FindFirstVolumeW.errcheck = validhandle

FindNextVolumeW = windll.kernel32.FindNextVolumeW
FindNextVolumeW.argtypes = [HANDLE, LPWSTR, DWORD]
FindNextVolumeW.restype = BOOL
FindNextVolumeW.errcheck = nonzero

FindVolumeClose = windll.kernel32.FindVolumeClose
FindVolumeClose.argtypes = [HANDLE]
FindVolumeClose.restype = BOOL
FindVolumeClose.errcheck = nonzero

GetVolumePathNamesForVolumeNameW = windll.kernel32.GetVolumePathNamesForVolumeNameW
GetVolumePathNamesForVolumeNameW.argtypes = [LPCWSTR, LPWCH, DWORD, PDWORD]
GetVolumePathNamesForVolumeNameW.restype = BOOL
GetVolumePathNamesForVolumeNameW.errcheck = nonzero
3 changes: 2 additions & 1 deletion cwinsdk/um/ioapiset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ctypes import POINTER
from ctypes.wintypes import BOOL, DWORD, HANDLE, LPVOID, ULONG

from .. import _not_available, windll
from .. import _not_available, nonzero, windll
from ..shared.basetsd import PULONG_PTR, ULONG_PTR
from ..shared.minwindef import LPDWORD, PULONG
from .minwinbase import LPOVERLAPPED, LPOVERLAPPED_ENTRY
Expand All @@ -25,6 +25,7 @@
DeviceIoControl = windll.kernel32.DeviceIoControl
DeviceIoControl.argtypes = [HANDLE, DWORD, LPVOID, DWORD, LPVOID, DWORD, LPDWORD, LPOVERLAPPED]
DeviceIoControl.restype = BOOL
DeviceIoControl.errcheck = nonzero

GetOverlappedResult = windll.kernel32.GetOverlappedResult
GetOverlappedResult.argtypes = [HANDLE, LPOVERLAPPED, LPDWORD, BOOL]
Expand Down
Loading

0 comments on commit b4136db

Please sign in to comment.