本文整理汇总了Python中ctypes.windll.kernel32方法的典型用法代码示例。如果您正苦于以下问题:Python windll.kernel32方法的具体用法?Python windll.kernel32怎么用?Python windll.kernel32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes.windll
的用法示例。
在下文中一共展示了windll.kernel32方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _open
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def _open(self, dwProcessId, debug=False):
if debug:
ppsidOwner = DWORD()
ppsidGroup = DWORD()
ppDacl = DWORD()
ppSacl = DWORD()
ppSecurityDescriptor = SECURITY_DESCRIPTOR()
process = kernel32.OpenProcess(262144, 0, dwProcessId)
advapi32.GetSecurityInfo(kernel32.GetCurrentProcess(), 6, 0, byref(ppsidOwner), byref(ppsidGroup), byref(ppDacl), byref(ppSacl), byref(ppSecurityDescriptor))
advapi32.SetSecurityInfo(process, 6, DACL_SECURITY_INFORMATION | UNPROTECTED_DACL_SECURITY_INFORMATION, None, None, ppSecurityDescriptor.dacl, ppSecurityDescriptor.group)
kernel32.CloseHandle(process)
self.h_process = kernel32.OpenProcess(2035711, 0, dwProcessId)
if self.h_process is not None:
self.isProcessOpen = True
self.pid = dwProcessId
return True
return False
示例2: write_bytes
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def write_bytes(self, address, data):
address = int(address)
if not self.isProcessOpen:
raise ProcessException("Can't write_bytes(%s, %s), process %s is not open" % (address, data, self.pid))
buffer = create_string_buffer(data)
sizeWriten = c_size_t(0)
bufferSize = sizeof(buffer) - 1
_address = address
_length = bufferSize + 1
try:
old_protect = self.VirtualProtectEx(_address, _length, PAGE_EXECUTE_READWRITE)
except:
pass
res = kernel32.WriteProcessMemory(self.h_process, address, buffer, bufferSize, byref(sizeWriten))
try:
self.VirtualProtectEx(_address, _length, old_protect)
except:
pass
return res
示例3: _get_geometry
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def _get_geometry(self):
"""Get details about the disk size bounds."""
geom = Win32_DiskGeometry()
bytes_returned = wintypes.DWORD()
ret_val = kernel32.DeviceIoControl(
self._handle,
winioctlcon.IOCTL_DISK_GET_DRIVE_GEOMETRY,
0,
0,
ctypes.byref(geom),
ctypes.sizeof(geom),
ctypes.byref(bytes_returned),
0)
if not ret_val:
raise exception.WindowsCloudbaseInitException(
"Cannot get disk geometry: %r")
_sector_size = geom.BytesPerSector
_disk_size = (geom.Cylinders * geom.TracksPerCylinder *
geom.SectorsPerTrack * geom.BytesPerSector)
fixed = geom.MediaType == Win32_DiskGeometry.FixedMedia
return _sector_size, _disk_size, fixed
示例4: win_handle_is_a_console
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def win_handle_is_a_console(handle):
"""Returns True if a Windows file handle is a handle to a console."""
# These types are available on linux but not Mac.
# pylint: disable=no-name-in-module,F0401
from ctypes import byref, POINTER, windll, WINFUNCTYPE
from ctypes.wintypes import BOOL, DWORD, HANDLE
FILE_TYPE_CHAR = 0x0002
FILE_TYPE_REMOTE = 0x8000
INVALID_HANDLE_VALUE = DWORD(-1).value
# <http://msdn.microsoft.com/en-us/library/ms683167.aspx>
GetConsoleMode = WINFUNCTYPE(BOOL, HANDLE, POINTER(DWORD))(
('GetConsoleMode', windll.kernel32))
# <http://msdn.microsoft.com/en-us/library/aa364960.aspx>
GetFileType = WINFUNCTYPE(DWORD, DWORD)(('GetFileType', windll.kernel32))
# GetStdHandle returns INVALID_HANDLE_VALUE, NULL, or a valid handle.
if handle == INVALID_HANDLE_VALUE or handle is None:
return False
return (
(GetFileType(handle) & ~FILE_TYPE_REMOTE) == FILE_TYPE_CHAR and
GetConsoleMode(handle, byref(DWORD())))
示例5: open
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def open(self):
access = self.GENERIC_READ
share_mode = self.FILE_SHARE_READ
if self._allow_write:
access |= self.GENERIC_WRITE
share_mode |= self.FILE_SHARE_WRITE
attributes = 0
else:
attributes = self.FILE_ATTRIBUTE_READONLY
handle = kernel32.CreateFileW(
ctypes.c_wchar_p(self._path),
access,
share_mode,
0,
self.OPEN_EXISTING,
attributes,
0)
if handle == self.INVALID_HANDLE_VALUE:
raise exception.WindowsCloudbaseInitException(
'Cannot open file: %r')
self._handle = handle
self._sector_size, self._disk_size, self.fixed =\
self._get_geometry()
示例6: __init__
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def __init__(self, console_handle, fileno, stream_name, encoding):
super(WinUnicodeConsoleOutput, self).__init__(
fileno, '<Unicode console %s>' % stream_name, encoding)
# Handle to use for WriteConsoleW
self._console_handle = console_handle
# Loads the necessary function.
# These types are available on linux but not Mac.
# pylint: disable=no-name-in-module,F0401
from ctypes import byref, GetLastError, POINTER, windll, WINFUNCTYPE
from ctypes.wintypes import BOOL, DWORD, HANDLE, LPWSTR
from ctypes.wintypes import LPVOID # pylint: disable=no-name-in-module
self._DWORD = DWORD
self._byref = byref
# <http://msdn.microsoft.com/en-us/library/ms687401.aspx>
self._WriteConsoleW = WINFUNCTYPE(
BOOL, HANDLE, LPWSTR, DWORD, POINTER(DWORD), LPVOID)(
('WriteConsoleW', windll.kernel32))
self._GetLastError = GetLastError
示例7: win32_utf8_argv
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def win32_utf8_argv():
"""Uses shell32.GetCommandLineArgvW to get sys.argv as a list of Unicode
strings.
Versions 2.x of Python don't support Unicode in sys.argv on
Windows, with the underlying Windows API instead replacing multi-byte
characters with '?'.
"""
from ctypes import POINTER, byref, cdll, c_int, windll
from ctypes.wintypes import LPCWSTR, LPWSTR
GetCommandLineW = cdll.kernel32.GetCommandLineW
GetCommandLineW.argtypes = []
GetCommandLineW.restype = LPCWSTR
CommandLineToArgvW = windll.shell32.CommandLineToArgvW
CommandLineToArgvW.argtypes = [LPCWSTR, POINTER(c_int)]
CommandLineToArgvW.restype = POINTER(LPWSTR)
cmd = GetCommandLineW()
argc = c_int(0)
argv = CommandLineToArgvW(cmd, byref(argc))
argnum = argc.value
sysnum = len(sys.argv)
result = []
if argnum > 0:
# Remove Python executable and commands if present
start = argnum - sysnum
for i in range(start, argnum):
result.append(argv[i].encode('utf-8'))
return result
# enable unicode output to windows console
# https://stackoverflow.com/questions/878972/windows-cmd-encoding-change-causes-python-crash
示例8: list
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def list():
processes=[]
arr = c_ulong * 256
lpidProcess= arr()
cb = sizeof(lpidProcess)
cbNeeded = c_ulong()
hModule = c_ulong()
count = c_ulong()
modname = create_string_buffer(100)
PROCESS_QUERY_INFORMATION = 0x0400
PROCESS_VM_READ = 0x0010
psapi.EnumProcesses(byref(lpidProcess), cb, byref(cbNeeded))
nReturned = cbNeeded.value/sizeof(c_ulong())
pidProcess = [i for i in lpidProcess][:nReturned]
for pid in pidProcess:
proc={ "pid": int(pid) }
hProcess = kernel32.OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, False, pid)
if hProcess:
psapi.EnumProcessModules(hProcess, byref(hModule), sizeof(hModule), byref(count))
psapi.GetModuleBaseNameA(hProcess, hModule.value, modname, sizeof(modname))
proc["name"]=modname.value
kernel32.CloseHandle(hProcess)
processes.append(proc)
return processes
示例9: close
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def close(self):
if self.h_process is not None:
ret = kernel32.CloseHandle(self.h_process) == 1
if ret:
self.h_process = None
self.pid = None
self.isProcessOpen = False
return ret
return False
示例10: GetSystemInfo
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def GetSystemInfo(self):
si = SYSTEM_INFO()
kernel32.GetSystemInfo(byref(si))
return si
示例11: GetNativeSystemInfo
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def GetNativeSystemInfo(self):
si = SYSTEM_INFO()
kernel32.GetNativeSystemInfo(byref(si))
return si
示例12: list_modules
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def list_modules(self):
module_list = []
if self.pid is not None:
hModuleSnap = CreateToolhelp32Snapshot(TH32CS_CLASS.SNAPMODULE, self.pid)
if hModuleSnap is not None:
module_entry = MODULEENTRY32()
module_entry.dwSize = sizeof(module_entry)
success = Module32First(hModuleSnap, byref(module_entry))
while success:
if module_entry.th32ProcessID == self.pid:
module_list.append(copy.copy(module_entry))
success = Module32Next(hModuleSnap, byref(module_entry))
kernel32.CloseHandle(hModuleSnap)
return module_list
示例13: _seek
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def _seek(self, offset):
high = wintypes.DWORD(offset >> 32)
low = wintypes.DWORD(offset & 0xFFFFFFFF)
ret_val = kernel32.SetFilePointer(self._handle, low,
ctypes.byref(high),
self.FILE_BEGIN)
if ret_val == self.INVALID_SET_FILE_POINTER:
raise exception.WindowsCloudbaseInitException(
"Seek error: %r")
示例14: _read
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def _read(self, size):
buff = ctypes.create_string_buffer(size)
bytes_read = wintypes.DWORD()
ret_val = kernel32.ReadFile(self._handle, buff, size,
ctypes.byref(bytes_read), 0)
if not ret_val:
raise exception.WindowsCloudbaseInitException(
"Read exception: %r")
return buff.raw[:bytes_read.value] # all bytes without the null byte
示例15: close
# 需要导入模块: from ctypes import windll [as 别名]
# 或者: from ctypes.windll import kernel32 [as 别名]
def close(self):
if self._handle:
kernel32.CloseHandle(self._handle)
self._handle = None