id int64 0 190k | prompt stringlengths 21 13.4M | docstring stringlengths 1 12k ⌀ |
|---|---|---|
177,172 | from winappdbg.win32.defines import *
from winappdbg.win32.kernel32 import LocalFree
def FindExecutableW(lpFile, lpDirectory = None):
_FindExecutableW = windll.shell32.FindExecutableW
_FindExecutableW.argtypes = [LPWSTR, LPWSTR, LPWSTR]
_FindExecutableW.restype = HINSTANCE
lpResult = ctypes.create_unicode_buffer(MAX_PATH)
success = _FindExecutableW(lpFile, lpDirectory, lpResult)
success = ctypes.cast(success, ctypes.c_void_p)
success = success.value
if not success > 32: # weird! isn't it?
raise ctypes.WinError(success)
return lpResult.value | null |
177,173 | from winappdbg.win32.defines import *
from winappdbg.win32.kernel32 import LocalFree
SHGFP_TYPE_CURRENT = 0
def SHGetFolderPathA(nFolder, hToken = None, dwFlags = SHGFP_TYPE_CURRENT):
_SHGetFolderPathA = windll.shell32.SHGetFolderPathA # shfolder.dll in older win versions
_SHGetFolderPathA.argtypes = [HWND, ctypes.c_int, HANDLE, DWORD, LPSTR]
_SHGetFolderPathA.restype = HRESULT
_SHGetFolderPathA.errcheck = RaiseIfNotZero # S_OK == 0
pszPath = ctypes.create_string_buffer(MAX_PATH + 1)
_SHGetFolderPathA(None, nFolder, hToken, dwFlags, pszPath)
return pszPath.value | null |
177,174 | from winappdbg.win32.defines import *
from winappdbg.win32.kernel32 import LocalFree
SHGFP_TYPE_CURRENT = 0
def SHGetFolderPathW(nFolder, hToken = None, dwFlags = SHGFP_TYPE_CURRENT):
_SHGetFolderPathW = windll.shell32.SHGetFolderPathW # shfolder.dll in older win versions
_SHGetFolderPathW.argtypes = [HWND, ctypes.c_int, HANDLE, DWORD, LPWSTR]
_SHGetFolderPathW.restype = HRESULT
_SHGetFolderPathW.errcheck = RaiseIfNotZero # S_OK == 0
pszPath = ctypes.create_unicode_buffer(MAX_PATH + 1)
_SHGetFolderPathW(None, nFolder, hToken, dwFlags, pszPath)
return pszPath.value | null |
177,175 | from winappdbg.win32.defines import *
from winappdbg.win32.kernel32 import LocalFree
def IsUserAnAdmin():
# Supposedly, IsUserAnAdmin() is deprecated in Vista.
# But I tried it on Windows 7 and it works just fine.
_IsUserAnAdmin = windll.shell32.IsUserAnAdmin
_IsUserAnAdmin.argtypes = []
_IsUserAnAdmin.restype = bool
return _IsUserAnAdmin() | null |
177,176 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetLastError():
_GetLastError = windll.kernel32.GetLastError
_GetLastError.argtypes = []
_GetLastError.restype = DWORD
return _GetLastError()
The provided code snippet includes necessary dependencies for implementing the `RaiseIfLastError` function. Write a Python function `def RaiseIfLastError(result, func = None, arguments = ())` to solve the following problem:
Error checking for Win32 API calls with no error-specific return value. Regardless of the return value, the function calls GetLastError(). If the code is not C{ERROR_SUCCESS} then a C{WindowsError} exception is raised. For this to work, the user MUST call SetLastError(ERROR_SUCCESS) prior to calling the API. Otherwise an exception may be raised even on success, since most API calls don't clear the error status code.
Here is the function:
def RaiseIfLastError(result, func = None, arguments = ()):
"""
Error checking for Win32 API calls with no error-specific return value.
Regardless of the return value, the function calls GetLastError(). If the
code is not C{ERROR_SUCCESS} then a C{WindowsError} exception is raised.
For this to work, the user MUST call SetLastError(ERROR_SUCCESS) prior to
calling the API. Otherwise an exception may be raised even on success,
since most API calls don't clear the error status code.
"""
code = GetLastError()
if code != ERROR_SUCCESS:
raise ctypes.WinError(code)
return result | Error checking for Win32 API calls with no error-specific return value. Regardless of the return value, the function calls GetLastError(). If the code is not C{ERROR_SUCCESS} then a C{WindowsError} exception is raised. For this to work, the user MUST call SetLastError(ERROR_SUCCESS) prior to calling the API. Otherwise an exception may be raised even on success, since most API calls don't clear the error status code. |
177,177 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetErrorMode():
_GetErrorMode = windll.kernel32.GetErrorMode
_GetErrorMode.argtypes = []
_GetErrorMode.restype = UINT
return _GetErrorMode() | null |
177,178 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def SetErrorMode(uMode):
_SetErrorMode = windll.kernel32.SetErrorMode
_SetErrorMode.argtypes = [UINT]
_SetErrorMode.restype = UINT
return _SetErrorMode(dwErrCode) | null |
177,179 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetThreadErrorMode():
_GetThreadErrorMode = windll.kernel32.GetThreadErrorMode
_GetThreadErrorMode.argtypes = []
_GetThreadErrorMode.restype = DWORD
return _GetThreadErrorMode() | null |
177,180 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def SetThreadErrorMode(dwNewMode):
_SetThreadErrorMode = windll.kernel32.SetThreadErrorMode
_SetThreadErrorMode.argtypes = [DWORD, LPDWORD]
_SetThreadErrorMode.restype = BOOL
_SetThreadErrorMode.errcheck = RaiseIfZero
old = DWORD(0)
_SetThreadErrorMode(dwErrCode, byref(old))
return old.value | null |
177,181 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
STANDARD_RIGHTS_ALL = long(0x001F0000)
DUPLICATE_SAME_ACCESS = 0x00000002
class Handle (object):
"""
Encapsulates Win32 handles to avoid leaking them.
C{False} otherwise.
closed. Must be set to C{False} before you're done using the handle,
or it will be left open until the debugger exits. Use with care!
L{ProcessHandle}, L{ThreadHandle}, L{FileHandle}, L{SnapshotHandle}
"""
# XXX DEBUG
# When this private flag is True each Handle will print a message to
# standard output when it's created and destroyed. This is useful for
# detecting handle leaks within WinAppDbg itself.
__bLeakDetection = False
def __init__(self, aHandle = None, bOwnership = True):
"""
C{True} if we own the handle and we need to close it.
C{False} if someone else will be calling L{CloseHandle}.
"""
super(Handle, self).__init__()
self._value = self._normalize(aHandle)
self.bOwnership = bOwnership
if Handle.__bLeakDetection: # XXX DEBUG
print("INIT HANDLE (%r) %r" % (self.value, self))
def value(self):
return self._value
def __del__(self):
"""
Closes the Win32 handle when the Python object is destroyed.
"""
try:
if Handle.__bLeakDetection: # XXX DEBUG
print("DEL HANDLE %r" % self)
self.close()
except Exception:
pass
def __enter__(self):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("ENTER HANDLE %r" % self)
return self
def __exit__(self, type, value, traceback):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("EXIT HANDLE %r" % self)
try:
self.close()
except Exception:
pass
def __copy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def __deepcopy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def _as_parameter_(self):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(self.value)
def from_param(value):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(value)
def close(self):
"""
Closes the Win32 handle.
"""
if self.bOwnership and self.value not in (None, INVALID_HANDLE_VALUE):
if Handle.__bLeakDetection: # XXX DEBUG
print("CLOSE HANDLE (%d) %r" % (self.value, self))
try:
self._close()
finally:
self._value = None
def _close(self):
"""
Low-level close method.
This is a private method, do not call it.
"""
CloseHandle(self.value)
def dup(self):
"""
"""
if self.value is None:
raise ValueError("Closed handles can't be duplicated!")
new_handle = DuplicateHandle(self.value)
if Handle.__bLeakDetection: # XXX DEBUG
print("DUP HANDLE (%d -> %d) %r %r" % \
(self.value, new_handle.value, self, new_handle))
return new_handle
def _normalize(value):
"""
Normalize handle values.
"""
if hasattr(value, 'value'):
value = value.value
if value is not None:
value = long(value)
return value
def wait(self, dwMilliseconds = None):
"""
Wait for the Win32 object to be signaled.
Use C{INFINITE} or C{None} for no timeout.
"""
if self.value is None:
raise ValueError("Handle is already closed!")
if dwMilliseconds is None:
dwMilliseconds = INFINITE
r = WaitForSingleObject(self.value, dwMilliseconds)
if r != WAIT_OBJECT_0:
raise ctypes.WinError(r)
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self.value)
def __get_inherit(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_INHERIT )
def __set_inherit(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_INHERIT)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
inherit = property(__get_inherit, __set_inherit)
def __get_protectFromClose(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_PROTECT_FROM_CLOSE )
def __set_protectFromClose(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_PROTECT_FROM_CLOSE)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
protectFromClose = property(__get_protectFromClose, __set_protectFromClose)
def DuplicateHandle(hSourceHandle, hSourceProcessHandle = None, hTargetProcessHandle = None, dwDesiredAccess = STANDARD_RIGHTS_ALL, bInheritHandle = False, dwOptions = DUPLICATE_SAME_ACCESS):
_DuplicateHandle = windll.kernel32.DuplicateHandle
_DuplicateHandle.argtypes = [HANDLE, HANDLE, HANDLE, LPHANDLE, DWORD, BOOL, DWORD]
_DuplicateHandle.restype = bool
_DuplicateHandle.errcheck = RaiseIfZero
# NOTE: the arguments to this function are in a different order,
# so we can set default values for all of them but one (hSourceHandle).
if hSourceProcessHandle is None:
hSourceProcessHandle = GetCurrentProcess()
if hTargetProcessHandle is None:
hTargetProcessHandle = hSourceProcessHandle
lpTargetHandle = HANDLE(INVALID_HANDLE_VALUE)
_DuplicateHandle(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, byref(lpTargetHandle), dwDesiredAccess, bool(bInheritHandle), dwOptions)
if isinstance(hSourceHandle, Handle):
HandleClass = hSourceHandle.__class__
else:
HandleClass = Handle
if hasattr(hSourceHandle, 'dwAccess'):
return HandleClass(lpTargetHandle.value, dwAccess = hSourceHandle.dwAccess)
else:
return HandleClass(lpTargetHandle.value) | null |
177,182 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetConsoleCP():
_GetConsoleCP = windll.kernel32.GetConsoleCP
_GetConsoleCP.argytpes = []
_GetConsoleCP.restype = UINT
return _GetConsoleCP() | null |
177,183 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetConsoleOutputCP():
_GetConsoleOutputCP = windll.kernel32.GetConsoleOutputCP
_GetConsoleOutputCP.argytpes = []
_GetConsoleOutputCP.restype = UINT
return _GetConsoleOutputCP() | null |
177,184 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def SetConsoleCP(wCodePageID):
_SetConsoleCP = windll.kernel32.SetConsoleCP
_SetConsoleCP.argytpes = [UINT]
_SetConsoleCP.restype = bool
_SetConsoleCP.errcheck = RaiseIfZero
_SetConsoleCP(wCodePageID) | null |
177,185 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def SetConsoleOutputCP(wCodePageID):
_SetConsoleOutputCP = windll.kernel32.SetConsoleOutputCP
_SetConsoleOutputCP.argytpes = [UINT]
_SetConsoleOutputCP.restype = bool
_SetConsoleOutputCP.errcheck = RaiseIfZero
_SetConsoleOutputCP(wCodePageID) | null |
177,186 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
STD_OUTPUT_HANDLE = 0xFFFFFFF5
def GetStdHandle(nStdHandle):
def SetConsoleActiveScreenBuffer(hConsoleOutput = None):
_SetConsoleActiveScreenBuffer = windll.kernel32.SetConsoleActiveScreenBuffer
_SetConsoleActiveScreenBuffer.argytpes = [HANDLE]
_SetConsoleActiveScreenBuffer.restype = bool
_SetConsoleActiveScreenBuffer.errcheck = RaiseIfZero
if hConsoleOutput is None:
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE)
_SetConsoleActiveScreenBuffer(hConsoleOutput) | null |
177,187 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
STD_OUTPUT_HANDLE = 0xFFFFFFF5
class CONSOLE_SCREEN_BUFFER_INFO(Structure):
_fields_ = [
('dwSize', COORD),
('dwCursorPosition', COORD),
('wAttributes', WORD),
('srWindow', SMALL_RECT),
('dwMaximumWindowSize', COORD),
]
PCONSOLE_SCREEN_BUFFER_INFO = POINTER(CONSOLE_SCREEN_BUFFER_INFO)
def GetStdHandle(nStdHandle):
_GetStdHandle = windll.kernel32.GetStdHandle
_GetStdHandle.argytpes = [DWORD]
_GetStdHandle.restype = HANDLE
_GetStdHandle.errcheck = RaiseIfZero
return Handle( _GetStdHandle(nStdHandle), bOwnership = False )
def GetConsoleScreenBufferInfo(hConsoleOutput = None):
_GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo
_GetConsoleScreenBufferInfo.argytpes = [HANDLE, PCONSOLE_SCREEN_BUFFER_INFO]
_GetConsoleScreenBufferInfo.restype = bool
_GetConsoleScreenBufferInfo.errcheck = RaiseIfZero
if hConsoleOutput is None:
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE)
ConsoleScreenBufferInfo = CONSOLE_SCREEN_BUFFER_INFO()
_GetConsoleScreenBufferInfo(hConsoleOutput, byref(ConsoleScreenBufferInfo))
return ConsoleScreenBufferInfo | null |
177,188 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
STD_OUTPUT_HANDLE = 0xFFFFFFF5
class SMALL_RECT(Structure):
_fields_ = [
('Left', SHORT),
('Top', SHORT),
('Right', SHORT),
('Bottom', SHORT),
]
PSMALL_RECT = POINTER(SMALL_RECT)
def GetStdHandle(nStdHandle):
_GetStdHandle = windll.kernel32.GetStdHandle
_GetStdHandle.argytpes = [DWORD]
_GetStdHandle.restype = HANDLE
_GetStdHandle.errcheck = RaiseIfZero
return Handle( _GetStdHandle(nStdHandle), bOwnership = False )
def SetConsoleWindowInfo(hConsoleOutput, bAbsolute, lpConsoleWindow):
_SetConsoleWindowInfo = windll.kernel32.SetConsoleWindowInfo
_SetConsoleWindowInfo.argytpes = [HANDLE, BOOL, PSMALL_RECT]
_SetConsoleWindowInfo.restype = bool
_SetConsoleWindowInfo.errcheck = RaiseIfZero
if hConsoleOutput is None:
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE)
if isinstance(lpConsoleWindow, SMALL_RECT):
ConsoleWindow = lpConsoleWindow
else:
ConsoleWindow = SMALL_RECT(*lpConsoleWindow)
_SetConsoleWindowInfo(hConsoleOutput, bAbsolute, byref(ConsoleWindow)) | null |
177,189 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
STD_OUTPUT_HANDLE = 0xFFFFFFF5
def GetStdHandle(nStdHandle):
_GetStdHandle = windll.kernel32.GetStdHandle
_GetStdHandle.argytpes = [DWORD]
_GetStdHandle.restype = HANDLE
_GetStdHandle.errcheck = RaiseIfZero
return Handle( _GetStdHandle(nStdHandle), bOwnership = False )
def SetConsoleTextAttribute(hConsoleOutput = None, wAttributes = 0):
_SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute
_SetConsoleTextAttribute.argytpes = [HANDLE, WORD]
_SetConsoleTextAttribute.restype = bool
_SetConsoleTextAttribute.errcheck = RaiseIfZero
if hConsoleOutput is None:
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE)
_SetConsoleTextAttribute(hConsoleOutput, wAttributes) | null |
177,190 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def AllocConsole():
_AllocConsole = windll.kernel32.AllocConsole
_AllocConsole.argytpes = []
_AllocConsole.restype = bool
_AllocConsole.errcheck = RaiseIfZero
_AllocConsole() | null |
177,191 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
ATTACH_PARENT_PROCESS = 0xFFFFFFFF
def AttachConsole(dwProcessId = ATTACH_PARENT_PROCESS):
_AttachConsole = windll.kernel32.AttachConsole
_AttachConsole.argytpes = [DWORD]
_AttachConsole.restype = bool
_AttachConsole.errcheck = RaiseIfZero
_AttachConsole(dwProcessId) | null |
177,192 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def FreeConsole():
_FreeConsole = windll.kernel32.FreeConsole
_FreeConsole.argytpes = []
_FreeConsole.restype = bool
_FreeConsole.errcheck = RaiseIfZero
_FreeConsole() | null |
177,193 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetDllDirectoryA():
_GetDllDirectoryA = windll.kernel32.GetDllDirectoryA
_GetDllDirectoryA.argytpes = [DWORD, LPSTR]
_GetDllDirectoryA.restype = DWORD
nBufferLength = _GetDllDirectoryA(0, None)
if nBufferLength == 0:
return None
lpBuffer = ctypes.create_string_buffer("", nBufferLength)
_GetDllDirectoryA(nBufferLength, byref(lpBuffer))
return lpBuffer.value | null |
177,194 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetDllDirectoryW():
_GetDllDirectoryW = windll.kernel32.GetDllDirectoryW
_GetDllDirectoryW.argytpes = [DWORD, LPWSTR]
_GetDllDirectoryW.restype = DWORD
nBufferLength = _GetDllDirectoryW(0, None)
if nBufferLength == 0:
return None
lpBuffer = ctypes.create_unicode_buffer(u"", nBufferLength)
_GetDllDirectoryW(nBufferLength, byref(lpBuffer))
return lpBuffer.value | null |
177,195 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def SetDllDirectoryA(lpPathName = None):
_SetDllDirectoryA = windll.kernel32.SetDllDirectoryA
_SetDllDirectoryA.argytpes = [LPSTR]
_SetDllDirectoryA.restype = bool
_SetDllDirectoryA.errcheck = RaiseIfZero
_SetDllDirectoryA(lpPathName) | null |
177,196 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def SetDllDirectoryW(lpPathName):
_SetDllDirectoryW = windll.kernel32.SetDllDirectoryW
_SetDllDirectoryW.argytpes = [LPWSTR]
_SetDllDirectoryW.restype = bool
_SetDllDirectoryW.errcheck = RaiseIfZero
_SetDllDirectoryW(lpPathName) | null |
177,197 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def LoadLibraryA(pszLibrary):
_LoadLibraryA = windll.kernel32.LoadLibraryA
_LoadLibraryA.argtypes = [LPSTR]
_LoadLibraryA.restype = HMODULE
hModule = _LoadLibraryA(pszLibrary)
if hModule == NULL:
raise ctypes.WinError()
return hModule | null |
177,198 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def LoadLibraryW(pszLibrary):
_LoadLibraryW = windll.kernel32.LoadLibraryW
_LoadLibraryW.argtypes = [LPWSTR]
_LoadLibraryW.restype = HMODULE
hModule = _LoadLibraryW(pszLibrary)
if hModule == NULL:
raise ctypes.WinError()
return hModule | null |
177,199 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def LoadLibraryExA(pszLibrary, dwFlags = 0):
_LoadLibraryExA = windll.kernel32.LoadLibraryExA
_LoadLibraryExA.argtypes = [LPSTR, HANDLE, DWORD]
_LoadLibraryExA.restype = HMODULE
hModule = _LoadLibraryExA(pszLibrary, NULL, dwFlags)
if hModule == NULL:
raise ctypes.WinError()
return hModule | null |
177,200 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def LoadLibraryExW(pszLibrary, dwFlags = 0):
_LoadLibraryExW = windll.kernel32.LoadLibraryExW
_LoadLibraryExW.argtypes = [LPWSTR, HANDLE, DWORD]
_LoadLibraryExW.restype = HMODULE
hModule = _LoadLibraryExW(pszLibrary, NULL, dwFlags)
if hModule == NULL:
raise ctypes.WinError()
return hModule | null |
177,201 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetModuleHandleA(lpModuleName):
_GetModuleHandleA = windll.kernel32.GetModuleHandleA
_GetModuleHandleA.argtypes = [LPSTR]
_GetModuleHandleA.restype = HMODULE
hModule = _GetModuleHandleA(lpModuleName)
if hModule == NULL:
raise ctypes.WinError()
return hModule | null |
177,202 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetModuleHandleW(lpModuleName):
_GetModuleHandleW = windll.kernel32.GetModuleHandleW
_GetModuleHandleW.argtypes = [LPWSTR]
_GetModuleHandleW.restype = HMODULE
hModule = _GetModuleHandleW(lpModuleName)
if hModule == NULL:
raise ctypes.WinError()
return hModule | null |
177,203 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
GetProcAddress = GuessStringType(GetProcAddressA, GetProcAddressW)
def GetProcAddressA(hModule, lpProcName):
_GetProcAddress = windll.kernel32.GetProcAddress
_GetProcAddress.argtypes = [HMODULE, LPVOID]
_GetProcAddress.restype = LPVOID
if type(lpProcName) in (type(0), type(long(0))):
lpProcName = LPVOID(lpProcName)
if lpProcName.value & (~0xFFFF):
raise ValueError('Ordinal number too large: %d' % lpProcName.value)
elif type(lpProcName) == type(compat.b("")):
lpProcName = ctypes.c_char_p(lpProcName)
else:
raise TypeError(str(type(lpProcName)))
return _GetProcAddress(hModule, lpProcName) | null |
177,204 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def FreeLibrary(hModule):
_FreeLibrary = windll.kernel32.FreeLibrary
_FreeLibrary.argtypes = [HMODULE]
_FreeLibrary.restype = bool
_FreeLibrary.errcheck = RaiseIfZero
_FreeLibrary(hModule) | null |
177,205 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def RtlPcToFileHeader(PcValue):
_RtlPcToFileHeader = windll.kernel32.RtlPcToFileHeader
_RtlPcToFileHeader.argtypes = [PVOID, POINTER(PVOID)]
_RtlPcToFileHeader.restype = PRUNTIME_FUNCTION
BaseOfImage = PVOID(0)
_RtlPcToFileHeader(PcValue, byref(BaseOfImage))
return BaseOfImage.value | null |
177,206 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetHandleInformation(hObject):
_GetHandleInformation = windll.kernel32.GetHandleInformation
_GetHandleInformation.argtypes = [HANDLE, PDWORD]
_GetHandleInformation.restype = bool
_GetHandleInformation.errcheck = RaiseIfZero
dwFlags = DWORD(0)
_GetHandleInformation(hObject, byref(dwFlags))
return dwFlags.value | null |
177,207 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def SetHandleInformation(hObject, dwMask, dwFlags):
_SetHandleInformation = windll.kernel32.SetHandleInformation
_SetHandleInformation.argtypes = [HANDLE, DWORD, DWORD]
_SetHandleInformation.restype = bool
_SetHandleInformation.errcheck = RaiseIfZero
_SetHandleInformation(hObject, dwMask, dwFlags) | null |
177,208 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetLastError():
_GetLastError = windll.kernel32.GetLastError
_GetLastError.argtypes = []
_GetLastError.restype = DWORD
return _GetLastError()
def QueryFullProcessImageNameA(hProcess, dwFlags = 0):
_QueryFullProcessImageNameA = windll.kernel32.QueryFullProcessImageNameA
_QueryFullProcessImageNameA.argtypes = [HANDLE, DWORD, LPSTR, PDWORD]
_QueryFullProcessImageNameA.restype = bool
dwSize = MAX_PATH
while 1:
lpdwSize = DWORD(dwSize)
lpExeName = ctypes.create_string_buffer('', lpdwSize.value + 1)
success = _QueryFullProcessImageNameA(hProcess, dwFlags, lpExeName, byref(lpdwSize))
if success and 0 < lpdwSize.value < dwSize:
break
error = GetLastError()
if error != ERROR_INSUFFICIENT_BUFFER:
raise ctypes.WinError(error)
dwSize = dwSize + 256
if dwSize > 0x1000:
# this prevents an infinite loop in Windows 2008 when the path has spaces,
# see http://msdn.microsoft.com/en-us/library/ms684919(VS.85).aspx#4
raise ctypes.WinError(error)
return lpExeName.value | null |
177,209 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetLastError():
_GetLastError = windll.kernel32.GetLastError
_GetLastError.argtypes = []
_GetLastError.restype = DWORD
return _GetLastError()
def QueryFullProcessImageNameW(hProcess, dwFlags = 0):
_QueryFullProcessImageNameW = windll.kernel32.QueryFullProcessImageNameW
_QueryFullProcessImageNameW.argtypes = [HANDLE, DWORD, LPWSTR, PDWORD]
_QueryFullProcessImageNameW.restype = bool
dwSize = MAX_PATH
while 1:
lpdwSize = DWORD(dwSize)
lpExeName = ctypes.create_unicode_buffer('', lpdwSize.value + 1)
success = _QueryFullProcessImageNameW(hProcess, dwFlags, lpExeName, byref(lpdwSize))
if success and 0 < lpdwSize.value < dwSize:
break
error = GetLastError()
if error != ERROR_INSUFFICIENT_BUFFER:
raise ctypes.WinError(error)
dwSize = dwSize + 256
if dwSize > 0x1000:
# this prevents an infinite loop in Windows 2008 when the path has spaces,
# see http://msdn.microsoft.com/en-us/library/ms684919(VS.85).aspx#4
raise ctypes.WinError(error)
return lpExeName.value | null |
177,210 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetLogicalDriveStringsA():
_GetLogicalDriveStringsA = ctypes.windll.kernel32.GetLogicalDriveStringsA
_GetLogicalDriveStringsA.argtypes = [DWORD, LPSTR]
_GetLogicalDriveStringsA.restype = DWORD
_GetLogicalDriveStringsA.errcheck = RaiseIfZero
nBufferLength = (4 * 26) + 1 # "X:\\\0" from A to Z plus empty string
lpBuffer = ctypes.create_string_buffer('', nBufferLength)
_GetLogicalDriveStringsA(nBufferLength, lpBuffer)
drive_strings = list()
string_p = addressof(lpBuffer)
sizeof_char = sizeof(ctypes.c_char)
while True:
string_v = ctypes.string_at(string_p)
if string_v == '':
break
drive_strings.append(string_v)
string_p += len(string_v) + sizeof_char
return drive_strings | null |
177,211 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetLogicalDriveStringsW():
_GetLogicalDriveStringsW = ctypes.windll.kernel32.GetLogicalDriveStringsW
_GetLogicalDriveStringsW.argtypes = [DWORD, LPWSTR]
_GetLogicalDriveStringsW.restype = DWORD
_GetLogicalDriveStringsW.errcheck = RaiseIfZero
nBufferLength = (4 * 26) + 1 # "X:\\\0" from A to Z plus empty string
lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength)
_GetLogicalDriveStringsW(nBufferLength, lpBuffer)
drive_strings = list()
string_p = addressof(lpBuffer)
sizeof_wchar = sizeof(ctypes.c_wchar)
while True:
string_v = ctypes.wstring_at(string_p)
if string_v == u'':
break
drive_strings.append(string_v)
string_p += (len(string_v) * sizeof_wchar) + sizeof_wchar
return drive_strings | null |
177,212 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def QueryDosDeviceA(lpDeviceName = None):
_QueryDosDeviceA = windll.kernel32.QueryDosDeviceA
_QueryDosDeviceA.argtypes = [LPSTR, LPSTR, DWORD]
_QueryDosDeviceA.restype = DWORD
_QueryDosDeviceA.errcheck = RaiseIfZero
if not lpDeviceName:
lpDeviceName = None
ucchMax = 0x1000
lpTargetPath = ctypes.create_string_buffer('', ucchMax)
_QueryDosDeviceA(lpDeviceName, lpTargetPath, ucchMax)
return lpTargetPath.value | null |
177,213 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def QueryDosDeviceW(lpDeviceName):
_QueryDosDeviceW = windll.kernel32.QueryDosDeviceW
_QueryDosDeviceW.argtypes = [LPWSTR, LPWSTR, DWORD]
_QueryDosDeviceW.restype = DWORD
_QueryDosDeviceW.errcheck = RaiseIfZero
if not lpDeviceName:
lpDeviceName = None
ucchMax = 0x1000
lpTargetPath = ctypes.create_unicode_buffer(u'', ucchMax)
_QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax)
return lpTargetPath.value | null |
177,214 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
class FileMappingHandle (Handle):
"""
File mapping handle.
"""
pass
def OpenFileMappingA(dwDesiredAccess, bInheritHandle, lpName):
_OpenFileMappingA = windll.kernel32.OpenFileMappingA
_OpenFileMappingA.argtypes = [DWORD, BOOL, LPSTR]
_OpenFileMappingA.restype = HANDLE
_OpenFileMappingA.errcheck = RaiseIfZero
hFileMappingObject = _OpenFileMappingA(dwDesiredAccess, bool(bInheritHandle), lpName)
return FileMappingHandle(hFileMappingObject) | null |
177,215 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
class FileMappingHandle (Handle):
"""
File mapping handle.
"""
pass
def OpenFileMappingW(dwDesiredAccess, bInheritHandle, lpName):
_OpenFileMappingW = windll.kernel32.OpenFileMappingW
_OpenFileMappingW.argtypes = [DWORD, BOOL, LPWSTR]
_OpenFileMappingW.restype = HANDLE
_OpenFileMappingW.errcheck = RaiseIfZero
hFileMappingObject = _OpenFileMappingW(dwDesiredAccess, bool(bInheritHandle), lpName)
return FileMappingHandle(hFileMappingObject) | null |
177,216 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
PAGE_EXECUTE_READWRITE = 0x40
class FileMappingHandle (Handle):
"""
File mapping handle.
"""
pass
def CreateFileMappingA(hFile, lpAttributes = None, flProtect = PAGE_EXECUTE_READWRITE, dwMaximumSizeHigh = 0, dwMaximumSizeLow = 0, lpName = None):
_CreateFileMappingA = windll.kernel32.CreateFileMappingA
_CreateFileMappingA.argtypes = [HANDLE, LPVOID, DWORD, DWORD, DWORD, LPSTR]
_CreateFileMappingA.restype = HANDLE
_CreateFileMappingA.errcheck = RaiseIfZero
if lpAttributes:
lpAttributes = ctypes.pointer(lpAttributes)
if not lpName:
lpName = None
hFileMappingObject = _CreateFileMappingA(hFile, lpAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName)
return FileMappingHandle(hFileMappingObject) | null |
177,217 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
PAGE_EXECUTE_READWRITE = 0x40
class FileMappingHandle (Handle):
"""
File mapping handle.
"""
pass
def CreateFileMappingW(hFile, lpAttributes = None, flProtect = PAGE_EXECUTE_READWRITE, dwMaximumSizeHigh = 0, dwMaximumSizeLow = 0, lpName = None):
_CreateFileMappingW = windll.kernel32.CreateFileMappingW
_CreateFileMappingW.argtypes = [HANDLE, LPVOID, DWORD, DWORD, DWORD, LPWSTR]
_CreateFileMappingW.restype = HANDLE
_CreateFileMappingW.errcheck = RaiseIfZero
if lpAttributes:
lpAttributes = ctypes.pointer(lpAttributes)
if not lpName:
lpName = None
hFileMappingObject = _CreateFileMappingW(hFile, lpAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName)
return FileMappingHandle(hFileMappingObject) | null |
177,218 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
GENERIC_ALL = 0x10000000
OPEN_ALWAYS = 4
FILE_ATTRIBUTE_NORMAL = 0x00000080
FILE_ATTRIBUTE_NORMAL = 0x00000080
class FileHandle (Handle):
"""
Win32 file handle.
"""
def get_filename(self):
"""
"""
#
# XXX BUG
#
# This code truncates the first two bytes of the path.
# It seems to be the expected behavior of NtQueryInformationFile.
#
# My guess is it only returns the NT pathname, without the device name.
# It's like dropping the drive letter in a Win32 pathname.
#
# Note that using the "official" GetFileInformationByHandleEx
# API introduced in Vista doesn't change the results!
#
dwBufferSize = 0x1004
lpFileInformation = ctypes.create_string_buffer(dwBufferSize)
try:
GetFileInformationByHandleEx(self.value,
FILE_INFO_BY_HANDLE_CLASS.FileNameInfo,
lpFileInformation, dwBufferSize)
except AttributeError:
from winappdbg.win32.ntdll import NtQueryInformationFile, \
FileNameInformation, \
FILE_NAME_INFORMATION
NtQueryInformationFile(self.value,
FileNameInformation,
lpFileInformation,
dwBufferSize)
FileName = compat.unicode(lpFileInformation.raw[sizeof(DWORD):], 'U16')
FileName = ctypes.create_unicode_buffer(FileName).value
if not FileName:
FileName = None
elif FileName[1:2] != ':':
# When the drive letter is missing, we'll assume SYSTEMROOT.
# Not a good solution but it could be worse.
import os
FileName = os.environ['SYSTEMROOT'][:2] + FileName
return FileName
def CreateFileA(lpFileName, dwDesiredAccess = GENERIC_ALL, dwShareMode = 0, lpSecurityAttributes = None, dwCreationDisposition = OPEN_ALWAYS, dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL, hTemplateFile = None):
_CreateFileA = windll.kernel32.CreateFileA
_CreateFileA.argtypes = [LPSTR, DWORD, DWORD, LPVOID, DWORD, DWORD, HANDLE]
_CreateFileA.restype = HANDLE
if not lpFileName:
lpFileName = None
if lpSecurityAttributes:
lpSecurityAttributes = ctypes.pointer(lpSecurityAttributes)
hFile = _CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)
if hFile == INVALID_HANDLE_VALUE:
raise ctypes.WinError()
return FileHandle(hFile) | null |
177,219 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
GENERIC_ALL = 0x10000000
OPEN_ALWAYS = 4
FILE_ATTRIBUTE_NORMAL = 0x00000080
FILE_ATTRIBUTE_NORMAL = 0x00000080
class FileHandle (Handle):
"""
Win32 file handle.
"""
def get_filename(self):
"""
"""
#
# XXX BUG
#
# This code truncates the first two bytes of the path.
# It seems to be the expected behavior of NtQueryInformationFile.
#
# My guess is it only returns the NT pathname, without the device name.
# It's like dropping the drive letter in a Win32 pathname.
#
# Note that using the "official" GetFileInformationByHandleEx
# API introduced in Vista doesn't change the results!
#
dwBufferSize = 0x1004
lpFileInformation = ctypes.create_string_buffer(dwBufferSize)
try:
GetFileInformationByHandleEx(self.value,
FILE_INFO_BY_HANDLE_CLASS.FileNameInfo,
lpFileInformation, dwBufferSize)
except AttributeError:
from winappdbg.win32.ntdll import NtQueryInformationFile, \
FileNameInformation, \
FILE_NAME_INFORMATION
NtQueryInformationFile(self.value,
FileNameInformation,
lpFileInformation,
dwBufferSize)
FileName = compat.unicode(lpFileInformation.raw[sizeof(DWORD):], 'U16')
FileName = ctypes.create_unicode_buffer(FileName).value
if not FileName:
FileName = None
elif FileName[1:2] != ':':
# When the drive letter is missing, we'll assume SYSTEMROOT.
# Not a good solution but it could be worse.
import os
FileName = os.environ['SYSTEMROOT'][:2] + FileName
return FileName
def CreateFileW(lpFileName, dwDesiredAccess = GENERIC_ALL, dwShareMode = 0, lpSecurityAttributes = None, dwCreationDisposition = OPEN_ALWAYS, dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL, hTemplateFile = None):
_CreateFileW = windll.kernel32.CreateFileW
_CreateFileW.argtypes = [LPWSTR, DWORD, DWORD, LPVOID, DWORD, DWORD, HANDLE]
_CreateFileW.restype = HANDLE
if not lpFileName:
lpFileName = None
if lpSecurityAttributes:
lpSecurityAttributes = ctypes.pointer(lpSecurityAttributes)
hFile = _CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)
if hFile == INVALID_HANDLE_VALUE:
raise ctypes.WinError()
return FileHandle(hFile) | null |
177,220 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def FlushFileBuffers(hFile):
_FlushFileBuffers = windll.kernel32.FlushFileBuffers
_FlushFileBuffers.argtypes = [HANDLE]
_FlushFileBuffers.restype = bool
_FlushFileBuffers.errcheck = RaiseIfZero
_FlushFileBuffers(hFile) | null |
177,221 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def FlushViewOfFile(lpBaseAddress, dwNumberOfBytesToFlush = 0):
_FlushViewOfFile = windll.kernel32.FlushViewOfFile
_FlushViewOfFile.argtypes = [LPVOID, SIZE_T]
_FlushViewOfFile.restype = bool
_FlushViewOfFile.errcheck = RaiseIfZero
_FlushViewOfFile(lpBaseAddress, dwNumberOfBytesToFlush) | null |
177,222 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetLastError():
_GetLastError = windll.kernel32.GetLastError
_GetLastError.argtypes = []
_GetLastError.restype = DWORD
return _GetLastError()
def SearchPathA(lpPath, lpFileName, lpExtension):
_SearchPathA = windll.kernel32.SearchPathA
_SearchPathA.argtypes = [LPSTR, LPSTR, LPSTR, DWORD, LPSTR, POINTER(LPSTR)]
_SearchPathA.restype = DWORD
_SearchPathA.errcheck = RaiseIfZero
if not lpPath:
lpPath = None
if not lpExtension:
lpExtension = None
nBufferLength = _SearchPathA(lpPath, lpFileName, lpExtension, 0, None, None)
lpBuffer = ctypes.create_string_buffer('', nBufferLength + 1)
lpFilePart = LPSTR()
_SearchPathA(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, byref(lpFilePart))
lpFilePart = lpFilePart.value
lpBuffer = lpBuffer.value
if lpBuffer == '':
if GetLastError() == ERROR_SUCCESS:
raise ctypes.WinError(ERROR_FILE_NOT_FOUND)
raise ctypes.WinError()
return (lpBuffer, lpFilePart) | null |
177,223 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetLastError():
def SearchPathW(lpPath, lpFileName, lpExtension):
_SearchPathW = windll.kernel32.SearchPathW
_SearchPathW.argtypes = [LPWSTR, LPWSTR, LPWSTR, DWORD, LPWSTR, POINTER(LPWSTR)]
_SearchPathW.restype = DWORD
_SearchPathW.errcheck = RaiseIfZero
if not lpPath:
lpPath = None
if not lpExtension:
lpExtension = None
nBufferLength = _SearchPathW(lpPath, lpFileName, lpExtension, 0, None, None)
lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength + 1)
lpFilePart = LPWSTR()
_SearchPathW(lpPath, lpFileName, lpExtension, nBufferLength, lpBuffer, byref(lpFilePart))
lpFilePart = lpFilePart.value
lpBuffer = lpBuffer.value
if lpBuffer == u'':
if GetLastError() == ERROR_SUCCESS:
raise ctypes.WinError(ERROR_FILE_NOT_FOUND)
raise ctypes.WinError()
return (lpBuffer, lpFilePart) | null |
177,224 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def SetSearchPathMode(Flags):
_SetSearchPathMode = windll.kernel32.SetSearchPathMode
_SetSearchPathMode.argtypes = [DWORD]
_SetSearchPathMode.restype = bool
_SetSearchPathMode.errcheck = RaiseIfZero
_SetSearchPathMode(Flags) | null |
177,225 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
LPOVERLAPPED = POINTER(OVERLAPPED)
def DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpOverlapped):
_DeviceIoControl = windll.kernel32.DeviceIoControl
_DeviceIoControl.argtypes = [HANDLE, DWORD, LPVOID, DWORD, LPVOID, DWORD, LPDWORD, LPOVERLAPPED]
_DeviceIoControl.restype = bool
_DeviceIoControl.errcheck = RaiseIfZero
if not lpInBuffer:
lpInBuffer = None
if not lpOutBuffer:
lpOutBuffer = None
if lpOverlapped:
lpOverlapped = ctypes.pointer(lpOverlapped)
lpBytesReturned = DWORD(0)
_DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, byref(lpBytesReturned), lpOverlapped)
return lpBytesReturned.value | null |
177,226 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
class BY_HANDLE_FILE_INFORMATION(Structure):
LPBY_HANDLE_FILE_INFORMATION = POINTER(BY_HANDLE_FILE_INFORMATION)
def GetFileInformationByHandle(hFile):
_GetFileInformationByHandle = windll.kernel32.GetFileInformationByHandle
_GetFileInformationByHandle.argtypes = [HANDLE, LPBY_HANDLE_FILE_INFORMATION]
_GetFileInformationByHandle.restype = bool
_GetFileInformationByHandle.errcheck = RaiseIfZero
lpFileInformation = BY_HANDLE_FILE_INFORMATION()
_GetFileInformationByHandle(hFile, byref(lpFileInformation))
return lpFileInformation | null |
177,227 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetFileInformationByHandleEx(hFile, FileInformationClass, lpFileInformation, dwBufferSize):
_GetFileInformationByHandleEx = windll.kernel32.GetFileInformationByHandleEx
_GetFileInformationByHandleEx.argtypes = [HANDLE, DWORD, LPVOID, DWORD]
_GetFileInformationByHandleEx.restype = bool
_GetFileInformationByHandleEx.errcheck = RaiseIfZero
# XXX TODO
# support each FileInformationClass so the function can allocate the
# corresponding structure for the lpFileInformation parameter
_GetFileInformationByHandleEx(hFile, FileInformationClass, byref(lpFileInformation), dwBufferSize) | null |
177,228 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
FILE_NAME_NORMALIZED = 0x0
VOLUME_NAME_DOS = 0x0
def GetFinalPathNameByHandleA(hFile, dwFlags = FILE_NAME_NORMALIZED | VOLUME_NAME_DOS):
_GetFinalPathNameByHandleA = windll.kernel32.GetFinalPathNameByHandleA
_GetFinalPathNameByHandleA.argtypes = [HANDLE, LPSTR, DWORD, DWORD]
_GetFinalPathNameByHandleA.restype = DWORD
cchFilePath = _GetFinalPathNameByHandleA(hFile, None, 0, dwFlags)
if cchFilePath == 0:
raise ctypes.WinError()
lpszFilePath = ctypes.create_string_buffer('', cchFilePath + 1)
nCopied = _GetFinalPathNameByHandleA(hFile, lpszFilePath, cchFilePath, dwFlags)
if nCopied <= 0 or nCopied > cchFilePath:
raise ctypes.WinError()
return lpszFilePath.value | null |
177,229 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
FILE_NAME_NORMALIZED = 0x0
VOLUME_NAME_DOS = 0x0
def GetFinalPathNameByHandleW(hFile, dwFlags = FILE_NAME_NORMALIZED | VOLUME_NAME_DOS):
_GetFinalPathNameByHandleW = windll.kernel32.GetFinalPathNameByHandleW
_GetFinalPathNameByHandleW.argtypes = [HANDLE, LPWSTR, DWORD, DWORD]
_GetFinalPathNameByHandleW.restype = DWORD
cchFilePath = _GetFinalPathNameByHandleW(hFile, None, 0, dwFlags)
if cchFilePath == 0:
raise ctypes.WinError()
lpszFilePath = ctypes.create_unicode_buffer(u'', cchFilePath + 1)
nCopied = _GetFinalPathNameByHandleW(hFile, lpszFilePath, cchFilePath, dwFlags)
if nCopied <= 0 or nCopied > cchFilePath:
raise ctypes.WinError()
return lpszFilePath.value | null |
177,230 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetFullPathNameA(lpFileName):
_GetFullPathNameA = windll.kernel32.GetFullPathNameA
_GetFullPathNameA.argtypes = [LPSTR, DWORD, LPSTR, POINTER(LPSTR)]
_GetFullPathNameA.restype = DWORD
nBufferLength = _GetFullPathNameA(lpFileName, 0, None, None)
if nBufferLength <= 0:
raise ctypes.WinError()
lpBuffer = ctypes.create_string_buffer('', nBufferLength + 1)
lpFilePart = LPSTR()
nCopied = _GetFullPathNameA(lpFileName, nBufferLength, lpBuffer, byref(lpFilePart))
if nCopied > nBufferLength or nCopied == 0:
raise ctypes.WinError()
return lpBuffer.value, lpFilePart.value | null |
177,231 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetFullPathNameW(lpFileName):
_GetFullPathNameW = windll.kernel32.GetFullPathNameW
_GetFullPathNameW.argtypes = [LPWSTR, DWORD, LPWSTR, POINTER(LPWSTR)]
_GetFullPathNameW.restype = DWORD
nBufferLength = _GetFullPathNameW(lpFileName, 0, None, None)
if nBufferLength <= 0:
raise ctypes.WinError()
lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength + 1)
lpFilePart = LPWSTR()
nCopied = _GetFullPathNameW(lpFileName, nBufferLength, lpBuffer, byref(lpFilePart))
if nCopied > nBufferLength or nCopied == 0:
raise ctypes.WinError()
return lpBuffer.value, lpFilePart.value | null |
177,232 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetTempPathA():
_GetTempPathA = windll.kernel32.GetTempPathA
_GetTempPathA.argtypes = [DWORD, LPSTR]
_GetTempPathA.restype = DWORD
nBufferLength = _GetTempPathA(0, None)
if nBufferLength <= 0:
raise ctypes.WinError()
lpBuffer = ctypes.create_string_buffer('', nBufferLength)
nCopied = _GetTempPathA(nBufferLength, lpBuffer)
if nCopied > nBufferLength or nCopied == 0:
raise ctypes.WinError()
return lpBuffer.value
def GetTempFileNameA(lpPathName = None, lpPrefixString = "TMP", uUnique = 0):
_GetTempFileNameA = windll.kernel32.GetTempFileNameA
_GetTempFileNameA.argtypes = [LPSTR, LPSTR, UINT, LPSTR]
_GetTempFileNameA.restype = UINT
if lpPathName is None:
lpPathName = GetTempPathA()
lpTempFileName = ctypes.create_string_buffer('', MAX_PATH)
uUnique = _GetTempFileNameA(lpPathName, lpPrefixString, uUnique, lpTempFileName)
if uUnique == 0:
raise ctypes.WinError()
return lpTempFileName.value, uUnique | null |
177,233 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetTempPathW():
_GetTempPathW = windll.kernel32.GetTempPathW
_GetTempPathW.argtypes = [DWORD, LPWSTR]
_GetTempPathW.restype = DWORD
nBufferLength = _GetTempPathW(0, None)
if nBufferLength <= 0:
raise ctypes.WinError()
lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength)
nCopied = _GetTempPathW(nBufferLength, lpBuffer)
if nCopied > nBufferLength or nCopied == 0:
raise ctypes.WinError()
return lpBuffer.value
def GetTempFileNameW(lpPathName = None, lpPrefixString = u"TMP", uUnique = 0):
_GetTempFileNameW = windll.kernel32.GetTempFileNameW
_GetTempFileNameW.argtypes = [LPWSTR, LPWSTR, UINT, LPWSTR]
_GetTempFileNameW.restype = UINT
if lpPathName is None:
lpPathName = GetTempPathW()
lpTempFileName = ctypes.create_unicode_buffer(u'', MAX_PATH)
uUnique = _GetTempFileNameW(lpPathName, lpPrefixString, uUnique, lpTempFileName)
if uUnique == 0:
raise ctypes.WinError()
return lpTempFileName.value, uUnique | null |
177,234 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetCurrentDirectoryA():
_GetCurrentDirectoryA = windll.kernel32.GetCurrentDirectoryA
_GetCurrentDirectoryA.argtypes = [DWORD, LPSTR]
_GetCurrentDirectoryA.restype = DWORD
nBufferLength = _GetCurrentDirectoryA(0, None)
if nBufferLength <= 0:
raise ctypes.WinError()
lpBuffer = ctypes.create_string_buffer('', nBufferLength)
nCopied = _GetCurrentDirectoryA(nBufferLength, lpBuffer)
if nCopied > nBufferLength or nCopied == 0:
raise ctypes.WinError()
return lpBuffer.value | null |
177,235 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetCurrentDirectoryW():
_GetCurrentDirectoryW = windll.kernel32.GetCurrentDirectoryW
_GetCurrentDirectoryW.argtypes = [DWORD, LPWSTR]
_GetCurrentDirectoryW.restype = DWORD
nBufferLength = _GetCurrentDirectoryW(0, None)
if nBufferLength <= 0:
raise ctypes.WinError()
lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength)
nCopied = _GetCurrentDirectoryW(nBufferLength, lpBuffer)
if nCopied > nBufferLength or nCopied == 0:
raise ctypes.WinError()
return lpBuffer.value | null |
177,236 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
PHANDLER_ROUTINE = ctypes.WINFUNCTYPE(BOOL, DWORD)
def SetConsoleCtrlHandler(HandlerRoutine = None, Add = True):
_SetConsoleCtrlHandler = windll.kernel32.SetConsoleCtrlHandler
_SetConsoleCtrlHandler.argtypes = [PHANDLER_ROUTINE, BOOL]
_SetConsoleCtrlHandler.restype = bool
_SetConsoleCtrlHandler.errcheck = RaiseIfZero
_SetConsoleCtrlHandler(HandlerRoutine, bool(Add))
# we can't automagically transform Python functions to PHANDLER_ROUTINE
# because a) the actual pointer value is meaningful to the API
# and b) if it gets garbage collected bad things would happen | null |
177,237 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GenerateConsoleCtrlEvent(dwCtrlEvent, dwProcessGroupId):
_GenerateConsoleCtrlEvent = windll.kernel32.GenerateConsoleCtrlEvent
_GenerateConsoleCtrlEvent.argtypes = [DWORD, DWORD]
_GenerateConsoleCtrlEvent.restype = bool
_GenerateConsoleCtrlEvent.errcheck = RaiseIfZero
_GenerateConsoleCtrlEvent(dwCtrlEvent, dwProcessGroupId) | null |
177,238 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
WAIT_TIMEOUT = 0x102
WAIT_FAILED = -1
def WaitForSingleObjectEx(hHandle, dwMilliseconds = INFINITE, bAlertable = True):
_WaitForSingleObjectEx = windll.kernel32.WaitForSingleObjectEx
_WaitForSingleObjectEx.argtypes = [HANDLE, DWORD, BOOL]
_WaitForSingleObjectEx.restype = DWORD
if not dwMilliseconds and dwMilliseconds != 0:
dwMilliseconds = INFINITE
if dwMilliseconds != INFINITE:
r = _WaitForSingleObjectEx(hHandle, dwMilliseconds, bool(bAlertable))
if r == WAIT_FAILED:
raise ctypes.WinError()
else:
while 1:
r = _WaitForSingleObjectEx(hHandle, 100, bool(bAlertable))
if r == WAIT_FAILED:
raise ctypes.WinError()
if r != WAIT_TIMEOUT:
break
return r | null |
177,239 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
WAIT_TIMEOUT = 0x102
WAIT_FAILED = -1
def WaitForMultipleObjects(handles, bWaitAll = False, dwMilliseconds = INFINITE):
_WaitForMultipleObjects = windll.kernel32.WaitForMultipleObjects
_WaitForMultipleObjects.argtypes = [DWORD, POINTER(HANDLE), BOOL, DWORD]
_WaitForMultipleObjects.restype = DWORD
if not dwMilliseconds and dwMilliseconds != 0:
dwMilliseconds = INFINITE
nCount = len(handles)
lpHandlesType = HANDLE * nCount
lpHandles = lpHandlesType(*handles)
if dwMilliseconds != INFINITE:
r = _WaitForMultipleObjects(byref(lpHandles), bool(bWaitAll), dwMilliseconds)
if r == WAIT_FAILED:
raise ctypes.WinError()
else:
while 1:
r = _WaitForMultipleObjects(byref(lpHandles), bool(bWaitAll), 100)
if r == WAIT_FAILED:
raise ctypes.WinError()
if r != WAIT_TIMEOUT:
break
return r | null |
177,240 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
WAIT_TIMEOUT = 0x102
WAIT_FAILED = -1
def WaitForMultipleObjectsEx(handles, bWaitAll = False, dwMilliseconds = INFINITE, bAlertable = True):
_WaitForMultipleObjectsEx = windll.kernel32.WaitForMultipleObjectsEx
_WaitForMultipleObjectsEx.argtypes = [DWORD, POINTER(HANDLE), BOOL, DWORD]
_WaitForMultipleObjectsEx.restype = DWORD
if not dwMilliseconds and dwMilliseconds != 0:
dwMilliseconds = INFINITE
nCount = len(handles)
lpHandlesType = HANDLE * nCount
lpHandles = lpHandlesType(*handles)
if dwMilliseconds != INFINITE:
r = _WaitForMultipleObjectsEx(byref(lpHandles), bool(bWaitAll), dwMilliseconds, bool(bAlertable))
if r == WAIT_FAILED:
raise ctypes.WinError()
else:
while 1:
r = _WaitForMultipleObjectsEx(byref(lpHandles), bool(bWaitAll), 100, bool(bAlertable))
if r == WAIT_FAILED:
raise ctypes.WinError()
if r != WAIT_TIMEOUT:
break
return r | null |
177,241 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
class Handle (object):
def __init__(self, aHandle = None, bOwnership = True):
def value(self):
def __del__(self):
def __enter__(self):
def __exit__(self, type, value, traceback):
def __copy__(self):
def __deepcopy__(self):
def _as_parameter_(self):
def from_param(value):
def close(self):
def _close(self):
def dup(self):
def _normalize(value):
def wait(self, dwMilliseconds = None):
def __repr__(self):
def __get_inherit(self):
def __set_inherit(self, value):
def __get_protectFromClose(self):
def __set_protectFromClose(self, value):
def CreateMutexA(lpMutexAttributes = None, bInitialOwner = True, lpName = None):
_CreateMutexA = windll.kernel32.CreateMutexA
_CreateMutexA.argtypes = [LPVOID, BOOL, LPSTR]
_CreateMutexA.restype = HANDLE
_CreateMutexA.errcheck = RaiseIfZero
return Handle( _CreateMutexA(lpMutexAttributes, bInitialOwner, lpName) ) | null |
177,242 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
class Handle (object):
"""
Encapsulates Win32 handles to avoid leaking them.
C{False} otherwise.
closed. Must be set to C{False} before you're done using the handle,
or it will be left open until the debugger exits. Use with care!
L{ProcessHandle}, L{ThreadHandle}, L{FileHandle}, L{SnapshotHandle}
"""
# XXX DEBUG
# When this private flag is True each Handle will print a message to
# standard output when it's created and destroyed. This is useful for
# detecting handle leaks within WinAppDbg itself.
__bLeakDetection = False
def __init__(self, aHandle = None, bOwnership = True):
"""
C{True} if we own the handle and we need to close it.
C{False} if someone else will be calling L{CloseHandle}.
"""
super(Handle, self).__init__()
self._value = self._normalize(aHandle)
self.bOwnership = bOwnership
if Handle.__bLeakDetection: # XXX DEBUG
print("INIT HANDLE (%r) %r" % (self.value, self))
def value(self):
return self._value
def __del__(self):
"""
Closes the Win32 handle when the Python object is destroyed.
"""
try:
if Handle.__bLeakDetection: # XXX DEBUG
print("DEL HANDLE %r" % self)
self.close()
except Exception:
pass
def __enter__(self):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("ENTER HANDLE %r" % self)
return self
def __exit__(self, type, value, traceback):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("EXIT HANDLE %r" % self)
try:
self.close()
except Exception:
pass
def __copy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def __deepcopy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def _as_parameter_(self):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(self.value)
def from_param(value):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(value)
def close(self):
"""
Closes the Win32 handle.
"""
if self.bOwnership and self.value not in (None, INVALID_HANDLE_VALUE):
if Handle.__bLeakDetection: # XXX DEBUG
print("CLOSE HANDLE (%d) %r" % (self.value, self))
try:
self._close()
finally:
self._value = None
def _close(self):
"""
Low-level close method.
This is a private method, do not call it.
"""
CloseHandle(self.value)
def dup(self):
"""
"""
if self.value is None:
raise ValueError("Closed handles can't be duplicated!")
new_handle = DuplicateHandle(self.value)
if Handle.__bLeakDetection: # XXX DEBUG
print("DUP HANDLE (%d -> %d) %r %r" % \
(self.value, new_handle.value, self, new_handle))
return new_handle
def _normalize(value):
"""
Normalize handle values.
"""
if hasattr(value, 'value'):
value = value.value
if value is not None:
value = long(value)
return value
def wait(self, dwMilliseconds = None):
"""
Wait for the Win32 object to be signaled.
Use C{INFINITE} or C{None} for no timeout.
"""
if self.value is None:
raise ValueError("Handle is already closed!")
if dwMilliseconds is None:
dwMilliseconds = INFINITE
r = WaitForSingleObject(self.value, dwMilliseconds)
if r != WAIT_OBJECT_0:
raise ctypes.WinError(r)
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self.value)
def __get_inherit(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_INHERIT )
def __set_inherit(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_INHERIT)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
inherit = property(__get_inherit, __set_inherit)
def __get_protectFromClose(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_PROTECT_FROM_CLOSE )
def __set_protectFromClose(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_PROTECT_FROM_CLOSE)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
protectFromClose = property(__get_protectFromClose, __set_protectFromClose)
def CreateMutexW(lpMutexAttributes = None, bInitialOwner = True, lpName = None):
_CreateMutexW = windll.kernel32.CreateMutexW
_CreateMutexW.argtypes = [LPVOID, BOOL, LPWSTR]
_CreateMutexW.restype = HANDLE
_CreateMutexW.errcheck = RaiseIfZero
return Handle( _CreateMutexW(lpMutexAttributes, bInitialOwner, lpName) ) | null |
177,243 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
MUTEX_ALL_ACCESS = 0x1F0001
class Handle (object):
"""
Encapsulates Win32 handles to avoid leaking them.
C{False} otherwise.
closed. Must be set to C{False} before you're done using the handle,
or it will be left open until the debugger exits. Use with care!
L{ProcessHandle}, L{ThreadHandle}, L{FileHandle}, L{SnapshotHandle}
"""
# XXX DEBUG
# When this private flag is True each Handle will print a message to
# standard output when it's created and destroyed. This is useful for
# detecting handle leaks within WinAppDbg itself.
__bLeakDetection = False
def __init__(self, aHandle = None, bOwnership = True):
"""
C{True} if we own the handle and we need to close it.
C{False} if someone else will be calling L{CloseHandle}.
"""
super(Handle, self).__init__()
self._value = self._normalize(aHandle)
self.bOwnership = bOwnership
if Handle.__bLeakDetection: # XXX DEBUG
print("INIT HANDLE (%r) %r" % (self.value, self))
def value(self):
return self._value
def __del__(self):
"""
Closes the Win32 handle when the Python object is destroyed.
"""
try:
if Handle.__bLeakDetection: # XXX DEBUG
print("DEL HANDLE %r" % self)
self.close()
except Exception:
pass
def __enter__(self):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("ENTER HANDLE %r" % self)
return self
def __exit__(self, type, value, traceback):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("EXIT HANDLE %r" % self)
try:
self.close()
except Exception:
pass
def __copy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def __deepcopy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def _as_parameter_(self):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(self.value)
def from_param(value):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(value)
def close(self):
"""
Closes the Win32 handle.
"""
if self.bOwnership and self.value not in (None, INVALID_HANDLE_VALUE):
if Handle.__bLeakDetection: # XXX DEBUG
print("CLOSE HANDLE (%d) %r" % (self.value, self))
try:
self._close()
finally:
self._value = None
def _close(self):
"""
Low-level close method.
This is a private method, do not call it.
"""
CloseHandle(self.value)
def dup(self):
"""
"""
if self.value is None:
raise ValueError("Closed handles can't be duplicated!")
new_handle = DuplicateHandle(self.value)
if Handle.__bLeakDetection: # XXX DEBUG
print("DUP HANDLE (%d -> %d) %r %r" % \
(self.value, new_handle.value, self, new_handle))
return new_handle
def _normalize(value):
"""
Normalize handle values.
"""
if hasattr(value, 'value'):
value = value.value
if value is not None:
value = long(value)
return value
def wait(self, dwMilliseconds = None):
"""
Wait for the Win32 object to be signaled.
Use C{INFINITE} or C{None} for no timeout.
"""
if self.value is None:
raise ValueError("Handle is already closed!")
if dwMilliseconds is None:
dwMilliseconds = INFINITE
r = WaitForSingleObject(self.value, dwMilliseconds)
if r != WAIT_OBJECT_0:
raise ctypes.WinError(r)
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self.value)
def __get_inherit(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_INHERIT )
def __set_inherit(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_INHERIT)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
inherit = property(__get_inherit, __set_inherit)
def __get_protectFromClose(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_PROTECT_FROM_CLOSE )
def __set_protectFromClose(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_PROTECT_FROM_CLOSE)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
protectFromClose = property(__get_protectFromClose, __set_protectFromClose)
def OpenMutexA(dwDesiredAccess = MUTEX_ALL_ACCESS, bInitialOwner = True, lpName = None):
_OpenMutexA = windll.kernel32.OpenMutexA
_OpenMutexA.argtypes = [DWORD, BOOL, LPSTR]
_OpenMutexA.restype = HANDLE
_OpenMutexA.errcheck = RaiseIfZero
return Handle( _OpenMutexA(lpMutexAttributes, bInitialOwner, lpName) ) | null |
177,244 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
MUTEX_ALL_ACCESS = 0x1F0001
class Handle (object):
def __init__(self, aHandle = None, bOwnership = True):
def value(self):
def __del__(self):
def __enter__(self):
def __exit__(self, type, value, traceback):
def __copy__(self):
def __deepcopy__(self):
def _as_parameter_(self):
def from_param(value):
def close(self):
def _close(self):
def dup(self):
def _normalize(value):
def wait(self, dwMilliseconds = None):
def __repr__(self):
def __get_inherit(self):
def __set_inherit(self, value):
def __get_protectFromClose(self):
def __set_protectFromClose(self, value):
def OpenMutexW(dwDesiredAccess = MUTEX_ALL_ACCESS, bInitialOwner = True, lpName = None):
_OpenMutexW = windll.kernel32.OpenMutexW
_OpenMutexW.argtypes = [DWORD, BOOL, LPWSTR]
_OpenMutexW.restype = HANDLE
_OpenMutexW.errcheck = RaiseIfZero
return Handle( _OpenMutexW(lpMutexAttributes, bInitialOwner, lpName) ) | null |
177,245 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
class Handle (object):
"""
Encapsulates Win32 handles to avoid leaking them.
C{False} otherwise.
closed. Must be set to C{False} before you're done using the handle,
or it will be left open until the debugger exits. Use with care!
L{ProcessHandle}, L{ThreadHandle}, L{FileHandle}, L{SnapshotHandle}
"""
# XXX DEBUG
# When this private flag is True each Handle will print a message to
# standard output when it's created and destroyed. This is useful for
# detecting handle leaks within WinAppDbg itself.
__bLeakDetection = False
def __init__(self, aHandle = None, bOwnership = True):
"""
C{True} if we own the handle and we need to close it.
C{False} if someone else will be calling L{CloseHandle}.
"""
super(Handle, self).__init__()
self._value = self._normalize(aHandle)
self.bOwnership = bOwnership
if Handle.__bLeakDetection: # XXX DEBUG
print("INIT HANDLE (%r) %r" % (self.value, self))
def value(self):
return self._value
def __del__(self):
"""
Closes the Win32 handle when the Python object is destroyed.
"""
try:
if Handle.__bLeakDetection: # XXX DEBUG
print("DEL HANDLE %r" % self)
self.close()
except Exception:
pass
def __enter__(self):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("ENTER HANDLE %r" % self)
return self
def __exit__(self, type, value, traceback):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("EXIT HANDLE %r" % self)
try:
self.close()
except Exception:
pass
def __copy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def __deepcopy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def _as_parameter_(self):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(self.value)
def from_param(value):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(value)
def close(self):
"""
Closes the Win32 handle.
"""
if self.bOwnership and self.value not in (None, INVALID_HANDLE_VALUE):
if Handle.__bLeakDetection: # XXX DEBUG
print("CLOSE HANDLE (%d) %r" % (self.value, self))
try:
self._close()
finally:
self._value = None
def _close(self):
"""
Low-level close method.
This is a private method, do not call it.
"""
CloseHandle(self.value)
def dup(self):
"""
"""
if self.value is None:
raise ValueError("Closed handles can't be duplicated!")
new_handle = DuplicateHandle(self.value)
if Handle.__bLeakDetection: # XXX DEBUG
print("DUP HANDLE (%d -> %d) %r %r" % \
(self.value, new_handle.value, self, new_handle))
return new_handle
def _normalize(value):
"""
Normalize handle values.
"""
if hasattr(value, 'value'):
value = value.value
if value is not None:
value = long(value)
return value
def wait(self, dwMilliseconds = None):
"""
Wait for the Win32 object to be signaled.
Use C{INFINITE} or C{None} for no timeout.
"""
if self.value is None:
raise ValueError("Handle is already closed!")
if dwMilliseconds is None:
dwMilliseconds = INFINITE
r = WaitForSingleObject(self.value, dwMilliseconds)
if r != WAIT_OBJECT_0:
raise ctypes.WinError(r)
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self.value)
def __get_inherit(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_INHERIT )
def __set_inherit(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_INHERIT)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
inherit = property(__get_inherit, __set_inherit)
def __get_protectFromClose(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_PROTECT_FROM_CLOSE )
def __set_protectFromClose(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_PROTECT_FROM_CLOSE)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
protectFromClose = property(__get_protectFromClose, __set_protectFromClose)
def CreateEventW(lpMutexAttributes = None, bManualReset = False, bInitialState = False, lpName = None):
_CreateEventW = windll.kernel32.CreateEventW
_CreateEventW.argtypes = [LPVOID, BOOL, BOOL, LPWSTR]
_CreateEventW.restype = HANDLE
_CreateEventW.errcheck = RaiseIfZero
return Handle( _CreateEventW(lpMutexAttributes, bManualReset, bInitialState, lpName) ) | null |
177,246 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
EVENT_ALL_ACCESS = 0x1F0003
class Handle (object):
"""
Encapsulates Win32 handles to avoid leaking them.
C{False} otherwise.
closed. Must be set to C{False} before you're done using the handle,
or it will be left open until the debugger exits. Use with care!
L{ProcessHandle}, L{ThreadHandle}, L{FileHandle}, L{SnapshotHandle}
"""
# XXX DEBUG
# When this private flag is True each Handle will print a message to
# standard output when it's created and destroyed. This is useful for
# detecting handle leaks within WinAppDbg itself.
__bLeakDetection = False
def __init__(self, aHandle = None, bOwnership = True):
"""
C{True} if we own the handle and we need to close it.
C{False} if someone else will be calling L{CloseHandle}.
"""
super(Handle, self).__init__()
self._value = self._normalize(aHandle)
self.bOwnership = bOwnership
if Handle.__bLeakDetection: # XXX DEBUG
print("INIT HANDLE (%r) %r" % (self.value, self))
def value(self):
return self._value
def __del__(self):
"""
Closes the Win32 handle when the Python object is destroyed.
"""
try:
if Handle.__bLeakDetection: # XXX DEBUG
print("DEL HANDLE %r" % self)
self.close()
except Exception:
pass
def __enter__(self):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("ENTER HANDLE %r" % self)
return self
def __exit__(self, type, value, traceback):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("EXIT HANDLE %r" % self)
try:
self.close()
except Exception:
pass
def __copy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def __deepcopy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def _as_parameter_(self):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(self.value)
def from_param(value):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(value)
def close(self):
"""
Closes the Win32 handle.
"""
if self.bOwnership and self.value not in (None, INVALID_HANDLE_VALUE):
if Handle.__bLeakDetection: # XXX DEBUG
print("CLOSE HANDLE (%d) %r" % (self.value, self))
try:
self._close()
finally:
self._value = None
def _close(self):
"""
Low-level close method.
This is a private method, do not call it.
"""
CloseHandle(self.value)
def dup(self):
"""
"""
if self.value is None:
raise ValueError("Closed handles can't be duplicated!")
new_handle = DuplicateHandle(self.value)
if Handle.__bLeakDetection: # XXX DEBUG
print("DUP HANDLE (%d -> %d) %r %r" % \
(self.value, new_handle.value, self, new_handle))
return new_handle
def _normalize(value):
"""
Normalize handle values.
"""
if hasattr(value, 'value'):
value = value.value
if value is not None:
value = long(value)
return value
def wait(self, dwMilliseconds = None):
"""
Wait for the Win32 object to be signaled.
Use C{INFINITE} or C{None} for no timeout.
"""
if self.value is None:
raise ValueError("Handle is already closed!")
if dwMilliseconds is None:
dwMilliseconds = INFINITE
r = WaitForSingleObject(self.value, dwMilliseconds)
if r != WAIT_OBJECT_0:
raise ctypes.WinError(r)
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self.value)
def __get_inherit(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_INHERIT )
def __set_inherit(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_INHERIT)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
inherit = property(__get_inherit, __set_inherit)
def __get_protectFromClose(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_PROTECT_FROM_CLOSE )
def __set_protectFromClose(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_PROTECT_FROM_CLOSE)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
protectFromClose = property(__get_protectFromClose, __set_protectFromClose)
def OpenEventA(dwDesiredAccess = EVENT_ALL_ACCESS, bInheritHandle = False, lpName = None):
_OpenEventA = windll.kernel32.OpenEventA
_OpenEventA.argtypes = [DWORD, BOOL, LPSTR]
_OpenEventA.restype = HANDLE
_OpenEventA.errcheck = RaiseIfZero
return Handle( _OpenEventA(dwDesiredAccess, bInheritHandle, lpName) ) | null |
177,247 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
EVENT_ALL_ACCESS = 0x1F0003
class Handle (object):
"""
Encapsulates Win32 handles to avoid leaking them.
C{False} otherwise.
closed. Must be set to C{False} before you're done using the handle,
or it will be left open until the debugger exits. Use with care!
L{ProcessHandle}, L{ThreadHandle}, L{FileHandle}, L{SnapshotHandle}
"""
# XXX DEBUG
# When this private flag is True each Handle will print a message to
# standard output when it's created and destroyed. This is useful for
# detecting handle leaks within WinAppDbg itself.
__bLeakDetection = False
def __init__(self, aHandle = None, bOwnership = True):
"""
C{True} if we own the handle and we need to close it.
C{False} if someone else will be calling L{CloseHandle}.
"""
super(Handle, self).__init__()
self._value = self._normalize(aHandle)
self.bOwnership = bOwnership
if Handle.__bLeakDetection: # XXX DEBUG
print("INIT HANDLE (%r) %r" % (self.value, self))
def value(self):
return self._value
def __del__(self):
"""
Closes the Win32 handle when the Python object is destroyed.
"""
try:
if Handle.__bLeakDetection: # XXX DEBUG
print("DEL HANDLE %r" % self)
self.close()
except Exception:
pass
def __enter__(self):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("ENTER HANDLE %r" % self)
return self
def __exit__(self, type, value, traceback):
"""
Compatibility with the "C{with}" Python statement.
"""
if Handle.__bLeakDetection: # XXX DEBUG
print("EXIT HANDLE %r" % self)
try:
self.close()
except Exception:
pass
def __copy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def __deepcopy__(self):
"""
Duplicates the Win32 handle when copying the Python object.
"""
return self.dup()
def _as_parameter_(self):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(self.value)
def from_param(value):
"""
Compatibility with ctypes.
Allows passing transparently a Handle object to an API call.
"""
return HANDLE(value)
def close(self):
"""
Closes the Win32 handle.
"""
if self.bOwnership and self.value not in (None, INVALID_HANDLE_VALUE):
if Handle.__bLeakDetection: # XXX DEBUG
print("CLOSE HANDLE (%d) %r" % (self.value, self))
try:
self._close()
finally:
self._value = None
def _close(self):
"""
Low-level close method.
This is a private method, do not call it.
"""
CloseHandle(self.value)
def dup(self):
"""
"""
if self.value is None:
raise ValueError("Closed handles can't be duplicated!")
new_handle = DuplicateHandle(self.value)
if Handle.__bLeakDetection: # XXX DEBUG
print("DUP HANDLE (%d -> %d) %r %r" % \
(self.value, new_handle.value, self, new_handle))
return new_handle
def _normalize(value):
"""
Normalize handle values.
"""
if hasattr(value, 'value'):
value = value.value
if value is not None:
value = long(value)
return value
def wait(self, dwMilliseconds = None):
"""
Wait for the Win32 object to be signaled.
Use C{INFINITE} or C{None} for no timeout.
"""
if self.value is None:
raise ValueError("Handle is already closed!")
if dwMilliseconds is None:
dwMilliseconds = INFINITE
r = WaitForSingleObject(self.value, dwMilliseconds)
if r != WAIT_OBJECT_0:
raise ctypes.WinError(r)
def __repr__(self):
return '<%s: %s>' % (self.__class__.__name__, self.value)
def __get_inherit(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_INHERIT )
def __set_inherit(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_INHERIT)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
inherit = property(__get_inherit, __set_inherit)
def __get_protectFromClose(self):
if self.value is None:
raise ValueError("Handle is already closed!")
return bool( GetHandleInformation(self.value) & HANDLE_FLAG_PROTECT_FROM_CLOSE )
def __set_protectFromClose(self, value):
if self.value is None:
raise ValueError("Handle is already closed!")
flag = (0, HANDLE_FLAG_PROTECT_FROM_CLOSE)[ bool(value) ]
SetHandleInformation(self.value, flag, flag)
protectFromClose = property(__get_protectFromClose, __set_protectFromClose)
def OpenEventW(dwDesiredAccess = EVENT_ALL_ACCESS, bInheritHandle = False, lpName = None):
_OpenEventW = windll.kernel32.OpenEventW
_OpenEventW.argtypes = [DWORD, BOOL, LPWSTR]
_OpenEventW.restype = HANDLE
_OpenEventW.errcheck = RaiseIfZero
return Handle( _OpenEventW(dwDesiredAccess, bInheritHandle, lpName) ) | null |
177,248 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def ReleaseMutex(hMutex):
_ReleaseMutex = windll.kernel32.ReleaseMutex
_ReleaseMutex.argtypes = [HANDLE]
_ReleaseMutex.restype = bool
_ReleaseMutex.errcheck = RaiseIfZero
_ReleaseMutex(hMutex) | null |
177,249 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def SetEvent(hEvent):
_SetEvent = windll.kernel32.SetEvent
_SetEvent.argtypes = [HANDLE]
_SetEvent.restype = bool
_SetEvent.errcheck = RaiseIfZero
_SetEvent(hEvent) | null |
177,250 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def ResetEvent(hEvent):
_ResetEvent = windll.kernel32.ResetEvent
_ResetEvent.argtypes = [HANDLE]
_ResetEvent.restype = bool
_ResetEvent.errcheck = RaiseIfZero
_ResetEvent(hEvent) | null |
177,251 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def PulseEvent(hEvent):
_PulseEvent = windll.kernel32.PulseEvent
_PulseEvent.argtypes = [HANDLE]
_PulseEvent.restype = bool
_PulseEvent.errcheck = RaiseIfZero
_PulseEvent(hEvent) | null |
177,252 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
WAIT_TIMEOUT = 0x102
class DEBUG_EVENT(Structure):
_fields_ = [
('dwDebugEventCode', DWORD),
('dwProcessId', DWORD),
('dwThreadId', DWORD),
('u', _DEBUG_EVENT_UNION_),
]
LPDEBUG_EVENT = POINTER(DEBUG_EVENT)
def GetLastError():
_GetLastError = windll.kernel32.GetLastError
_GetLastError.argtypes = []
_GetLastError.restype = DWORD
return _GetLastError()
def WaitForDebugEvent(dwMilliseconds = INFINITE):
_WaitForDebugEvent = windll.kernel32.WaitForDebugEvent
_WaitForDebugEvent.argtypes = [LPDEBUG_EVENT, DWORD]
_WaitForDebugEvent.restype = DWORD
if not dwMilliseconds and dwMilliseconds != 0:
dwMilliseconds = INFINITE
lpDebugEvent = DEBUG_EVENT()
lpDebugEvent.dwDebugEventCode = 0
lpDebugEvent.dwProcessId = 0
lpDebugEvent.dwThreadId = 0
if dwMilliseconds != INFINITE:
success = _WaitForDebugEvent(byref(lpDebugEvent), dwMilliseconds)
if success == 0:
raise ctypes.WinError()
else:
# this avoids locking the Python GIL for too long
while 1:
success = _WaitForDebugEvent(byref(lpDebugEvent), 100)
if success != 0:
break
code = GetLastError()
if code not in (ERROR_SEM_TIMEOUT, WAIT_TIMEOUT):
raise ctypes.WinError(code)
return lpDebugEvent | null |
177,253 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
DBG_EXCEPTION_NOT_HANDLED = long(0x80010001)
def ContinueDebugEvent(dwProcessId, dwThreadId, dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED):
_ContinueDebugEvent = windll.kernel32.ContinueDebugEvent
_ContinueDebugEvent.argtypes = [DWORD, DWORD, DWORD]
_ContinueDebugEvent.restype = bool
_ContinueDebugEvent.errcheck = RaiseIfZero
_ContinueDebugEvent(dwProcessId, dwThreadId, dwContinueStatus) | null |
177,254 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def FlushInstructionCache(hProcess, lpBaseAddress = None, dwSize = 0):
# http://blogs.msdn.com/oldnewthing/archive/2003/12/08/55954.aspx#55958
_FlushInstructionCache = windll.kernel32.FlushInstructionCache
_FlushInstructionCache.argtypes = [HANDLE, LPVOID, SIZE_T]
_FlushInstructionCache.restype = bool
_FlushInstructionCache.errcheck = RaiseIfZero
_FlushInstructionCache(hProcess, lpBaseAddress, dwSize) | null |
177,255 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def DebugActiveProcess(dwProcessId):
_DebugActiveProcess = windll.kernel32.DebugActiveProcess
_DebugActiveProcess.argtypes = [DWORD]
_DebugActiveProcess.restype = bool
_DebugActiveProcess.errcheck = RaiseIfZero
_DebugActiveProcess(dwProcessId) | null |
177,256 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def DebugActiveProcessStop(dwProcessId):
_DebugActiveProcessStop = windll.kernel32.DebugActiveProcessStop
_DebugActiveProcessStop.argtypes = [DWORD]
_DebugActiveProcessStop.restype = bool
_DebugActiveProcessStop.errcheck = RaiseIfZero
_DebugActiveProcessStop(dwProcessId) | null |
177,257 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def CheckRemoteDebuggerPresent(hProcess):
_CheckRemoteDebuggerPresent = windll.kernel32.CheckRemoteDebuggerPresent
_CheckRemoteDebuggerPresent.argtypes = [HANDLE, PBOOL]
_CheckRemoteDebuggerPresent.restype = bool
_CheckRemoteDebuggerPresent.errcheck = RaiseIfZero
pbDebuggerPresent = BOOL(0)
_CheckRemoteDebuggerPresent(hProcess, byref(pbDebuggerPresent))
return bool(pbDebuggerPresent.value) | null |
177,258 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def DebugSetProcessKillOnExit(KillOnExit):
_DebugSetProcessKillOnExit = windll.kernel32.DebugSetProcessKillOnExit
_DebugSetProcessKillOnExit.argtypes = [BOOL]
_DebugSetProcessKillOnExit.restype = bool
_DebugSetProcessKillOnExit.errcheck = RaiseIfZero
_DebugSetProcessKillOnExit(bool(KillOnExit)) | null |
177,259 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def DebugBreakProcess(hProcess):
_DebugBreakProcess = windll.kernel32.DebugBreakProcess
_DebugBreakProcess.argtypes = [HANDLE]
_DebugBreakProcess.restype = bool
_DebugBreakProcess.errcheck = RaiseIfZero
_DebugBreakProcess(hProcess) | null |
177,260 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def OutputDebugStringA(lpOutputString):
_OutputDebugStringA = windll.kernel32.OutputDebugStringA
_OutputDebugStringA.argtypes = [LPSTR]
_OutputDebugStringA.restype = None
_OutputDebugStringA(lpOutputString) | null |
177,261 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def OutputDebugStringW(lpOutputString):
_OutputDebugStringW = windll.kernel32.OutputDebugStringW
_OutputDebugStringW.argtypes = [LPWSTR]
_OutputDebugStringW.restype = None
_OutputDebugStringW(lpOutputString) | null |
177,262 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetLastError():
_GetLastError = windll.kernel32.GetLastError
_GetLastError.argtypes = []
_GetLastError.restype = DWORD
return _GetLastError()
def ReadProcessMemory(hProcess, lpBaseAddress, nSize):
_ReadProcessMemory = windll.kernel32.ReadProcessMemory
_ReadProcessMemory.argtypes = [HANDLE, LPVOID, LPVOID, SIZE_T, POINTER(SIZE_T)]
_ReadProcessMemory.restype = bool
lpBuffer = ctypes.create_string_buffer(compat.b(''), nSize)
lpNumberOfBytesRead = SIZE_T(0)
success = _ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, byref(lpNumberOfBytesRead))
if not success and GetLastError() != ERROR_PARTIAL_COPY:
raise ctypes.WinError()
return compat.b(lpBuffer.raw)[:lpNumberOfBytesRead.value] | null |
177,263 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
def GetLastError():
_GetLastError = windll.kernel32.GetLastError
_GetLastError.argtypes = []
_GetLastError.restype = DWORD
return _GetLastError()
def WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer):
_WriteProcessMemory = windll.kernel32.WriteProcessMemory
_WriteProcessMemory.argtypes = [HANDLE, LPVOID, LPVOID, SIZE_T, POINTER(SIZE_T)]
_WriteProcessMemory.restype = bool
nSize = len(lpBuffer)
lpBuffer = ctypes.create_string_buffer(lpBuffer)
lpNumberOfBytesWritten = SIZE_T(0)
success = _WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, byref(lpNumberOfBytesWritten))
if not success and GetLastError() != ERROR_PARTIAL_COPY:
raise ctypes.WinError()
return lpNumberOfBytesWritten.value | null |
177,264 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
PAGE_EXECUTE_READWRITE = 0x40
MEM_COMMIT = 0x1000
MEM_RESERVE = 0x2000
def VirtualAllocEx(hProcess, lpAddress = 0, dwSize = 0x1000, flAllocationType = MEM_COMMIT | MEM_RESERVE, flProtect = PAGE_EXECUTE_READWRITE):
_VirtualAllocEx = windll.kernel32.VirtualAllocEx
_VirtualAllocEx.argtypes = [HANDLE, LPVOID, SIZE_T, DWORD, DWORD]
_VirtualAllocEx.restype = LPVOID
lpAddress = _VirtualAllocEx(hProcess, lpAddress, dwSize, flAllocationType, flProtect)
if lpAddress == NULL:
raise ctypes.WinError()
return lpAddress | null |
177,265 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
class MemoryBasicInformation (object):
def __init__(self, mbi=None):
def __contains__(self, address):
def is_free(self):
def is_reserved(self):
def is_commited(self):
def is_image(self):
def is_mapped(self):
def is_private(self):
def is_guard(self):
def has_content(self):
def is_readable(self):
def is_writeable(self):
def is_copy_on_write(self):
def is_executable(self):
def is_executable_and_writeable(self):
class MEMORY_BASIC_INFORMATION(Structure):
PMEMORY_BASIC_INFORMATION = POINTER(MEMORY_BASIC_INFORMATION)
def VirtualQueryEx(hProcess, lpAddress):
_VirtualQueryEx = windll.kernel32.VirtualQueryEx
_VirtualQueryEx.argtypes = [HANDLE, LPVOID, PMEMORY_BASIC_INFORMATION, SIZE_T]
_VirtualQueryEx.restype = SIZE_T
lpBuffer = MEMORY_BASIC_INFORMATION()
dwLength = sizeof(MEMORY_BASIC_INFORMATION)
success = _VirtualQueryEx(hProcess, lpAddress, byref(lpBuffer), dwLength)
if success == 0:
raise ctypes.WinError()
return MemoryBasicInformation(lpBuffer) | null |
177,266 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
PAGE_EXECUTE_READWRITE = 0x40
def VirtualProtectEx(hProcess, lpAddress, dwSize, flNewProtect = PAGE_EXECUTE_READWRITE):
_VirtualProtectEx = windll.kernel32.VirtualProtectEx
_VirtualProtectEx.argtypes = [HANDLE, LPVOID, SIZE_T, DWORD, PDWORD]
_VirtualProtectEx.restype = bool
_VirtualProtectEx.errcheck = RaiseIfZero
flOldProtect = DWORD(0)
_VirtualProtectEx(hProcess, lpAddress, dwSize, flNewProtect, byref(flOldProtect))
return flOldProtect.value | null |
177,267 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
MEM_RELEASE = 0x8000
def VirtualFreeEx(hProcess, lpAddress, dwSize = 0, dwFreeType = MEM_RELEASE):
_VirtualFreeEx = windll.kernel32.VirtualFreeEx
_VirtualFreeEx.argtypes = [HANDLE, LPVOID, SIZE_T, DWORD]
_VirtualFreeEx.restype = bool
_VirtualFreeEx.errcheck = RaiseIfZero
_VirtualFreeEx(hProcess, lpAddress, dwSize, dwFreeType) | null |
177,268 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
class ThreadHandle (Handle):
"""
Win32 thread handle.
This is the same value passed to L{OpenThread}.
Can only be C{None} if C{aHandle} is also C{None}.
Defaults to L{THREAD_ALL_ACCESS}.
"""
def __init__(self, aHandle = None, bOwnership = True,
dwAccess = THREAD_ALL_ACCESS):
"""
C{True} if we own the handle and we need to close it.
C{False} if someone else will be calling L{CloseHandle}.
This is the same value passed to L{OpenThread}.
Can only be C{None} if C{aHandle} is also C{None}.
Defaults to L{THREAD_ALL_ACCESS}.
"""
super(ThreadHandle, self).__init__(aHandle, bOwnership)
self.dwAccess = dwAccess
if aHandle is not None and dwAccess is None:
msg = "Missing access flags for thread handle: %x" % aHandle
raise TypeError(msg)
def get_tid(self):
"""
"""
return GetThreadId(self.value)
LPSECURITY_ATTRIBUTES = POINTER(SECURITY_ATTRIBUTES)
def CreateRemoteThread(hProcess, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags):
_CreateRemoteThread = windll.kernel32.CreateRemoteThread
_CreateRemoteThread.argtypes = [HANDLE, LPSECURITY_ATTRIBUTES, SIZE_T, LPVOID, LPVOID, DWORD, LPDWORD]
_CreateRemoteThread.restype = HANDLE
if not lpThreadAttributes:
lpThreadAttributes = None
else:
lpThreadAttributes = byref(lpThreadAttributes)
dwThreadId = DWORD(0)
hThread = _CreateRemoteThread(hProcess, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, byref(dwThreadId))
if not hThread:
raise ctypes.WinError()
return ThreadHandle(hThread), dwThreadId.value | null |
177,269 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
class ProcessInformation (object):
"""
Process information object returned by L{CreateProcess}.
"""
def __init__(self, pi):
self.hProcess = ProcessHandle(pi.hProcess)
self.hThread = ThreadHandle(pi.hThread)
self.dwProcessId = pi.dwProcessId
self.dwThreadId = pi.dwThreadId
LPSECURITY_ATTRIBUTES = POINTER(SECURITY_ATTRIBUTES)
class PROCESS_INFORMATION(Structure):
_fields_ = [
('hProcess', HANDLE),
('hThread', HANDLE),
('dwProcessId', DWORD),
('dwThreadId', DWORD),
]
LPPROCESS_INFORMATION = POINTER(PROCESS_INFORMATION)
class STARTUPINFO(Structure):
_fields_ = [
('cb', DWORD),
('lpReserved', LPSTR),
('lpDesktop', LPSTR),
('lpTitle', LPSTR),
('dwX', DWORD),
('dwY', DWORD),
('dwXSize', DWORD),
('dwYSize', DWORD),
('dwXCountChars', DWORD),
('dwYCountChars', DWORD),
('dwFillAttribute', DWORD),
('dwFlags', DWORD),
('wShowWindow', WORD),
('cbReserved2', WORD),
('lpReserved2', LPVOID), # LPBYTE
('hStdInput', HANDLE),
('hStdOutput', HANDLE),
('hStdError', HANDLE),
]
def CreateProcessA(lpApplicationName, lpCommandLine=None, lpProcessAttributes=None, lpThreadAttributes=None, bInheritHandles=False, dwCreationFlags=0, lpEnvironment=None, lpCurrentDirectory=None, lpStartupInfo=None):
_CreateProcessA = windll.kernel32.CreateProcessA
_CreateProcessA.argtypes = [LPSTR, LPSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPSTR, LPVOID, LPPROCESS_INFORMATION]
_CreateProcessA.restype = bool
_CreateProcessA.errcheck = RaiseIfZero
if not lpApplicationName:
lpApplicationName = None
if not lpCommandLine:
lpCommandLine = None
else:
lpCommandLine = ctypes.create_string_buffer(lpCommandLine, max(MAX_PATH, len(lpCommandLine)))
if not lpEnvironment:
lpEnvironment = None
else:
lpEnvironment = ctypes.create_string_buffer(lpEnvironment)
if not lpCurrentDirectory:
lpCurrentDirectory = None
if not lpProcessAttributes:
lpProcessAttributes = None
else:
lpProcessAttributes = byref(lpProcessAttributes)
if not lpThreadAttributes:
lpThreadAttributes = None
else:
lpThreadAttributes = byref(lpThreadAttributes)
if not lpStartupInfo:
lpStartupInfo = STARTUPINFO()
lpStartupInfo.cb = sizeof(STARTUPINFO)
lpStartupInfo.lpReserved = 0
lpStartupInfo.lpDesktop = 0
lpStartupInfo.lpTitle = 0
lpStartupInfo.dwFlags = 0
lpStartupInfo.cbReserved2 = 0
lpStartupInfo.lpReserved2 = 0
lpProcessInformation = PROCESS_INFORMATION()
lpProcessInformation.hProcess = INVALID_HANDLE_VALUE
lpProcessInformation.hThread = INVALID_HANDLE_VALUE
lpProcessInformation.dwProcessId = 0
lpProcessInformation.dwThreadId = 0
_CreateProcessA(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bool(bInheritHandles), dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation))
return ProcessInformation(lpProcessInformation) | null |
177,270 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
class ProcessInformation (object):
"""
Process information object returned by L{CreateProcess}.
"""
def __init__(self, pi):
self.hProcess = ProcessHandle(pi.hProcess)
self.hThread = ThreadHandle(pi.hThread)
self.dwProcessId = pi.dwProcessId
self.dwThreadId = pi.dwThreadId
LPSECURITY_ATTRIBUTES = POINTER(SECURITY_ATTRIBUTES)
class PROCESS_INFORMATION(Structure):
_fields_ = [
('hProcess', HANDLE),
('hThread', HANDLE),
('dwProcessId', DWORD),
('dwThreadId', DWORD),
]
LPPROCESS_INFORMATION = POINTER(PROCESS_INFORMATION)
class STARTUPINFO(Structure):
_fields_ = [
('cb', DWORD),
('lpReserved', LPSTR),
('lpDesktop', LPSTR),
('lpTitle', LPSTR),
('dwX', DWORD),
('dwY', DWORD),
('dwXSize', DWORD),
('dwYSize', DWORD),
('dwXCountChars', DWORD),
('dwYCountChars', DWORD),
('dwFillAttribute', DWORD),
('dwFlags', DWORD),
('wShowWindow', WORD),
('cbReserved2', WORD),
('lpReserved2', LPVOID), # LPBYTE
('hStdInput', HANDLE),
('hStdOutput', HANDLE),
('hStdError', HANDLE),
]
def CreateProcessW(lpApplicationName, lpCommandLine=None, lpProcessAttributes=None, lpThreadAttributes=None, bInheritHandles=False, dwCreationFlags=0, lpEnvironment=None, lpCurrentDirectory=None, lpStartupInfo=None):
_CreateProcessW = windll.kernel32.CreateProcessW
_CreateProcessW.argtypes = [LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPWSTR, LPVOID, LPPROCESS_INFORMATION]
_CreateProcessW.restype = bool
_CreateProcessW.errcheck = RaiseIfZero
if not lpApplicationName:
lpApplicationName = None
if not lpCommandLine:
lpCommandLine = None
else:
lpCommandLine = ctypes.create_unicode_buffer(lpCommandLine, max(MAX_PATH, len(lpCommandLine)))
if not lpEnvironment:
lpEnvironment = None
else:
lpEnvironment = ctypes.create_unicode_buffer(lpEnvironment)
if not lpCurrentDirectory:
lpCurrentDirectory = None
if not lpProcessAttributes:
lpProcessAttributes = None
else:
lpProcessAttributes = byref(lpProcessAttributes)
if not lpThreadAttributes:
lpThreadAttributes = None
else:
lpThreadAttributes = byref(lpThreadAttributes)
if not lpStartupInfo:
lpStartupInfo = STARTUPINFO()
lpStartupInfo.cb = sizeof(STARTUPINFO)
lpStartupInfo.lpReserved = 0
lpStartupInfo.lpDesktop = 0
lpStartupInfo.lpTitle = 0
lpStartupInfo.dwFlags = 0
lpStartupInfo.cbReserved2 = 0
lpStartupInfo.lpReserved2 = 0
lpProcessInformation = PROCESS_INFORMATION()
lpProcessInformation.hProcess = INVALID_HANDLE_VALUE
lpProcessInformation.hThread = INVALID_HANDLE_VALUE
lpProcessInformation.dwProcessId = 0
lpProcessInformation.dwThreadId = 0
_CreateProcessW(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bool(bInheritHandles), dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation))
return ProcessInformation(lpProcessInformation) | null |
177,271 | import warnings
from winappdbg.win32.defines import *
from winappdbg.win32 import context_i386
from winappdbg.win32 import context_amd64
from winappdbg.win32.version import *
LPPROC_THREAD_ATTRIBUTE_LIST = PPROC_THREAD_ATTRIBUTE_LIST
def InitializeProcThreadAttributeList(dwAttributeCount):
_InitializeProcThreadAttributeList = windll.kernel32.InitializeProcThreadAttributeList
_InitializeProcThreadAttributeList.argtypes = [LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD, PSIZE_T]
_InitializeProcThreadAttributeList.restype = bool
Size = SIZE_T(0)
_InitializeProcThreadAttributeList(None, dwAttributeCount, 0, byref(Size))
RaiseIfZero(Size.value)
AttributeList = (BYTE * Size.value)()
success = _InitializeProcThreadAttributeList(byref(AttributeList), dwAttributeCount, 0, byref(Size))
RaiseIfZero(success)
return AttributeList | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.