id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
177,272
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 UpdateProcThreadAttribute(lpAttributeList, Attribute, Value, cbSize = None): _UpdateProcThreadAttribute = windll.kernel32.UpdateProcThreadAttribute _UpdateProcThreadAttribute.argtypes = [LPPROC_THREAD_ATTRIBUTE_LIST, DWORD, DWORD_PTR, PVOID, SIZE_T, PVOID, PSIZE_T] _UpdateProcThreadAttribute.restype = bool _UpdateProcThreadAttribute.errcheck = RaiseIfZero if cbSize is None: cbSize = sizeof(Value) _UpdateProcThreadAttribute(byref(lpAttributeList), 0, Attribute, byref(Value), cbSize, None, None)
null
177,273
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 DeleteProcThreadAttributeList(lpAttributeList): _DeleteProcThreadAttributeList = windll.kernel32.DeleteProcThreadAttributeList _DeleteProcThreadAttributeList.restype = None _DeleteProcThreadAttributeList(byref(lpAttributeList))
null
177,274
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 ProcessHandle (Handle): """ Win32 process handle. This is the same value passed to L{OpenProcess}. Can only be C{None} if C{aHandle} is also C{None}. Defaults to L{PROCESS_ALL_ACCESS}. """ def __init__(self, aHandle = None, bOwnership = True, dwAccess = PROCESS_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{OpenProcess}. Can only be C{None} if C{aHandle} is also C{None}. Defaults to L{PROCESS_ALL_ACCESS}. """ super(ProcessHandle, self).__init__(aHandle, bOwnership) self.dwAccess = dwAccess if aHandle is not None and dwAccess is None: msg = "Missing access flags for process handle: %x" % aHandle raise TypeError(msg) def get_pid(self): """ """ return GetProcessId(self.value) def OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId): _OpenProcess = windll.kernel32.OpenProcess _OpenProcess.argtypes = [DWORD, BOOL, DWORD] _OpenProcess.restype = HANDLE hProcess = _OpenProcess(dwDesiredAccess, bool(bInheritHandle), dwProcessId) if hProcess == NULL: raise ctypes.WinError() return ProcessHandle(hProcess, dwAccess = dwDesiredAccess)
null
177,275
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) def OpenThread(dwDesiredAccess, bInheritHandle, dwThreadId): _OpenThread = windll.kernel32.OpenThread _OpenThread.argtypes = [DWORD, BOOL, DWORD] _OpenThread.restype = HANDLE hThread = _OpenThread(dwDesiredAccess, bool(bInheritHandle), dwThreadId) if hThread == NULL: raise ctypes.WinError() return ThreadHandle(hThread, dwAccess = dwDesiredAccess)
null
177,276
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 SuspendThread(hThread): _SuspendThread = windll.kernel32.SuspendThread _SuspendThread.argtypes = [HANDLE] _SuspendThread.restype = DWORD previousCount = _SuspendThread(hThread) if previousCount == DWORD(-1).value: raise ctypes.WinError() return previousCount
null
177,277
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 ResumeThread(hThread): _ResumeThread = windll.kernel32.ResumeThread _ResumeThread.argtypes = [HANDLE] _ResumeThread.restype = DWORD previousCount = _ResumeThread(hThread) if previousCount == DWORD(-1).value: raise ctypes.WinError() return previousCount
null
177,278
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 TerminateThread(hThread, dwExitCode = 0): _TerminateThread = windll.kernel32.TerminateThread _TerminateThread.argtypes = [HANDLE, DWORD] _TerminateThread.restype = bool _TerminateThread.errcheck = RaiseIfZero _TerminateThread(hThread, dwExitCode)
null
177,279
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 TerminateProcess(hProcess, dwExitCode = 0): _TerminateProcess = windll.kernel32.TerminateProcess _TerminateProcess.argtypes = [HANDLE, DWORD] _TerminateProcess.restype = bool _TerminateProcess.errcheck = RaiseIfZero _TerminateProcess(hProcess, dwExitCode)
null
177,280
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 GetCurrentProcessId(): _GetCurrentProcessId = windll.kernel32.GetCurrentProcessId _GetCurrentProcessId.argtypes = [] _GetCurrentProcessId.restype = DWORD return _GetCurrentProcessId()
null
177,281
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 GetCurrentThreadId(): _GetCurrentThreadId = windll.kernel32.GetCurrentThreadId _GetCurrentThreadId.argtypes = [] _GetCurrentThreadId.restype = DWORD return _GetCurrentThreadId()
null
177,282
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 GetProcessId(hProcess): _GetProcessId = windll.kernel32.GetProcessId _GetProcessId.argtypes = [HANDLE] _GetProcessId.restype = DWORD _GetProcessId.errcheck = RaiseIfZero return _GetProcessId(hProcess)
null
177,283
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 GetThreadId(hThread): _GetThreadId = windll.kernel32._GetThreadId _GetThreadId.argtypes = [HANDLE] _GetThreadId.restype = DWORD dwThreadId = _GetThreadId(hThread) if dwThreadId == 0: raise ctypes.WinError() return dwThreadId
null
177,284
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 GetProcessIdOfThread(hThread): _GetProcessIdOfThread = windll.kernel32.GetProcessIdOfThread _GetProcessIdOfThread.argtypes = [HANDLE] _GetProcessIdOfThread.restype = DWORD dwProcessId = _GetProcessIdOfThread(hThread) if dwProcessId == 0: raise ctypes.WinError() return dwProcessId
null
177,285
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 GetExitCodeProcess(hProcess): _GetExitCodeProcess = windll.kernel32.GetExitCodeProcess _GetExitCodeProcess.argtypes = [HANDLE] _GetExitCodeProcess.restype = bool _GetExitCodeProcess.errcheck = RaiseIfZero lpExitCode = DWORD(0) _GetExitCodeProcess(hProcess, byref(lpExitCode)) return lpExitCode.value
null
177,286
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 GetExitCodeThread(hThread): _GetExitCodeThread = windll.kernel32.GetExitCodeThread _GetExitCodeThread.argtypes = [HANDLE] _GetExitCodeThread.restype = bool _GetExitCodeThread.errcheck = RaiseIfZero lpExitCode = DWORD(0) _GetExitCodeThread(hThread, byref(lpExitCode)) return lpExitCode.value
null
177,287
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 GetProcessVersion(ProcessId): _GetProcessVersion = windll.kernel32.GetProcessVersion _GetProcessVersion.argtypes = [DWORD] _GetProcessVersion.restype = DWORD retval = _GetProcessVersion(ProcessId) if retval == 0: raise ctypes.WinError() return retval
null
177,288
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 GetPriorityClass(hProcess): _GetPriorityClass = windll.kernel32.GetPriorityClass _GetPriorityClass.argtypes = [HANDLE] _GetPriorityClass.restype = DWORD retval = _GetPriorityClass(hProcess) if retval == 0: raise ctypes.WinError() return retval
null
177,289
import warnings from winappdbg.win32.defines import * from winappdbg.win32 import context_i386 from winappdbg.win32 import context_amd64 from winappdbg.win32.version import * NORMAL_PRIORITY_CLASS = 0x00000020 NORMAL_PRIORITY_CLASS = 0x00000020 def SetPriorityClass(hProcess, dwPriorityClass = NORMAL_PRIORITY_CLASS): _SetPriorityClass = windll.kernel32.SetPriorityClass _SetPriorityClass.argtypes = [HANDLE, DWORD] _SetPriorityClass.restype = bool _SetPriorityClass.errcheck = RaiseIfZero _SetPriorityClass(hProcess, dwPriorityClass)
null
177,290
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 GetProcessPriorityBoost(hProcess): _GetProcessPriorityBoost = windll.kernel32.GetProcessPriorityBoost _GetProcessPriorityBoost.argtypes = [HANDLE, PBOOL] _GetProcessPriorityBoost.restype = bool _GetProcessPriorityBoost.errcheck = RaiseIfZero pDisablePriorityBoost = BOOL(False) _GetProcessPriorityBoost(hProcess, byref(pDisablePriorityBoost)) return bool(pDisablePriorityBoost.value)
null
177,291
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 SetProcessPriorityBoost(hProcess, DisablePriorityBoost): _SetProcessPriorityBoost = windll.kernel32.SetProcessPriorityBoost _SetProcessPriorityBoost.argtypes = [HANDLE, BOOL] _SetProcessPriorityBoost.restype = bool _SetProcessPriorityBoost.errcheck = RaiseIfZero _SetProcessPriorityBoost(hProcess, bool(DisablePriorityBoost))
null
177,292
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 GetProcessAffinityMask(hProcess): _GetProcessAffinityMask = windll.kernel32.GetProcessAffinityMask _GetProcessAffinityMask.argtypes = [HANDLE, PDWORD_PTR, PDWORD_PTR] _GetProcessAffinityMask.restype = bool _GetProcessAffinityMask.errcheck = RaiseIfZero lpProcessAffinityMask = DWORD_PTR(0) lpSystemAffinityMask = DWORD_PTR(0) _GetProcessAffinityMask(hProcess, byref(lpProcessAffinityMask), byref(lpSystemAffinityMask)) return lpProcessAffinityMask.value, lpSystemAffinityMask.value
null
177,293
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 SetProcessAffinityMask(hProcess, dwProcessAffinityMask): _SetProcessAffinityMask = windll.kernel32.SetProcessAffinityMask _SetProcessAffinityMask.argtypes = [HANDLE, DWORD_PTR] _SetProcessAffinityMask.restype = bool _SetProcessAffinityMask.errcheck = RaiseIfZero _SetProcessAffinityMask(hProcess, dwProcessAffinityMask)
null
177,294
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 SnapshotHandle (Handle): """ Toolhelp32 snapshot handle. """ pass TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD | TH32CS_SNAPMODULE) def CreateToolhelp32Snapshot(dwFlags = TH32CS_SNAPALL, th32ProcessID = 0): _CreateToolhelp32Snapshot = windll.kernel32.CreateToolhelp32Snapshot _CreateToolhelp32Snapshot.argtypes = [DWORD, DWORD] _CreateToolhelp32Snapshot.restype = HANDLE hSnapshot = _CreateToolhelp32Snapshot(dwFlags, th32ProcessID) if hSnapshot == INVALID_HANDLE_VALUE: raise ctypes.WinError() return SnapshotHandle(hSnapshot)
null
177,295
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 PROCESSENTRY32(Structure): _fields_ = [ ('dwSize', DWORD), ('cntUsage', DWORD), ('th32ProcessID', DWORD), ('th32DefaultHeapID', ULONG_PTR), ('th32ModuleID', DWORD), ('cntThreads', DWORD), ('th32ParentProcessID', DWORD), ('pcPriClassBase', LONG), ('dwFlags', DWORD), ('szExeFile', TCHAR * 260), ] LPPROCESSENTRY32 = POINTER(PROCESSENTRY32) def GetLastError(): _GetLastError = windll.kernel32.GetLastError _GetLastError.argtypes = [] _GetLastError.restype = DWORD return _GetLastError() def Process32First(hSnapshot): _Process32First = windll.kernel32.Process32First _Process32First.argtypes = [HANDLE, LPPROCESSENTRY32] _Process32First.restype = bool pe = PROCESSENTRY32() pe.dwSize = sizeof(PROCESSENTRY32) success = _Process32First(hSnapshot, byref(pe)) if not success: if GetLastError() == ERROR_NO_MORE_FILES: return None raise ctypes.WinError() return pe
null
177,296
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 PROCESSENTRY32(Structure): LPPROCESSENTRY32 = POINTER(PROCESSENTRY32) def GetLastError(): def Process32Next(hSnapshot, pe = None): _Process32Next = windll.kernel32.Process32Next _Process32Next.argtypes = [HANDLE, LPPROCESSENTRY32] _Process32Next.restype = bool if pe is None: pe = PROCESSENTRY32() pe.dwSize = sizeof(PROCESSENTRY32) success = _Process32Next(hSnapshot, byref(pe)) if not success: if GetLastError() == ERROR_NO_MORE_FILES: return None raise ctypes.WinError() return pe
null
177,297
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 THREADENTRY32(Structure): _fields_ = [ ('dwSize', DWORD), ('cntUsage', DWORD), ('th32ThreadID', DWORD), ('th32OwnerProcessID', DWORD), ('tpBasePri', LONG), ('tpDeltaPri', LONG), ('dwFlags', DWORD), ] LPTHREADENTRY32 = POINTER(THREADENTRY32) def GetLastError(): _GetLastError = windll.kernel32.GetLastError _GetLastError.argtypes = [] _GetLastError.restype = DWORD return _GetLastError() def Thread32First(hSnapshot): _Thread32First = windll.kernel32.Thread32First _Thread32First.argtypes = [HANDLE, LPTHREADENTRY32] _Thread32First.restype = bool te = THREADENTRY32() te.dwSize = sizeof(THREADENTRY32) success = _Thread32First(hSnapshot, byref(te)) if not success: if GetLastError() == ERROR_NO_MORE_FILES: return None raise ctypes.WinError() return te
null
177,298
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 THREADENTRY32(Structure): _fields_ = [ ('dwSize', DWORD), ('cntUsage', DWORD), ('th32ThreadID', DWORD), ('th32OwnerProcessID', DWORD), ('tpBasePri', LONG), ('tpDeltaPri', LONG), ('dwFlags', DWORD), ] LPTHREADENTRY32 = POINTER(THREADENTRY32) def GetLastError(): _GetLastError = windll.kernel32.GetLastError _GetLastError.argtypes = [] _GetLastError.restype = DWORD return _GetLastError() def Thread32Next(hSnapshot, te = None): _Thread32Next = windll.kernel32.Thread32Next _Thread32Next.argtypes = [HANDLE, LPTHREADENTRY32] _Thread32Next.restype = bool if te is None: te = THREADENTRY32() te.dwSize = sizeof(THREADENTRY32) success = _Thread32Next(hSnapshot, byref(te)) if not success: if GetLastError() == ERROR_NO_MORE_FILES: return None raise ctypes.WinError() return te
null
177,299
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 MODULEENTRY32(Structure): _fields_ = [ ("dwSize", DWORD), ("th32ModuleID", DWORD), ("th32ProcessID", DWORD), ("GlblcntUsage", DWORD), ("ProccntUsage", DWORD), ("modBaseAddr", LPVOID), # BYTE* ("modBaseSize", DWORD), ("hModule", HMODULE), ("szModule", TCHAR * (MAX_MODULE_NAME32 + 1)), ("szExePath", TCHAR * MAX_PATH), ] LPMODULEENTRY32 = POINTER(MODULEENTRY32) def GetLastError(): _GetLastError = windll.kernel32.GetLastError _GetLastError.argtypes = [] _GetLastError.restype = DWORD return _GetLastError() def Module32First(hSnapshot): _Module32First = windll.kernel32.Module32First _Module32First.argtypes = [HANDLE, LPMODULEENTRY32] _Module32First.restype = bool me = MODULEENTRY32() me.dwSize = sizeof(MODULEENTRY32) success = _Module32First(hSnapshot, byref(me)) if not success: if GetLastError() == ERROR_NO_MORE_FILES: return None raise ctypes.WinError() return me
null
177,300
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 MODULEENTRY32(Structure): _fields_ = [ ("dwSize", DWORD), ("th32ModuleID", DWORD), ("th32ProcessID", DWORD), ("GlblcntUsage", DWORD), ("ProccntUsage", DWORD), ("modBaseAddr", LPVOID), # BYTE* ("modBaseSize", DWORD), ("hModule", HMODULE), ("szModule", TCHAR * (MAX_MODULE_NAME32 + 1)), ("szExePath", TCHAR * MAX_PATH), ] LPMODULEENTRY32 = POINTER(MODULEENTRY32) def GetLastError(): _GetLastError = windll.kernel32.GetLastError _GetLastError.argtypes = [] _GetLastError.restype = DWORD return _GetLastError() def Module32Next(hSnapshot, me = None): _Module32Next = windll.kernel32.Module32Next _Module32Next.argtypes = [HANDLE, LPMODULEENTRY32] _Module32Next.restype = bool if me is None: me = MODULEENTRY32() me.dwSize = sizeof(MODULEENTRY32) success = _Module32Next(hSnapshot, byref(me)) if not success: if GetLastError() == ERROR_NO_MORE_FILES: return None raise ctypes.WinError() return me
null
177,301
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 HEAPENTRY32(Structure): LPHEAPENTRY32 = POINTER(HEAPENTRY32) def GetLastError(): def Heap32First(th32ProcessID, th32HeapID): _Heap32First = windll.kernel32.Heap32First _Heap32First.argtypes = [LPHEAPENTRY32, DWORD, ULONG_PTR] _Heap32First.restype = bool he = HEAPENTRY32() he.dwSize = sizeof(HEAPENTRY32) success = _Heap32First(byref(he), th32ProcessID, th32HeapID) if not success: if GetLastError() == ERROR_NO_MORE_FILES: return None raise ctypes.WinError() return he
null
177,302
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 HEAPENTRY32(Structure): _fields_ = [ ("dwSize", SIZE_T), ("hHandle", HANDLE), ("dwAddress", ULONG_PTR), ("dwBlockSize", SIZE_T), ("dwFlags", DWORD), ("dwLockCount", DWORD), ("dwResvd", DWORD), ("th32ProcessID", DWORD), ("th32HeapID", ULONG_PTR), ] LPHEAPENTRY32 = POINTER(HEAPENTRY32) def GetLastError(): _GetLastError = windll.kernel32.GetLastError _GetLastError.argtypes = [] _GetLastError.restype = DWORD return _GetLastError() def Heap32Next(he): _Heap32Next = windll.kernel32.Heap32Next _Heap32Next.argtypes = [LPHEAPENTRY32] _Heap32Next.restype = bool he.dwSize = sizeof(HEAPENTRY32) success = _Heap32Next(byref(he)) if not success: if GetLastError() == ERROR_NO_MORE_FILES: return None raise ctypes.WinError() return he
null
177,303
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 HEAPLIST32(Structure): _fields_ = [ ("dwSize", SIZE_T), ("th32ProcessID", DWORD), ("th32HeapID", ULONG_PTR), ("dwFlags", DWORD), ] LPHEAPLIST32 = POINTER(HEAPLIST32) def GetLastError(): _GetLastError = windll.kernel32.GetLastError _GetLastError.argtypes = [] _GetLastError.restype = DWORD return _GetLastError() def Heap32ListFirst(hSnapshot): _Heap32ListFirst = windll.kernel32.Heap32ListFirst _Heap32ListFirst.argtypes = [HANDLE, LPHEAPLIST32] _Heap32ListFirst.restype = bool hl = HEAPLIST32() hl.dwSize = sizeof(HEAPLIST32) success = _Heap32ListFirst(hSnapshot, byref(hl)) if not success: if GetLastError() == ERROR_NO_MORE_FILES: return None raise ctypes.WinError() return hl
null
177,304
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 HEAPLIST32(Structure): _fields_ = [ ("dwSize", SIZE_T), ("th32ProcessID", DWORD), ("th32HeapID", ULONG_PTR), ("dwFlags", DWORD), ] LPHEAPLIST32 = POINTER(HEAPLIST32) def GetLastError(): _GetLastError = windll.kernel32.GetLastError _GetLastError.argtypes = [] _GetLastError.restype = DWORD return _GetLastError() def Heap32ListNext(hSnapshot, hl = None): _Heap32ListNext = windll.kernel32.Heap32ListNext _Heap32ListNext.argtypes = [HANDLE, LPHEAPLIST32] _Heap32ListNext.restype = bool if hl is None: hl = HEAPLIST32() hl.dwSize = sizeof(HEAPLIST32) success = _Heap32ListNext(hSnapshot, byref(hl)) if not success: if GetLastError() == ERROR_NO_MORE_FILES: return None raise ctypes.WinError() return hl
null
177,305
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 Toolhelp32ReadProcessMemory(th32ProcessID, lpBaseAddress, cbRead): _Toolhelp32ReadProcessMemory = windll.kernel32.Toolhelp32ReadProcessMemory _Toolhelp32ReadProcessMemory.argtypes = [DWORD, LPVOID, LPVOID, SIZE_T, POINTER(SIZE_T)] _Toolhelp32ReadProcessMemory.restype = bool lpBuffer = ctypes.create_string_buffer('', cbRead) lpNumberOfBytesRead = SIZE_T(0) success = _Toolhelp32ReadProcessMemory(th32ProcessID, lpBaseAddress, lpBuffer, cbRead, byref(lpNumberOfBytesRead)) if not success and GetLastError() != ERROR_PARTIAL_COPY: raise ctypes.WinError() return str(lpBuffer.raw)[:lpNumberOfBytesRead.value]
null
177,306
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 GetProcessDEPPolicy(hProcess): _GetProcessDEPPolicy = windll.kernel32.GetProcessDEPPolicy _GetProcessDEPPolicy.argtypes = [HANDLE, LPDWORD, PBOOL] _GetProcessDEPPolicy.restype = bool _GetProcessDEPPolicy.errcheck = RaiseIfZero lpFlags = DWORD(0) lpPermanent = BOOL(0) _GetProcessDEPPolicy(hProcess, byref(lpFlags), byref(lpPermanent)) return (lpFlags.value, lpPermanent.value)
null
177,307
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 GetCurrentProcessorNumber(): _GetCurrentProcessorNumber = windll.kernel32.GetCurrentProcessorNumber _GetCurrentProcessorNumber.argtypes = [] _GetCurrentProcessorNumber.restype = DWORD _GetCurrentProcessorNumber.errcheck = RaiseIfZero return _GetCurrentProcessorNumber()
null
177,308
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 FlushProcessWriteBuffers(): _FlushProcessWriteBuffers = windll.kernel32.FlushProcessWriteBuffers _FlushProcessWriteBuffers.argtypes = [] _FlushProcessWriteBuffers.restype = None _FlushProcessWriteBuffers()
null
177,309
import warnings from winappdbg.win32.defines import * from winappdbg.win32 import context_i386 from winappdbg.win32 import context_amd64 from winappdbg.win32.version import * GR_GDIOBJECTS = 0 def GetLastError(): _GetLastError = windll.kernel32.GetLastError _GetLastError.argtypes = [] _GetLastError.restype = DWORD return _GetLastError() def GetGuiResources(hProcess, uiFlags = GR_GDIOBJECTS): _GetGuiResources = windll.kernel32.GetGuiResources _GetGuiResources.argtypes = [HANDLE, DWORD] _GetGuiResources.restype = DWORD dwCount = _GetGuiResources(hProcess, uiFlags) if dwCount == 0: errcode = GetLastError() if errcode != ERROR_SUCCESS: raise ctypes.WinError(errcode) return dwCount
null
177,310
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 GetProcessHandleCount(hProcess): _GetProcessHandleCount = windll.kernel32.GetProcessHandleCount _GetProcessHandleCount.argtypes = [HANDLE, PDWORD] _GetProcessHandleCount.restype = DWORD _GetProcessHandleCount.errcheck = RaiseIfZero pdwHandleCount = DWORD(0) _GetProcessHandleCount(hProcess, byref(pdwHandleCount)) return pdwHandleCount.value
null
177,311
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 FILETIME(Structure): _fields_ = [ ('dwLowDateTime', DWORD), ('dwHighDateTime', DWORD), ] LPFILETIME = POINTER(FILETIME) def GetProcessTimes(hProcess = None): _GetProcessTimes = windll.kernel32.GetProcessTimes _GetProcessTimes.argtypes = [HANDLE, LPFILETIME, LPFILETIME, LPFILETIME, LPFILETIME] _GetProcessTimes.restype = bool _GetProcessTimes.errcheck = RaiseIfZero if hProcess is None: hProcess = GetCurrentProcess() CreationTime = FILETIME() ExitTime = FILETIME() KernelTime = FILETIME() UserTime = FILETIME() _GetProcessTimes(hProcess, byref(CreationTime), byref(ExitTime), byref(KernelTime), byref(UserTime)) return (CreationTime, ExitTime, KernelTime, UserTime)
null
177,312
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 FILETIME(Structure): _fields_ = [ ('dwLowDateTime', DWORD), ('dwHighDateTime', DWORD), ] LPFILETIME = POINTER(FILETIME) class SYSTEMTIME(Structure): _fields_ = [ ('wYear', WORD), ('wMonth', WORD), ('wDayOfWeek', WORD), ('wDay', WORD), ('wHour', WORD), ('wMinute', WORD), ('wSecond', WORD), ('wMilliseconds', WORD), ] LPSYSTEMTIME = POINTER(SYSTEMTIME) def FileTimeToSystemTime(lpFileTime): _FileTimeToSystemTime = windll.kernel32.FileTimeToSystemTime _FileTimeToSystemTime.argtypes = [LPFILETIME, LPSYSTEMTIME] _FileTimeToSystemTime.restype = bool _FileTimeToSystemTime.errcheck = RaiseIfZero if isinstance(lpFileTime, FILETIME): FileTime = lpFileTime else: FileTime = FILETIME() FileTime.dwLowDateTime = lpFileTime & 0xFFFFFFFF FileTime.dwHighDateTime = lpFileTime >> 32 SystemTime = SYSTEMTIME() _FileTimeToSystemTime(byref(FileTime), byref(SystemTime)) return SystemTime
null
177,313
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 FILETIME(Structure): LPFILETIME = POINTER(FILETIME) def GetSystemTimeAsFileTime(): _GetSystemTimeAsFileTime = windll.kernel32.GetSystemTimeAsFileTime _GetSystemTimeAsFileTime.argtypes = [LPFILETIME] _GetSystemTimeAsFileTime.restype = None FileTime = FILETIME() _GetSystemTimeAsFileTime(byref(FileTime)) return FileTime
null
177,314
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 GlobalAddAtomA(lpString): _GlobalAddAtomA = windll.kernel32.GlobalAddAtomA _GlobalAddAtomA.argtypes = [LPSTR] _GlobalAddAtomA.restype = ATOM _GlobalAddAtomA.errcheck = RaiseIfZero return _GlobalAddAtomA(lpString)
null
177,315
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 GlobalAddAtomW(lpString): _GlobalAddAtomW = windll.kernel32.GlobalAddAtomW _GlobalAddAtomW.argtypes = [LPWSTR] _GlobalAddAtomW.restype = ATOM _GlobalAddAtomW.errcheck = RaiseIfZero return _GlobalAddAtomW(lpString)
null
177,316
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 GlobalFindAtomA(lpString): _GlobalFindAtomA = windll.kernel32.GlobalFindAtomA _GlobalFindAtomA.argtypes = [LPSTR] _GlobalFindAtomA.restype = ATOM _GlobalFindAtomA.errcheck = RaiseIfZero return _GlobalFindAtomA(lpString)
null
177,317
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 GlobalFindAtomW(lpString): _GlobalFindAtomW = windll.kernel32.GlobalFindAtomW _GlobalFindAtomW.argtypes = [LPWSTR] _GlobalFindAtomW.restype = ATOM _GlobalFindAtomW.errcheck = RaiseIfZero return _GlobalFindAtomW(lpString)
null
177,318
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 GlobalGetAtomNameA(nAtom): _GlobalGetAtomNameA = windll.kernel32.GlobalGetAtomNameA _GlobalGetAtomNameA.argtypes = [ATOM, LPSTR, ctypes.c_int] _GlobalGetAtomNameA.restype = UINT _GlobalGetAtomNameA.errcheck = RaiseIfZero nSize = 64 while 1: lpBuffer = ctypes.create_string_buffer("", nSize) nCopied = _GlobalGetAtomNameA(nAtom, lpBuffer, nSize) if nCopied < nSize - 1: break nSize = nSize + 64 return lpBuffer.value
null
177,319
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 GlobalGetAtomNameW(nAtom): _GlobalGetAtomNameW = windll.kernel32.GlobalGetAtomNameW _GlobalGetAtomNameW.argtypes = [ATOM, LPWSTR, ctypes.c_int] _GlobalGetAtomNameW.restype = UINT _GlobalGetAtomNameW.errcheck = RaiseIfZero nSize = 64 while 1: lpBuffer = ctypes.create_unicode_buffer(u"", nSize) nCopied = _GlobalGetAtomNameW(nAtom, lpBuffer, nSize) if nCopied < nSize - 1: break nSize = nSize + 64 return lpBuffer.value
null
177,320
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 SetLastError(dwErrCode): _SetLastError = windll.kernel32.SetLastError _SetLastError.argtypes = [DWORD] _SetLastError.restype = None _SetLastError(dwErrCode) def GlobalDeleteAtom(nAtom): _GlobalDeleteAtom = windll.kernel32.GlobalDeleteAtom _GlobalDeleteAtom.argtypes _GlobalDeleteAtom.restype SetLastError(ERROR_SUCCESS) _GlobalDeleteAtom(nAtom) error = GetLastError() if error != ERROR_SUCCESS: raise ctypes.WinError(error)
null
177,321
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 Wow64SuspendThread(hThread): _Wow64SuspendThread = windll.kernel32.Wow64SuspendThread _Wow64SuspendThread.argtypes = [HANDLE] _Wow64SuspendThread.restype = DWORD previousCount = _Wow64SuspendThread(hThread) if previousCount == DWORD(-1).value: raise ctypes.WinError() return previousCount
null
177,322
import warnings from winappdbg.win32.defines import * from winappdbg.win32 import context_i386 from winappdbg.win32 import context_amd64 from winappdbg.win32.version import * The provided code snippet includes necessary dependencies for implementing the `Wow64EnableWow64FsRedirection` function. Write a Python function `def Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection)` to solve the following problem: This function may not work reliably when there are nested calls. Therefore, this function has been replaced by the L{Wow64DisableWow64FsRedirection} and L{Wow64RevertWow64FsRedirection} functions. @see: U{http://msdn.microsoft.com/en-us/library/windows/desktop/aa365744(v=vs.85).aspx} Here is the function: def Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection): """ This function may not work reliably when there are nested calls. Therefore, this function has been replaced by the L{Wow64DisableWow64FsRedirection} and L{Wow64RevertWow64FsRedirection} functions. @see: U{http://msdn.microsoft.com/en-us/library/windows/desktop/aa365744(v=vs.85).aspx} """ _Wow64EnableWow64FsRedirection = windll.kernel32.Wow64EnableWow64FsRedirection _Wow64EnableWow64FsRedirection.argtypes = [BOOLEAN] _Wow64EnableWow64FsRedirection.restype = BOOLEAN _Wow64EnableWow64FsRedirection.errcheck = RaiseIfZero
This function may not work reliably when there are nested calls. Therefore, this function has been replaced by the L{Wow64DisableWow64FsRedirection} and L{Wow64RevertWow64FsRedirection} functions. @see: U{http://msdn.microsoft.com/en-us/library/windows/desktop/aa365744(v=vs.85).aspx}
177,323
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 Wow64DisableWow64FsRedirection(): _Wow64DisableWow64FsRedirection = windll.kernel32.Wow64DisableWow64FsRedirection _Wow64DisableWow64FsRedirection.argtypes = [PPVOID] _Wow64DisableWow64FsRedirection.restype = BOOL _Wow64DisableWow64FsRedirection.errcheck = RaiseIfZero OldValue = PVOID(None) _Wow64DisableWow64FsRedirection(byref(OldValue)) return OldValue
null
177,324
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 Wow64RevertWow64FsRedirection(OldValue): _Wow64RevertWow64FsRedirection = windll.kernel32.Wow64RevertWow64FsRedirection _Wow64RevertWow64FsRedirection.argtypes = [PVOID] _Wow64RevertWow64FsRedirection.restype = BOOL _Wow64RevertWow64FsRedirection.errcheck = RaiseIfZero _Wow64RevertWow64FsRedirection(OldValue)
null
177,325
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def GetUserNameA(): _GetUserNameA = windll.advapi32.GetUserNameA _GetUserNameA.argtypes = [LPSTR, LPDWORD] _GetUserNameA.restype = bool nSize = DWORD(0) _GetUserNameA(None, byref(nSize)) error = GetLastError() if error != ERROR_INSUFFICIENT_BUFFER: raise ctypes.WinError(error) lpBuffer = ctypes.create_string_buffer('', nSize.value + 1) success = _GetUserNameA(lpBuffer, byref(nSize)) if not success: raise ctypes.WinError() return lpBuffer.value
null
177,326
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def GetUserNameW(): _GetUserNameW = windll.advapi32.GetUserNameW _GetUserNameW.argtypes = [LPWSTR, LPDWORD] _GetUserNameW.restype = bool nSize = DWORD(0) _GetUserNameW(None, byref(nSize)) error = GetLastError() if error != ERROR_INSUFFICIENT_BUFFER: raise ctypes.WinError(error) lpBuffer = ctypes.create_unicode_buffer(u'', nSize.value + 1) success = _GetUserNameW(lpBuffer, byref(nSize)) if not success: raise ctypes.WinError() return lpBuffer.value
null
177,327
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def LookupAccountSidA(lpSystemName, lpSid): _LookupAccountSidA = windll.advapi32.LookupAccountSidA _LookupAccountSidA.argtypes = [LPSTR, PSID, LPSTR, LPDWORD, LPSTR, LPDWORD, LPDWORD] _LookupAccountSidA.restype = bool cchName = DWORD(0) cchReferencedDomainName = DWORD(0) peUse = DWORD(0) _LookupAccountSidA(lpSystemName, lpSid, None, byref(cchName), None, byref(cchReferencedDomainName), byref(peUse)) error = GetLastError() if error != ERROR_INSUFFICIENT_BUFFER: raise ctypes.WinError(error) lpName = ctypes.create_string_buffer('', cchName + 1) lpReferencedDomainName = ctypes.create_string_buffer('', cchReferencedDomainName + 1) success = _LookupAccountSidA(lpSystemName, lpSid, lpName, byref(cchName), lpReferencedDomainName, byref(cchReferencedDomainName), byref(peUse)) if not success: raise ctypes.WinError() return lpName.value, lpReferencedDomainName.value, peUse.value def LookupAccountSidW(lpSystemName, lpSid): _LookupAccountSidW = windll.advapi32.LookupAccountSidA _LookupAccountSidW.argtypes = [LPSTR, PSID, LPWSTR, LPDWORD, LPWSTR, LPDWORD, LPDWORD] _LookupAccountSidW.restype = bool cchName = DWORD(0) cchReferencedDomainName = DWORD(0) peUse = DWORD(0) _LookupAccountSidW(lpSystemName, lpSid, None, byref(cchName), None, byref(cchReferencedDomainName), byref(peUse)) error = GetLastError() if error != ERROR_INSUFFICIENT_BUFFER: raise ctypes.WinError(error) lpName = ctypes.create_unicode_buffer(u'', cchName + 1) lpReferencedDomainName = ctypes.create_unicode_buffer(u'', cchReferencedDomainName + 1) success = _LookupAccountSidW(lpSystemName, lpSid, lpName, byref(cchName), lpReferencedDomainName, byref(cchReferencedDomainName), byref(peUse)) if not success: raise ctypes.WinError() return lpName.value, lpReferencedDomainName.value, peUse.value
null
177,328
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def ConvertSidToStringSidA(Sid): _ConvertSidToStringSidA = windll.advapi32.ConvertSidToStringSidA _ConvertSidToStringSidA.argtypes = [PSID, LPSTR] _ConvertSidToStringSidA.restype = bool _ConvertSidToStringSidA.errcheck = RaiseIfZero pStringSid = LPSTR() _ConvertSidToStringSidA(Sid, byref(pStringSid)) try: StringSid = pStringSid.value finally: LocalFree(pStringSid) return StringSid
null
177,329
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def ConvertSidToStringSidW(Sid): _ConvertSidToStringSidW = windll.advapi32.ConvertSidToStringSidW _ConvertSidToStringSidW.argtypes = [PSID, LPWSTR] _ConvertSidToStringSidW.restype = bool _ConvertSidToStringSidW.errcheck = RaiseIfZero pStringSid = LPWSTR() _ConvertSidToStringSidW(Sid, byref(pStringSid)) try: StringSid = pStringSid.value finally: LocalFree(pStringSid) return StringSid
null
177,330
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def ConvertStringSidToSidA(StringSid): _ConvertStringSidToSidA = windll.advapi32.ConvertStringSidToSidA _ConvertStringSidToSidA.argtypes = [LPSTR, PVOID] _ConvertStringSidToSidA.restype = bool _ConvertStringSidToSidA.errcheck = RaiseIfZero Sid = PVOID() _ConvertStringSidToSidA(StringSid, ctypes.pointer(Sid)) return Sid.value
null
177,331
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def ConvertStringSidToSidW(StringSid): _ConvertStringSidToSidW = windll.advapi32.ConvertStringSidToSidW _ConvertStringSidToSidW.argtypes = [LPWSTR, PVOID] _ConvertStringSidToSidW.restype = bool _ConvertStringSidToSidW.errcheck = RaiseIfZero Sid = PVOID() _ConvertStringSidToSidW(StringSid, ctypes.pointer(Sid)) return Sid.value
null
177,332
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def IsValidSid(pSid): _IsValidSid = windll.advapi32.IsValidSid _IsValidSid.argtypes = [PSID] _IsValidSid.restype = bool return _IsValidSid(pSid)
null
177,333
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def EqualSid(pSid1, pSid2): _EqualSid = windll.advapi32.EqualSid _EqualSid.argtypes = [PSID, PSID] _EqualSid.restype = bool return _EqualSid(pSid1, pSid2)
null
177,334
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def GetLengthSid(pSid): _GetLengthSid = windll.advapi32.GetLengthSid _GetLengthSid.argtypes = [PSID] _GetLengthSid.restype = DWORD return _GetLengthSid(pSid) def CopySid(pSourceSid): _CopySid = windll.advapi32.CopySid _CopySid.argtypes = [DWORD, PVOID, PSID] _CopySid.restype = bool _CopySid.errcheck = RaiseIfZero nDestinationSidLength = GetLengthSid(pSourceSid) DestinationSid = ctypes.create_string_buffer('', nDestinationSidLength) pDestinationSid = ctypes.cast(ctypes.pointer(DestinationSid), PVOID) _CopySid(nDestinationSidLength, pDestinationSid, pSourceSid) return ctypes.cast(pDestinationSid, PSID)
null
177,335
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def FreeSid(pSid): _FreeSid = windll.advapi32.FreeSid _FreeSid.argtypes = [PSID] _FreeSid.restype = PSID _FreeSid.errcheck = RaiseIfNotZero _FreeSid(pSid)
null
177,336
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * TOKEN_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT | TOKEN_ADJUST_SESSIONID) class TokenHandle (Handle): def OpenProcessToken(ProcessHandle, DesiredAccess = TOKEN_ALL_ACCESS): _OpenProcessToken = windll.advapi32.OpenProcessToken _OpenProcessToken.argtypes = [HANDLE, DWORD, PHANDLE] _OpenProcessToken.restype = bool _OpenProcessToken.errcheck = RaiseIfZero NewTokenHandle = HANDLE(INVALID_HANDLE_VALUE) _OpenProcessToken(ProcessHandle, DesiredAccess, byref(NewTokenHandle)) return TokenHandle(NewTokenHandle.value)
null
177,337
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * class TokenHandle (Handle): """ Access token handle. """ pass def OpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf = True): _OpenThreadToken = windll.advapi32.OpenThreadToken _OpenThreadToken.argtypes = [HANDLE, DWORD, BOOL, PHANDLE] _OpenThreadToken.restype = bool _OpenThreadToken.errcheck = RaiseIfZero NewTokenHandle = HANDLE(INVALID_HANDLE_VALUE) _OpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, byref(NewTokenHandle)) return TokenHandle(NewTokenHandle.value)
null
177,338
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * SecurityImpersonation = 2 SECURITY_IMPERSONATION_LEVEL = ctypes.c_int class TokenHandle (Handle): """ Access token handle. """ pass def DuplicateToken(ExistingTokenHandle, ImpersonationLevel = SecurityImpersonation): _DuplicateToken = windll.advapi32.DuplicateToken _DuplicateToken.argtypes = [HANDLE, SECURITY_IMPERSONATION_LEVEL, PHANDLE] _DuplicateToken.restype = bool _DuplicateToken.errcheck = RaiseIfZero DuplicateTokenHandle = HANDLE(INVALID_HANDLE_VALUE) _DuplicateToken(ExistingTokenHandle, ImpersonationLevel, byref(DuplicateTokenHandle)) return TokenHandle(DuplicateTokenHandle.value)
null
177,339
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * TOKEN_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY | TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT | TOKEN_ADJUST_SESSIONID) TOKEN_TYPE = ctypes.c_int TokenPrimary = 1 SecurityImpersonation = 2 SECURITY_IMPERSONATION_LEVEL = ctypes.c_int class TokenHandle (Handle): def DuplicateTokenEx(hExistingToken, dwDesiredAccess = TOKEN_ALL_ACCESS, lpTokenAttributes = None, ImpersonationLevel = SecurityImpersonation, TokenType = TokenPrimary): _DuplicateTokenEx = windll.advapi32.DuplicateTokenEx _DuplicateTokenEx.argtypes = [HANDLE, DWORD, LPSECURITY_ATTRIBUTES, SECURITY_IMPERSONATION_LEVEL, TOKEN_TYPE, PHANDLE] _DuplicateTokenEx.restype = bool _DuplicateTokenEx.errcheck = RaiseIfZero DuplicateTokenHandle = HANDLE(INVALID_HANDLE_VALUE) _DuplicateTokenEx(hExistingToken, dwDesiredAccess, lpTokenAttributes, ImpersonationLevel, TokenType, byref(DuplicateTokenHandle)) return TokenHandle(DuplicateTokenHandle.value)
null
177,340
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def IsTokenRestricted(hTokenHandle): _IsTokenRestricted = windll.advapi32.IsTokenRestricted _IsTokenRestricted.argtypes = [HANDLE] _IsTokenRestricted.restype = bool _IsTokenRestricted.errcheck = RaiseIfNotErrorSuccess SetLastError(ERROR_SUCCESS) return _IsTokenRestricted(hTokenHandle)
null
177,341
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * class LUID(Structure): _fields_ = [ ("LowPart", DWORD), ("HighPart", LONG), ] PLUID = POINTER(LUID) def LookupPrivilegeValueA(lpSystemName, lpName): _LookupPrivilegeValueA = windll.advapi32.LookupPrivilegeValueA _LookupPrivilegeValueA.argtypes = [LPSTR, LPSTR, PLUID] _LookupPrivilegeValueA.restype = bool _LookupPrivilegeValueA.errcheck = RaiseIfZero lpLuid = LUID() if not lpSystemName: lpSystemName = None _LookupPrivilegeValueA(lpSystemName, lpName, byref(lpLuid)) return lpLuid
null
177,342
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * class LUID(Structure): _fields_ = [ ("LowPart", DWORD), ("HighPart", LONG), ] PLUID = POINTER(LUID) def LookupPrivilegeValueW(lpSystemName, lpName): _LookupPrivilegeValueW = windll.advapi32.LookupPrivilegeValueW _LookupPrivilegeValueW.argtypes = [LPWSTR, LPWSTR, PLUID] _LookupPrivilegeValueW.restype = bool _LookupPrivilegeValueW.errcheck = RaiseIfZero lpLuid = LUID() if not lpSystemName: lpSystemName = None _LookupPrivilegeValueW(lpSystemName, lpName, byref(lpLuid)) return lpLuid
null
177,343
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * PLUID = POINTER(LUID) def LookupPrivilegeNameA(lpSystemName, lpLuid): _LookupPrivilegeNameA = windll.advapi32.LookupPrivilegeNameA _LookupPrivilegeNameA.argtypes = [LPSTR, PLUID, LPSTR, LPDWORD] _LookupPrivilegeNameA.restype = bool _LookupPrivilegeNameA.errcheck = RaiseIfZero cchName = DWORD(0) _LookupPrivilegeNameA(lpSystemName, byref(lpLuid), NULL, byref(cchName)) lpName = ctypes.create_string_buffer("", cchName.value) _LookupPrivilegeNameA(lpSystemName, byref(lpLuid), byref(lpName), byref(cchName)) return lpName.value
null
177,344
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * PLUID = POINTER(LUID) def LookupPrivilegeNameW(lpSystemName, lpLuid): _LookupPrivilegeNameW = windll.advapi32.LookupPrivilegeNameW _LookupPrivilegeNameW.argtypes = [LPWSTR, PLUID, LPWSTR, LPDWORD] _LookupPrivilegeNameW.restype = bool _LookupPrivilegeNameW.errcheck = RaiseIfZero cchName = DWORD(0) _LookupPrivilegeNameW(lpSystemName, byref(lpLuid), NULL, byref(cchName)) lpName = ctypes.create_unicode_buffer(u"", cchName.value) _LookupPrivilegeNameW(lpSystemName, byref(lpLuid), byref(lpName), byref(cchName)) return lpName.value
null
177,345
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * SE_PRIVILEGE_ENABLED = 0x00000002 SE_PRIVILEGE_REMOVED = 0x00000004 class LUID(Structure): _fields_ = [ ("LowPart", DWORD), ("HighPart", LONG), ] class LUID_AND_ATTRIBUTES(Structure): _fields_ = [ ("Luid", LUID), ("Attributes", DWORD), ] class TOKEN_PRIVILEGES(Structure): _fields_ = [ ("PrivilegeCount", DWORD), ## ("Privileges", LUID_AND_ATTRIBUTES * ANYSIZE_ARRAY), ("Privileges", LUID_AND_ATTRIBUTES), ] # See comments on AdjustTokenPrivileges about this structure LookupPrivilegeValue = GuessStringType(LookupPrivilegeValueA, LookupPrivilegeValueW) def AdjustTokenPrivileges(TokenHandle, NewState = ()): _AdjustTokenPrivileges = windll.advapi32.AdjustTokenPrivileges _AdjustTokenPrivileges.argtypes = [HANDLE, BOOL, LPVOID, DWORD, LPVOID, LPVOID] _AdjustTokenPrivileges.restype = bool _AdjustTokenPrivileges.errcheck = RaiseIfZero # # I don't know how to allocate variable sized structures in ctypes :( # so this hack will work by using always TOKEN_PRIVILEGES of one element # and calling the API many times. This also means the PreviousState # parameter won't be supported yet as it's too much hassle. In a future # version I look forward to implementing this function correctly. # if not NewState: _AdjustTokenPrivileges(TokenHandle, TRUE, NULL, 0, NULL, NULL) else: success = True for (privilege, enabled) in NewState: if not isinstance(privilege, LUID): privilege = LookupPrivilegeValue(NULL, privilege) if enabled == True: flags = SE_PRIVILEGE_ENABLED elif enabled == False: flags = SE_PRIVILEGE_REMOVED elif enabled == None: flags = 0 else: flags = enabled laa = LUID_AND_ATTRIBUTES(privilege, flags) tp = TOKEN_PRIVILEGES(1, laa) _AdjustTokenPrivileges(TokenHandle, FALSE, byref(tp), sizeof(tp), NULL, NULL)
null
177,346
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def CreateProcessWithLogonW(lpUsername = None, lpDomain = None, lpPassword = None, dwLogonFlags = 0, lpApplicationName = None, lpCommandLine = None, dwCreationFlags = 0, lpEnvironment = None, lpCurrentDirectory = None, lpStartupInfo = None): _CreateProcessWithLogonW = windll.advapi32.CreateProcessWithLogonW _CreateProcessWithLogonW.argtypes = [LPWSTR, LPWSTR, LPWSTR, DWORD, LPWSTR, LPWSTR, DWORD, LPVOID, LPWSTR, LPVOID, LPPROCESS_INFORMATION] _CreateProcessWithLogonW.restype = bool _CreateProcessWithLogonW.errcheck = RaiseIfZero if not lpUsername: lpUsername = None if not lpDomain: lpDomain = None if not lpPassword: lpPassword = None 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 lpStartupInfo: lpStartupInfo = STARTUPINFOW() lpStartupInfo.cb = sizeof(STARTUPINFOW) 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 _CreateProcessWithLogonW(lpUsername, lpDomain, lpPassword, dwLogonFlags, lpApplicationName, lpCommandLine, dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation)) return ProcessInformation(lpProcessInformation)
null
177,347
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def CreateProcessWithTokenW(hToken = None, dwLogonFlags = 0, lpApplicationName = None, lpCommandLine = None, dwCreationFlags = 0, lpEnvironment = None, lpCurrentDirectory = None, lpStartupInfo = None): _CreateProcessWithTokenW = windll.advapi32.CreateProcessWithTokenW _CreateProcessWithTokenW.argtypes = [HANDLE, DWORD, LPWSTR, LPWSTR, DWORD, LPVOID, LPWSTR, LPVOID, LPPROCESS_INFORMATION] _CreateProcessWithTokenW.restype = bool _CreateProcessWithTokenW.errcheck = RaiseIfZero if not hToken: hToken = None 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 lpStartupInfo: lpStartupInfo = STARTUPINFOW() lpStartupInfo.cb = sizeof(STARTUPINFOW) 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 _CreateProcessWithTokenW(hToken, dwLogonFlags, lpApplicationName, lpCommandLine, dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation)) return ProcessInformation(lpProcessInformation)
null
177,348
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def CreateProcessAsUserA(hToken = None, lpApplicationName = None, lpCommandLine=None, lpProcessAttributes=None, lpThreadAttributes=None, bInheritHandles=False, dwCreationFlags=0, lpEnvironment=None, lpCurrentDirectory=None, lpStartupInfo=None): _CreateProcessAsUserA = windll.advapi32.CreateProcessAsUserA _CreateProcessAsUserA.argtypes = [HANDLE, LPSTR, LPSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPSTR, LPVOID, LPPROCESS_INFORMATION] _CreateProcessAsUserA.restype = bool _CreateProcessAsUserA.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 _CreateProcessAsUserA(hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bool(bInheritHandles), dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation)) return ProcessInformation(lpProcessInformation)
null
177,349
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def CreateProcessAsUserW(hToken = None, lpApplicationName = None, lpCommandLine=None, lpProcessAttributes=None, lpThreadAttributes=None, bInheritHandles=False, dwCreationFlags=0, lpEnvironment=None, lpCurrentDirectory=None, lpStartupInfo=None): _CreateProcessAsUserW = windll.advapi32.CreateProcessAsUserW _CreateProcessAsUserW.argtypes = [HANDLE, LPWSTR, LPWSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, BOOL, DWORD, LPVOID, LPWSTR, LPVOID, LPPROCESS_INFORMATION] _CreateProcessAsUserW.restype = bool _CreateProcessAsUserW.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 _CreateProcessAsUserW(hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bool(bInheritHandles), dwCreationFlags, lpEnvironment, lpCurrentDirectory, byref(lpStartupInfo), byref(lpProcessInformation)) return ProcessInformation(lpProcessInformation)
null
177,350
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HWCT = LPVOID class ThreadWaitChainSessionHandle (Handle): """ Thread wait chain session handle. Returned by L{OpenThreadWaitChainSession}. """ def __init__(self, aHandle = None): """ """ super(ThreadWaitChainSessionHandle, self).__init__(aHandle, bOwnership = True) def _close(self): if self.value is None: raise ValueError("Handle was already closed!") CloseThreadWaitChainSession(self.value) def dup(self): raise NotImplementedError() def wait(self, dwMilliseconds = None): raise NotImplementedError() def inherit(self): return False def protectFromClose(self): return False PWAITCHAINCALLBACK = WINFUNCTYPE(HWCT, DWORD_PTR, DWORD, LPDWORD, PWAITCHAIN_NODE_INFO, LPBOOL) def OpenThreadWaitChainSession(Flags = 0, callback = None): _OpenThreadWaitChainSession = windll.advapi32.OpenThreadWaitChainSession _OpenThreadWaitChainSession.argtypes = [DWORD, PVOID] _OpenThreadWaitChainSession.restype = HWCT _OpenThreadWaitChainSession.errcheck = RaiseIfZero if callback is not None: callback = PWAITCHAINCALLBACK(callback) aHandle = _OpenThreadWaitChainSession(Flags, callback) return ThreadWaitChainSessionHandle(aHandle)
null
177,351
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * WCT_MAX_NODE_COUNT = 16 WCTP_GETINFO_ALL_FLAGS = WCT_OUT_OF_PROC_FLAG | WCT_OUT_OF_PROC_COM_FLAG | WCT_OUT_OF_PROC_CS_FLAG HWCT = LPVOID class WAITCHAIN_NODE_INFO(Structure): _fields_ = [ ("ObjectType", WCT_OBJECT_TYPE), ("ObjectStatus", WCT_OBJECT_STATUS), ("u", _WAITCHAIN_NODE_INFO_UNION), ] PWAITCHAIN_NODE_INFO = POINTER(WAITCHAIN_NODE_INFO) class WaitChainNodeInfo (object): """ Represents a node in the wait chain. It's a wrapper on the L{WAITCHAIN_NODE_INFO} structure. The following members are defined only if the node is of L{WctThreadType} type: - C{ProcessId} - C{ThreadId} - C{WaitTime} - C{ContextSwitches} Should be one of the following values: - L{WctCriticalSectionType} - L{WctSendMessageType} - L{WctMutexType} - L{WctAlpcType} - L{WctComType} - L{WctThreadWaitType} - L{WctProcessWaitType} - L{WctThreadType} - L{WctComActivationType} - L{WctUnknownType} Should be one of the following values: - L{WctStatusNoAccess} I{(ACCESS_DENIED for this object)} - L{WctStatusRunning} I{(Thread status)} - L{WctStatusBlocked} I{(Thread status)} - L{WctStatusPidOnly} I{(Thread status)} - L{WctStatusPidOnlyRpcss} I{(Thread status)} - L{WctStatusOwned} I{(Dispatcher object status)} - L{WctStatusNotOwned} I{(Dispatcher object status)} - L{WctStatusAbandoned} I{(Dispatcher object status)} - L{WctStatusUnknown} I{(All objects)} - L{WctStatusError} I{(All objects)} """ #@type Timeout: int #@ivar Timeout: Currently not documented in MSDN. # #@type Alertable: bool #@ivar Alertable: Currently not documented in MSDN. # TODO: __repr__ def __init__(self, aStructure): self.ObjectType = aStructure.ObjectType self.ObjectStatus = aStructure.ObjectStatus if self.ObjectType == WctThreadType: self.ProcessId = aStructure.u.ThreadObject.ProcessId self.ThreadId = aStructure.u.ThreadObject.ThreadId self.WaitTime = aStructure.u.ThreadObject.WaitTime self.ContextSwitches = aStructure.u.ThreadObject.ContextSwitches self.ObjectName = u'' else: self.ObjectName = aStructure.u.LockObject.ObjectName.value #self.Timeout = aStructure.u.LockObject.Timeout #self.Alertable = bool(aStructure.u.LockObject.Alertable) def GetThreadWaitChain(WctHandle, Context = None, Flags = WCTP_GETINFO_ALL_FLAGS, ThreadId = -1, NodeCount = WCT_MAX_NODE_COUNT): _GetThreadWaitChain = windll.advapi32.GetThreadWaitChain _GetThreadWaitChain.argtypes = [HWCT, LPDWORD, DWORD, DWORD, LPDWORD, PWAITCHAIN_NODE_INFO, LPBOOL] _GetThreadWaitChain.restype = bool _GetThreadWaitChain.errcheck = RaiseIfZero dwNodeCount = DWORD(NodeCount) NodeInfoArray = (WAITCHAIN_NODE_INFO * NodeCount)() IsCycle = BOOL(0) _GetThreadWaitChain(WctHandle, Context, Flags, ThreadId, byref(dwNodeCount), ctypes.cast(ctypes.pointer(NodeInfoArray), PWAITCHAIN_NODE_INFO), byref(IsCycle)) while dwNodeCount.value > NodeCount: NodeCount = dwNodeCount.value NodeInfoArray = (WAITCHAIN_NODE_INFO * NodeCount)() _GetThreadWaitChain(WctHandle, Context, Flags, ThreadId, byref(dwNodeCount), ctypes.cast(ctypes.pointer(NodeInfoArray), PWAITCHAIN_NODE_INFO), byref(IsCycle)) return ( [ WaitChainNodeInfo(NodeInfoArray[index]) for index in compat.xrange(dwNodeCount.value) ], bool(IsCycle.value) )
null
177,352
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HWCT = LPVOID def CloseThreadWaitChainSession(WctHandle): _CloseThreadWaitChainSession = windll.advapi32.CloseThreadWaitChainSession _CloseThreadWaitChainSession.argtypes = [HWCT] _CloseThreadWaitChainSession(WctHandle)
null
177,353
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * SAFER_LEVEL_HANDLE = HANDLE SAFER_SCOPEID_USER = 2 SAFER_LEVELID_NORMALUSER = 0x20000 class SaferLevelHandle (UserModeHandle): """ Safer level handle. """ _TYPE = SAFER_LEVEL_HANDLE def _close(self): SaferCloseLevel(self.value) def SaferCreateLevel(dwScopeId=SAFER_SCOPEID_USER, dwLevelId=SAFER_LEVELID_NORMALUSER, OpenFlags=0): _SaferCreateLevel = windll.advapi32.SaferCreateLevel _SaferCreateLevel.argtypes = [DWORD, DWORD, DWORD, POINTER(SAFER_LEVEL_HANDLE), LPVOID] _SaferCreateLevel.restype = BOOL _SaferCreateLevel.errcheck = RaiseIfZero hLevelHandle = SAFER_LEVEL_HANDLE(INVALID_HANDLE_VALUE) _SaferCreateLevel(dwScopeId, dwLevelId, OpenFlags, byref(hLevelHandle), None) return SaferLevelHandle(hLevelHandle.value)
null
177,354
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * SAFER_LEVEL_HANDLE = HANDLE class TokenHandle (Handle): """ Access token handle. """ pass def SaferComputeTokenFromLevel(LevelHandle, InAccessToken=None, dwFlags=0): _SaferComputeTokenFromLevel = windll.advapi32.SaferComputeTokenFromLevel _SaferComputeTokenFromLevel.argtypes = [SAFER_LEVEL_HANDLE, HANDLE, PHANDLE, DWORD, LPDWORD] _SaferComputeTokenFromLevel.restype = BOOL _SaferComputeTokenFromLevel.errcheck = RaiseIfZero OutAccessToken = HANDLE(INVALID_HANDLE_VALUE) lpReserved = DWORD(0) _SaferComputeTokenFromLevel(LevelHandle, InAccessToken, byref(OutAccessToken), dwFlags, byref(lpReserved)) return TokenHandle(OutAccessToken.value), lpReserved.value
null
177,355
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * SAFER_LEVEL_HANDLE = HANDLE def SaferCloseLevel(hLevelHandle): _SaferCloseLevel = windll.advapi32.SaferCloseLevel _SaferCloseLevel.argtypes = [SAFER_LEVEL_HANDLE] _SaferCloseLevel.restype = BOOL _SaferCloseLevel.errcheck = RaiseIfZero if hasattr(hLevelHandle, 'value'): _SaferCloseLevel(hLevelHandle.value) else: _SaferCloseLevel(hLevelHandle)
null
177,356
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def SaferiIsExecutableFileType(szFullPath, bFromShellExecute = False): _SaferiIsExecutableFileType = windll.advapi32.SaferiIsExecutableFileType _SaferiIsExecutableFileType.argtypes = [LPWSTR, BOOLEAN] _SaferiIsExecutableFileType.restype = BOOL _SaferiIsExecutableFileType.errcheck = RaiseIfLastError SetLastError(ERROR_SUCCESS) return bool(_SaferiIsExecutableFileType(compat.unicode(szFullPath), bFromShellExecute))
null
177,357
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HKEY_CLASSES_ROOT = 0x80000000 HKEY_CURRENT_USER = 0x80000001 HKEY_LOCAL_MACHINE = 0x80000002 HKEY_USERS = 0x80000003 HKEY_PERFORMANCE_DATA = 0x80000004 HKEY_CURRENT_CONFIG = 0x80000005 def RegCloseKey(hKey): if hasattr(hKey, 'value'): value = hKey.value else: value = hKey if value in ( HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA, HKEY_CURRENT_CONFIG ): return _RegCloseKey = windll.advapi32.RegCloseKey _RegCloseKey.argtypes = [HKEY] _RegCloseKey.restype = LONG _RegCloseKey.errcheck = RaiseIfNotErrorSuccess _RegCloseKey(hKey)
null
177,358
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HKEY_LOCAL_MACHINE = 0x80000002 class RegistryKeyHandle (UserModeHandle): """ Registry key handle. """ _TYPE = HKEY def _close(self): RegCloseKey(self.value) def RegConnectRegistryA(lpMachineName = None, hKey = HKEY_LOCAL_MACHINE): _RegConnectRegistryA = windll.advapi32.RegConnectRegistryA _RegConnectRegistryA.argtypes = [LPSTR, HKEY, PHKEY] _RegConnectRegistryA.restype = LONG _RegConnectRegistryA.errcheck = RaiseIfNotErrorSuccess hkResult = HKEY(INVALID_HANDLE_VALUE) _RegConnectRegistryA(lpMachineName, hKey, byref(hkResult)) return RegistryKeyHandle(hkResult.value)
null
177,359
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HKEY_LOCAL_MACHINE = 0x80000002 class RegistryKeyHandle (UserModeHandle): def _close(self): def RegConnectRegistryW(lpMachineName = None, hKey = HKEY_LOCAL_MACHINE): _RegConnectRegistryW = windll.advapi32.RegConnectRegistryW _RegConnectRegistryW.argtypes = [LPWSTR, HKEY, PHKEY] _RegConnectRegistryW.restype = LONG _RegConnectRegistryW.errcheck = RaiseIfNotErrorSuccess hkResult = HKEY(INVALID_HANDLE_VALUE) _RegConnectRegistryW(lpMachineName, hKey, byref(hkResult)) return RegistryKeyHandle(hkResult.value)
null
177,360
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HKEY_LOCAL_MACHINE = 0x80000002 class RegistryKeyHandle (UserModeHandle): """ Registry key handle. """ _TYPE = HKEY def _close(self): RegCloseKey(self.value) def RegCreateKeyA(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None): _RegCreateKeyA = windll.advapi32.RegCreateKeyA _RegCreateKeyA.argtypes = [HKEY, LPSTR, PHKEY] _RegCreateKeyA.restype = LONG _RegCreateKeyA.errcheck = RaiseIfNotErrorSuccess hkResult = HKEY(INVALID_HANDLE_VALUE) _RegCreateKeyA(hKey, lpSubKey, byref(hkResult)) return RegistryKeyHandle(hkResult.value)
null
177,361
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HKEY_LOCAL_MACHINE = 0x80000002 class RegistryKeyHandle (UserModeHandle): """ Registry key handle. """ _TYPE = HKEY def _close(self): RegCloseKey(self.value) def RegCreateKeyW(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None): _RegCreateKeyW = windll.advapi32.RegCreateKeyW _RegCreateKeyW.argtypes = [HKEY, LPWSTR, PHKEY] _RegCreateKeyW.restype = LONG _RegCreateKeyW.errcheck = RaiseIfNotErrorSuccess hkResult = HKEY(INVALID_HANDLE_VALUE) _RegCreateKeyW(hKey, lpSubKey, byref(hkResult)) return RegistryKeyHandle(hkResult.value)
null
177,362
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HKEY_LOCAL_MACHINE = 0x80000002 class RegistryKeyHandle (UserModeHandle): """ Registry key handle. """ _TYPE = HKEY def _close(self): RegCloseKey(self.value) def RegOpenKeyA(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None): _RegOpenKeyA = windll.advapi32.RegOpenKeyA _RegOpenKeyA.argtypes = [HKEY, LPSTR, PHKEY] _RegOpenKeyA.restype = LONG _RegOpenKeyA.errcheck = RaiseIfNotErrorSuccess hkResult = HKEY(INVALID_HANDLE_VALUE) _RegOpenKeyA(hKey, lpSubKey, byref(hkResult)) return RegistryKeyHandle(hkResult.value)
null
177,363
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HKEY_LOCAL_MACHINE = 0x80000002 class RegistryKeyHandle (UserModeHandle): """ Registry key handle. """ _TYPE = HKEY def _close(self): RegCloseKey(self.value) def RegOpenKeyW(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None): _RegOpenKeyW = windll.advapi32.RegOpenKeyW _RegOpenKeyW.argtypes = [HKEY, LPWSTR, PHKEY] _RegOpenKeyW.restype = LONG _RegOpenKeyW.errcheck = RaiseIfNotErrorSuccess hkResult = HKEY(INVALID_HANDLE_VALUE) _RegOpenKeyW(hKey, lpSubKey, byref(hkResult)) return RegistryKeyHandle(hkResult.value)
null
177,364
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HKEY_LOCAL_MACHINE = 0x80000002 KEY_ALL_ACCESS = 0xF003F class RegistryKeyHandle (UserModeHandle): def _close(self): def RegOpenKeyExA(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None, samDesired = KEY_ALL_ACCESS): _RegOpenKeyExA = windll.advapi32.RegOpenKeyExA _RegOpenKeyExA.argtypes = [HKEY, LPSTR, DWORD, REGSAM, PHKEY] _RegOpenKeyExA.restype = LONG _RegOpenKeyExA.errcheck = RaiseIfNotErrorSuccess hkResult = HKEY(INVALID_HANDLE_VALUE) _RegOpenKeyExA(hKey, lpSubKey, 0, samDesired, byref(hkResult)) return RegistryKeyHandle(hkResult.value)
null
177,365
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * HKEY_LOCAL_MACHINE = 0x80000002 KEY_ALL_ACCESS = 0xF003F class RegistryKeyHandle (UserModeHandle): """ Registry key handle. """ _TYPE = HKEY def _close(self): RegCloseKey(self.value) def RegOpenKeyExW(hKey = HKEY_LOCAL_MACHINE, lpSubKey = None, samDesired = KEY_ALL_ACCESS): _RegOpenKeyExW = windll.advapi32.RegOpenKeyExW _RegOpenKeyExW.argtypes = [HKEY, LPWSTR, DWORD, REGSAM, PHKEY] _RegOpenKeyExW.restype = LONG _RegOpenKeyExW.errcheck = RaiseIfNotErrorSuccess hkResult = HKEY(INVALID_HANDLE_VALUE) _RegOpenKeyExW(hKey, lpSubKey, 0, samDesired, byref(hkResult)) return RegistryKeyHandle(hkResult.value)
null
177,366
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * KEY_ALL_ACCESS = 0xF003F class RegistryKeyHandle (UserModeHandle): """ Registry key handle. """ _TYPE = HKEY def _close(self): RegCloseKey(self.value) def RegOpenCurrentUser(samDesired = KEY_ALL_ACCESS): _RegOpenCurrentUser = windll.advapi32.RegOpenCurrentUser _RegOpenCurrentUser.argtypes = [REGSAM, PHKEY] _RegOpenCurrentUser.restype = LONG _RegOpenCurrentUser.errcheck = RaiseIfNotErrorSuccess hkResult = HKEY(INVALID_HANDLE_VALUE) _RegOpenCurrentUser(samDesired, byref(hkResult)) return RegistryKeyHandle(hkResult.value)
null
177,367
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * KEY_ALL_ACCESS = 0xF003F class RegistryKeyHandle (UserModeHandle): """ Registry key handle. """ _TYPE = HKEY def _close(self): RegCloseKey(self.value) def RegOpenUserClassesRoot(hToken, samDesired = KEY_ALL_ACCESS): _RegOpenUserClassesRoot = windll.advapi32.RegOpenUserClassesRoot _RegOpenUserClassesRoot.argtypes = [HANDLE, DWORD, REGSAM, PHKEY] _RegOpenUserClassesRoot.restype = LONG _RegOpenUserClassesRoot.errcheck = RaiseIfNotErrorSuccess hkResult = HKEY(INVALID_HANDLE_VALUE) _RegOpenUserClassesRoot(hToken, 0, samDesired, byref(hkResult)) return RegistryKeyHandle(hkResult.value)
null
177,368
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def RegQueryValueA(hKey, lpSubKey = None): _RegQueryValueA = windll.advapi32.RegQueryValueA _RegQueryValueA.argtypes = [HKEY, LPSTR, LPVOID, PLONG] _RegQueryValueA.restype = LONG _RegQueryValueA.errcheck = RaiseIfNotErrorSuccess cbValue = LONG(0) _RegQueryValueA(hKey, lpSubKey, None, byref(cbValue)) lpValue = ctypes.create_string_buffer(cbValue.value) _RegQueryValueA(hKey, lpSubKey, lpValue, byref(cbValue)) return lpValue.value
null
177,369
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def RegQueryValueW(hKey, lpSubKey = None): _RegQueryValueW = windll.advapi32.RegQueryValueW _RegQueryValueW.argtypes = [HKEY, LPWSTR, LPVOID, PLONG] _RegQueryValueW.restype = LONG _RegQueryValueW.errcheck = RaiseIfNotErrorSuccess cbValue = LONG(0) _RegQueryValueW(hKey, lpSubKey, None, byref(cbValue)) lpValue = ctypes.create_unicode_buffer(cbValue.value * sizeof(WCHAR)) _RegQueryValueW(hKey, lpSubKey, lpValue, byref(cbValue)) return lpValue.value
null
177,370
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * REG_NONE = 0 REG_SZ = 1 REG_EXPAND_SZ = 2 REG_BINARY = 3 REG_DWORD = 4 REG_DWORD_BIG_ENDIAN = 5 REG_LINK = 6 REG_MULTI_SZ = 7 REG_QWORD = 11 RegSetValueExA = RegSetValueExW = RegSetValueEx def RegSetValueEx(hKey, lpValueName = None, lpData = None, dwType = None): # Determine which version of the API to use, ANSI or Widechar. if lpValueName is None: if isinstance(lpData, GuessStringType.t_ansi): ansi = True elif isinstance(lpData, GuessStringType.t_unicode): ansi = False else: ansi = (GuessStringType.t_ansi == GuessStringType.t_default) elif isinstance(lpValueName, GuessStringType.t_ansi): ansi = True elif isinstance(lpValueName, GuessStringType.t_unicode): ansi = False else: raise TypeError("String expected, got %s instead" % type(lpValueName)) # Autodetect the type when not given. # TODO: improve detection of DWORD and QWORD by seeing if the value "fits". if dwType is None: if lpValueName is None: dwType = REG_SZ elif lpData is None: dwType = REG_NONE elif isinstance(lpData, GuessStringType.t_ansi): dwType = REG_SZ elif isinstance(lpData, GuessStringType.t_unicode): dwType = REG_SZ elif isinstance(lpData, int): dwType = REG_DWORD elif isinstance(lpData, long): dwType = REG_QWORD else: dwType = REG_BINARY # Load the ctypes caller. if ansi: _RegSetValueEx = windll.advapi32.RegSetValueExA _RegSetValueEx.argtypes = [HKEY, LPSTR, DWORD, DWORD, LPVOID, DWORD] else: _RegSetValueEx = windll.advapi32.RegSetValueExW _RegSetValueEx.argtypes = [HKEY, LPWSTR, DWORD, DWORD, LPVOID, DWORD] _RegSetValueEx.restype = LONG _RegSetValueEx.errcheck = RaiseIfNotErrorSuccess # Convert the arguments so ctypes can understand them. if lpData is None: DataRef = None DataSize = 0 else: if dwType in (REG_DWORD, REG_DWORD_BIG_ENDIAN): # REG_DWORD_LITTLE_ENDIAN Data = DWORD(lpData) elif dwType == REG_QWORD: # REG_QWORD_LITTLE_ENDIAN Data = QWORD(lpData) elif dwType in (REG_SZ, REG_EXPAND_SZ): if ansi: Data = ctypes.create_string_buffer(lpData) else: Data = ctypes.create_unicode_buffer(lpData) elif dwType == REG_MULTI_SZ: if ansi: Data = ctypes.create_string_buffer('\0'.join(lpData) + '\0\0') else: Data = ctypes.create_unicode_buffer(u'\0'.join(lpData) + u'\0\0') elif dwType == REG_LINK: Data = ctypes.create_unicode_buffer(lpData) else: Data = ctypes.create_string_buffer(lpData) DataRef = byref(Data) DataSize = sizeof(Data) # Call the API with the converted arguments. _RegSetValueEx(hKey, lpValueName, 0, dwType, DataRef, DataSize)
null
177,371
from winappdbg.win32.defines import * from winappdbg.win32.kernel32 import * def RegEnumKeyA(hKey, dwIndex): _RegEnumKeyA = windll.advapi32.RegEnumKeyA _RegEnumKeyA.argtypes = [HKEY, DWORD, LPSTR, DWORD] _RegEnumKeyA.restype = LONG cchName = 1024 while True: lpName = ctypes.create_string_buffer(cchName) errcode = _RegEnumKeyA(hKey, dwIndex, lpName, cchName) if errcode != ERROR_MORE_DATA: break cchName = cchName + 1024 if cchName > 65536: raise ctypes.WinError(errcode) if errcode == ERROR_NO_MORE_ITEMS: return None if errcode != ERROR_SUCCESS: raise ctypes.WinError(errcode) return lpName.value
null