mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-14 18:47:09 -07:00
Move Windows libs to libs/windows
This commit is contained in:
parent
3975aaceb2
commit
3a692c94a5
684 changed files with 4 additions and 1 deletions
0
libs/win/jaraco/windows/api/__init__.py
Normal file
0
libs/win/jaraco/windows/api/__init__.py
Normal file
53
libs/win/jaraco/windows/api/clipboard.py
Normal file
53
libs/win/jaraco/windows/api/clipboard.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
# Clipboard Formats
|
||||
CF_TEXT = 1
|
||||
CF_BITMAP = 2
|
||||
CF_METAFILEPICT = 3
|
||||
CF_SYLK = 4
|
||||
CF_DIF = 5
|
||||
CF_TIFF = 6
|
||||
CF_OEMTEXT = 7
|
||||
CF_DIB = 8
|
||||
CF_PALETTE = 9
|
||||
CF_PENDATA = 10
|
||||
CF_RIFF = 11
|
||||
CF_WAVE = 12
|
||||
CF_UNICODETEXT = 13
|
||||
CF_ENHMETAFILE = 14
|
||||
CF_HDROP = 15
|
||||
CF_LOCALE = 16
|
||||
CF_DIBV5 = 17
|
||||
CF_MAX = 18
|
||||
CF_OWNERDISPLAY = 0x0080
|
||||
CF_DSPTEXT = 0x0081
|
||||
CF_DSPBITMAP = 0x0082
|
||||
CF_DSPMETAFILEPICT = 0x0083
|
||||
CF_DSPENHMETAFILE = 0x008E
|
||||
CF_PRIVATEFIRST = 0x0200
|
||||
CF_PRIVATELAST = 0x02FF
|
||||
CF_GDIOBJFIRST = 0x0300
|
||||
CF_GDIOBJLAST = 0x03FF
|
||||
|
||||
RegisterClipboardFormat = ctypes.windll.user32.RegisterClipboardFormatW
|
||||
RegisterClipboardFormat.argtypes = ctypes.wintypes.LPWSTR,
|
||||
RegisterClipboardFormat.restype = ctypes.wintypes.UINT
|
||||
CF_HTML = RegisterClipboardFormat('HTML Format')
|
||||
|
||||
EnumClipboardFormats = ctypes.windll.user32.EnumClipboardFormats
|
||||
EnumClipboardFormats.argtypes = ctypes.wintypes.UINT,
|
||||
EnumClipboardFormats.restype = ctypes.wintypes.UINT
|
||||
|
||||
GetClipboardData = ctypes.windll.user32.GetClipboardData
|
||||
GetClipboardData.argtypes = ctypes.wintypes.UINT,
|
||||
GetClipboardData.restype = ctypes.wintypes.HANDLE
|
||||
|
||||
SetClipboardData = ctypes.windll.user32.SetClipboardData
|
||||
SetClipboardData.argtypes = ctypes.wintypes.UINT, ctypes.wintypes.HANDLE
|
||||
SetClipboardData.restype = ctypes.wintypes.HANDLE
|
||||
|
||||
OpenClipboard = ctypes.windll.user32.OpenClipboard
|
||||
OpenClipboard.argtypes = ctypes.wintypes.HANDLE,
|
||||
OpenClipboard.restype = ctypes.wintypes.BOOL
|
||||
|
||||
ctypes.windll.user32.CloseClipboard.restype = ctypes.wintypes.BOOL
|
62
libs/win/jaraco/windows/api/credential.py
Normal file
62
libs/win/jaraco/windows/api/credential.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
"""
|
||||
Support for Credential Vault
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
from ctypes.wintypes import DWORD, LPCWSTR, BOOL, LPWSTR, FILETIME
|
||||
|
||||
try:
|
||||
from ctypes.wintypes import LPBYTE
|
||||
except ImportError:
|
||||
LPBYTE = ctypes.POINTER(ctypes.wintypes.BYTE)
|
||||
|
||||
|
||||
class CredentialAttribute(ctypes.Structure):
|
||||
_fields_ = []
|
||||
|
||||
|
||||
class Credential(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('flags', DWORD),
|
||||
('type', DWORD),
|
||||
('target_name', LPWSTR),
|
||||
('comment', LPWSTR),
|
||||
('last_written', FILETIME),
|
||||
('credential_blob_size', DWORD),
|
||||
('credential_blob', LPBYTE),
|
||||
('persist', DWORD),
|
||||
('attribute_count', DWORD),
|
||||
('attributes', ctypes.POINTER(CredentialAttribute)),
|
||||
('target_alias', LPWSTR),
|
||||
('user_name', LPWSTR),
|
||||
]
|
||||
|
||||
def __del__(self):
|
||||
ctypes.windll.advapi32.CredFree(ctypes.byref(self))
|
||||
|
||||
|
||||
PCREDENTIAL = ctypes.POINTER(Credential)
|
||||
|
||||
CredRead = ctypes.windll.advapi32.CredReadW
|
||||
CredRead.argtypes = (
|
||||
LPCWSTR, # TargetName
|
||||
DWORD, # Type
|
||||
DWORD, # Flags
|
||||
ctypes.POINTER(PCREDENTIAL), # Credential
|
||||
)
|
||||
CredRead.restype = BOOL
|
||||
|
||||
CredWrite = ctypes.windll.advapi32.CredWriteW
|
||||
CredWrite.argtypes = (
|
||||
PCREDENTIAL, # Credential
|
||||
DWORD, # Flags
|
||||
)
|
||||
CredWrite.restype = BOOL
|
||||
|
||||
CredDelete = ctypes.windll.advapi32.CredDeleteW
|
||||
CredDelete.argtypes = (
|
||||
LPCWSTR, # TargetName
|
||||
DWORD, # Type
|
||||
DWORD, # Flags
|
||||
)
|
||||
CredDelete.restype = BOOL
|
13
libs/win/jaraco/windows/api/environ.py
Normal file
13
libs/win/jaraco/windows/api/environ.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
SetEnvironmentVariable = ctypes.windll.kernel32.SetEnvironmentVariableW
|
||||
SetEnvironmentVariable.restype = ctypes.wintypes.BOOL
|
||||
SetEnvironmentVariable.argtypes = [ctypes.wintypes.LPCWSTR] * 2
|
||||
|
||||
GetEnvironmentVariable = ctypes.windll.kernel32.GetEnvironmentVariableW
|
||||
GetEnvironmentVariable.restype = ctypes.wintypes.BOOL
|
||||
GetEnvironmentVariable.argtypes = [
|
||||
ctypes.wintypes.LPCWSTR,
|
||||
ctypes.wintypes.LPWSTR,
|
||||
ctypes.wintypes.DWORD,
|
||||
]
|
7
libs/win/jaraco/windows/api/errors.py
Normal file
7
libs/win/jaraco/windows/api/errors.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
# from error.h
|
||||
NO_ERROR = 0
|
||||
ERROR_INSUFFICIENT_BUFFER = 122
|
||||
ERROR_BUFFER_OVERFLOW = 111
|
||||
ERROR_NO_DATA = 232
|
||||
ERROR_INVALID_PARAMETER = 87
|
||||
ERROR_NOT_SUPPORTED = 50
|
38
libs/win/jaraco/windows/api/event.py
Normal file
38
libs/win/jaraco/windows/api/event.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
from ctypes import windll, POINTER
|
||||
from ctypes.wintypes import (
|
||||
LPWSTR, DWORD, LPVOID, HANDLE, BOOL,
|
||||
)
|
||||
|
||||
CreateEvent = windll.kernel32.CreateEventW
|
||||
CreateEvent.argtypes = (
|
||||
LPVOID, # LPSECURITY_ATTRIBUTES
|
||||
BOOL,
|
||||
BOOL,
|
||||
LPWSTR,
|
||||
)
|
||||
CreateEvent.restype = HANDLE
|
||||
|
||||
SetEvent = windll.kernel32.SetEvent
|
||||
SetEvent.argtypes = HANDLE,
|
||||
SetEvent.restype = BOOL
|
||||
|
||||
WaitForSingleObject = windll.kernel32.WaitForSingleObject
|
||||
WaitForSingleObject.argtypes = HANDLE, DWORD
|
||||
WaitForSingleObject.restype = DWORD
|
||||
|
||||
_WaitForMultipleObjects = windll.kernel32.WaitForMultipleObjects
|
||||
_WaitForMultipleObjects.argtypes = DWORD, POINTER(HANDLE), BOOL, DWORD
|
||||
_WaitForMultipleObjects.restype = DWORD
|
||||
|
||||
|
||||
def WaitForMultipleObjects(handles, wait_all=False, timeout=0):
|
||||
n_handles = len(handles)
|
||||
handle_array = (HANDLE * n_handles)()
|
||||
for index, handle in enumerate(handles):
|
||||
handle_array[index] = handle
|
||||
return _WaitForMultipleObjects(n_handles, handle_array, wait_all, timeout)
|
||||
|
||||
|
||||
WAIT_OBJECT_0 = 0
|
||||
INFINITE = -1
|
||||
WAIT_TIMEOUT = 0x102
|
317
libs/win/jaraco/windows/api/filesystem.py
Normal file
317
libs/win/jaraco/windows/api/filesystem.py
Normal file
|
@ -0,0 +1,317 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
CreateSymbolicLink = ctypes.windll.kernel32.CreateSymbolicLinkW
|
||||
CreateSymbolicLink.argtypes = (
|
||||
ctypes.wintypes.LPWSTR,
|
||||
ctypes.wintypes.LPWSTR,
|
||||
ctypes.wintypes.DWORD,
|
||||
)
|
||||
CreateSymbolicLink.restype = ctypes.wintypes.BOOLEAN
|
||||
|
||||
CreateHardLink = ctypes.windll.kernel32.CreateHardLinkW
|
||||
CreateHardLink.argtypes = (
|
||||
ctypes.wintypes.LPWSTR,
|
||||
ctypes.wintypes.LPWSTR,
|
||||
ctypes.wintypes.LPVOID, # reserved for LPSECURITY_ATTRIBUTES
|
||||
)
|
||||
CreateHardLink.restype = ctypes.wintypes.BOOLEAN
|
||||
|
||||
GetFileAttributes = ctypes.windll.kernel32.GetFileAttributesW
|
||||
GetFileAttributes.argtypes = ctypes.wintypes.LPWSTR,
|
||||
GetFileAttributes.restype = ctypes.wintypes.DWORD
|
||||
|
||||
SetFileAttributes = ctypes.windll.kernel32.SetFileAttributesW
|
||||
SetFileAttributes.argtypes = ctypes.wintypes.LPWSTR, ctypes.wintypes.DWORD
|
||||
SetFileAttributes.restype = ctypes.wintypes.BOOL
|
||||
|
||||
MAX_PATH = 260
|
||||
|
||||
GetFinalPathNameByHandle = ctypes.windll.kernel32.GetFinalPathNameByHandleW
|
||||
GetFinalPathNameByHandle.argtypes = (
|
||||
ctypes.wintypes.HANDLE, ctypes.wintypes.LPWSTR, ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.DWORD,
|
||||
)
|
||||
GetFinalPathNameByHandle.restype = ctypes.wintypes.DWORD
|
||||
|
||||
|
||||
class SECURITY_ATTRIBUTES(ctypes.Structure):
|
||||
_fields_ = (
|
||||
('length', ctypes.wintypes.DWORD),
|
||||
('p_security_descriptor', ctypes.wintypes.LPVOID),
|
||||
('inherit_handle', ctypes.wintypes.BOOLEAN),
|
||||
)
|
||||
|
||||
|
||||
LPSECURITY_ATTRIBUTES = ctypes.POINTER(SECURITY_ATTRIBUTES)
|
||||
|
||||
CreateFile = ctypes.windll.kernel32.CreateFileW
|
||||
CreateFile.argtypes = (
|
||||
ctypes.wintypes.LPWSTR,
|
||||
ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.DWORD,
|
||||
LPSECURITY_ATTRIBUTES,
|
||||
ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.HANDLE,
|
||||
)
|
||||
CreateFile.restype = ctypes.wintypes.HANDLE
|
||||
FILE_SHARE_READ = 1
|
||||
FILE_SHARE_WRITE = 2
|
||||
FILE_SHARE_DELETE = 4
|
||||
FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
|
||||
FILE_FLAG_BACKUP_SEMANTICS = 0x2000000
|
||||
NULL = 0
|
||||
OPEN_EXISTING = 3
|
||||
FILE_ATTRIBUTE_READONLY = 0x1
|
||||
FILE_ATTRIBUTE_HIDDEN = 0x2
|
||||
FILE_ATTRIBUTE_DIRECTORY = 0x10
|
||||
FILE_ATTRIBUTE_NORMAL = 0x80
|
||||
FILE_ATTRIBUTE_REPARSE_POINT = 0x400
|
||||
GENERIC_READ = 0x80000000
|
||||
FILE_READ_ATTRIBUTES = 0x80
|
||||
INVALID_HANDLE_VALUE = ctypes.wintypes.HANDLE(-1).value
|
||||
|
||||
INVALID_FILE_ATTRIBUTES = 0xFFFFFFFF
|
||||
|
||||
ERROR_NO_MORE_FILES = 0x12
|
||||
|
||||
VOLUME_NAME_DOS = 0
|
||||
|
||||
CloseHandle = ctypes.windll.kernel32.CloseHandle
|
||||
CloseHandle.argtypes = (ctypes.wintypes.HANDLE,)
|
||||
CloseHandle.restype = ctypes.wintypes.BOOLEAN
|
||||
|
||||
|
||||
class WIN32_FIND_DATA(ctypes.wintypes.WIN32_FIND_DATAW):
|
||||
"""
|
||||
_fields_ = [
|
||||
("dwFileAttributes", DWORD),
|
||||
("ftCreationTime", FILETIME),
|
||||
("ftLastAccessTime", FILETIME),
|
||||
("ftLastWriteTime", FILETIME),
|
||||
("nFileSizeHigh", DWORD),
|
||||
("nFileSizeLow", DWORD),
|
||||
("dwReserved0", DWORD),
|
||||
("dwReserved1", DWORD),
|
||||
("cFileName", WCHAR * MAX_PATH),
|
||||
("cAlternateFileName", WCHAR * 14)]
|
||||
]
|
||||
"""
|
||||
|
||||
@property
|
||||
def file_attributes(self):
|
||||
return self.dwFileAttributes
|
||||
|
||||
@property
|
||||
def creation_time(self):
|
||||
return self.ftCreationTime
|
||||
|
||||
@property
|
||||
def last_access_time(self):
|
||||
return self.ftLastAccessTime
|
||||
|
||||
@property
|
||||
def last_write_time(self):
|
||||
return self.ftLastWriteTime
|
||||
|
||||
@property
|
||||
def file_size_words(self):
|
||||
return [self.nFileSizeHigh, self.nFileSizeLow]
|
||||
|
||||
@property
|
||||
def reserved(self):
|
||||
return [self.dwReserved0, self.dwReserved1]
|
||||
|
||||
@property
|
||||
def filename(self):
|
||||
return self.cFileName
|
||||
|
||||
@property
|
||||
def alternate_filename(self):
|
||||
return self.cAlternateFileName
|
||||
|
||||
@property
|
||||
def file_size(self):
|
||||
return self.nFileSizeHigh << 32 + self.nFileSizeLow
|
||||
|
||||
|
||||
LPWIN32_FIND_DATA = ctypes.POINTER(ctypes.wintypes.WIN32_FIND_DATAW)
|
||||
|
||||
FindFirstFile = ctypes.windll.kernel32.FindFirstFileW
|
||||
FindFirstFile.argtypes = (ctypes.wintypes.LPWSTR, LPWIN32_FIND_DATA)
|
||||
FindFirstFile.restype = ctypes.wintypes.HANDLE
|
||||
FindNextFile = ctypes.windll.kernel32.FindNextFileW
|
||||
FindNextFile.argtypes = (ctypes.wintypes.HANDLE, LPWIN32_FIND_DATA)
|
||||
FindNextFile.restype = ctypes.wintypes.BOOLEAN
|
||||
|
||||
ctypes.windll.kernel32.FindClose.argtypes = ctypes.wintypes.HANDLE,
|
||||
|
||||
SCS_32BIT_BINARY = 0 # A 32-bit Windows-based application
|
||||
SCS_64BIT_BINARY = 6 # A 64-bit Windows-based application
|
||||
SCS_DOS_BINARY = 1 # An MS-DOS-based application
|
||||
SCS_OS216_BINARY = 5 # A 16-bit OS/2-based application
|
||||
SCS_PIF_BINARY = 3 # A PIF file that executes an MS-DOS-based application
|
||||
SCS_POSIX_BINARY = 4 # A POSIX-based application
|
||||
SCS_WOW_BINARY = 2 # A 16-bit Windows-based application
|
||||
|
||||
_GetBinaryType = ctypes.windll.kernel32.GetBinaryTypeW
|
||||
_GetBinaryType.argtypes = (
|
||||
ctypes.wintypes.LPWSTR, ctypes.POINTER(ctypes.wintypes.DWORD),
|
||||
)
|
||||
_GetBinaryType.restype = ctypes.wintypes.BOOL
|
||||
|
||||
FILEOP_FLAGS = ctypes.wintypes.WORD
|
||||
|
||||
|
||||
class BY_HANDLE_FILE_INFORMATION(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('file_attributes', ctypes.wintypes.DWORD),
|
||||
('creation_time', ctypes.wintypes.FILETIME),
|
||||
('last_access_time', ctypes.wintypes.FILETIME),
|
||||
('last_write_time', ctypes.wintypes.FILETIME),
|
||||
('volume_serial_number', ctypes.wintypes.DWORD),
|
||||
('file_size_high', ctypes.wintypes.DWORD),
|
||||
('file_size_low', ctypes.wintypes.DWORD),
|
||||
('number_of_links', ctypes.wintypes.DWORD),
|
||||
('file_index_high', ctypes.wintypes.DWORD),
|
||||
('file_index_low', ctypes.wintypes.DWORD),
|
||||
]
|
||||
|
||||
@property
|
||||
def file_size(self):
|
||||
return (self.file_size_high << 32) + self.file_size_low
|
||||
|
||||
@property
|
||||
def file_index(self):
|
||||
return (self.file_index_high << 32) + self.file_index_low
|
||||
|
||||
|
||||
GetFileInformationByHandle = ctypes.windll.kernel32.GetFileInformationByHandle
|
||||
GetFileInformationByHandle.restype = ctypes.wintypes.BOOL
|
||||
GetFileInformationByHandle.argtypes = (
|
||||
ctypes.wintypes.HANDLE,
|
||||
ctypes.POINTER(BY_HANDLE_FILE_INFORMATION),
|
||||
)
|
||||
|
||||
|
||||
class SHFILEOPSTRUCT(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('status_dialog', ctypes.wintypes.HWND),
|
||||
('operation', ctypes.wintypes.UINT),
|
||||
('from_', ctypes.wintypes.LPWSTR),
|
||||
('to', ctypes.wintypes.LPWSTR),
|
||||
('flags', FILEOP_FLAGS),
|
||||
('operations_aborted', ctypes.wintypes.BOOL),
|
||||
('name_mapping_handles', ctypes.wintypes.LPVOID),
|
||||
('progress_title', ctypes.wintypes.LPWSTR),
|
||||
]
|
||||
|
||||
|
||||
_SHFileOperation = ctypes.windll.shell32.SHFileOperationW
|
||||
_SHFileOperation.argtypes = [ctypes.POINTER(SHFILEOPSTRUCT)]
|
||||
_SHFileOperation.restype = ctypes.c_int
|
||||
|
||||
FOF_ALLOWUNDO = 64
|
||||
FOF_NOCONFIRMATION = 16
|
||||
FO_DELETE = 3
|
||||
|
||||
ReplaceFile = ctypes.windll.kernel32.ReplaceFileW
|
||||
ReplaceFile.restype = ctypes.wintypes.BOOL
|
||||
ReplaceFile.argtypes = [
|
||||
ctypes.wintypes.LPWSTR,
|
||||
ctypes.wintypes.LPWSTR,
|
||||
ctypes.wintypes.LPWSTR,
|
||||
ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.LPVOID,
|
||||
ctypes.wintypes.LPVOID,
|
||||
]
|
||||
|
||||
REPLACEFILE_WRITE_THROUGH = 0x1
|
||||
REPLACEFILE_IGNORE_MERGE_ERRORS = 0x2
|
||||
REPLACEFILE_IGNORE_ACL_ERRORS = 0x4
|
||||
|
||||
|
||||
class STAT_STRUCT(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('dev', ctypes.c_uint),
|
||||
('ino', ctypes.c_ushort),
|
||||
('mode', ctypes.c_ushort),
|
||||
('nlink', ctypes.c_short),
|
||||
('uid', ctypes.c_short),
|
||||
('gid', ctypes.c_short),
|
||||
('rdev', ctypes.c_uint),
|
||||
# the following 4 fields are ctypes.c_uint64 for _stat64
|
||||
('size', ctypes.c_uint),
|
||||
('atime', ctypes.c_uint),
|
||||
('mtime', ctypes.c_uint),
|
||||
('ctime', ctypes.c_uint),
|
||||
]
|
||||
|
||||
|
||||
_wstat = ctypes.windll.msvcrt._wstat
|
||||
_wstat.argtypes = [ctypes.wintypes.LPWSTR, ctypes.POINTER(STAT_STRUCT)]
|
||||
_wstat.restype = ctypes.c_int
|
||||
|
||||
FILE_NOTIFY_CHANGE_LAST_WRITE = 0x10
|
||||
|
||||
FindFirstChangeNotification = (
|
||||
ctypes.windll.kernel32.FindFirstChangeNotificationW)
|
||||
FindFirstChangeNotification.argtypes = (
|
||||
ctypes.wintypes.LPWSTR, ctypes.wintypes.BOOL, ctypes.wintypes.DWORD,
|
||||
)
|
||||
FindFirstChangeNotification.restype = ctypes.wintypes.HANDLE
|
||||
|
||||
FindCloseChangeNotification = (
|
||||
ctypes.windll.kernel32.FindCloseChangeNotification)
|
||||
FindCloseChangeNotification.argtypes = ctypes.wintypes.HANDLE,
|
||||
FindCloseChangeNotification.restype = ctypes.wintypes.BOOL
|
||||
|
||||
FindNextChangeNotification = ctypes.windll.kernel32.FindNextChangeNotification
|
||||
FindNextChangeNotification.argtypes = ctypes.wintypes.HANDLE,
|
||||
FindNextChangeNotification.restype = ctypes.wintypes.BOOL
|
||||
|
||||
FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
|
||||
IO_REPARSE_TAG_SYMLINK = 0xA000000C
|
||||
FSCTL_GET_REPARSE_POINT = 0x900a8
|
||||
|
||||
LPDWORD = ctypes.POINTER(ctypes.wintypes.DWORD)
|
||||
LPOVERLAPPED = ctypes.wintypes.LPVOID
|
||||
|
||||
DeviceIoControl = ctypes.windll.kernel32.DeviceIoControl
|
||||
DeviceIoControl.argtypes = [
|
||||
ctypes.wintypes.HANDLE,
|
||||
ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.LPVOID,
|
||||
ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.LPVOID,
|
||||
ctypes.wintypes.DWORD,
|
||||
LPDWORD,
|
||||
LPOVERLAPPED,
|
||||
]
|
||||
DeviceIoControl.restype = ctypes.wintypes.BOOL
|
||||
|
||||
|
||||
class REPARSE_DATA_BUFFER(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('tag', ctypes.c_ulong),
|
||||
('data_length', ctypes.c_ushort),
|
||||
('reserved', ctypes.c_ushort),
|
||||
('substitute_name_offset', ctypes.c_ushort),
|
||||
('substitute_name_length', ctypes.c_ushort),
|
||||
('print_name_offset', ctypes.c_ushort),
|
||||
('print_name_length', ctypes.c_ushort),
|
||||
('flags', ctypes.c_ulong),
|
||||
('path_buffer', ctypes.c_byte * 1),
|
||||
]
|
||||
|
||||
def get_print_name(self):
|
||||
wchar_size = ctypes.sizeof(ctypes.wintypes.WCHAR)
|
||||
arr_typ = ctypes.wintypes.WCHAR * (self.print_name_length // wchar_size)
|
||||
data = ctypes.byref(self.path_buffer, self.print_name_offset)
|
||||
return ctypes.cast(data, ctypes.POINTER(arr_typ)).contents.value
|
||||
|
||||
def get_substitute_name(self):
|
||||
wchar_size = ctypes.sizeof(ctypes.wintypes.WCHAR)
|
||||
arr_typ = ctypes.wintypes.WCHAR * (self.substitute_name_length // wchar_size)
|
||||
data = ctypes.byref(self.path_buffer, self.substitute_name_offset)
|
||||
return ctypes.cast(data, ctypes.POINTER(arr_typ)).contents.value
|
217
libs/win/jaraco/windows/api/inet.py
Normal file
217
libs/win/jaraco/windows/api/inet.py
Normal file
|
@ -0,0 +1,217 @@
|
|||
import struct
|
||||
import ctypes.wintypes
|
||||
from ctypes.wintypes import DWORD, WCHAR, BYTE, BOOL
|
||||
|
||||
|
||||
# from mprapi.h
|
||||
MAX_INTERFACE_NAME_LEN = 2**8
|
||||
|
||||
# from iprtrmib.h
|
||||
MAXLEN_PHYSADDR = 2**3
|
||||
MAXLEN_IFDESCR = 2**8
|
||||
|
||||
# from iptypes.h
|
||||
MAX_ADAPTER_ADDRESS_LENGTH = 8
|
||||
MAX_DHCPV6_DUID_LENGTH = 130
|
||||
|
||||
|
||||
class MIB_IFROW(ctypes.Structure):
|
||||
_fields_ = (
|
||||
('name', WCHAR * MAX_INTERFACE_NAME_LEN),
|
||||
('index', DWORD),
|
||||
('type', DWORD),
|
||||
('MTU', DWORD),
|
||||
('speed', DWORD),
|
||||
('physical_address_length', DWORD),
|
||||
('physical_address_raw', BYTE * MAXLEN_PHYSADDR),
|
||||
('admin_status', DWORD),
|
||||
('operational_status', DWORD),
|
||||
('last_change', DWORD),
|
||||
('octets_received', DWORD),
|
||||
('unicast_packets_received', DWORD),
|
||||
('non_unicast_packets_received', DWORD),
|
||||
('incoming_discards', DWORD),
|
||||
('incoming_errors', DWORD),
|
||||
('incoming_unknown_protocols', DWORD),
|
||||
('octets_sent', DWORD),
|
||||
('unicast_packets_sent', DWORD),
|
||||
('non_unicast_packets_sent', DWORD),
|
||||
('outgoing_discards', DWORD),
|
||||
('outgoing_errors', DWORD),
|
||||
('outgoing_queue_length', DWORD),
|
||||
('description_length', DWORD),
|
||||
('description_raw', ctypes.c_char * MAXLEN_IFDESCR),
|
||||
)
|
||||
|
||||
def _get_binary_property(self, name):
|
||||
val_prop = '{0}_raw'.format(name)
|
||||
val = getattr(self, val_prop)
|
||||
len_prop = '{0}_length'.format(name)
|
||||
length = getattr(self, len_prop)
|
||||
return str(memoryview(val))[:length]
|
||||
|
||||
@property
|
||||
def physical_address(self):
|
||||
return self._get_binary_property('physical_address')
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return self._get_binary_property('description')
|
||||
|
||||
|
||||
class MIB_IFTABLE(ctypes.Structure):
|
||||
_fields_ = (
|
||||
('num_entries', DWORD), # dwNumEntries
|
||||
('entries', MIB_IFROW * 0), # table
|
||||
)
|
||||
|
||||
|
||||
class MIB_IPADDRROW(ctypes.Structure):
|
||||
_fields_ = (
|
||||
('address_num', DWORD),
|
||||
('index', DWORD),
|
||||
('mask', DWORD),
|
||||
('broadcast_address', DWORD),
|
||||
('reassembly_size', DWORD),
|
||||
('unused', ctypes.c_ushort),
|
||||
('type', ctypes.c_ushort),
|
||||
)
|
||||
|
||||
@property
|
||||
def address(self):
|
||||
"The address in big-endian"
|
||||
_ = struct.pack('L', self.address_num)
|
||||
return struct.unpack('!L', _)[0]
|
||||
|
||||
|
||||
class MIB_IPADDRTABLE(ctypes.Structure):
|
||||
_fields_ = (
|
||||
('num_entries', DWORD),
|
||||
('entries', MIB_IPADDRROW * 0),
|
||||
)
|
||||
|
||||
|
||||
class SOCKADDR(ctypes.Structure):
|
||||
_fields_ = (
|
||||
('family', ctypes.c_ushort),
|
||||
('data', ctypes.c_byte * 14),
|
||||
)
|
||||
|
||||
|
||||
LPSOCKADDR = ctypes.POINTER(SOCKADDR)
|
||||
|
||||
|
||||
class SOCKET_ADDRESS(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('address', LPSOCKADDR),
|
||||
('length', ctypes.c_int),
|
||||
]
|
||||
|
||||
|
||||
class _IP_ADAPTER_ADDRESSES_METRIC(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('length', ctypes.c_ulong),
|
||||
('interface_index', DWORD),
|
||||
]
|
||||
|
||||
|
||||
class _IP_ADAPTER_ADDRESSES_U1(ctypes.Union):
|
||||
_fields_ = [
|
||||
('alignment', ctypes.c_ulonglong),
|
||||
('metric', _IP_ADAPTER_ADDRESSES_METRIC),
|
||||
]
|
||||
|
||||
|
||||
class IP_ADAPTER_ADDRESSES(ctypes.Structure):
|
||||
pass
|
||||
|
||||
|
||||
LP_IP_ADAPTER_ADDRESSES = ctypes.POINTER(IP_ADAPTER_ADDRESSES)
|
||||
|
||||
# for now, just use void * for pointers to unused structures
|
||||
PIP_ADAPTER_UNICAST_ADDRESS = ctypes.c_void_p
|
||||
PIP_ADAPTER_ANYCAST_ADDRESS = ctypes.c_void_p
|
||||
PIP_ADAPTER_MULTICAST_ADDRESS = ctypes.c_void_p
|
||||
PIP_ADAPTER_DNS_SERVER_ADDRESS = ctypes.c_void_p
|
||||
PIP_ADAPTER_PREFIX = ctypes.c_void_p
|
||||
PIP_ADAPTER_WINS_SERVER_ADDRESS_LH = ctypes.c_void_p
|
||||
PIP_ADAPTER_GATEWAY_ADDRESS_LH = ctypes.c_void_p
|
||||
PIP_ADAPTER_DNS_SUFFIX = ctypes.c_void_p
|
||||
|
||||
IF_OPER_STATUS = ctypes.c_uint # this is an enum, consider
|
||||
# http://code.activestate.com/recipes/576415/
|
||||
IF_LUID = ctypes.c_uint64
|
||||
|
||||
NET_IF_COMPARTMENT_ID = ctypes.c_uint32
|
||||
GUID = ctypes.c_byte * 16
|
||||
NET_IF_NETWORK_GUID = GUID
|
||||
NET_IF_CONNECTION_TYPE = ctypes.c_uint # enum
|
||||
TUNNEL_TYPE = ctypes.c_uint # enum
|
||||
|
||||
IP_ADAPTER_ADDRESSES._fields_ = [
|
||||
# ('u', _IP_ADAPTER_ADDRESSES_U1),
|
||||
('length', ctypes.c_ulong),
|
||||
('interface_index', DWORD),
|
||||
('next', LP_IP_ADAPTER_ADDRESSES),
|
||||
('adapter_name', ctypes.c_char_p),
|
||||
('first_unicast_address', PIP_ADAPTER_UNICAST_ADDRESS),
|
||||
('first_anycast_address', PIP_ADAPTER_ANYCAST_ADDRESS),
|
||||
('first_multicast_address', PIP_ADAPTER_MULTICAST_ADDRESS),
|
||||
('first_dns_server_address', PIP_ADAPTER_DNS_SERVER_ADDRESS),
|
||||
('dns_suffix', ctypes.c_wchar_p),
|
||||
('description', ctypes.c_wchar_p),
|
||||
('friendly_name', ctypes.c_wchar_p),
|
||||
('byte', BYTE * MAX_ADAPTER_ADDRESS_LENGTH),
|
||||
('physical_address_length', DWORD),
|
||||
('flags', DWORD),
|
||||
('mtu', DWORD),
|
||||
('interface_type', DWORD),
|
||||
('oper_status', IF_OPER_STATUS),
|
||||
('ipv6_interface_index', DWORD),
|
||||
('zone_indices', DWORD),
|
||||
('first_prefix', PIP_ADAPTER_PREFIX),
|
||||
('transmit_link_speed', ctypes.c_uint64),
|
||||
('receive_link_speed', ctypes.c_uint64),
|
||||
('first_wins_server_address', PIP_ADAPTER_WINS_SERVER_ADDRESS_LH),
|
||||
('first_gateway_address', PIP_ADAPTER_GATEWAY_ADDRESS_LH),
|
||||
('ipv4_metric', ctypes.c_ulong),
|
||||
('ipv6_metric', ctypes.c_ulong),
|
||||
('luid', IF_LUID),
|
||||
('dhcpv4_server', SOCKET_ADDRESS),
|
||||
('compartment_id', NET_IF_COMPARTMENT_ID),
|
||||
('network_guid', NET_IF_NETWORK_GUID),
|
||||
('connection_type', NET_IF_CONNECTION_TYPE),
|
||||
('tunnel_type', TUNNEL_TYPE),
|
||||
('dhcpv6_server', SOCKET_ADDRESS),
|
||||
('dhcpv6_client_duid', ctypes.c_byte * MAX_DHCPV6_DUID_LENGTH),
|
||||
('dhcpv6_client_duid_length', ctypes.c_ulong),
|
||||
('dhcpv6_iaid', ctypes.c_ulong),
|
||||
('first_dns_suffix', PIP_ADAPTER_DNS_SUFFIX),
|
||||
]
|
||||
|
||||
# define some parameters to the API Functions
|
||||
GetIfTable = ctypes.windll.iphlpapi.GetIfTable
|
||||
GetIfTable.argtypes = [
|
||||
ctypes.POINTER(MIB_IFTABLE),
|
||||
ctypes.POINTER(ctypes.c_ulong),
|
||||
BOOL,
|
||||
]
|
||||
GetIfTable.restype = DWORD
|
||||
|
||||
GetIpAddrTable = ctypes.windll.iphlpapi.GetIpAddrTable
|
||||
GetIpAddrTable.argtypes = [
|
||||
ctypes.POINTER(MIB_IPADDRTABLE),
|
||||
ctypes.POINTER(ctypes.c_ulong),
|
||||
BOOL,
|
||||
]
|
||||
GetIpAddrTable.restype = DWORD
|
||||
|
||||
GetAdaptersAddresses = ctypes.windll.iphlpapi.GetAdaptersAddresses
|
||||
GetAdaptersAddresses.argtypes = [
|
||||
ctypes.c_ulong,
|
||||
ctypes.c_ulong,
|
||||
ctypes.c_void_p,
|
||||
ctypes.POINTER(IP_ADAPTER_ADDRESSES),
|
||||
ctypes.POINTER(ctypes.c_ulong),
|
||||
]
|
||||
GetAdaptersAddresses.restype = ctypes.c_ulong
|
9
libs/win/jaraco/windows/api/library.py
Normal file
9
libs/win/jaraco/windows/api/library.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
GetModuleFileName = ctypes.windll.kernel32.GetModuleFileNameW
|
||||
GetModuleFileName.argtypes = (
|
||||
ctypes.wintypes.HANDLE,
|
||||
ctypes.wintypes.LPWSTR,
|
||||
ctypes.wintypes.DWORD,
|
||||
)
|
||||
GetModuleFileName.restype = ctypes.wintypes.DWORD
|
45
libs/win/jaraco/windows/api/memory.py
Normal file
45
libs/win/jaraco/windows/api/memory.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
GMEM_MOVEABLE = 0x2
|
||||
|
||||
GlobalAlloc = ctypes.windll.kernel32.GlobalAlloc
|
||||
GlobalAlloc.argtypes = ctypes.wintypes.UINT, ctypes.c_size_t
|
||||
GlobalAlloc.restype = ctypes.wintypes.HANDLE
|
||||
|
||||
GlobalLock = ctypes.windll.kernel32.GlobalLock
|
||||
GlobalLock.argtypes = ctypes.wintypes.HGLOBAL,
|
||||
GlobalLock.restype = ctypes.wintypes.LPVOID
|
||||
|
||||
GlobalUnlock = ctypes.windll.kernel32.GlobalUnlock
|
||||
GlobalUnlock.argtypes = ctypes.wintypes.HGLOBAL,
|
||||
GlobalUnlock.restype = ctypes.wintypes.BOOL
|
||||
|
||||
GlobalSize = ctypes.windll.kernel32.GlobalSize
|
||||
GlobalSize.argtypes = ctypes.wintypes.HGLOBAL,
|
||||
GlobalSize.restype = ctypes.c_size_t
|
||||
|
||||
CreateFileMapping = ctypes.windll.kernel32.CreateFileMappingW
|
||||
CreateFileMapping.argtypes = [
|
||||
ctypes.wintypes.HANDLE,
|
||||
ctypes.c_void_p,
|
||||
ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.LPWSTR,
|
||||
]
|
||||
CreateFileMapping.restype = ctypes.wintypes.HANDLE
|
||||
|
||||
MapViewOfFile = ctypes.windll.kernel32.MapViewOfFile
|
||||
MapViewOfFile.restype = ctypes.wintypes.HANDLE
|
||||
|
||||
UnmapViewOfFile = ctypes.windll.kernel32.UnmapViewOfFile
|
||||
UnmapViewOfFile.argtypes = ctypes.wintypes.HANDLE,
|
||||
|
||||
RtlMoveMemory = ctypes.windll.kernel32.RtlMoveMemory
|
||||
RtlMoveMemory.argtypes = (
|
||||
ctypes.c_void_p,
|
||||
ctypes.c_void_p,
|
||||
ctypes.c_size_t,
|
||||
)
|
||||
|
||||
ctypes.windll.kernel32.LocalFree.argtypes = ctypes.wintypes.HLOCAL,
|
54
libs/win/jaraco/windows/api/message.py
Normal file
54
libs/win/jaraco/windows/api/message.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
jaraco.windows.message
|
||||
|
||||
Windows Messaging support
|
||||
"""
|
||||
|
||||
import ctypes
|
||||
from ctypes.wintypes import HWND, UINT, WPARAM, LPARAM, DWORD, LPVOID
|
||||
|
||||
import six
|
||||
|
||||
LRESULT = LPARAM
|
||||
|
||||
|
||||
class LPARAM_wstr(LPARAM):
|
||||
"""
|
||||
A special instance of LPARAM that can be constructed from a string
|
||||
instance (for functions such as SendMessage, whose LPARAM may point to
|
||||
a unicode string).
|
||||
"""
|
||||
@classmethod
|
||||
def from_param(cls, param):
|
||||
if isinstance(param, six.string_types):
|
||||
return LPVOID.from_param(six.text_type(param))
|
||||
return LPARAM.from_param(param)
|
||||
|
||||
|
||||
SendMessage = ctypes.windll.user32.SendMessageW
|
||||
SendMessage.argtypes = (HWND, UINT, WPARAM, LPARAM_wstr)
|
||||
SendMessage.restype = LRESULT
|
||||
|
||||
HWND_BROADCAST = 0xFFFF
|
||||
WM_SETTINGCHANGE = 0x1A
|
||||
|
||||
# constants from http://msdn.microsoft.com
|
||||
# /en-us/library/ms644952%28v=vs.85%29.aspx
|
||||
SMTO_ABORTIFHUNG = 0x02
|
||||
SMTO_BLOCK = 0x01
|
||||
SMTO_NORMAL = 0x00
|
||||
SMTO_NOTIMEOUTIFNOTHUNG = 0x08
|
||||
SMTO_ERRORONEXIT = 0x20
|
||||
|
||||
SendMessageTimeout = ctypes.windll.user32.SendMessageTimeoutW
|
||||
SendMessageTimeout.argtypes = SendMessage.argtypes + (
|
||||
UINT, UINT, ctypes.POINTER(DWORD)
|
||||
)
|
||||
SendMessageTimeout.restype = LRESULT
|
||||
|
||||
|
||||
def unicode_as_lparam(source):
|
||||
pointer = ctypes.cast(ctypes.c_wchar_p(source), ctypes.c_void_p)
|
||||
return LPARAM(pointer.value)
|
30
libs/win/jaraco/windows/api/net.py
Normal file
30
libs/win/jaraco/windows/api/net.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
# MPR - Multiple Provider Router
|
||||
mpr = ctypes.windll.mpr
|
||||
|
||||
RESOURCETYPE_ANY = 0
|
||||
|
||||
|
||||
class NETRESOURCE(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('scope', ctypes.wintypes.DWORD),
|
||||
('type', ctypes.wintypes.DWORD),
|
||||
('display_type', ctypes.wintypes.DWORD),
|
||||
('usage', ctypes.wintypes.DWORD),
|
||||
('local_name', ctypes.wintypes.LPWSTR),
|
||||
('remote_name', ctypes.wintypes.LPWSTR),
|
||||
('comment', ctypes.wintypes.LPWSTR),
|
||||
('provider', ctypes.wintypes.LPWSTR),
|
||||
]
|
||||
|
||||
|
||||
LPNETRESOURCE = ctypes.POINTER(NETRESOURCE)
|
||||
|
||||
WNetAddConnection2 = mpr.WNetAddConnection2W
|
||||
WNetAddConnection2.argtypes = (
|
||||
LPNETRESOURCE,
|
||||
ctypes.wintypes.LPCWSTR,
|
||||
ctypes.wintypes.LPCWSTR,
|
||||
ctypes.wintypes.DWORD,
|
||||
)
|
37
libs/win/jaraco/windows/api/power.py
Normal file
37
libs/win/jaraco/windows/api/power.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
|
||||
class SYSTEM_POWER_STATUS(ctypes.Structure):
|
||||
_fields_ = (
|
||||
('ac_line_status', ctypes.wintypes.BYTE),
|
||||
('battery_flag', ctypes.wintypes.BYTE),
|
||||
('battery_life_percent', ctypes.wintypes.BYTE),
|
||||
('reserved', ctypes.wintypes.BYTE),
|
||||
('battery_life_time', ctypes.wintypes.DWORD),
|
||||
('battery_full_life_time', ctypes.wintypes.DWORD),
|
||||
)
|
||||
|
||||
@property
|
||||
def ac_line_status_string(self):
|
||||
return {
|
||||
0: 'offline', 1: 'online', 255: 'unknown'}[self.ac_line_status]
|
||||
|
||||
|
||||
LPSYSTEM_POWER_STATUS = ctypes.POINTER(SYSTEM_POWER_STATUS)
|
||||
GetSystemPowerStatus = ctypes.windll.kernel32.GetSystemPowerStatus
|
||||
GetSystemPowerStatus.argtypes = LPSYSTEM_POWER_STATUS,
|
||||
GetSystemPowerStatus.restype = ctypes.wintypes.BOOL
|
||||
|
||||
SetThreadExecutionState = ctypes.windll.kernel32.SetThreadExecutionState
|
||||
SetThreadExecutionState.argtypes = [ctypes.c_uint]
|
||||
SetThreadExecutionState.restype = ctypes.c_uint
|
||||
|
||||
|
||||
class ES:
|
||||
"""
|
||||
Execution state constants
|
||||
"""
|
||||
continuous = 0x80000000
|
||||
system_required = 1
|
||||
display_required = 2
|
||||
awaymode_required = 0x40
|
117
libs/win/jaraco/windows/api/privilege.py
Normal file
117
libs/win/jaraco/windows/api/privilege.py
Normal file
|
@ -0,0 +1,117 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
|
||||
class LUID(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('low_part', ctypes.wintypes.DWORD),
|
||||
('high_part', ctypes.wintypes.LONG),
|
||||
]
|
||||
|
||||
def __eq__(self, other):
|
||||
return (
|
||||
self.high_part == other.high_part and
|
||||
self.low_part == other.low_part
|
||||
)
|
||||
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
||||
|
||||
LookupPrivilegeValue = ctypes.windll.advapi32.LookupPrivilegeValueW
|
||||
LookupPrivilegeValue.argtypes = (
|
||||
ctypes.wintypes.LPWSTR, # system name
|
||||
ctypes.wintypes.LPWSTR, # name
|
||||
ctypes.POINTER(LUID),
|
||||
)
|
||||
LookupPrivilegeValue.restype = ctypes.wintypes.BOOL
|
||||
|
||||
|
||||
class TOKEN_INFORMATION_CLASS:
|
||||
TokenUser = 1
|
||||
TokenGroups = 2
|
||||
TokenPrivileges = 3
|
||||
# ... see http://msdn.microsoft.com/en-us/library/aa379626%28VS.85%29.aspx
|
||||
|
||||
|
||||
SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001
|
||||
SE_PRIVILEGE_ENABLED = 0x00000002
|
||||
SE_PRIVILEGE_REMOVED = 0x00000004
|
||||
SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000
|
||||
|
||||
|
||||
class LUID_AND_ATTRIBUTES(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('LUID', LUID),
|
||||
('attributes', ctypes.wintypes.DWORD),
|
||||
]
|
||||
|
||||
def is_enabled(self):
|
||||
return bool(self.attributes & SE_PRIVILEGE_ENABLED)
|
||||
|
||||
def enable(self):
|
||||
self.attributes |= SE_PRIVILEGE_ENABLED
|
||||
|
||||
def get_name(self):
|
||||
size = ctypes.wintypes.DWORD(10240)
|
||||
buf = ctypes.create_unicode_buffer(size.value)
|
||||
res = LookupPrivilegeName(None, self.LUID, buf, size)
|
||||
if res == 0:
|
||||
raise RuntimeError
|
||||
return buf[:size.value]
|
||||
|
||||
def __str__(self):
|
||||
res = self.get_name()
|
||||
if self.is_enabled():
|
||||
res += ' (enabled)'
|
||||
return res
|
||||
|
||||
|
||||
LookupPrivilegeName = ctypes.windll.advapi32.LookupPrivilegeNameW
|
||||
LookupPrivilegeName.argtypes = (
|
||||
ctypes.wintypes.LPWSTR, # lpSystemName
|
||||
ctypes.POINTER(LUID), # lpLuid
|
||||
ctypes.wintypes.LPWSTR, # lpName
|
||||
ctypes.POINTER(ctypes.wintypes.DWORD), # cchName
|
||||
)
|
||||
LookupPrivilegeName.restype = ctypes.wintypes.BOOL
|
||||
|
||||
|
||||
class TOKEN_PRIVILEGES(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('count', ctypes.wintypes.DWORD),
|
||||
('privileges', LUID_AND_ATTRIBUTES * 0),
|
||||
]
|
||||
|
||||
def get_array(self):
|
||||
array_type = LUID_AND_ATTRIBUTES * self.count
|
||||
privileges = ctypes.cast(
|
||||
self.privileges, ctypes.POINTER(array_type)).contents
|
||||
return privileges
|
||||
|
||||
def __iter__(self):
|
||||
return iter(self.get_array())
|
||||
|
||||
|
||||
PTOKEN_PRIVILEGES = ctypes.POINTER(TOKEN_PRIVILEGES)
|
||||
|
||||
GetTokenInformation = ctypes.windll.advapi32.GetTokenInformation
|
||||
GetTokenInformation.argtypes = [
|
||||
ctypes.wintypes.HANDLE, # TokenHandle
|
||||
ctypes.c_uint, # TOKEN_INFORMATION_CLASS value
|
||||
ctypes.c_void_p, # TokenInformation
|
||||
ctypes.wintypes.DWORD, # TokenInformationLength
|
||||
ctypes.POINTER(ctypes.wintypes.DWORD), # ReturnLength
|
||||
]
|
||||
GetTokenInformation.restype = ctypes.wintypes.BOOL
|
||||
|
||||
# http://msdn.microsoft.com/en-us/library/aa375202%28VS.85%29.aspx
|
||||
AdjustTokenPrivileges = ctypes.windll.advapi32.AdjustTokenPrivileges
|
||||
AdjustTokenPrivileges.restype = ctypes.wintypes.BOOL
|
||||
AdjustTokenPrivileges.argtypes = [
|
||||
ctypes.wintypes.HANDLE, # TokenHandle
|
||||
ctypes.wintypes.BOOL, # DisableAllPrivileges
|
||||
PTOKEN_PRIVILEGES, # NewState (optional)
|
||||
ctypes.wintypes.DWORD, # BufferLength of PreviousState
|
||||
PTOKEN_PRIVILEGES, # PreviousState (out, optional)
|
||||
ctypes.POINTER(ctypes.wintypes.DWORD), # ReturnLength
|
||||
]
|
11
libs/win/jaraco/windows/api/process.py
Normal file
11
libs/win/jaraco/windows/api/process.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
TOKEN_ALL_ACCESS = 0xf01ff
|
||||
|
||||
GetCurrentProcess = ctypes.windll.kernel32.GetCurrentProcess
|
||||
GetCurrentProcess.restype = ctypes.wintypes.HANDLE
|
||||
OpenProcessToken = ctypes.windll.advapi32.OpenProcessToken
|
||||
OpenProcessToken.argtypes = (
|
||||
ctypes.wintypes.HANDLE, ctypes.wintypes.DWORD,
|
||||
ctypes.POINTER(ctypes.wintypes.HANDLE))
|
||||
OpenProcessToken.restype = ctypes.wintypes.BOOL
|
139
libs/win/jaraco/windows/api/security.py
Normal file
139
libs/win/jaraco/windows/api/security.py
Normal file
|
@ -0,0 +1,139 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
# from WinNT.h
|
||||
READ_CONTROL = 0x00020000
|
||||
STANDARD_RIGHTS_REQUIRED = 0x000F0000
|
||||
STANDARD_RIGHTS_READ = READ_CONTROL
|
||||
STANDARD_RIGHTS_WRITE = READ_CONTROL
|
||||
STANDARD_RIGHTS_EXECUTE = READ_CONTROL
|
||||
STANDARD_RIGHTS_ALL = 0x001F0000
|
||||
|
||||
# from NTSecAPI.h
|
||||
POLICY_VIEW_LOCAL_INFORMATION = 0x00000001
|
||||
POLICY_VIEW_AUDIT_INFORMATION = 0x00000002
|
||||
POLICY_GET_PRIVATE_INFORMATION = 0x00000004
|
||||
POLICY_TRUST_ADMIN = 0x00000008
|
||||
POLICY_CREATE_ACCOUNT = 0x00000010
|
||||
POLICY_CREATE_SECRET = 0x00000020
|
||||
POLICY_CREATE_PRIVILEGE = 0x00000040
|
||||
POLICY_SET_DEFAULT_QUOTA_LIMITS = 0x00000080
|
||||
POLICY_SET_AUDIT_REQUIREMENTS = 0x00000100
|
||||
POLICY_AUDIT_LOG_ADMIN = 0x00000200
|
||||
POLICY_SERVER_ADMIN = 0x00000400
|
||||
POLICY_LOOKUP_NAMES = 0x00000800
|
||||
POLICY_NOTIFICATION = 0x00001000
|
||||
|
||||
POLICY_ALL_ACCESS = (
|
||||
STANDARD_RIGHTS_REQUIRED |
|
||||
POLICY_VIEW_LOCAL_INFORMATION |
|
||||
POLICY_VIEW_AUDIT_INFORMATION |
|
||||
POLICY_GET_PRIVATE_INFORMATION |
|
||||
POLICY_TRUST_ADMIN |
|
||||
POLICY_CREATE_ACCOUNT |
|
||||
POLICY_CREATE_SECRET |
|
||||
POLICY_CREATE_PRIVILEGE |
|
||||
POLICY_SET_DEFAULT_QUOTA_LIMITS |
|
||||
POLICY_SET_AUDIT_REQUIREMENTS |
|
||||
POLICY_AUDIT_LOG_ADMIN |
|
||||
POLICY_SERVER_ADMIN |
|
||||
POLICY_LOOKUP_NAMES)
|
||||
|
||||
|
||||
POLICY_READ = (
|
||||
STANDARD_RIGHTS_READ |
|
||||
POLICY_VIEW_AUDIT_INFORMATION |
|
||||
POLICY_GET_PRIVATE_INFORMATION)
|
||||
|
||||
POLICY_WRITE = (
|
||||
STANDARD_RIGHTS_WRITE |
|
||||
POLICY_TRUST_ADMIN |
|
||||
POLICY_CREATE_ACCOUNT |
|
||||
POLICY_CREATE_SECRET |
|
||||
POLICY_CREATE_PRIVILEGE |
|
||||
POLICY_SET_DEFAULT_QUOTA_LIMITS |
|
||||
POLICY_SET_AUDIT_REQUIREMENTS |
|
||||
POLICY_AUDIT_LOG_ADMIN |
|
||||
POLICY_SERVER_ADMIN)
|
||||
|
||||
POLICY_EXECUTE = (
|
||||
STANDARD_RIGHTS_EXECUTE |
|
||||
POLICY_VIEW_LOCAL_INFORMATION |
|
||||
POLICY_LOOKUP_NAMES)
|
||||
|
||||
|
||||
class TokenAccess:
|
||||
TOKEN_QUERY = 0x8
|
||||
|
||||
|
||||
class TokenInformationClass:
|
||||
TokenUser = 1
|
||||
|
||||
|
||||
class TOKEN_USER(ctypes.Structure):
|
||||
num = 1
|
||||
_fields_ = [
|
||||
('SID', ctypes.c_void_p),
|
||||
('ATTRIBUTES', ctypes.wintypes.DWORD),
|
||||
]
|
||||
|
||||
|
||||
class SECURITY_DESCRIPTOR(ctypes.Structure):
|
||||
"""
|
||||
typedef struct _SECURITY_DESCRIPTOR
|
||||
{
|
||||
UCHAR Revision;
|
||||
UCHAR Sbz1;
|
||||
SECURITY_DESCRIPTOR_CONTROL Control;
|
||||
PSID Owner;
|
||||
PSID Group;
|
||||
PACL Sacl;
|
||||
PACL Dacl;
|
||||
} SECURITY_DESCRIPTOR;
|
||||
"""
|
||||
SECURITY_DESCRIPTOR_CONTROL = ctypes.wintypes.USHORT
|
||||
REVISION = 1
|
||||
|
||||
_fields_ = [
|
||||
('Revision', ctypes.c_ubyte),
|
||||
('Sbz1', ctypes.c_ubyte),
|
||||
('Control', SECURITY_DESCRIPTOR_CONTROL),
|
||||
('Owner', ctypes.c_void_p),
|
||||
('Group', ctypes.c_void_p),
|
||||
('Sacl', ctypes.c_void_p),
|
||||
('Dacl', ctypes.c_void_p),
|
||||
]
|
||||
|
||||
|
||||
class SECURITY_ATTRIBUTES(ctypes.Structure):
|
||||
"""
|
||||
typedef struct _SECURITY_ATTRIBUTES {
|
||||
DWORD nLength;
|
||||
LPVOID lpSecurityDescriptor;
|
||||
BOOL bInheritHandle;
|
||||
} SECURITY_ATTRIBUTES;
|
||||
"""
|
||||
_fields_ = [
|
||||
('nLength', ctypes.wintypes.DWORD),
|
||||
('lpSecurityDescriptor', ctypes.c_void_p),
|
||||
('bInheritHandle', ctypes.wintypes.BOOL),
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SECURITY_ATTRIBUTES, self).__init__(*args, **kwargs)
|
||||
self.nLength = ctypes.sizeof(SECURITY_ATTRIBUTES)
|
||||
|
||||
@property
|
||||
def descriptor(self):
|
||||
return self._descriptor
|
||||
|
||||
@descriptor.setter
|
||||
def descriptor(self, value):
|
||||
self._descriptor = value
|
||||
self.lpSecurityDescriptor = ctypes.addressof(value)
|
||||
|
||||
|
||||
ctypes.windll.advapi32.SetSecurityDescriptorOwner.argtypes = (
|
||||
ctypes.POINTER(SECURITY_DESCRIPTOR),
|
||||
ctypes.c_void_p,
|
||||
ctypes.wintypes.BOOL,
|
||||
)
|
130
libs/win/jaraco/windows/api/shell.py
Normal file
130
libs/win/jaraco/windows/api/shell.py
Normal file
|
@ -0,0 +1,130 @@
|
|||
import ctypes.wintypes
|
||||
BOOL = ctypes.wintypes.BOOL
|
||||
|
||||
|
||||
class SHELLSTATE(ctypes.Structure):
|
||||
_fields_ = [
|
||||
('show_all_objects', BOOL, 1),
|
||||
('show_extensions', BOOL, 1),
|
||||
('no_confirm_recycle', BOOL, 1),
|
||||
('show_sys_files', BOOL, 1),
|
||||
('show_comp_color', BOOL, 1),
|
||||
('double_click_in_web_view', BOOL, 1),
|
||||
('desktop_HTML', BOOL, 1),
|
||||
('win95_classic', BOOL, 1),
|
||||
('dont_pretty_path', BOOL, 1),
|
||||
('show_attrib_col', BOOL, 1),
|
||||
('map_network_drive_button', BOOL, 1),
|
||||
('show_info_tip', BOOL, 1),
|
||||
('hide_icons', BOOL, 1),
|
||||
('web_view', BOOL, 1),
|
||||
('filter', BOOL, 1),
|
||||
('show_super_hidden', BOOL, 1),
|
||||
('no_net_crawling', BOOL, 1),
|
||||
('win95_unused', ctypes.wintypes.DWORD),
|
||||
('param_sort', ctypes.wintypes.LONG),
|
||||
('sort_direction', ctypes.c_int),
|
||||
('version', ctypes.wintypes.UINT),
|
||||
('not_used', ctypes.wintypes.UINT),
|
||||
('sep_process', BOOL, 1),
|
||||
('start_panel_on', BOOL, 1),
|
||||
('show_start_page', BOOL, 1),
|
||||
('auto_check_select', BOOL, 1),
|
||||
('icons_only', BOOL, 1),
|
||||
('show_type_overlay', BOOL, 1),
|
||||
('spare_flags', ctypes.wintypes.UINT, 13),
|
||||
]
|
||||
|
||||
|
||||
SSF_SHOWALLOBJECTS = 0x00000001
|
||||
"The fShowAllObjects member is being requested."
|
||||
|
||||
SSF_SHOWEXTENSIONS = 0x00000002
|
||||
"The fShowExtensions member is being requested."
|
||||
|
||||
SSF_HIDDENFILEEXTS = 0x00000004
|
||||
"Not used."
|
||||
|
||||
SSF_SERVERADMINUI = 0x00000004
|
||||
"Not used."
|
||||
|
||||
SSF_SHOWCOMPCOLOR = 0x00000008
|
||||
"The fShowCompColor member is being requested."
|
||||
|
||||
SSF_SORTCOLUMNS = 0x00000010
|
||||
"The lParamSort and iSortDirection members are being requested."
|
||||
|
||||
SSF_SHOWSYSFILES = 0x00000020
|
||||
"The fShowSysFiles member is being requested."
|
||||
|
||||
SSF_DOUBLECLICKINWEBVIEW = 0x00000080
|
||||
"The fDoubleClickInWebView member is being requested."
|
||||
|
||||
SSF_SHOWATTRIBCOL = 0x00000100
|
||||
"The fShowAttribCol member is being requested. (Windows Vista: Not used.)"
|
||||
|
||||
SSF_DESKTOPHTML = 0x00000200
|
||||
"""
|
||||
The fDesktopHTML member is being requested. Set is not available.
|
||||
Instead, for versions of Microsoft Windows prior to Windows XP,
|
||||
enable Desktop HTML by IActiveDesktop. The use of IActiveDesktop
|
||||
for this purpose, however, is not recommended for Windows XP and
|
||||
later versions of Windows, and is deprecated in Windows Vista.
|
||||
"""
|
||||
|
||||
SSF_WIN95CLASSIC = 0x00000400
|
||||
"The fWin95Classic member is being requested."
|
||||
|
||||
SSF_DONTPRETTYPATH = 0x00000800
|
||||
"The fDontPrettyPath member is being requested."
|
||||
|
||||
SSF_MAPNETDRVBUTTON = 0x00001000
|
||||
"The fMapNetDrvBtn member is being requested."
|
||||
|
||||
SSF_SHOWINFOTIP = 0x00002000
|
||||
"The fShowInfoTip member is being requested."
|
||||
|
||||
SSF_HIDEICONS = 0x00004000
|
||||
"The fHideIcons member is being requested."
|
||||
|
||||
SSF_NOCONFIRMRECYCLE = 0x00008000
|
||||
"The fNoConfirmRecycle member is being requested."
|
||||
|
||||
SSF_FILTER = 0x00010000
|
||||
"The fFilter member is being requested. (Windows Vista: Not used.)"
|
||||
|
||||
SSF_WEBVIEW = 0x00020000
|
||||
"The fWebView member is being requested."
|
||||
|
||||
SSF_SHOWSUPERHIDDEN = 0x00040000
|
||||
"The fShowSuperHidden member is being requested."
|
||||
|
||||
SSF_SEPPROCESS = 0x00080000
|
||||
"The fSepProcess member is being requested."
|
||||
|
||||
SSF_NONETCRAWLING = 0x00100000
|
||||
"Windows XP and later. The fNoNetCrawling member is being requested."
|
||||
|
||||
SSF_STARTPANELON = 0x00200000
|
||||
"Windows XP and later. The fStartPanelOn member is being requested."
|
||||
|
||||
SSF_SHOWSTARTPAGE = 0x00400000
|
||||
"Not used."
|
||||
|
||||
SSF_AUTOCHECKSELECT = 0x00800000
|
||||
"Windows Vista and later. The fAutoCheckSelect member is being requested."
|
||||
|
||||
SSF_ICONSONLY = 0x01000000
|
||||
"Windows Vista and later. The fIconsOnly member is being requested."
|
||||
|
||||
SSF_SHOWTYPEOVERLAY = 0x02000000
|
||||
"Windows Vista and later. The fShowTypeOverlay member is being requested."
|
||||
|
||||
|
||||
SHGetSetSettings = ctypes.windll.shell32.SHGetSetSettings
|
||||
SHGetSetSettings.argtypes = [
|
||||
ctypes.POINTER(SHELLSTATE),
|
||||
ctypes.wintypes.DWORD,
|
||||
ctypes.wintypes.BOOL, # get or set (True: set)
|
||||
]
|
||||
SHGetSetSettings.restype = None
|
14
libs/win/jaraco/windows/api/system.py
Normal file
14
libs/win/jaraco/windows/api/system.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
SystemParametersInfo = ctypes.windll.user32.SystemParametersInfoW
|
||||
SystemParametersInfo.argtypes = (
|
||||
ctypes.wintypes.UINT,
|
||||
ctypes.wintypes.UINT,
|
||||
ctypes.c_void_p,
|
||||
ctypes.wintypes.UINT,
|
||||
)
|
||||
|
||||
SPI_GETACTIVEWINDOWTRACKING = 0x1000
|
||||
SPI_SETACTIVEWINDOWTRACKING = 0x1001
|
||||
SPI_GETACTIVEWNDTRKTIMEOUT = 0x2002
|
||||
SPI_SETACTIVEWNDTRKTIMEOUT = 0x2003
|
10
libs/win/jaraco/windows/api/user.py
Normal file
10
libs/win/jaraco/windows/api/user.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
import ctypes.wintypes
|
||||
|
||||
try:
|
||||
from ctypes.wintypes import LPDWORD
|
||||
except ImportError:
|
||||
LPDWORD = ctypes.POINTER(ctypes.wintypes.DWORD)
|
||||
|
||||
GetUserName = ctypes.windll.advapi32.GetUserNameW
|
||||
GetUserName.argtypes = ctypes.wintypes.LPWSTR, LPDWORD
|
||||
GetUserName.restype = ctypes.wintypes.DWORD
|
Loading…
Add table
Add a link
Reference in a new issue