mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
Refactor winproxy into a directory
This commit is contained in:
-2168
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,8 @@
|
||||
print("Hello from winproxy")
|
||||
|
||||
from .apiproxy import (is_implemented,
|
||||
get_target,
|
||||
resolve)
|
||||
|
||||
from .error import WinproxyError
|
||||
from .apis import * # Import all functions
|
||||
@@ -0,0 +1,100 @@
|
||||
import ctypes
|
||||
import functools
|
||||
|
||||
import windows.generated_def as gdef
|
||||
|
||||
# Utils
|
||||
def is_implemented(apiproxy):
|
||||
"""Return :obj:`True` if DLL/Api can be found"""
|
||||
try:
|
||||
apiproxy.force_resolution()
|
||||
except ExportNotFound:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def get_target(apiproxy):
|
||||
"""POC for newshook"""
|
||||
return apiproxy.target_dll, apiproxy.target_func
|
||||
|
||||
|
||||
def resolve(apiproxy):
|
||||
"""Resolve the address of ``apiproxy``. Might raise if ``apiproxy`` is not implemented"""
|
||||
apiproxy.force_resolution()
|
||||
func = ctypes.WinDLL(dll_name)[func_name]
|
||||
return ctypes.cast(func, gdef.PVOID).value
|
||||
|
||||
# ApiProxy stuff
|
||||
class ExportNotFound(RuntimeError):
|
||||
def __init__(self, func_name, api_name):
|
||||
self.func_name = func_name
|
||||
self.api_name = api_name
|
||||
super(ExportNotFound, self).__init__("Function {0} not found into {1}".format(func_name, api_name))
|
||||
|
||||
|
||||
class NeededParameterType(object):
|
||||
_inst = None
|
||||
|
||||
def __new__(cls):
|
||||
if cls._inst is None:
|
||||
cls._inst = super(NeededParameterType, cls).__new__(cls)
|
||||
return cls._inst
|
||||
|
||||
def __repr__(self):
|
||||
return "NeededParameter"
|
||||
NeededParameter = NeededParameterType()
|
||||
|
||||
class ApiProxy(object):
|
||||
APIDLL = None
|
||||
"""Create a python wrapper around a kernel32 function"""
|
||||
def __init__(self, func_name=None, error_check=None, deffunc_module=None):
|
||||
self.deffunc_module = deffunc_module if deffunc_module is not None else gdef.winfuncs
|
||||
self.func_name = func_name
|
||||
if error_check is None:
|
||||
error_check = self.default_error_check
|
||||
self.error_check = functools.wraps(error_check)(functools.partial(error_check, func_name))
|
||||
self._cprototyped = None
|
||||
|
||||
def __call__(self, python_proxy):
|
||||
# Use the name of the sub-function if None was given
|
||||
if self.func_name is None:
|
||||
self.func_name = python_proxy.__name__
|
||||
prototype = getattr(self.deffunc_module, self.func_name + "Prototype")
|
||||
params = getattr(self.deffunc_module, self.func_name + "Params")
|
||||
python_proxy.prototype = prototype
|
||||
python_proxy.params = params
|
||||
python_proxy.errcheck = self.error_check
|
||||
python_proxy.target_dll = self.APIDLL
|
||||
python_proxy.target_func = self.func_name
|
||||
# Give access to the 'ApiProxy' object from the function
|
||||
python_proxy.proxy = self
|
||||
params_name = [param[1] for param in params]
|
||||
if (self.error_check.__doc__):
|
||||
doc = python_proxy.__doc__
|
||||
doc = doc if doc else ""
|
||||
python_proxy.__doc__ = doc + "\nErrcheck:\n " + self.error_check.__doc__
|
||||
|
||||
def generate_ctypes_function():
|
||||
try:
|
||||
c_prototyped = prototype((self.func_name, getattr(ctypes.windll, self.APIDLL)), params)
|
||||
except (AttributeError, WindowsError):
|
||||
raise ExportNotFound(self.func_name, self.APIDLL)
|
||||
c_prototyped.errcheck = self.error_check
|
||||
self._cprototyped = c_prototyped
|
||||
|
||||
def perform_call(*args):
|
||||
if len(params_name) != len(args):
|
||||
print("ERROR:")
|
||||
print("Expected params: {0}".format(params_name))
|
||||
print("Just Got params: {0}".format(args))
|
||||
raise ValueError("I do not have all parameters: how is that possible ?")
|
||||
for param_name, param_value in zip(params_name, args):
|
||||
if param_value is NeededParameter:
|
||||
raise TypeError("{0}: Missing Mandatory parameter <{1}>".format(self.func_name, param_name))
|
||||
if self._cprototyped is None:
|
||||
generate_ctypes_function()
|
||||
return self._cprototyped(*args)
|
||||
|
||||
setattr(python_proxy, "ctypes_function", perform_call)
|
||||
setattr(python_proxy, "force_resolution", generate_ctypes_function)
|
||||
return python_proxy
|
||||
@@ -0,0 +1,16 @@
|
||||
from advapi32 import *
|
||||
from crypt32 import *
|
||||
from cryptui import *
|
||||
from iphlpapi import *
|
||||
from kernel32 import *
|
||||
from ktmw32 import *
|
||||
from ntdll import *
|
||||
from ole32 import *
|
||||
from oleacc import *
|
||||
from psapi import *
|
||||
from shell32 import *
|
||||
from shlwapi import *
|
||||
from user32 import *
|
||||
from version import *
|
||||
from wevtapi import *
|
||||
from wintrust import *
|
||||
@@ -0,0 +1,341 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import fail_on_zero, succeed_on_zero, result_is_error_code
|
||||
|
||||
class Advapi32Proxy(ApiProxy):
|
||||
APIDLL = "advapi32"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
# Process
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CreateProcessAsUserA(hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation):
|
||||
return CreateProcessAsUserA.ctypes_function(hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CreateProcessAsUserW(hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation):
|
||||
return CreateProcessAsUserW.ctypes_function(hToken, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation)
|
||||
|
||||
|
||||
# Token
|
||||
|
||||
@Advapi32Proxy()
|
||||
def OpenProcessToken(ProcessHandle=None, DesiredAccess=NeededParameter, TokenHandle=NeededParameter):
|
||||
"""If ProcessHandle is None: take the current process"""
|
||||
if ProcessHandle is None:
|
||||
# TODO: FAIL
|
||||
ProcessHandle = GetCurrentProcess()
|
||||
return OpenProcessToken.ctypes_function(ProcessHandle, DesiredAccess, TokenHandle)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def OpenThreadToken(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle):
|
||||
return OpenThreadToken.ctypes_function(ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def SetThreadToken(Thread, Token):
|
||||
return SetThreadToken.ctypes_function(Thread, Token)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def DuplicateToken(ExistingTokenHandle, ImpersonationLevel, DuplicateTokenHandle):
|
||||
return DuplicateToken.ctypes_function(ExistingTokenHandle, ImpersonationLevel, DuplicateTokenHandle)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def DuplicateTokenEx(hExistingToken, dwDesiredAccess, lpTokenAttributes, ImpersonationLevel, TokenType, phNewToken):
|
||||
return DuplicateTokenEx.ctypes_function(hExistingToken, dwDesiredAccess, lpTokenAttributes, ImpersonationLevel, TokenType, phNewToken)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetTokenInformation(TokenHandle=NeededParameter, TokenInformationClass=NeededParameter, TokenInformation=None, TokenInformationLength=0, ReturnLength=None):
|
||||
if ReturnLength is None:
|
||||
ReturnLength = ctypes.byref(gdef.DWORD())
|
||||
return GetTokenInformation.ctypes_function(TokenHandle, TokenInformationClass, TokenInformation, TokenInformationLength, ReturnLength)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def SetTokenInformation(TokenHandle, TokenInformationClass, TokenInformation, TokenInformationLength):
|
||||
return SetTokenInformation.ctypes_function(TokenHandle, TokenInformationClass, TokenInformation, TokenInformationLength)
|
||||
|
||||
|
||||
# Token - Privilege
|
||||
|
||||
@Advapi32Proxy()
|
||||
def LookupPrivilegeValueA(lpSystemName=None, lpName=NeededParameter, lpLuid=NeededParameter):
|
||||
return LookupPrivilegeValueA.ctypes_function(lpSystemName, lpName, lpLuid)
|
||||
|
||||
|
||||
@Advapi32Proxy()
|
||||
def LookupPrivilegeValueW(lpSystemName=None, lpName=NeededParameter, lpLuid=NeededParameter):
|
||||
return LookupPrivilegeValueW.ctypes_function(lpSystemName, lpName, lpLuid)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def LookupPrivilegeNameA(lpSystemName, lpLuid, lpName, cchName):
|
||||
return LookupPrivilegeNameA.ctypes_function(lpSystemName, lpLuid, lpName, cchName)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def LookupPrivilegeNameW(lpSystemName, lpLuid, lpName, cchName):
|
||||
return LookupPrivilegeNameW.ctypes_function(lpSystemName, lpLuid, lpName, cchName)
|
||||
|
||||
|
||||
@Advapi32Proxy()
|
||||
def AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges=False, NewState=NeededParameter, BufferLength=None, PreviousState=None, ReturnLength=None):
|
||||
if BufferLength is None:
|
||||
BufferLength = ctypes.sizeof(NewState)
|
||||
return AdjustTokenPrivileges.ctypes_function(TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength)
|
||||
|
||||
# Sid
|
||||
|
||||
@Advapi32Proxy()
|
||||
def LookupAccountSidA(lpSystemName, lpSid, lpName, cchName, lpReferencedDomainName, cchReferencedDomainName, peUse):
|
||||
return LookupAccountSidA.ctypes_function(lpSystemName, lpSid, lpName, cchName, lpReferencedDomainName, cchReferencedDomainName, peUse)
|
||||
|
||||
|
||||
@Advapi32Proxy()
|
||||
def LookupAccountSidW(lpSystemName, lpSid, lpName, cchName, lpReferencedDomainName, cchReferencedDomainName, peUse):
|
||||
return LookupAccountSidW.ctypes_function(lpSystemName, lpSid, lpName, cchName, lpReferencedDomainName, cchReferencedDomainName, peUse)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CreateWellKnownSid(WellKnownSidType, DomainSid=None, pSid=None, cbSid=NeededParameter):
|
||||
return CreateWellKnownSid.ctypes_function(WellKnownSidType, DomainSid, pSid, cbSid)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetLengthSid(pSid):
|
||||
return GetLengthSid.ctypes_function(pSid)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def EqualSid(pSid1, pSid2):
|
||||
return EqualSid.ctypes_function(pSid1, pSid2)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetSidSubAuthority(pSid, nSubAuthority):
|
||||
return GetSidSubAuthority.ctypes_function(pSid, nSubAuthority)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetSidSubAuthorityCount(pSid):
|
||||
return GetSidSubAuthorityCount.ctypes_function(pSid)
|
||||
|
||||
# Sid stuff
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ConvertStringSidToSidA(StringSid, Sid):
|
||||
return ConvertStringSidToSidA.ctypes_function(StringSid, Sid)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ConvertStringSidToSidW(StringSid, Sid):
|
||||
return ConvertStringSidToSidW.ctypes_function(StringSid, Sid)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ConvertSidToStringSidA(Sid, StringSid):
|
||||
return ConvertSidToStringSidA.ctypes_function(Sid, StringSid)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ConvertSidToStringSidW(Sid, StringSid):
|
||||
return ConvertSidToStringSidW.ctypes_function(Sid, StringSid)
|
||||
|
||||
# Security descriptor
|
||||
|
||||
@Advapi32Proxy(error_check=result_is_error_code)
|
||||
def GetNamedSecurityInfoA(pObjectName, ObjectType, SecurityInfo, ppsidOwner=None, ppsidGroup=None, ppDacl=None, ppSacl=None, ppSecurityDescriptor=None):
|
||||
return GetNamedSecurityInfoA.ctypes_function(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
|
||||
|
||||
@Advapi32Proxy(error_check=result_is_error_code)
|
||||
def GetNamedSecurityInfoW(pObjectName, ObjectType, SecurityInfo, ppsidOwner=None, ppsidGroup=None, ppDacl=None, ppSacl=None, ppSecurityDescriptor=None):
|
||||
return GetNamedSecurityInfoW.ctypes_function(pObjectName, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
|
||||
|
||||
@Advapi32Proxy(error_check=succeed_on_zero)
|
||||
def GetSecurityInfo(handle, ObjectType, SecurityInfo, ppsidOwner=None, ppsidGroup=None, ppDacl=None, ppSacl=None, ppSecurityDescriptor=None):
|
||||
return GetSecurityInfo.ctypes_function(handle, ObjectType, SecurityInfo, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def IsValidSecurityDescriptor(pSecurityDescriptor):
|
||||
return IsValidSecurityDescriptor.ctypes_function(pSecurityDescriptor)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ConvertStringSecurityDescriptorToSecurityDescriptorA(StringSecurityDescriptor, StringSDRevision, SecurityDescriptor, SecurityDescriptorSize):
|
||||
return ConvertStringSecurityDescriptorToSecurityDescriptorA.ctypes_function(StringSecurityDescriptor, StringSDRevision, SecurityDescriptor, SecurityDescriptorSize)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ConvertStringSecurityDescriptorToSecurityDescriptorW(StringSecurityDescriptor, StringSDRevision, SecurityDescriptor, SecurityDescriptorSize):
|
||||
return ConvertStringSecurityDescriptorToSecurityDescriptorW.ctypes_function(StringSecurityDescriptor, StringSDRevision, SecurityDescriptor, SecurityDescriptorSize)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ConvertSecurityDescriptorToStringSecurityDescriptorA(SecurityDescriptor, RequestedStringSDRevision, SecurityInformation, StringSecurityDescriptor, StringSecurityDescriptorLen):
|
||||
return ConvertSecurityDescriptorToStringSecurityDescriptorA.ctypes_function(SecurityDescriptor, RequestedStringSDRevision, SecurityInformation, StringSecurityDescriptor, StringSecurityDescriptorLen)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ConvertSecurityDescriptorToStringSecurityDescriptorW(SecurityDescriptor, RequestedStringSDRevision, SecurityInformation, StringSecurityDescriptor, StringSecurityDescriptorLen):
|
||||
return ConvertSecurityDescriptorToStringSecurityDescriptorW.ctypes_function(SecurityDescriptor, RequestedStringSDRevision, SecurityInformation, StringSecurityDescriptor, StringSecurityDescriptorLen)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetSecurityDescriptorDacl(pSecurityDescriptor, lpbDaclPresent, pDacl, lpbDaclDefaulted):
|
||||
return GetSecurityDescriptorDacl.ctypes_function(pSecurityDescriptor, lpbDaclPresent, pDacl, lpbDaclDefaulted)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetSecurityDescriptorLength(pSecurityDescriptor):
|
||||
return GetSecurityDescriptorLength.ctypes_function(pSecurityDescriptor)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetSecurityDescriptorControl(pSecurityDescriptor, pControl, lpdwRevision):
|
||||
return GetSecurityDescriptorControl.ctypes_function(pSecurityDescriptor, pControl, lpdwRevision)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetSecurityDescriptorOwner(pSecurityDescriptor, pOwner, lpbOwnerDefaulted):
|
||||
return GetSecurityDescriptorOwner.ctypes_function(pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetSecurityDescriptorGroup(pSecurityDescriptor, pGroup, lpbGroupDefaulted):
|
||||
return GetSecurityDescriptorGroup.ctypes_function(pSecurityDescriptor, pGroup, lpbGroupDefaulted)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetSecurityDescriptorSacl(pSecurityDescriptor, lpbSaclPresent, pSacl, lpbSaclDefaulted):
|
||||
return GetSecurityDescriptorSacl.ctypes_function(pSecurityDescriptor, lpbSaclPresent, pSacl, lpbSaclDefaulted)
|
||||
|
||||
# ACE - ACL
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetAclInformation(pAcl, pAclInformation, nAclInformationLength, dwAclInformationClass):
|
||||
return GetAclInformation.ctypes_function(pAcl, pAclInformation, nAclInformationLength, dwAclInformationClass)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetAce(pAcl, dwAceIndex, pAce):
|
||||
return GetAce.ctypes_function(pAcl, dwAceIndex, pAce)
|
||||
|
||||
# Registry
|
||||
|
||||
@Advapi32Proxy(error_check=succeed_on_zero)
|
||||
def RegOpenKeyExA(hKey, lpSubKey, ulOptions, samDesired, phkResult):
|
||||
return RegOpenKeyExA.ctypes_function(hKey, lpSubKey, ulOptions, samDesired, phkResult)
|
||||
|
||||
@Advapi32Proxy(error_check=succeed_on_zero)
|
||||
def RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult):
|
||||
return RegOpenKeyExW.ctypes_function(hKey, lpSubKey, ulOptions, samDesired, phkResult)
|
||||
|
||||
@Advapi32Proxy(error_check=succeed_on_zero)
|
||||
def RegGetValueA(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData):
|
||||
return RegGetValueA.ctypes_function(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData)
|
||||
|
||||
@Advapi32Proxy(error_check=succeed_on_zero)
|
||||
def RegGetValueW(hkey, lpSubKey=None, lpValue=NeededParameter, dwFlags=0, pdwType=None, pvData=None, pcbData=None):
|
||||
return RegGetValueW.ctypes_function(hkey, lpSubKey, lpValue, dwFlags, pdwType, pvData, pcbData)
|
||||
|
||||
@Advapi32Proxy(error_check=succeed_on_zero)
|
||||
def RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData):
|
||||
return RegQueryValueExA.ctypes_function(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData)
|
||||
|
||||
@Advapi32Proxy(error_check=succeed_on_zero)
|
||||
def RegQueryValueExW(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData):
|
||||
return RegQueryValueExA.ctypes_function(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData)
|
||||
|
||||
@Advapi32Proxy(error_check=succeed_on_zero)
|
||||
def RegCloseKey(hKey):
|
||||
return RegCloseKey.ctypes_function(hKey)
|
||||
|
||||
# Service
|
||||
|
||||
@Advapi32Proxy()
|
||||
def OpenSCManagerA(lpMachineName=None, lpDatabaseName=None, dwDesiredAccess=gdef.SC_MANAGER_ALL_ACCESS):
|
||||
return OpenSCManagerA.ctypes_function(lpMachineName, lpDatabaseName, dwDesiredAccess)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def OpenSCManagerW(lpMachineName=None, lpDatabaseName=None, dwDesiredAccess=gdef.SC_MANAGER_ALL_ACCESS):
|
||||
return OpenSCManagerW.ctypes_function(lpMachineName, lpDatabaseName, dwDesiredAccess)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def EnumServicesStatusExA(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName):
|
||||
return EnumServicesStatusExA.ctypes_function(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def EnumServicesStatusExW(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName):
|
||||
return EnumServicesStatusExW.ctypes_function(hSCManager, InfoLevel, dwServiceType, dwServiceState, lpServices, cbBufSize, pcbBytesNeeded, lpServicesReturned, lpResumeHandle, pszGroupName)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def StartServiceA(hService, dwNumServiceArgs, lpServiceArgVectors):
|
||||
return StartServiceA.ctypes_function(hService, dwNumServiceArgs, lpServiceArgVectors)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def StartServiceW(hService, dwNumServiceArgs, lpServiceArgVectors):
|
||||
return StartServiceW.ctypes_function(hService, dwNumServiceArgs, lpServiceArgVectors)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def OpenServiceA(hSCManager, lpServiceName, dwDesiredAccess):
|
||||
return OpenServiceA.ctypes_function(hSCManager, lpServiceName, dwDesiredAccess)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def OpenServiceW(hSCManager, lpServiceName, dwDesiredAccess):
|
||||
return OpenServiceW.ctypes_function(hSCManager, lpServiceName, dwDesiredAccess)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CloseServiceHandle(hSCObject):
|
||||
return CloseServiceHandle.ctypes_function(hSCObject)
|
||||
|
||||
# Event log
|
||||
|
||||
@Advapi32Proxy()
|
||||
def OpenEventLogA(lpUNCServerName=None, lpSourceName=NeededParameter):
|
||||
return OpenEventLogA.ctypes_function(lpUNCServerName, lpSourceName)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def OpenEventLogW(lpUNCServerName=None, lpSourceName=NeededParameter):
|
||||
return OpenEventLogW.ctypes_function(lpUNCServerName, lpSourceName)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def OpenBackupEventLogA(lpUNCServerName=None, lpSourceName=NeededParameter):
|
||||
return OpenBackupEventLogA.ctypes_function(lpUNCServerName, lpSourceName)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def OpenBackupEventLogW(lpUNCServerName=None, lpSourceName=NeededParameter):
|
||||
return OpenBackupEventLogW.ctypes_function(lpUNCServerName, lpSourceName)
|
||||
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ReadEventLogA(hEventLog, dwReadFlags, dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded):
|
||||
return ReadEventLogA.ctypes_function(hEventLog, dwReadFlags, dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def ReadEventLogW(hEventLog, dwReadFlags, dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded):
|
||||
return ReadEventLogW.ctypes_function(hEventLog, dwReadFlags, dwRecordOffset, lpBuffer, nNumberOfBytesToRead, pnBytesRead, pnMinNumberOfBytesNeeded)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetEventLogInformation(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded):
|
||||
return GetEventLogInformation.ctypes_function(hEventLog, dwInfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def GetNumberOfEventLogRecords(hEventLog, NumberOfRecords):
|
||||
return GetNumberOfEventLogRecords.ctypes_function(hEventLog, NumberOfRecords)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CloseEventLog(hEventLog):
|
||||
return CloseEventLog.ctypes_function(hEventLog)
|
||||
|
||||
|
||||
# Crypto
|
||||
## Crypto key
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CryptGenKey(hProv, Algid, dwFlags, phKey):
|
||||
return CryptGenKey.ctypes_function(hProv, Algid, dwFlags, phKey)
|
||||
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CryptDestroyKey(hKey):
|
||||
return CryptDestroyKey.ctypes_function(hKey)
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CryptExportKey(hKey, hExpKey, dwBlobType, dwFlags, pbData, pdwDataLen):
|
||||
return CryptExportKey.ctypes_function(hKey, hExpKey, dwBlobType, dwFlags, pbData, pdwDataLen)
|
||||
|
||||
## crypt context
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CryptAcquireContextA(phProv, pszContainer, pszProvider, dwProvType, dwFlags):
|
||||
return CryptAcquireContextA.ctypes_function(phProv, pszContainer, pszProvider, dwProvType, dwFlags)
|
||||
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CryptAcquireContextW(phProv, pszContainer, pszProvider, dwProvType, dwFlags):
|
||||
return CryptAcquireContextW.ctypes_function(phProv, pszContainer, pszProvider, dwProvType, dwFlags)
|
||||
|
||||
|
||||
@Advapi32Proxy()
|
||||
def CryptReleaseContext(hProv, dwFlags):
|
||||
return CryptReleaseContext.ctypes_function(hProv, dwFlags)
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import no_error_check, fail_on_zero
|
||||
|
||||
class Crypt32Proxy(ApiProxy):
|
||||
APIDLL = "crypt32"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
# Certificate
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertStrToNameA(dwCertEncodingType, pszX500, dwStrType, pvReserved, pbEncoded, pcbEncoded, ppszError):
|
||||
return CertStrToNameA.ctypes_function(dwCertEncodingType, pszX500, dwStrType, pvReserved, pbEncoded, pcbEncoded, ppszError)
|
||||
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertStrToNameW(dwCertEncodingType, pszX500, dwStrType, pvReserved, pbEncoded, pcbEncoded, ppszError):
|
||||
return CertStrToNameW.ctypes_function(dwCertEncodingType, pszX500, dwStrType, pvReserved, pbEncoded, pcbEncoded, ppszError)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertGetNameStringA(pCertContext, dwType, dwFlags, pvTypePara, pszNameString, cchNameString):
|
||||
return CertGetNameStringA.ctypes_function(pCertContext, dwType, dwFlags, pvTypePara, pszNameString, cchNameString)
|
||||
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertGetNameStringW(pCertContext, dwType, dwFlags, pvTypePara, pszNameString, cchNameString):
|
||||
return CertGetNameStringW.ctypes_function(pCertContext, dwType, dwFlags, pvTypePara, pszNameString, cchNameString)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertCreateSelfSignCertificate(hCryptProvOrNCryptKey, pSubjectIssuerBlob, dwFlags, pKeyProvInfo, pSignatureAlgorithm, pStartTime, pEndTime, pExtensions):
|
||||
return CertCreateSelfSignCertificate.ctypes_function(hCryptProvOrNCryptKey, pSubjectIssuerBlob, dwFlags, pKeyProvInfo, pSignatureAlgorithm, pStartTime, pEndTime, pExtensions)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertGetCertificateContextProperty(pCertContext, dwPropId, pvData, pcbData):
|
||||
return CertGetCertificateContextProperty.ctypes_function(pCertContext, dwPropId, pvData, pcbData)
|
||||
|
||||
@Crypt32Proxy(error_check=no_error_check)
|
||||
def CertEnumCertificateContextProperties(pCertContext, dwPropId):
|
||||
return CertEnumCertificateContextProperties.ctypes_function(pCertContext, dwPropId)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertCreateCertificateContext(dwCertEncodingType, pbCertEncoded, cbCertEncoded):
|
||||
return CertCreateCertificateContext.ctypes_function(dwCertEncodingType, pbCertEncoded, cbCertEncoded)
|
||||
|
||||
|
||||
## Certificate chain
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertGetCertificateChain(hChainEngine, pCertContext, pTime, hAdditionalStore, pChainPara, dwFlags, pvReserved, ppChainContext):
|
||||
return CertGetCertificateChain.ctypes_function(hChainEngine, pCertContext, pTime, hAdditionalStore, pChainPara, dwFlags, pvReserved, ppChainContext)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertDuplicateCertificateContext(pCertContext):
|
||||
return CertDuplicateCertificateContext.ctypes_function(pCertContext)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertFreeCertificateContext(pCertContext):
|
||||
return CertFreeCertificateContext.ctypes_function(pCertContext)
|
||||
|
||||
@Crypt32Proxy(error_check=no_error_check)
|
||||
def CertCompareCertificate(dwCertEncodingType, pCertId1, pCertId2):
|
||||
"""This function does not raise is compare has failed:
|
||||
return 0 if cert are NOT equals
|
||||
"""
|
||||
return CertCompareCertificate.ctypes_function(dwCertEncodingType, pCertId1, pCertId2)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptHashCertificate(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash):
|
||||
return CryptHashCertificate.ctypes_function(hCryptProv, Algid, dwFlags, pbEncoded, cbEncoded, pbComputedHash, pcbComputedHash)
|
||||
|
||||
## Certificate store
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertOpenStore(lpszStoreProvider, dwMsgAndCertEncodingType, hCryptProv, dwFlags, pvPara):
|
||||
if isinstance(lpszStoreProvider, (long, int)):
|
||||
lpszStoreProvider = gdef.LPCSTR(lpszStoreProvider)
|
||||
return CertOpenStore.ctypes_function(lpszStoreProvider, dwMsgAndCertEncodingType, hCryptProv, dwFlags, pvPara)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertAddCertificateContextToStore(hCertStore, pCertContext, dwAddDisposition, ppStoreContext):
|
||||
return CertAddCertificateContextToStore.ctypes_function(hCertStore, pCertContext, dwAddDisposition, ppStoreContext)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertFindCertificateInStore(hCertStore, dwCertEncodingType, dwFindFlags, dwFindType, pvFindPara, pPrevCertContext):
|
||||
return CertFindCertificateInStore.ctypes_function(hCertStore, dwCertEncodingType, dwFindFlags, dwFindType, pvFindPara, pPrevCertContext)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertEnumCertificatesInStore(hCertStore, pPrevCertContext):
|
||||
return CertEnumCertificatesInStore.ctypes_function(hCertStore, pPrevCertContext)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def PFXExportCertStoreEx(hStore, pPFX, szPassword, pvPara, dwFlags):
|
||||
return PFXExportCertStoreEx.ctypes_function(hStore, pPFX, szPassword, pvPara, dwFlags)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def PFXImportCertStore(pPFX, szPassword, dwFlags):
|
||||
return PFXImportCertStore.ctypes_function(pPFX, szPassword, dwFlags)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CertEnumCTLsInStore(hCertStore, pPrevCtlContext):
|
||||
return CertEnumCTLsInStore.ctypes_function(hCertStore, pPrevCtlContext)
|
||||
|
||||
|
||||
# Key
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptAcquireCertificatePrivateKey(pCert, dwFlags, pvParameters, phCryptProvOrNCryptKey, pdwKeySpec, pfCallerFreeProvOrNCryptKey):
|
||||
return CryptAcquireCertificatePrivateKey.ctypes_function(pCert, dwFlags, pvParameters, phCryptProvOrNCryptKey, pdwKeySpec, pfCallerFreeProvOrNCryptKey)
|
||||
|
||||
|
||||
|
||||
# Encrypt / Decrypt
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptEncryptMessage(pEncryptPara, cRecipientCert, rgpRecipientCert, pbToBeEncrypted, cbToBeEncrypted, pbEncryptedBlob, pcbEncryptedBlob):
|
||||
if isinstance(pbToBeEncrypted, basestring):
|
||||
# Transform string to array of byte
|
||||
pbToBeEncrypted = (gdef.BYTE * len(pbToBeEncrypted))(*bytearray(pbToBeEncrypted))
|
||||
if cbToBeEncrypted is None and pbToBeEncrypted is not None:
|
||||
cbToBeEncrypted = len(pbToBeEncrypted)
|
||||
return CryptEncryptMessage.ctypes_function(pEncryptPara, cRecipientCert, rgpRecipientCert, pbToBeEncrypted, cbToBeEncrypted, pbEncryptedBlob, pcbEncryptedBlob)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptDecryptMessage(pDecryptPara, pbEncryptedBlob, cbEncryptedBlob, pbDecrypted, pcbDecrypted, ppXchgCert):
|
||||
return CryptDecryptMessage.ctypes_function(pDecryptPara, pbEncryptedBlob, cbEncryptedBlob, pbDecrypted, pcbDecrypted, ppXchgCert)
|
||||
|
||||
# Sign / Verify
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptSignMessage(pSignPara, fDetachedSignature, cToBeSigned, rgpbToBeSigned, rgcbToBeSigned, pbSignedBlob, pcbSignedBlob):
|
||||
return CryptSignMessage.ctypes_function(pSignPara, fDetachedSignature, cToBeSigned, rgpbToBeSigned, rgcbToBeSigned, pbSignedBlob, pcbSignedBlob)
|
||||
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptSignAndEncryptMessage(pSignPara, pEncryptPara, cRecipientCert, rgpRecipientCert, pbToBeSignedAndEncrypted, cbToBeSignedAndEncrypted, pbSignedAndEncryptedBlob, pcbSignedAndEncryptedBlob):
|
||||
return CryptSignAndEncryptMessage.ctypes_function(pSignPara, pEncryptPara, cRecipientCert, rgpRecipientCert, pbToBeSignedAndEncrypted, cbToBeSignedAndEncrypted, pbSignedAndEncryptedBlob, pcbSignedAndEncryptedBlob)
|
||||
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptVerifyMessageSignature(pVerifyPara, dwSignerIndex, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded, ppSignerCert):
|
||||
return CryptVerifyMessageSignature.ctypes_function(pVerifyPara, dwSignerIndex, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded, ppSignerCert)
|
||||
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptVerifyMessageSignatureWithKey(pVerifyPara, pPublicKeyInfo, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded):
|
||||
return CryptVerifyMessageSignatureWithKey.ctypes_function(pVerifyPara, pPublicKeyInfo, pbSignedBlob, cbSignedBlob, pbDecoded, pcbDecoded)
|
||||
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptVerifyMessageHash(pHashPara, pbHashedBlob, cbHashedBlob, pbToBeHashed, pcbToBeHashed, pbComputedHash, pcbComputedHash):
|
||||
return CryptVerifyMessageHash.ctypes_function(pHashPara, pbHashedBlob, cbHashedBlob, pbToBeHashed, pcbToBeHashed, pbComputedHash, pcbComputedHash)
|
||||
|
||||
|
||||
# Crypt-object
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptEncodeObjectEx(dwCertEncodingType, lpszStructType, pvStructInfo, dwFlags, pEncodePara, pvEncoded, pcbEncoded):
|
||||
lpszStructType = gdef.LPCSTR(lpszStructType) if isinstance(lpszStructType, (int, long)) else lpszStructType
|
||||
return CryptEncodeObjectEx.ctypes_function(dwCertEncodingType, lpszStructType, pvStructInfo, dwFlags, pEncodePara, pvEncoded, pcbEncoded)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptQueryObject(dwObjectType, pvObject, dwExpectedContentTypeFlags, dwExpectedFormatTypeFlags, dwFlags, pdwMsgAndCertEncodingType, pdwContentType, pdwFormatType, phCertStore, phMsg, ppvContext):
|
||||
return CryptQueryObject.ctypes_function(dwObjectType, pvObject, dwExpectedContentTypeFlags, dwExpectedFormatTypeFlags, dwFlags, pdwMsgAndCertEncodingType, pdwContentType, pdwFormatType, phCertStore, phMsg, ppvContext)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptDecodeObject(dwCertEncodingType, lpszStructType, pbEncoded, cbEncoded, dwFlags, pvStructInfo, pcbStructInfo):
|
||||
return CryptDecodeObject.ctypes_function(dwCertEncodingType, lpszStructType, pbEncoded, cbEncoded, dwFlags, pvStructInfo, pcbStructInfo)
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptMsgGetParam(hCryptMsg, dwParamType, dwIndex, pvData, pcbData):
|
||||
return CryptMsgGetParam.ctypes_function(hCryptMsg, dwParamType, dwIndex, pvData, pcbData)
|
||||
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptMsgVerifyCountersignatureEncoded(hCryptProv, dwEncodingType, pbSignerInfo, cbSignerInfo, pbSignerInfoCountersignature, cbSignerInfoCountersignature, pciCountersigner):
|
||||
return CryptMsgVerifyCountersignatureEncoded.ctypes_function(hCryptProv, dwEncodingType, pbSignerInfo, cbSignerInfo, pbSignerInfoCountersignature, cbSignerInfoCountersignature, pciCountersigner)
|
||||
|
||||
|
||||
@Crypt32Proxy()
|
||||
def CryptMsgVerifyCountersignatureEncodedEx(hCryptProv, dwEncodingType, pbSignerInfo, cbSignerInfo, pbSignerInfoCountersignature, cbSignerInfoCountersignature, dwSignerType, pvSigner, dwFlags, pvExtra):
|
||||
return CryptMsgVerifyCountersignatureEncodedEx.ctypes_function(hCryptProv, dwEncodingType, pbSignerInfo, cbSignerInfo, pbSignerInfoCountersignature, cbSignerInfoCountersignature, dwSignerType, pvSigner, dwFlags, pvExtra)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import fail_on_zero
|
||||
|
||||
class CryptUIProxy(ApiProxy):
|
||||
APIDLL = "cryptui"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
|
||||
@CryptUIProxy()
|
||||
def CryptUIDlgViewContext(dwContextType, pvContext, hwnd, pwszTitle, dwFlags, pvReserved):
|
||||
return CryptUIDlgViewContext.ctypes_function(dwContextType, pvContext, hwnd, pwszTitle, dwFlags, pvReserved)
|
||||
@@ -0,0 +1,34 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import succeed_on_zero
|
||||
|
||||
class IphlpapiProxy(ApiProxy):
|
||||
APIDLL = "iphlpapi"
|
||||
default_error_check = staticmethod(succeed_on_zero)
|
||||
|
||||
|
||||
@IphlpapiProxy()
|
||||
def SetTcpEntry(pTcpRow):
|
||||
return SetTcpEntry.ctypes_function(pTcpRow)
|
||||
|
||||
@IphlpapiProxy()
|
||||
def GetExtendedTcpTable(pTcpTable, pdwSize=None, bOrder=True, ulAf=NeededParameter, TableClass=gdef.TCP_TABLE_OWNER_PID_ALL, Reserved=0):
|
||||
if pdwSize is None:
|
||||
pdwSize = gdef.ULONG(ctypes.sizeof(pTcpTable))
|
||||
return GetExtendedTcpTable.ctypes_function(pTcpTable, pdwSize, bOrder, ulAf, TableClass, Reserved)
|
||||
|
||||
@IphlpapiProxy()
|
||||
def GetInterfaceInfo(pIfTable, dwOutBufLen=None):
|
||||
if dwOutBufLen is None:
|
||||
dwOutBufLen = gdef.ULONG(ctypes.sizeof(pIfTable))
|
||||
return GetInterfaceInfo.ctypes_function(pIfTable, dwOutBufLen)
|
||||
|
||||
@IphlpapiProxy()
|
||||
def GetIfTable(pIfTable, pdwSize, bOrder=False):
|
||||
return GetIfTable.ctypes_function(pIfTable, pdwSize, bOrder)
|
||||
|
||||
@IphlpapiProxy()
|
||||
def GetIpAddrTable(pIpAddrTable, pdwSize, bOrder=False):
|
||||
return GetIpAddrTable.ctypes_function(pIpAddrTable, pdwSize, bOrder)
|
||||
@@ -0,0 +1,695 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import (fail_on_zero,
|
||||
no_error_check,
|
||||
result_is_handle,
|
||||
succeed_on_zero,
|
||||
fail_on_minus_one)
|
||||
|
||||
|
||||
class Kernel32Proxy(ApiProxy):
|
||||
APIDLL = "kernel32"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
# Process
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetCurrentProcess():
|
||||
return GetCurrentProcess.ctypes_function()
|
||||
|
||||
@Kernel32Proxy()
|
||||
def ExitProcess(uExitCode):
|
||||
return ExitProcess.ctypes_function(uExitCode)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def TerminateProcess(hProcess, uExitCode):
|
||||
return TerminateProcess.ctypes_function(hProcess, uExitCode)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetExitCodeProcess(hProcess, lpExitCode):
|
||||
return GetExitCodeProcess.ctypes_function(hProcess, lpExitCode)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetProcessId(Process):
|
||||
return GetProcessId.ctypes_function(Process)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def CreateProcessA(lpApplicationName, lpCommandLine=None, lpProcessAttributes=None, lpThreadAttributes=None, bInheritHandles=False,
|
||||
dwCreationFlags=0, lpEnvironment=None, lpCurrentDirectory=None, lpStartupInfo=None, lpProcessInformation=None):
|
||||
if lpStartupInfo is None:
|
||||
StartupInfo = gdef.STARTUPINFOA()
|
||||
StartupInfo.cb = ctypes.sizeof(StartupInfo)
|
||||
StartupInfo.dwFlags = gdef.STARTF_USESHOWWINDOW
|
||||
StartupInfo.wShowWindow = gdef.SW_HIDE
|
||||
lpStartupInfo = ctypes.byref(StartupInfo)
|
||||
if lpProcessInformation is None:
|
||||
lpProcessInformation = ctypes.byref(gdef.PROCESS_INFORMATION())
|
||||
return CreateProcessA.ctypes_function(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def CreateProcessW(lpApplicationName, lpCommandLine=None, lpProcessAttributes=None, lpThreadAttributes=None, bInheritHandles=False,
|
||||
dwCreationFlags=0, lpEnvironment=None, lpCurrentDirectory=None, lpStartupInfo=None, lpProcessInformation=None):
|
||||
if lpStartupInfo is None:
|
||||
StartupInfo = gdef.STARTUPINFOW()
|
||||
StartupInfo.cb = ctypes.sizeof(StartupInfo)
|
||||
StartupInfo.dwFlags = gdef.STARTF_USESHOWWINDOW
|
||||
StartupInfo.wShowWindow = gdef.SW_HIDE
|
||||
lpStartupInfo = ctypes.byref(StartupInfo)
|
||||
if lpProcessInformation is None:
|
||||
lpProcessInformation = ctypes.byref(gdef.PROCESS_INFORMATION())
|
||||
return CreateProcessW.ctypes_function(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def OpenProcess(dwDesiredAccess=gdef.PROCESS_ALL_ACCESS, bInheritHandle=0, dwProcessId=NeededParameter):
|
||||
return OpenProcess.ctypes_function(dwDesiredAccess, bInheritHandle, dwProcessId)
|
||||
|
||||
|
||||
## Process Infos
|
||||
@Kernel32Proxy()
|
||||
def GetProcessTimes(hProcess, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime):
|
||||
return GetProcessTimes.ctypes_function(hProcess, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetPriorityClass(hProcess):
|
||||
return GetPriorityClass.ctypes_function(hProcess)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def SetPriorityClass(hProcess, dwPriorityClass):
|
||||
return SetPriorityClass.ctypes_function(hProcess, dwPriorityClass)
|
||||
|
||||
|
||||
PROCESS_MITIGATION_STUCTS = (gdef.PROCESS_MITIGATION_ASLR_POLICY,
|
||||
gdef.PROCESS_MITIGATION_BINARY_SIGNATURE_POLICY,
|
||||
gdef.PROCESS_MITIGATION_CONTROL_FLOW_GUARD_POLICY,
|
||||
gdef.PROCESS_MITIGATION_DEP_POLICY,
|
||||
gdef.PROCESS_MITIGATION_DYNAMIC_CODE_POLICY,
|
||||
gdef.PROCESS_MITIGATION_EXTENSION_POINT_DISABLE_POLICY,
|
||||
gdef.PROCESS_MITIGATION_IMAGE_LOAD_POLICY,
|
||||
gdef.PROCESS_MITIGATION_POLICY,
|
||||
gdef.PROCESS_MITIGATION_STRICT_HANDLE_CHECK_POLICY,
|
||||
gdef.PROCESS_MITIGATION_SYSTEM_CALL_DISABLE_POLICY)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetProcessMitigationPolicy(hProcess, MitigationPolicy, lpBuffer, dwLength=None):
|
||||
if dwLength is None:
|
||||
dwLength = ctypes.sizeof(lpBuffer)
|
||||
return GetProcessMitigationPolicy.ctypes_function(hProcess, MitigationPolicy, lpBuffer, dwLength)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def SetProcessMitigationPolicy(MitigationPolicy, lpBuffer, dwLength=None):
|
||||
if dwLength is None:
|
||||
dwLength = ctypes.sizeof(lpBuffer)
|
||||
if isinstance(lpBuffer, PROCESS_MITIGATION_STUCTS):
|
||||
lpBuffer = ctypes.byref(lpBuffer)
|
||||
return SetProcessMitigationPolicy.ctypes_function(MitigationPolicy, lpBuffer, dwLength)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetProcessDEPPolicy(hProcess, lpFlags, lpPermanent):
|
||||
return GetProcessDEPPolicy.ctypes_function(hProcess, lpFlags, lpPermanent)
|
||||
|
||||
## Process Infos ThreadAttribute
|
||||
|
||||
# ProcThreadAttributeList
|
||||
def initializeprocthreadattributelist_error_check(func_name, result, func, args):
|
||||
if result:
|
||||
return args
|
||||
error = GetLastError()
|
||||
if error == gdef.ERROR_INSUFFICIENT_BUFFER and args[0] is None:
|
||||
return args
|
||||
raise WinproxyError(func_name)
|
||||
|
||||
@Kernel32Proxy(error_check=initializeprocthreadattributelist_error_check)
|
||||
def InitializeProcThreadAttributeList(lpAttributeList=None, dwAttributeCount=NeededParameter, dwFlags=0, lpSize=NeededParameter):
|
||||
return InitializeProcThreadAttributeList.ctypes_function(lpAttributeList, dwAttributeCount, dwFlags, lpSize)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def UpdateProcThreadAttribute(lpAttributeList, dwFlags=0, Attribute=NeededParameter, lpValue=NeededParameter, cbSize=NeededParameter, lpPreviousValue=None, lpReturnSize=None):
|
||||
return UpdateProcThreadAttribute.ctypes_function(lpAttributeList, dwFlags, Attribute, lpValue, cbSize, lpPreviousValue, lpReturnSize)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def DeleteProcThreadAttributeList(lpAttributeList):
|
||||
return DeleteProcThreadAttributeList.ctypes_function(lpAttributeList)
|
||||
|
||||
|
||||
## Process-module
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetModuleHandleA(lpModuleName):
|
||||
return GetModuleHandleA.ctypes_function(lpModuleName)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetModuleHandleW(lpModuleName):
|
||||
return GetModuleHandleW.ctypes_function(lpModuleName)
|
||||
|
||||
## Thread
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetExitCodeThread(hThread, lpExitCode):
|
||||
return GetExitCodeThread.ctypes_function(hThread, lpExitCode)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetCurrentThread():
|
||||
return GetCurrentThread.ctypes_function()
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetCurrentThreadId():
|
||||
return GetCurrentThreadId.ctypes_function()
|
||||
|
||||
@Kernel32Proxy()
|
||||
def TerminateThread(hThread, dwExitCode):
|
||||
return TerminateThread.ctypes_function(hThread, dwExitCode)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def ExitThread(dwExitCode):
|
||||
return ExitThread.ctypes_function(dwExitCode)
|
||||
|
||||
@Kernel32Proxy(error_check=fail_on_minus_one)
|
||||
def ResumeThread(hThread):
|
||||
return ResumeThread.ctypes_function(hThread)
|
||||
|
||||
@Kernel32Proxy(error_check=fail_on_minus_one)
|
||||
def SuspendThread(hThread):
|
||||
return SuspendThread.ctypes_function(hThread)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetThreadId(Thread):
|
||||
return GetThreadId.ctypes_function(Thread)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def CreateThread(lpThreadAttributes=None, dwStackSize=0, lpStartAddress=NeededParameter, lpParameter=NeededParameter, dwCreationFlags=0, lpThreadId=None):
|
||||
return CreateThread.ctypes_function(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def CreateRemoteThread(hProcess=NeededParameter, lpThreadAttributes=None, dwStackSize=0,
|
||||
lpStartAddress=NeededParameter, lpParameter=NeededParameter, dwCreationFlags=0, lpThreadId=None):
|
||||
return CreateRemoteThread.ctypes_function(hProcess, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetThreadContext(hThread, lpContext):
|
||||
# TODO: RM ME IF TEST PASS
|
||||
# if lpContext is None:
|
||||
# Context = CONTEXT()
|
||||
# context.ContextFlags = CONTEXT_FULL | CONTEXT_DEBUG_REGISTERS
|
||||
# lpContext = ctypes.byref(Context)
|
||||
return GetThreadContext.ctypes_function(hThread, lpContext)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def SetThreadContext(hThread, lpContext):
|
||||
return SetThreadContext.ctypes_function(hThread, lpContext)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def OpenThread(dwDesiredAccess=gdef.THREAD_ALL_ACCESS, bInheritHandle=0, dwThreadId=NeededParameter):
|
||||
return OpenThread.ctypes_function(dwDesiredAccess, bInheritHandle, dwThreadId)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def SetThreadAffinityMask(hThread=None, dwThreadAffinityMask=NeededParameter):
|
||||
"""If hThread is not given, it will be the current thread"""
|
||||
if hThread is None:
|
||||
hThread = GetCurrentThread()
|
||||
return SetThreadAffinityMask.ctypes_function(hThread, dwThreadAffinityMask)
|
||||
|
||||
|
||||
## Memory
|
||||
|
||||
@Kernel32Proxy(error_check=succeed_on_zero)
|
||||
def LocalFree(hMem):
|
||||
return LocalFree.ctypes_function(hMem)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def VirtualAlloc(lpAddress=0, dwSize=NeededParameter, flAllocationType=gdef.MEM_COMMIT, flProtect=gdef.PAGE_EXECUTE_READWRITE):
|
||||
return VirtualAlloc.ctypes_function(lpAddress, dwSize, flAllocationType, flProtect)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def VirtualFree(lpAddress, dwSize=0, dwFreeType=gdef.MEM_RELEASE):
|
||||
return VirtualFree.ctypes_function(lpAddress, dwSize, dwFreeType)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect=None):
|
||||
if lpflOldProtect is None:
|
||||
lpflOldProtect = ctypes.byref(gdef.DWORD())
|
||||
return VirtualProtect.ctypes_function(lpAddress, dwSize, flNewProtect, lpflOldProtect)
|
||||
|
||||
|
||||
## Memory remote
|
||||
|
||||
@Kernel32Proxy()
|
||||
def VirtualQueryEx(hProcess, lpAddress, lpBuffer, dwLength):
|
||||
return VirtualQueryEx.ctypes_function(hProcess, lpAddress, lpBuffer, dwLength)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def VirtualAllocEx(hProcess, lpAddress=0, dwSize=NeededParameter, flAllocationType=gdef.MEM_COMMIT, flProtect=gdef.PAGE_EXECUTE_READWRITE):
|
||||
return VirtualAllocEx.ctypes_function(hProcess, lpAddress, dwSize, flAllocationType, flProtect)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def VirtualFreeEx(hProcess, lpAddress, dwSize=0, dwFreeType=gdef.MEM_RELEASE):
|
||||
return VirtualFreeEx.ctypes_function(hProcess, lpAddress, dwSize, dwFreeType)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def VirtualProtectEx(hProcess, lpAddress, dwSize, flNewProtect, lpflOldProtect=None):
|
||||
if lpflOldProtect is None:
|
||||
lpflOldProtect = ctypes.byref(gdef.DWORD())
|
||||
return VirtualProtectEx.ctypes_function(hProcess, lpAddress, dwSize, flNewProtect, lpflOldProtect)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead=None):
|
||||
return ReadProcessMemory.ctypes_function(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize=None, lpNumberOfBytesWritten=None):
|
||||
"""Computer nSize with len(lpBuffer) if not given"""
|
||||
if nSize is None:
|
||||
nSize = len(lpBuffer)
|
||||
return WriteProcessMemory.ctypes_function(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten)
|
||||
|
||||
|
||||
## Error
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetLastError():
|
||||
return GetLastError.ctypes_function()
|
||||
|
||||
## Handle
|
||||
|
||||
@Kernel32Proxy()
|
||||
def CloseHandle(hObject):
|
||||
return CloseHandle.ctypes_function(hObject)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def DuplicateHandle(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, lpTargetHandle, dwDesiredAccess=0, bInheritHandle=False, dwOptions=0):
|
||||
return DuplicateHandle.ctypes_function(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, lpTargetHandle, dwDesiredAccess, bInheritHandle, dwOptions)
|
||||
|
||||
|
||||
|
||||
## Process Modules
|
||||
@Kernel32Proxy()
|
||||
def GetProcAddress(hModule, lpProcName):
|
||||
return GetProcAddress.ctypes_function(hModule, lpProcName)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def LoadLibraryA(lpFileName):
|
||||
return LoadLibraryA.ctypes_function(lpFileName)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def LoadLibraryW(lpFileName):
|
||||
return LoadLibraryW.ctypes_function(lpFileName)
|
||||
|
||||
## Version
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetVersionExA(lpVersionInformation):
|
||||
return GetVersionExA.ctypes_function(lpVersionInformation)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetVersionExW(lpVersionInformation):
|
||||
return GetVersionExW.ctypes_function(lpVersionInformation)
|
||||
|
||||
## Hardware
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetCurrentProcessorNumber():
|
||||
return GetCurrentProcessorNumber.ctypes_function()
|
||||
|
||||
## Console
|
||||
|
||||
@Kernel32Proxy()
|
||||
def AllocConsole():
|
||||
return AllocConsole.ctypes_function()
|
||||
|
||||
@Kernel32Proxy()
|
||||
def FreeConsole():
|
||||
return FreeConsole.ctypes_function()
|
||||
|
||||
@Kernel32Proxy()
|
||||
def SetConsoleCtrlHandler(HandlerRoutine, Add):
|
||||
return SetConsoleCtrlHandler.ctypes_function(HandlerRoutine, Add)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetStdHandle(nStdHandle):
|
||||
return GetStdHandle.ctypes_function(nStdHandle)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def SetStdHandle(nStdHandle, hHandle):
|
||||
return SetStdHandle.ctypes_function(nStdHandle, hHandle)
|
||||
|
||||
## System
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetComputerNameA(lpBuffer, lpnSize):
|
||||
return GetComputerNameA.ctypes_function(lpBuffer, lpnSize)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetComputerNameW(lpBuffer, lpnSize):
|
||||
return GetComputerNameW.ctypes_function(lpBuffer, lpnSize)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetWindowsDirectoryA(lpBuffer, uSize=None):
|
||||
if uSize is None:
|
||||
uSize = gdef.DWORD(len(lpBuffer))
|
||||
return GetWindowsDirectoryA.ctypes_function(lpBuffer, uSize)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetWindowsDirectoryW(lpBuffer, uSize=None):
|
||||
if uSize is None:
|
||||
uSize = gdef.DWORD(len(lpBuffer))
|
||||
return GetWindowsDirectoryW.ctypes_function(lpBuffer, uSize)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetProductInfo(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType):
|
||||
return GetProductInfo.ctypes_function(dwOSMajorVersion, dwOSMinorVersion, dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType)
|
||||
|
||||
## Other
|
||||
|
||||
@Kernel32Proxy(error_check=no_error_check)
|
||||
def lstrcmpA(lpString1, lpString2):
|
||||
return lstrcmpA.ctypes_function(lpString1, lpString2)
|
||||
|
||||
@Kernel32Proxy(error_check=no_error_check)
|
||||
def lstrcmpW(lpString1, lpString2):
|
||||
return lstrcmpW.ctypes_function(lpString1, lpString2)
|
||||
|
||||
@Kernel32Proxy("Sleep", no_error_check)
|
||||
def Sleep(dwMilliseconds):
|
||||
return Sleep.ctypes_function(dwMilliseconds)
|
||||
|
||||
@Kernel32Proxy("SleepEx", no_error_check)
|
||||
def SleepEx(dwMilliseconds, bAlertable=False):
|
||||
return SleepEx.ctypes_function(dwMilliseconds, bAlertable)
|
||||
|
||||
|
||||
@Kernel32Proxy(error_check=succeed_on_zero)
|
||||
def WaitForSingleObject(hHandle, dwMilliseconds=gdef.INFINITE):
|
||||
return WaitForSingleObject.ctypes_function(hHandle, dwMilliseconds)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize=None, lpOutBuffer=NeededParameter, nOutBufferSize=None, lpBytesReturned=None, lpOverlapped=None):
|
||||
if nInBufferSize is None:
|
||||
nInBufferSize = len(lpInBuffer)
|
||||
if nOutBufferSize is None:
|
||||
nOutBufferSize = len(lpOutBuffer)
|
||||
if lpBytesReturned is None:
|
||||
# Some windows check 0 / others does not
|
||||
lpBytesReturned = ctypes.byref(gdef.DWORD())
|
||||
return DeviceIoControl.ctypes_function(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpBytesReturned, lpOverlapped)
|
||||
|
||||
|
||||
# Wow64
|
||||
|
||||
@Kernel32Proxy()
|
||||
def Wow64DisableWow64FsRedirection(OldValue):
|
||||
return Wow64DisableWow64FsRedirection.ctypes_function(OldValue)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def Wow64RevertWow64FsRedirection(OldValue):
|
||||
return Wow64RevertWow64FsRedirection.ctypes_function(OldValue)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def Wow64EnableWow64FsRedirection(Wow64FsEnableRedirection):
|
||||
return Wow64EnableWow64FsRedirection.ctypes_function(Wow64FsEnableRedirection)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def Wow64GetThreadContext(hThread, lpContext):
|
||||
return Wow64GetThreadContext.ctypes_function(hThread, lpContext)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def Wow64SetThreadContext(hThread, lpContext):
|
||||
return Wow64SetThreadContext.ctypes_function(hThread, lpContext)
|
||||
|
||||
|
||||
|
||||
## File
|
||||
|
||||
@Kernel32Proxy(error_check=result_is_handle)
|
||||
def CreateFileA(lpFileName, dwDesiredAccess=gdef.GENERIC_READ, dwShareMode=0, lpSecurityAttributes=None, dwCreationDisposition=gdef.OPEN_EXISTING, dwFlagsAndAttributes=gdef.FILE_ATTRIBUTE_NORMAL, hTemplateFile=None):
|
||||
return CreateFileA.ctypes_function(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)
|
||||
|
||||
|
||||
@Kernel32Proxy(error_check=result_is_handle)
|
||||
def CreateFileW(lpFileName, dwDesiredAccess=gdef.GENERIC_READ, dwShareMode=0, lpSecurityAttributes=None, dwCreationDisposition=gdef.OPEN_EXISTING, dwFlagsAndAttributes=gdef.FILE_ATTRIBUTE_NORMAL, hTemplateFile=None):
|
||||
return CreateFileA.ctypes_function(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)
|
||||
|
||||
@Kernel32Proxy(error_check=result_is_handle)
|
||||
def CreateFileTransactedA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, hTransaction, pusMiniVersion, pExtendedParameter):
|
||||
return CreateFileTransactedA.ctypes_function(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, hTransaction, pusMiniVersion, pExtendedParameter)
|
||||
|
||||
@Kernel32Proxy(error_check=result_is_handle)
|
||||
def CreateFileTransactedW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, hTransaction, pusMiniVersion, pExtendedParameter):
|
||||
return CreateFileTransactedW.ctypes_function(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, hTransaction, pusMiniVersion, pExtendedParameter)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def ReadFile(hFile, lpBuffer, nNumberOfBytesToRead=None, lpNumberOfBytesRead=None, lpOverlapped=None):
|
||||
if nNumberOfBytesToRead is None:
|
||||
nNumberOfBytesToRead = len(lpBuffer)
|
||||
if lpOverlapped is None and lpNumberOfBytesRead is None:
|
||||
lpNumberOfBytesRead = ctypes.byref(gdef.DWORD())
|
||||
return ReadFile.ctypes_function(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def WriteFile(hFile, lpBuffer, nNumberOfBytesToWrite=None, lpNumberOfBytesWritten=None, lpOverlapped=None):
|
||||
if nNumberOfBytesToWrite is None:
|
||||
nNumberOfBytesToWrite = len(lpBuffer)
|
||||
if lpOverlapped is None and lpNumberOfBytesWritten is None:
|
||||
lpNumberOfBytesWritten = ctypes.byref(gdef.DWORD())
|
||||
return WriteFile.ctypes_function(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def CreateFileMappingA(hFile, lpFileMappingAttributes=None, flProtect=gdef.PAGE_READWRITE, dwMaximumSizeHigh=0, dwMaximumSizeLow=NeededParameter, lpName=NeededParameter):
|
||||
return CreateFileMappingA.ctypes_function(hFile, lpFileMappingAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def CreateFileMappingW(hFile, lpFileMappingAttributes=None, flProtect=gdef.PAGE_READWRITE, dwMaximumSizeHigh=0, dwMaximumSizeLow=0, lpName=NeededParameter):
|
||||
return CreateFileMappingW.ctypes_function(hFile, lpFileMappingAttributes, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def MapViewOfFile(hFileMappingObject, dwDesiredAccess=gdef.FILE_MAP_ALL_ACCESS, dwFileOffsetHigh=0, dwFileOffsetLow=0, dwNumberOfBytesToMap=NeededParameter):
|
||||
return MapViewOfFile.ctypes_function(hFileMappingObject, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow, dwNumberOfBytesToMap)
|
||||
|
||||
|
||||
## Tlhelp (snapshoot)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def CreateToolhelp32Snapshot(dwFlags, th32ProcessID=0):
|
||||
return CreateToolhelp32Snapshot.ctypes_function(dwFlags, th32ProcessID)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def Thread32First(hSnapshot, lpte):
|
||||
"""Set byref(lpte) if needed"""
|
||||
if type(lpte) == gdef.THREADENTRY32:
|
||||
lpte = ctypes.byref(lpte)
|
||||
return Thread32First.ctypes_function(hSnapshot, lpte)
|
||||
|
||||
@Kernel32Proxy(error_check=no_error_check)
|
||||
def Thread32Next(hSnapshot, lpte):
|
||||
"""Set byref(lpte) if needed"""
|
||||
if type(lpte) == gdef.THREADENTRY32:
|
||||
lpte = ctypes.byref(lpte)
|
||||
return Thread32Next.ctypes_function(hSnapshot, lpte)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def Process32First(hSnapshot, lpte):
|
||||
return Process32First.ctypes_function(hSnapshot, lpte)
|
||||
|
||||
@Kernel32Proxy(error_check=no_error_check)
|
||||
def Process32Next(hSnapshot, lpte):
|
||||
return Process32Next.ctypes_function(hSnapshot, lpte)
|
||||
|
||||
## VEH
|
||||
|
||||
@Kernel32Proxy()
|
||||
def AddVectoredContinueHandler(FirstHandler=1, VectoredHandler=NeededParameter):
|
||||
return AddVectoredContinueHandler.ctypes_function(FirstHandler, VectoredHandler)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def AddVectoredExceptionHandler(FirstHandler=1, VectoredHandler=NeededParameter):
|
||||
return AddVectoredExceptionHandler.ctypes_function(FirstHandler, VectoredHandler)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def RemoveVectoredExceptionHandler(Handler):
|
||||
return RemoveVectoredExceptionHandler.ctypes_function(Handler)
|
||||
|
||||
## Event
|
||||
|
||||
@Kernel32Proxy()
|
||||
def OpenEventA(dwDesiredAccess, bInheritHandle, lpName):
|
||||
return OpenEventA.ctypes_function(dwDesiredAccess, bInheritHandle, lpName)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def OpenEventW(dwDesiredAccess, bInheritHandle, lpName):
|
||||
return OpenEventA.ctypes_function(dwDesiredAccess, bInheritHandle, lpName)
|
||||
|
||||
|
||||
## Path
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetLongPathNameA(lpszShortPath, lpszLongPath, cchBuffer=None):
|
||||
if cchBuffer is None:
|
||||
cchBuffer = len(lpszLongPath)
|
||||
return GetLongPathNameA.ctypes_function(lpszShortPath, lpszLongPath, cchBuffer)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetLongPathNameW(lpszShortPath, lpszLongPath, cchBuffer=None):
|
||||
if cchBuffer is None:
|
||||
cchBuffer = len(lpszLongPath)
|
||||
return GetLongPathNameW.ctypes_function(lpszShortPath, lpszLongPath, cchBuffer)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetShortPathNameA(lpszLongPath, lpszShortPath, cchBuffer=None):
|
||||
if cchBuffer is None:
|
||||
cchBuffer = len(lpszShortPath)
|
||||
return GetShortPathNameA.ctypes_function(lpszLongPath, lpszShortPath, cchBuffer)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetShortPathNameW(lpszLongPath, lpszShortPath, cchBuffer=None):
|
||||
if cchBuffer is None:
|
||||
cchBuffer = len(lpszShortPath)
|
||||
return GetShortPathNameW.ctypes_function(lpszLongPath, lpszShortPath, cchBuffer)
|
||||
|
||||
|
||||
# Debug-API
|
||||
|
||||
@Kernel32Proxy()
|
||||
def WaitForDebugEvent(lpDebugEvent, dwMilliseconds=gdef.INFINITE):
|
||||
return WaitForDebugEvent.ctypes_function(lpDebugEvent, dwMilliseconds)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def DebugBreak():
|
||||
return DebugBreak.ctypes_function()
|
||||
|
||||
@Kernel32Proxy()
|
||||
def ContinueDebugEvent(dwProcessId, dwThreadId, dwContinueStatus):
|
||||
return ContinueDebugEvent.ctypes_function(dwProcessId, dwThreadId, dwContinueStatus)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def DebugActiveProcess(dwProcessId):
|
||||
return DebugActiveProcess.ctypes_function(dwProcessId)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def DebugActiveProcessStop(dwProcessId):
|
||||
return DebugActiveProcessStop.ctypes_function(dwProcessId)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def DebugSetProcessKillOnExit(KillOnExit):
|
||||
return DebugSetProcessKillOnExit.ctypes_function(KillOnExit)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def DebugBreakProcess(Process):
|
||||
return DebugBreakProcess.ctypes_function(Process)
|
||||
|
||||
# Volumes
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetLogicalDriveStringsA(nBufferLength, lpBuffer):
|
||||
return GetLogicalDriveStringsA.ctypes_function(nBufferLength, lpBuffer)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetLogicalDriveStringsW(nBufferLength, lpBuffer):
|
||||
return GetLogicalDriveStringsW.ctypes_function(nBufferLength, lpBuffer)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetVolumeNameForVolumeMountPointA(lpszVolumeMountPoint, lpszVolumeName, cchBufferLength):
|
||||
return GetVolumeNameForVolumeMountPointA.ctypes_function(lpszVolumeMountPoint, lpszVolumeName, cchBufferLength)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetVolumeNameForVolumeMountPointW(lpszVolumeMountPoint, lpszVolumeName, cchBufferLength):
|
||||
return GetVolumeNameForVolumeMountPointW.ctypes_function(lpszVolumeMountPoint, lpszVolumeName, cchBufferLength)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetDriveTypeA(lpRootPathName):
|
||||
return GetDriveTypeA.ctypes_function(lpRootPathName)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetDriveTypeW(lpRootPathName):
|
||||
return GetDriveTypeW.ctypes_function(lpRootPathName)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def QueryDosDeviceA(lpDeviceName, lpTargetPath, ucchMax):
|
||||
return QueryDosDeviceA.ctypes_function(lpDeviceName, lpTargetPath, ucchMax)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def QueryDosDeviceW(lpDeviceName, lpTargetPath, ucchMax):
|
||||
return QueryDosDeviceW.ctypes_function(lpDeviceName, lpTargetPath, ucchMax)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetVolumeInformationA(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize):
|
||||
if nVolumeNameSize == 0 and lpVolumeNameBuffer is not None:
|
||||
nVolumeNameSize = len(lpVolumeNameBuffer)
|
||||
if nFileSystemNameSize == 0 and lpFileSystemNameBuffer is not None:
|
||||
nFileSystemNameSize = len(lpFileSystemNameBuffer)
|
||||
return GetVolumeInformationA.ctypes_function(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def GetVolumeInformationW(lpRootPathName, lpVolumeNameBuffer=None, nVolumeNameSize=0, lpVolumeSerialNumber=None, lpMaximumComponentLength=None, lpFileSystemFlags=None, lpFileSystemNameBuffer=None, nFileSystemNameSize=0):
|
||||
if nVolumeNameSize == 0 and lpVolumeNameBuffer is not None:
|
||||
nVolumeNameSize = len(lpVolumeNameBuffer)
|
||||
if nFileSystemNameSize == 0 and lpFileSystemNameBuffer is not None:
|
||||
nFileSystemNameSize = len(lpFileSystemNameBuffer)
|
||||
return GetVolumeInformationW.ctypes_function(lpRootPathName, lpVolumeNameBuffer, nVolumeNameSize, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer, nFileSystemNameSize)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def FindFirstVolumeA(lpszVolumeName, cchBufferLength):
|
||||
if cchBufferLength is None:
|
||||
cchBufferLength = len(lpszVolumeName)
|
||||
return FindFirstVolumeA.ctypes_function(lpszVolumeName, cchBufferLength)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def FindFirstVolumeW(lpszVolumeName, cchBufferLength):
|
||||
if cchBufferLength is None:
|
||||
cchBufferLength = len(lpszVolumeName)
|
||||
return FindFirstVolumeW.ctypes_function(lpszVolumeName, cchBufferLength)
|
||||
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def FindNextVolumeA(hFindVolume, lpszVolumeName, cchBufferLength):
|
||||
if cchBufferLength is None:
|
||||
cchBufferLength = len(lpszVolumeName)
|
||||
return FindNextVolumeA.ctypes_function(hFindVolume, lpszVolumeName, cchBufferLength)
|
||||
|
||||
|
||||
@Kernel32Proxy()
|
||||
def FindNextVolumeW(hFindVolume, lpszVolumeName, cchBufferLength):
|
||||
if cchBufferLength is None:
|
||||
cchBufferLength = len(lpszVolumeName)
|
||||
return FindNextVolumeW.ctypes_function(hFindVolume, lpszVolumeName, cchBufferLength)
|
||||
|
||||
# pipe
|
||||
|
||||
@Kernel32Proxy()
|
||||
def CreateNamedPipeA(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes):
|
||||
return CreateNamedPipeA.ctypes_function(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def CreateNamedPipeW(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes):
|
||||
return CreateNamedPipeW.ctypes_function(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, lpSecurityAttributes)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def ConnectNamedPipe(hNamedPipe, lpOverlapped):
|
||||
return ConnectNamedPipe.ctypes_function(hNamedPipe, lpOverlapped)
|
||||
|
||||
@Kernel32Proxy()
|
||||
def SetNamedPipeHandleState(hNamedPipe, lpMode, lpMaxCollectionCount, lpCollectDataTimeout):
|
||||
return SetNamedPipeHandleState.ctypes_function(hNamedPipe, lpMode, lpMaxCollectionCount, lpCollectDataTimeout)
|
||||
|
||||
|
||||
#####
|
||||
@@ -0,0 +1,29 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import fail_on_zero
|
||||
|
||||
class Ktmw32Proxy(ApiProxy):
|
||||
APIDLL = "Ktmw32"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
|
||||
@Ktmw32Proxy()
|
||||
def CommitTransaction(TransactionHandle):
|
||||
return CommitTransaction.ctypes_function(TransactionHandle)
|
||||
|
||||
|
||||
@Ktmw32Proxy()
|
||||
def CreateTransaction(lpTransactionAttributes, UOW, CreateOptions, IsolationLevel, IsolationFlags, Timeout, Description):
|
||||
return CreateTransaction.ctypes_function(lpTransactionAttributes, UOW, CreateOptions, IsolationLevel, IsolationFlags, Timeout, Description)
|
||||
|
||||
|
||||
@Ktmw32Proxy()
|
||||
def RollbackTransaction(TransactionHandle):
|
||||
return RollbackTransaction.ctypes_function(TransactionHandle)
|
||||
|
||||
|
||||
@Ktmw32Proxy()
|
||||
def OpenTransaction(dwDesiredAccess, TransactionId):
|
||||
return OpenTransaction.ctypes_function(dwDesiredAccess, TransactionId)
|
||||
@@ -0,0 +1,350 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import WinproxyError, result_is_ntstatus, fail_on_zero
|
||||
|
||||
class NtdllProxy(ApiProxy):
|
||||
APIDLL = "ntdll"
|
||||
default_error_check = staticmethod(result_is_ntstatus)
|
||||
|
||||
|
||||
# Memory
|
||||
|
||||
@NtdllProxy()
|
||||
def NtReadVirtualMemory(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead):
|
||||
return NtReadVirtualMemory.ctypes_function(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtWriteVirtualMemory(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten):
|
||||
return NtWriteVirtualMemory.ctypes_function(ProcessHandle, BaseAddress, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten)
|
||||
|
||||
# Wow64
|
||||
|
||||
@NtdllProxy()
|
||||
def NtWow64ReadVirtualMemory64(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead=None):
|
||||
return NtWow64ReadVirtualMemory64.ctypes_function(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtWow64WriteVirtualMemory64(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten=None):
|
||||
return NtWow64WriteVirtualMemory64.ctypes_function(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesWritten)
|
||||
|
||||
# File
|
||||
|
||||
@NtdllProxy()
|
||||
def NtCreateFile(FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, AllocationSize, FileAttributes, ShareAccess, CreateDisposition, CreateOptions, EaBuffer, EaLength):
|
||||
return NtCreateFile.ctypes_function(FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, AllocationSize, FileAttributes, ShareAccess, CreateDisposition, CreateOptions, EaBuffer, EaLength)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtSetInformationFile(FileHandle, IoStatusBlock, FileInformation, Length, FileInformationClass):
|
||||
return NtSetInformationFile.ctypes_function(FileHandle, IoStatusBlock, FileInformation, Length, FileInformationClass)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQueryInformationFile(FileHandle, IoStatusBlock, FileInformation, Length=None, FileInformationClass=NeededParameter):
|
||||
if Length is None:
|
||||
Length = ctypes.sizeof(FileInformation)
|
||||
return NtQueryInformationFile.ctypes_function(FileHandle, IoStatusBlock, FileInformation, Length, FileInformationClass)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQueryDirectoryFile(FileHandle, Event=None, ApcRoutine=None, ApcContext=None, IoStatusBlock=NeededParameter, FileInformation=NeededParameter, Length=None, FileInformationClass=NeededParameter, ReturnSingleEntry=NeededParameter, FileName=None, RestartScan=NeededParameter):
|
||||
if Length is None:
|
||||
Length = ctypes.sizeof(FileInformation)
|
||||
return NtQueryDirectoryFile.ctypes_function(FileHandle, Event, ApcRoutine, ApcContext, IoStatusBlock, FileInformation, Length, FileInformationClass, ReturnSingleEntry, FileName, RestartScan)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQueryVolumeInformationFile(FileHandle, IoStatusBlock, FsInformation, Length=None, FsInformationClass=NeededParameter):
|
||||
if Length is None:
|
||||
Length = ctypes.sizeof(FsInformation)
|
||||
return NtQueryVolumeInformationFile.ctypes_function(FileHandle, IoStatusBlock, FsInformation, Length, FsInformationClass)
|
||||
|
||||
|
||||
# Process
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQueryInformationProcess(ProcessHandle, ProcessInformationClass, ProcessInformation, ProcessInformationLength=0, ReturnLength=None):
|
||||
if ProcessInformation is not None and ProcessInformationLength == 0:
|
||||
ProcessInformationLength = ctypes.sizeof(ProcessInformation)
|
||||
if type(ProcessInformation) == gdef.PROCESS_BASIC_INFORMATION:
|
||||
ProcessInformation = ctypes.byref(ProcessInformation)
|
||||
if ReturnLength is None:
|
||||
ReturnLength = ctypes.byref(gdef.ULONG())
|
||||
return NtQueryInformationProcess.ctypes_function(ProcessHandle, ProcessInformationClass, ProcessInformation, ProcessInformationLength, ReturnLength)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtSetInformationProcess(ProcessHandle, ProcessInformationClass, ProcessInformation, ProcessInformationLength=0):
|
||||
if not ProcessInformationLength:
|
||||
ProcessInformationLength = ctypes.sizeof(ProcessInformation)
|
||||
return NtSetInformationProcess.ctypes_function(ProcessHandle, ProcessInformationClass, ProcessInformation, ProcessInformationLength)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def LdrLoadDll(PathToFile, Flags, ModuleFileName, ModuleHandle):
|
||||
return LdrLoadDll.ctypes_function(PathToFile, Flags, ModuleFileName, ModuleHandle)
|
||||
|
||||
@NtdllProxy()
|
||||
def RtlGetUnloadEventTraceEx(ElementSize, ElementCount, EventTrace):
|
||||
return RtlGetUnloadEventTraceEx.ctypes_function(ElementSize, ElementCount, EventTrace)
|
||||
|
||||
|
||||
# Thread
|
||||
|
||||
@NtdllProxy()
|
||||
def NtGetContextThread(hThread, lpContext):
|
||||
return NtGetContextThread.ctypes_function(hThread, lpContext)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQueryInformationThread(ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength=0, ReturnLength=None):
|
||||
if ReturnLength is None:
|
||||
ReturnLength = ctypes.byref(gdef.ULONG())
|
||||
if ThreadInformation is not None and ThreadInformationLength == 0:
|
||||
ThreadInformationLength = ctypes.sizeof(ThreadInformation)
|
||||
return NtQueryInformationThread.ctypes_function(ThreadHandle, ThreadInformationClass, ThreadInformation, ThreadInformationLength, ReturnLength)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtCreateThreadEx(ThreadHandle=None, DesiredAccess=0x1fffff, ObjectAttributes=0, ProcessHandle=NeededParameter, lpStartAddress=NeededParameter, lpParameter=NeededParameter, CreateSuspended=0, dwStackSize=0, Unknown1=0, Unknown2=0, Unknown=0):
|
||||
if ThreadHandle is None:
|
||||
ThreadHandle = ctypes.byref(gdef.HANDLE())
|
||||
return NtCreateThreadEx.ctypes_function(ThreadHandle, DesiredAccess, ObjectAttributes, ProcessHandle, lpStartAddress, lpParameter, CreateSuspended, dwStackSize, Unknown1, Unknown2, Unknown3)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtSetContextThread(hThread, lpContext):
|
||||
return NtSetContextThread.ctypes_function(hThread, lpContext)
|
||||
|
||||
|
||||
# Memory
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAllocateVirtualMemory(ProcessHandle, BaseAddress, ZeroBits, RegionSize, AllocationType, Protect):
|
||||
return NtAllocateVirtualMemory.ctypes_function(ProcessHandle, BaseAddress, ZeroBits, RegionSize, AllocationType, Protect)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtFreeVirtualMemory(ProcessHandle, BaseAddress, RegionSize, FreeType):
|
||||
return NtFreeVirtualMemory.ctypes_function(ProcessHandle, BaseAddress, RegionSize, FreeType)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtProtectVirtualMemory(ProcessHandle, BaseAddress, NumberOfBytesToProtect, NewAccessProtection, OldAccessProtection=None):
|
||||
if OldAccessProtection is None:
|
||||
OldAccessProtection = gdef.DWORD()
|
||||
return NtProtectVirtualMemory.ctypes_function(ProcessHandle, BaseAddress, NumberOfBytesToProtect, NewAccessProtection, OldAccessProtection)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQueryVirtualMemory(ProcessHandle, BaseAddress, MemoryInformationClass, MemoryInformation=NeededParameter, MemoryInformationLength=0, ReturnLength=None):
|
||||
if ReturnLength is None:
|
||||
ReturnLength = ctypes.byref(gdef.ULONG())
|
||||
if MemoryInformation is not None and MemoryInformationLength == 0:
|
||||
ProcessInformationLength = ctypes.sizeof(MemoryInformation)
|
||||
if type(MemoryInformation) == gdef.MEMORY_BASIC_INFORMATION64:
|
||||
MemoryInformation = ctypes.byref(MemoryInformation)
|
||||
return NtQueryVirtualMemory.ctypes_function(ProcessHandle, BaseAddress, MemoryInformationClass, MemoryInformation=NeededParameter, MemoryInformationLength=0, ReturnLength=None)
|
||||
|
||||
|
||||
# System
|
||||
|
||||
def ntquerysysteminformation_error_check(func_name, result, func, args):
|
||||
if result == 0:
|
||||
return args
|
||||
# Ignore STATUS_INFO_LENGTH_MISMATCH if SystemInformation is None
|
||||
if result == gdef.STATUS_INFO_LENGTH_MISMATCH and args[1] is None:
|
||||
return args
|
||||
raise WinproxyError("{0} failed with NTStatus {1}".format(func_name, hex(result)))
|
||||
|
||||
|
||||
@NtdllProxy(error_check=ntquerysysteminformation_error_check)
|
||||
def NtQuerySystemInformation(SystemInformationClass, SystemInformation=None, SystemInformationLength=0, ReturnLength=NeededParameter):
|
||||
if SystemInformation is not None and SystemInformationLength == 0:
|
||||
SystemInformationLength = ctypes.sizeof(SystemInformation)
|
||||
return NtQuerySystemInformation.ctypes_function(SystemInformationClass, SystemInformation, SystemInformationLength, ReturnLength)
|
||||
|
||||
# path
|
||||
|
||||
@NtdllProxy(error_check=fail_on_zero)
|
||||
def RtlDosPathNameToNtPathName_U(DosName, NtName=None, PartName=None, RelativeName=None):
|
||||
return RtlDosPathNameToNtPathName_U.ctypes_function(DosName, NtName, PartName, RelativeName)
|
||||
|
||||
|
||||
|
||||
# kernel Object
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQueryObject(Handle, ObjectInformationClass, ObjectInformation=None, ObjectInformationLength=0, ReturnLength=NeededParameter):
|
||||
return NtQueryObject.ctypes_function(Handle, ObjectInformationClass, ObjectInformation, ObjectInformationLength, ReturnLength)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtOpenDirectoryObject(DirectoryHandle, DesiredAccess, ObjectAttributes):
|
||||
return NtOpenDirectoryObject.ctypes_function(DirectoryHandle, DesiredAccess, ObjectAttributes)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQueryDirectoryObject(DirectoryHandle, Buffer, Length, ReturnSingleEntry, RestartScan, Context, ReturnLength):
|
||||
return NtQueryDirectoryObject.ctypes_function(DirectoryHandle, Buffer, Length, ReturnSingleEntry, RestartScan, Context, ReturnLength)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQuerySymbolicLinkObject(LinkHandle, LinkTarget, ReturnedLength):
|
||||
return NtQuerySymbolicLinkObject.ctypes_function(LinkHandle, LinkTarget, ReturnedLength)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtOpenSymbolicLinkObject(LinkHandle, DesiredAccess, ObjectAttributes):
|
||||
return NtOpenSymbolicLinkObject.ctypes_function(LinkHandle, DesiredAccess, ObjectAttributes)
|
||||
|
||||
|
||||
# Event
|
||||
|
||||
@NtdllProxy()
|
||||
def NtOpenEvent(EventHandle, DesiredAccess, ObjectAttributes):
|
||||
return NtOpenEvent.ctypes_function(EventHandle, DesiredAccess, ObjectAttributes)
|
||||
|
||||
# ALPC
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcCreatePort(PortHandle, ObjectAttributes, PortAttributes):
|
||||
return NtAlpcCreatePort.ctypes_function(PortHandle, ObjectAttributes, PortAttributes)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcConnectPort(PortHandle, PortName, ObjectAttributes, PortAttributes, Flags, RequiredServerSid, ConnectionMessage, BufferLength, OutMessageAttributes, InMessageAttributes, Timeout):
|
||||
return NtAlpcConnectPort.ctypes_function(PortHandle, PortName, ObjectAttributes, PortAttributes, Flags, RequiredServerSid, ConnectionMessage, BufferLength, OutMessageAttributes, InMessageAttributes, Timeout)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcConnectPortEx(PortHandle, ConnectionPortObjectAttributes, ClientPortObjectAttributes, PortAttributes, Flags, ServerSecurityRequirements, ConnectionMessage, BufferLength, OutMessageAttributes, InMessageAttributes, Timeout):
|
||||
return NtAlpcConnectPortEx.ctypes_function(PortHandle, ConnectionPortObjectAttributes, ClientPortObjectAttributes, PortAttributes, Flags, ServerSecurityRequirements, ConnectionMessage, BufferLength, OutMessageAttributes, InMessageAttributes, Timeout)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcAcceptConnectPort(PortHandle, ConnectionPortHandle, Flags, ObjectAttributes, PortAttributes, PortContext, ConnectionRequest, ConnectionMessageAttributes, AcceptConnection):
|
||||
return NtAlpcAcceptConnectPort.ctypes_function(PortHandle, ConnectionPortHandle, Flags, ObjectAttributes, PortAttributes, PortContext, ConnectionRequest, ConnectionMessageAttributes, AcceptConnection)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcQueryInformation(PortHandle, PortInformationClass, PortInformation, Length, ReturnLength):
|
||||
return NtAlpcQueryInformation.ctypes_function(PortHandle, PortInformationClass, PortInformation, Length, ReturnLength)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcDisconnectPort(PortHandle, Flags):
|
||||
return NtAlpcDisconnectPort.ctypes_function(PortHandle, Flags)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcSendWaitReceivePort(PortHandle, Flags, SendMessage, SendMessageAttributes, ReceiveMessage, BufferLength, ReceiveMessageAttributes, Timeout):
|
||||
return NtAlpcSendWaitReceivePort.ctypes_function(PortHandle, Flags, SendMessage, SendMessageAttributes, ReceiveMessage, BufferLength, ReceiveMessageAttributes, Timeout)
|
||||
|
||||
@NtdllProxy()
|
||||
def AlpcInitializeMessageAttribute(AttributeFlags, Buffer, BufferSize, RequiredBufferSize):
|
||||
return AlpcInitializeMessageAttribute.ctypes_function(AttributeFlags, Buffer, BufferSize, RequiredBufferSize)
|
||||
|
||||
@NtdllProxy()
|
||||
def AlpcGetMessageAttribute(Buffer, AttributeFlag):
|
||||
return AlpcGetMessageAttribute.ctypes_function(Buffer, AttributeFlag)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcCreatePortSection(PortHandle, Flags, SectionHandle, SectionSize, AlpcSectionHandle, ActualSectionSize):
|
||||
return NtAlpcCreatePortSection.ctypes_function(PortHandle, Flags, SectionHandle, SectionSize, AlpcSectionHandle, ActualSectionSize)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcDeletePortSection(PortHandle, Flags, SectionHandle):
|
||||
return NtAlpcDeletePortSection.ctypes_function(PortHandle, Flags, SectionHandle)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcCreateSectionView(PortHandle, Flags, ViewAttributes):
|
||||
return NtAlpcCreateSectionView.ctypes_function(PortHandle, Flags, ViewAttributes)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcDeleteSectionView(PortHandle, Flags, ViewBase):
|
||||
return NtAlpcDeleteSectionView.ctypes_function(PortHandle, Flags, ViewBase)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtAlpcQueryInformationMessage(PortHandle, PortMessage, MessageInformationClass, MessageInformation, Length, ReturnLength):
|
||||
return NtAlpcQueryInformationMessage.ctypes_function(PortHandle, PortMessage, MessageInformationClass, MessageInformation, Length, ReturnLength)
|
||||
|
||||
@NtdllProxy()
|
||||
def TpCallbackSendAlpcMessageOnCompletion(TpHandle, PortHandle, Flags, SendMessage):
|
||||
return TpCallbackSendAlpcMessageOnCompletion.ctypes_function(TpHandle, PortHandle, Flags, SendMessage)
|
||||
|
||||
|
||||
# Compression
|
||||
|
||||
@NtdllProxy()
|
||||
def RtlDecompressBuffer(CompressionFormat, UncompressedBuffer, UncompressedBufferSize, CompressedBuffer, CompressedBufferSize=None, FinalUncompressedSize=NeededParameter):
|
||||
if CompressedBufferSize is None:
|
||||
CompressedBufferSize = len(CompressedBuffer)
|
||||
return RtlDecompressBuffer.ctypes_function(CompressionFormat, UncompressedBuffer, UncompressedBufferSize, CompressedBuffer, CompressedBufferSize, FinalUncompressedSize)
|
||||
|
||||
@NtdllProxy()
|
||||
def RtlDecompressBufferEx(CompressionFormat, UncompressedBuffer, UncompressedBufferSize, CompressedBuffer, CompressedBufferSize=None, FinalUncompressedSize=NeededParameter, WorkSpace=NeededParameter):
|
||||
if CompressedBufferSize is None:
|
||||
CompressedBufferSize = len(CompressedBuffer)
|
||||
# TODO: automatic 'WorkSpace' size calc + allocation ?
|
||||
return RtlDecompressBufferEx.ctypes_function(CompressionFormat, UncompressedBuffer, UncompressedBufferSize, CompressedBuffer, CompressedBufferSize, FinalUncompressedSize, WorkSpace)
|
||||
|
||||
@NtdllProxy()
|
||||
def RtlGetCompressionWorkSpaceSize(CompressionFormatAndEngine, CompressBufferWorkSpaceSize, CompressFragmentWorkSpaceSize):
|
||||
return RtlGetCompressionWorkSpaceSize.ctypes_function(CompressionFormatAndEngine, CompressBufferWorkSpaceSize, CompressFragmentWorkSpaceSize)
|
||||
|
||||
|
||||
# Section
|
||||
|
||||
@NtdllProxy()
|
||||
def NtCreateSection(SectionHandle, DesiredAccess, ObjectAttributes, MaximumSize, SectionPageProtection, AllocationAttributes, FileHandle):
|
||||
return NtCreateSection.ctypes_function(SectionHandle, DesiredAccess, ObjectAttributes, MaximumSize, SectionPageProtection, AllocationAttributes, FileHandle)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtOpenSection(SectionHandle, DesiredAccess, ObjectAttributes):
|
||||
return NtOpenSection.ctypes_function(SectionHandle, DesiredAccess, ObjectAttributes)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtMapViewOfSection(SectionHandle, ProcessHandle, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect):
|
||||
return NtMapViewOfSection.ctypes_function(SectionHandle, ProcessHandle, BaseAddress, ZeroBits, CommitSize, SectionOffset, ViewSize, InheritDisposition, AllocationType, Win32Protect)
|
||||
|
||||
|
||||
@NtdllProxy()
|
||||
def NtUnmapViewOfSection(ProcessHandle, BaseAddress):
|
||||
return NtUnmapViewOfSection.ctypes_function(ProcessHandle, BaseAddress)
|
||||
|
||||
# Registry
|
||||
|
||||
@NtdllProxy()
|
||||
def NtOpenKey(KeyHandle, DesiredAccess, ObjectAttributes):
|
||||
return NtOpenKey.ctypes_function(KeyHandle, DesiredAccess, ObjectAttributes)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtCreateKey(pKeyHandle, DesiredAccess, ObjectAttributes, TitleIndex, Class, CreateOptions, Disposition):
|
||||
return NtCreateKey.ctypes_function(pKeyHandle, DesiredAccess, ObjectAttributes, TitleIndex, Class, CreateOptions, Disposition)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtSetValueKey(KeyHandle, ValueName, TitleIndex, Type, Data, DataSize):
|
||||
return NtSetValueKey.ctypes_function(KeyHandle, ValueName, TitleIndex, Type, Data, DataSize)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQueryValueKey(KeyHandle, ValueName, KeyValueInformationClass, KeyValueInformation, Length, ResultLength):
|
||||
return NtQueryValueKey.ctypes_function(KeyHandle, ValueName, KeyValueInformationClass, KeyValueInformation, Length, ResultLength)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtEnumerateValueKey(KeyHandle, Index, KeyValueInformationClass, KeyValueInformation, Length, ResultLength):
|
||||
return NtEnumerateValueKey.ctypes_function(KeyHandle, Index, KeyValueInformationClass, KeyValueInformation, Length, ResultLength)
|
||||
|
||||
@NtdllProxy()
|
||||
def NtQueryLicenseValue(Name, Type, Buffer, Length=None, DataLength=NeededParameter):
|
||||
if Length is None and Buffer:
|
||||
Length = len(buffer)
|
||||
return NtQueryLicenseValue.ctypes_function(Name, Type, Buffer, Length, DataLength)
|
||||
|
||||
|
||||
# Other
|
||||
|
||||
@NtdllProxy()
|
||||
def RtlEqualUnicodeString(String1, String2, CaseInSensitive):
|
||||
return RtlEqualUnicodeString.ctypes_function(String1, String2, CaseInSensitive)
|
||||
|
||||
|
||||
|
||||
#########
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import no_error_check
|
||||
|
||||
# IMPORTANT:
|
||||
# Functions that returns HRESULT (like CoInitializeEx) will raise if HRESULT is an error
|
||||
# even if there is no error check on the return value
|
||||
|
||||
class Ole32Proxy(ApiProxy):
|
||||
APIDLL = "ole32"
|
||||
default_error_check = staticmethod(no_error_check)
|
||||
|
||||
|
||||
@Ole32Proxy()
|
||||
def CoInitializeEx(pvReserved=None, dwCoInit=gdef.COINIT_MULTITHREADED):
|
||||
return CoInitializeEx.ctypes_function(pvReserved, dwCoInit)
|
||||
|
||||
|
||||
@Ole32Proxy()
|
||||
def CoInitializeSecurity(pSecDesc, cAuthSvc, asAuthSvc, pReserved1, dwAuthnLevel, dwImpLevel, pAuthList, dwCapabilities, pReserved3):
|
||||
return CoInitializeSecurity.ctypes_function(pSecDesc, cAuthSvc, asAuthSvc, pReserved1, dwAuthnLevel, dwImpLevel, pAuthList, dwCapabilities, pReserved3)
|
||||
|
||||
|
||||
@Ole32Proxy()
|
||||
def CoCreateInstance(rclsid, pUnkOuter=None, dwClsContext=gdef.CLSCTX_INPROC_SERVER, riid=NeededParameter, ppv=NeededParameter):
|
||||
return CoCreateInstance.ctypes_function(rclsid, pUnkOuter, dwClsContext, riid, ppv)
|
||||
|
||||
@Ole32Proxy()
|
||||
def CoCreateInstanceEx(rclsid, punkOuter, dwClsCtx, pServerInfo, dwCount, pResults):
|
||||
return CoCreateInstanceEx.ctypes_function(rclsid, punkOuter, dwClsCtx, pServerInfo, dwCount, pResults)
|
||||
|
||||
|
||||
@Ole32Proxy()
|
||||
def CoGetInterceptor(iidIntercepted, punkOuter, iid, ppv):
|
||||
return CoGetInterceptor.ctypes_function(iidIntercepted, punkOuter, iid, ppv)
|
||||
|
||||
@Ole32Proxy()
|
||||
def CLSIDFromProgID(lpszProgID, lpclsid):
|
||||
return CLSIDFromProgID.ctypes_function(lpszProgID, lpclsid)
|
||||
@@ -0,0 +1,13 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter, is_implemented
|
||||
from ..error import succeed_on_zero
|
||||
|
||||
class OleaccProxy(ApiProxy):
|
||||
APIDLL = "Oleacc"
|
||||
default_error_check = staticmethod(succeed_on_zero)
|
||||
|
||||
@OleaccProxy()
|
||||
def ObjectFromLresult(lResult, riid, wParam, ppvObject):
|
||||
return ObjectFromLresult.ctypes_function(lResult, riid, wParam, ppvObject)
|
||||
@@ -0,0 +1,64 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import fail_on_zero
|
||||
|
||||
class PsapiProxy(ApiProxy):
|
||||
APIDLL = "psapi"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
# TODO: fallback to kernel32 for old version
|
||||
|
||||
|
||||
@PsapiProxy()
|
||||
def GetMappedFileNameW(hProcess, lpv, lpFilename, nSize=None):
|
||||
if nSize is None:
|
||||
nSize = ctypes.sizeof(lpFilename)
|
||||
return GetMappedFileNameW.ctypes_function(hProcess, lpv, lpFilename, nSize)
|
||||
|
||||
|
||||
@PsapiProxy()
|
||||
def GetMappedFileNameA(hProcess, lpv, lpFilename, nSize=None):
|
||||
if nSize is None:
|
||||
nSize = ctypes.sizeof(lpFilename)
|
||||
return GetMappedFileNameA.ctypes_function(hProcess, lpv, lpFilename, nSize)
|
||||
|
||||
|
||||
@PsapiProxy()
|
||||
def QueryWorkingSet(hProcess, pv, cb):
|
||||
return QueryWorkingSet.ctypes_function(hProcess, pv, cb)
|
||||
|
||||
|
||||
@PsapiProxy()
|
||||
def QueryWorkingSetEx(hProcess, pv, cb):
|
||||
return QueryWorkingSetEx.ctypes_function(hProcess, pv, cb)
|
||||
|
||||
|
||||
@PsapiProxy()
|
||||
def GetModuleBaseNameA(hProcess, hModule, lpBaseName, nSize=None):
|
||||
if nSize is None:
|
||||
nSize = len(lpBaseName)
|
||||
return GetModuleBaseNameA.ctypes_function(hProcess, hModule, lpBaseName, nSize)
|
||||
|
||||
@PsapiProxy()
|
||||
def GetModuleBaseNameW(hProcess, hModule, lpBaseName, nSize=None):
|
||||
if nSize is None:
|
||||
nSize = len(lpBaseName)
|
||||
return GetModuleBaseNameW.ctypes_function(hProcess, hModule, lpBaseName, nSize)
|
||||
|
||||
@PsapiProxy()
|
||||
def GetProcessImageFileNameA(hProcess, lpImageFileName, nSize=None):
|
||||
if nSize is None:
|
||||
nSize = len(lpImageFileName)
|
||||
return GetProcessImageFileNameA.ctypes_function(hProcess, lpImageFileName, nSize)
|
||||
|
||||
@PsapiProxy()
|
||||
def GetProcessImageFileNameW(hProcess, lpImageFileName, nSize=None):
|
||||
if nSize is None:
|
||||
nSize = len(lpImageFileName)
|
||||
return GetProcessImageFileNameW.ctypes_function(hProcess, lpImageFileName, nSize)
|
||||
|
||||
@PsapiProxy()
|
||||
def GetProcessMemoryInfo(Process, ppsmemCounters, cb):
|
||||
return GetProcessMemoryInfo.ctypes_function(Process, ppsmemCounters, cb)
|
||||
@@ -0,0 +1,17 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import fail_on_zero
|
||||
|
||||
class Shell32Proxy(ApiProxy):
|
||||
APIDLL = "shell32"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
@Shell32Proxy()
|
||||
def ShellExecuteA(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd):
|
||||
return ShellExecuteA.ctypes_function(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd)
|
||||
|
||||
@Shell32Proxy()
|
||||
def ShellExecuteW(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd):
|
||||
return ShellExecuteW.ctypes_function(hwnd, lpOperation, lpFile, lpParameters, lpDirectory, nShowCmd)
|
||||
@@ -0,0 +1,27 @@
|
||||
import ctypes
|
||||
import windows
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter, is_implemented
|
||||
from ..error import fail_on_zero
|
||||
|
||||
class ShlwapiProxy(ApiProxy):
|
||||
APIDLL = "Shlwapi"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
@ShlwapiProxy()
|
||||
def StrStrIW(pszFirst, pszSrch):
|
||||
return StrStrIW.ctypes_function(pszFirst, pszSrch)
|
||||
|
||||
@ShlwapiProxy()
|
||||
def StrStrIA(pszFirst, pszSrch):
|
||||
return StrStrIA.ctypes_function(pszFirst, pszSrch)
|
||||
|
||||
@ShlwapiProxy()
|
||||
def IsOS(dwOS):
|
||||
if not is_implemented(IsOS) and windows.system.version[0] < 6:
|
||||
# Before Vista:
|
||||
# If so use ordinal 437 from DOCUMENTATION
|
||||
# https://docs.microsoft.com/en-us/windows/desktop/api/shlwapi/nf-shlwapi-isos#remarks
|
||||
IsOS.proxy.func_name = 437
|
||||
return IsOS.ctypes_function(dwOS)
|
||||
@@ -0,0 +1,106 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import fail_on_zero
|
||||
|
||||
class User32Proxy(ApiProxy):
|
||||
APIDLL = "user32"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
|
||||
# Window
|
||||
|
||||
@User32Proxy()
|
||||
def EnumWindows(lpEnumFunc, lParam):
|
||||
return EnumWindows.ctypes_function(lpEnumFunc, lParam)
|
||||
|
||||
@User32Proxy()
|
||||
def GetWindowTextA(hWnd, lpString, nMaxCount):
|
||||
return GetWindowTextA.ctypes_function(hWnd, lpString, nMaxCount)
|
||||
|
||||
@User32Proxy()
|
||||
def GetParent(hWnd):
|
||||
return GetParent.ctypes_function(hWnd)
|
||||
|
||||
@User32Proxy()
|
||||
def GetWindowTextW(hWnd, lpString, nMaxCount):
|
||||
return GetWindowTextW.ctypes_function(hWnd, lpString, nMaxCount)
|
||||
|
||||
@User32Proxy()
|
||||
def GetWindowModuleFileNameA(hwnd, pszFileName, cchFileNameMax):
|
||||
return GetWindowModuleFileNameA.ctypes_function(hwnd, pszFileName, cchFileNameMax)
|
||||
|
||||
@User32Proxy()
|
||||
def GetWindowModuleFileNameW(hwnd, pszFileName, cchFileNameMax):
|
||||
return GetWindowModuleFileNameW.ctypes_function(hwnd, pszFileName, cchFileNameMax)
|
||||
|
||||
@User32Proxy()
|
||||
def EnumChildWindows(hWndParent, lpEnumFunc, lParam):
|
||||
return EnumChildWindows.ctypes_function(hWndParent, lpEnumFunc, lParam)
|
||||
|
||||
@User32Proxy()
|
||||
def GetClassInfoExA(hinst, lpszClass, lpwcx):
|
||||
return GetClassInfoExA.ctypes_function(hinst, lpszClass, lpwcx)
|
||||
|
||||
@User32Proxy()
|
||||
def GetClassInfoExW(hinst, lpszClass, lpwcx):
|
||||
return GetClassInfoExW.ctypes_function(hinst, lpszClass, lpwcx)
|
||||
|
||||
@User32Proxy()
|
||||
def GetWindowThreadProcessId(hWnd, lpdwProcessId):
|
||||
return GetWindowThreadProcessId.ctypes_function(hWnd, lpdwProcessId)
|
||||
|
||||
@User32Proxy()
|
||||
def WindowFromPoint(Point):
|
||||
return WindowFromPoint.ctypes_function(Point)
|
||||
|
||||
@User32Proxy()
|
||||
def GetWindowRect(hWnd, lpRect):
|
||||
return GetWindowRect.ctypes_function(hWnd, lpRect)
|
||||
|
||||
@User32Proxy("RealGetWindowClassA")
|
||||
def RealGetWindowClassA(hwnd, pszType, cchType=None):
|
||||
if cchType is None:
|
||||
cchType = len(pszType)
|
||||
return RealGetWindowClassA.ctypes_function(hwnd, pszType, cchType)
|
||||
|
||||
@User32Proxy("RealGetWindowClassW")
|
||||
def RealGetWindowClassW(hwnd, pszType, cchType=None):
|
||||
if cchType is None:
|
||||
cchType = len(pszType)
|
||||
return RealGetWindowClassW.ctypes_function(hwnd, pszType, cchType)
|
||||
|
||||
@User32Proxy("GetClassNameA")
|
||||
def GetClassNameA (hwnd, pszType, cchType=None):
|
||||
if cchType is None:
|
||||
cchType = len(pszType)
|
||||
return GetClassNameA .ctypes_function(hwnd, pszType, cchType)
|
||||
|
||||
@User32Proxy("GetClassNameW")
|
||||
def GetClassNameW (hwnd, pszType, cchType=None):
|
||||
if cchType is None:
|
||||
cchType = len(pszType)
|
||||
return GetClassNameW .ctypes_function(hwnd, pszType, cchType)
|
||||
|
||||
## Windows Message
|
||||
|
||||
@User32Proxy()
|
||||
def MessageBoxA(hWnd=0, lpText=NeededParameter, lpCaption=None, uType=0):
|
||||
return MessageBoxA.ctypes_function(hWnd, lpText, lpCaption, uType)
|
||||
|
||||
@User32Proxy()
|
||||
def MessageBoxW(hWnd=0, lpText=NeededParameter, lpCaption=None, uType=0):
|
||||
return MessageBoxW.ctypes_function(hWnd, lpText, lpCaption, uType)
|
||||
|
||||
# Cursor
|
||||
|
||||
@User32Proxy()
|
||||
def GetCursorPos(lpPoint):
|
||||
return GetCursorPos.ctypes_function(lpPoint)
|
||||
|
||||
# System
|
||||
|
||||
@User32Proxy()
|
||||
def GetSystemMetrics(nIndex):
|
||||
return GetSystemMetrics.ctypes_function(nIndex)
|
||||
@@ -0,0 +1,43 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import fail_on_zero
|
||||
|
||||
class VersionProxy(ApiProxy):
|
||||
APIDLL = "version"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
|
||||
@VersionProxy()
|
||||
def GetFileVersionInfoA(lptstrFilename, dwHandle=0, dwLen=None, lpData=NeededParameter):
|
||||
if dwLen is None and lpData is not None:
|
||||
dwLen = len(lpData)
|
||||
return GetFileVersionInfoA.ctypes_function(lptstrFilename, dwHandle, dwLen, lpData)
|
||||
|
||||
@VersionProxy()
|
||||
def GetFileVersionInfoW(lptstrFilename, dwHandle=0, dwLen=None, lpData=NeededParameter):
|
||||
if dwLen is None and lpData is not None:
|
||||
dwLen = len(lpData)
|
||||
return GetFileVersionInfoA.ctypes_function(lptstrFilename, dwHandle, dwLen, lpData)
|
||||
|
||||
@VersionProxy()
|
||||
def GetFileVersionInfoSizeA(lptstrFilename, lpdwHandle=None):
|
||||
if lpdwHandle is None:
|
||||
lpdwHandle = ctypes.byref(gdef.DWORD())
|
||||
return GetFileVersionInfoSizeA.ctypes_function(lptstrFilename, lpdwHandle)
|
||||
|
||||
@VersionProxy()
|
||||
def GetFileVersionInfoSizeW(lptstrFilename, lpdwHandle=None):
|
||||
if lpdwHandle is None:
|
||||
lpdwHandle = ctypes.byref(gdef.DWORD())
|
||||
return GetFileVersionInfoSizeW.ctypes_function(lptstrFilename, lpdwHandle)
|
||||
|
||||
@VersionProxy()
|
||||
def VerQueryValueA(pBlock, lpSubBlock, lplpBuffer, puLen):
|
||||
return VerQueryValueA.ctypes_function(pBlock, lpSubBlock, lplpBuffer, puLen)
|
||||
|
||||
@VersionProxy()
|
||||
def VerQueryValueW(pBlock, lpSubBlock, lplpBuffer, puLen):
|
||||
return VerQueryValueW.ctypes_function(pBlock, lpSubBlock, lplpBuffer, puLen)
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import fail_on_zero
|
||||
|
||||
class WevtapiProxy(ApiProxy):
|
||||
APIDLL = "Wevtapi"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
|
||||
# Event
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtOpenLog(Session, Path, Flags):
|
||||
return EvtOpenLog.ctypes_function(Session, Path, Flags)
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtClose(Object):
|
||||
return EvtClose.ctypes_function(Object)
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtQuery(Session, Path, Query, Flags):
|
||||
return EvtQuery.ctypes_function(Session, Path, Query, Flags)
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtNext(ResultSet, EventArraySize, EventArray, Timeout, Flags, Returned):
|
||||
return EvtNext.ctypes_function(ResultSet, EventArraySize, EventArray, Timeout, Flags, Returned)
|
||||
|
||||
# Channel
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtOpenChannelEnum(Session, Flags):
|
||||
return EvtOpenChannelEnum.ctypes_function(Session, Flags)
|
||||
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtNextChannelPath(ChannelEnum, ChannelPathBufferSize, ChannelPathBuffer, ChannelPathBufferUsed):
|
||||
return EvtNextChannelPath.ctypes_function(ChannelEnum, ChannelPathBufferSize, ChannelPathBuffer, ChannelPathBufferUsed)
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtOpenChannelConfig(Session, ChannelPath, Flags):
|
||||
return EvtOpenChannelConfig.ctypes_function(Session, ChannelPath, Flags)
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtGetChannelConfigProperty(ChannelConfig, PropertyId, Flags, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed):
|
||||
return EvtGetChannelConfigProperty.ctypes_function(ChannelConfig, PropertyId, Flags, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed)
|
||||
|
||||
# Publisher
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtOpenPublisherEnum(Session, Flags):
|
||||
return EvtOpenPublisherEnum.ctypes_function(Session, Flags)
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtNextPublisherId(PublisherEnum, PublisherIdBufferSize, PublisherIdBuffer, PublisherIdBufferUsed):
|
||||
return EvtNextPublisherId.ctypes_function(PublisherEnum, PublisherIdBufferSize, PublisherIdBuffer, PublisherIdBufferUsed)
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtOpenPublisherMetadata(Session, PublisherIdentity, LogFilePath, Locale, Flags):
|
||||
return EvtOpenPublisherMetadata.ctypes_function(Session, PublisherIdentity, LogFilePath, Locale, Flags)
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtGetPublisherMetadataProperty(PublisherMetadata, PropertyId, Flags, PublisherMetadataPropertyBufferSize, PublisherMetadataPropertyBuffer, PublisherMetadataPropertyBufferUsed):
|
||||
return EvtGetPublisherMetadataProperty.ctypes_function(PublisherMetadata, PropertyId, Flags, PublisherMetadataPropertyBufferSize, PublisherMetadataPropertyBuffer, PublisherMetadataPropertyBufferUsed)
|
||||
|
||||
|
||||
# Evt metadata
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtOpenEventMetadataEnum(PublisherMetadata, Flags):
|
||||
return EvtOpenEventMetadataEnum.ctypes_function(PublisherMetadata, Flags)
|
||||
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtNextEventMetadata(EventMetadataEnum, Flags):
|
||||
return EvtNextEventMetadata.ctypes_function(EventMetadataEnum, Flags)
|
||||
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtGetEventMetadataProperty(EventMetadata, PropertyId, Flags, EventMetadataPropertyBufferSize, EventMetadataPropertyBuffer, EventMetadataPropertyBufferUsed):
|
||||
return EvtGetEventMetadataProperty.ctypes_function(EventMetadata, PropertyId, Flags, EventMetadataPropertyBufferSize, EventMetadataPropertyBuffer, EventMetadataPropertyBufferUsed)
|
||||
|
||||
# Render
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtCreateRenderContext(ValuePathsCount, ValuePaths, Flags):
|
||||
return EvtCreateRenderContext.ctypes_function(ValuePathsCount, ValuePaths, Flags)
|
||||
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtRender(Context, Fragment, Flags, BufferSize, Buffer, BufferUsed, PropertyCount):
|
||||
return EvtRender.ctypes_function(Context, Fragment, Flags, BufferSize, Buffer, BufferUsed, PropertyCount)
|
||||
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtFormatMessage(PublisherMetadata, Event, MessageId, ValueCount, Values, Flags, BufferSize, Buffer, BufferUsed):
|
||||
return EvtFormatMessage.ctypes_function(PublisherMetadata, Event, MessageId, ValueCount, Values, Flags, BufferSize, Buffer, BufferUsed)
|
||||
|
||||
# Other
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtGetLogInfo(Log, PropertyId, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed):
|
||||
return EvtGetLogInfo.ctypes_function(Log, PropertyId, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed)
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtGetObjectArraySize(ObjectArray, ObjectArraySize):
|
||||
return EvtGetObjectArraySize.ctypes_function(ObjectArray, ObjectArraySize)
|
||||
|
||||
|
||||
@WevtapiProxy()
|
||||
def EvtGetObjectArrayProperty(ObjectArray, PropertyId, ArrayIndex, Flags, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed):
|
||||
return EvtGetObjectArrayProperty.ctypes_function(ObjectArray, PropertyId, ArrayIndex, Flags, PropertyValueBufferSize, PropertyValueBuffer, PropertyValueBufferUsed)
|
||||
|
||||
|
||||
####
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import ctypes
|
||||
import windows.generated_def as gdef
|
||||
|
||||
from ..apiproxy import ApiProxy, NeededParameter
|
||||
from ..error import no_error_check, fail_on_zero
|
||||
|
||||
class WinTrustProxy(ApiProxy):
|
||||
APIDLL = "wintrust"
|
||||
default_error_check = staticmethod(fail_on_zero)
|
||||
|
||||
|
||||
# Trust
|
||||
|
||||
@WinTrustProxy(error_check=no_error_check)
|
||||
def WinVerifyTrust(hwnd, pgActionID, pWVTData):
|
||||
return WinVerifyTrust.ctypes_function(hwnd, pgActionID, pWVTData)
|
||||
|
||||
# Catalog
|
||||
|
||||
@WinTrustProxy()
|
||||
def CryptCATAdminCalcHashFromFileHandle(hFile, pcbHash, pbHash, dwFlags):
|
||||
return CryptCATAdminCalcHashFromFileHandle.ctypes_function(hFile, pcbHash, pbHash, dwFlags)
|
||||
|
||||
@WinTrustProxy()
|
||||
def CryptCATAdminCalcHashFromFileHandle2(hCatAdmin, hFile, pcbHash, pbHash, dwFlags):
|
||||
return CryptCATAdminCalcHashFromFileHandle2.ctypes_function(hCatAdmin, hFile, pcbHash, pbHash, dwFlags)
|
||||
|
||||
@WinTrustProxy(error_check=no_error_check)
|
||||
def CryptCATAdminEnumCatalogFromHash(hCatAdmin, pbHash, cbHash, dwFlags, phPrevCatInfo):
|
||||
return CryptCATAdminEnumCatalogFromHash.ctypes_function(hCatAdmin, pbHash, cbHash, dwFlags, phPrevCatInfo)
|
||||
|
||||
@WinTrustProxy()
|
||||
def CryptCATAdminAcquireContext(phCatAdmin, pgSubsystem, dwFlags):
|
||||
return CryptCATAdminAcquireContext.ctypes_function(phCatAdmin, pgSubsystem, dwFlags)
|
||||
|
||||
@WinTrustProxy()
|
||||
def CryptCATAdminAcquireContext2(phCatAdmin, pgSubsystem, pwszHashAlgorithm, pStrongHashPolicy, dwFlags):
|
||||
return CryptCATAdminAcquireContext2.ctypes_function(phCatAdmin, pgSubsystem, pwszHashAlgorithm, pStrongHashPolicy, dwFlags)
|
||||
|
||||
|
||||
@WinTrustProxy()
|
||||
def CryptCATCatalogInfoFromContext(hCatInfo, psCatInfo, dwFlags):
|
||||
return CryptCATCatalogInfoFromContext.ctypes_function(hCatInfo, psCatInfo, dwFlags)
|
||||
|
||||
|
||||
@WinTrustProxy(error_check=no_error_check)
|
||||
def CryptCATAdminReleaseCatalogContext(hCatAdmin, hCatInfo, dwFlags):
|
||||
return CryptCATAdminReleaseCatalogContext.ctypes_function(hCatAdmin, hCatInfo, dwFlags)
|
||||
|
||||
|
||||
@WinTrustProxy()
|
||||
def CryptCATAdminReleaseContext(hCatAdmin, dwFlags):
|
||||
return CryptCATAdminReleaseContext.ctypes_function(hCatAdmin, dwFlags)
|
||||
|
||||
|
||||
@WinTrustProxy(error_check=no_error_check)
|
||||
def CryptCATEnumerateAttr(hCatalog, pCatMember, pPrevAttr):
|
||||
return CryptCATEnumerateAttr.ctypes_function(hCatalog, pCatMember, pPrevAttr)
|
||||
|
||||
|
||||
@WinTrustProxy(error_check=no_error_check)
|
||||
def CryptCATEnumerateCatAttr(hCatalog, pPrevAttr):
|
||||
return CryptCATEnumerateCatAttr.ctypes_function(hCatalog, pPrevAttr)
|
||||
|
||||
|
||||
@WinTrustProxy(error_check=no_error_check)
|
||||
def CryptCATEnumerateMember(hCatalog, pPrevMember):
|
||||
return CryptCATEnumerateMember.ctypes_function(hCatalog, pPrevMember)
|
||||
@@ -0,0 +1,75 @@
|
||||
import ctypes
|
||||
|
||||
import windows.generated_def as gdef
|
||||
from windows.generated_def.ntstatus import NtStatusException
|
||||
|
||||
# PFW Winproxy Exception type
|
||||
class WinproxyError(WindowsError):
|
||||
def __new__(cls, func_name, error_code=None):
|
||||
win_error = ctypes.WinError(error_code) #GetLastError by default
|
||||
api_error = super(WinproxyError, cls).__new__(cls)
|
||||
api_error.api_name = func_name
|
||||
api_error.winerror = win_error.winerror & 0xffffffff
|
||||
api_error.strerror = win_error.strerror
|
||||
api_error.args = (func_name, win_error.winerror, win_error.strerror)
|
||||
return api_error
|
||||
|
||||
def __init__(self, func_name, error_code=None):
|
||||
super(WinproxyError, self).__init__(func_name)
|
||||
|
||||
def __repr__(self):
|
||||
return "{0}: {1}".format(self.api_name, super(WinproxyError, self).__repr__())
|
||||
|
||||
def __str__(self):
|
||||
return "{0}: {1}".format(self.api_name, super(WinproxyError, self).__str__())
|
||||
|
||||
|
||||
# winproxy Error check
|
||||
|
||||
# Try None instead :')
|
||||
def no_error_check(func_name, result, func, args):
|
||||
"""No error check"""
|
||||
return args
|
||||
|
||||
|
||||
def fail_on_minus_one(func_name, result, func, args):
|
||||
"""Raise WinproxyError if call result is -1"""
|
||||
if result == -1:
|
||||
raise WinproxyError(func_name)
|
||||
return args
|
||||
|
||||
|
||||
def fail_on_zero(func_name, result, func, args):
|
||||
"""raise WinproxyError if result is 0"""
|
||||
if not result:
|
||||
raise WinproxyError(func_name)
|
||||
return args
|
||||
|
||||
|
||||
def succeed_on_zero(func_name, result, func, args):
|
||||
"""raise WinproxyError if result is NOT 0"""
|
||||
if result:
|
||||
raise WinproxyError(func_name)
|
||||
return args
|
||||
|
||||
|
||||
def result_is_error_code(func_name, result, func, args):
|
||||
"""raise WinproxyError(result) if result is NOT 0"""
|
||||
if result:
|
||||
raise WinproxyError(func_name, error_code=result)
|
||||
return args
|
||||
|
||||
|
||||
def result_is_ntstatus(func_name, result, func, args):
|
||||
"""raise NtStatusException is result is not 0"""
|
||||
if result:
|
||||
raise NtStatusException(result & 0xffffffff)
|
||||
return args
|
||||
|
||||
|
||||
def result_is_handle(func_name, result, func, args):
|
||||
"""raise WinproxyError is result is INVALID_HANDLE_VALUE"""
|
||||
if result == gdef.INVALID_HANDLE_VALUE:
|
||||
raise WinproxyError(func_name)
|
||||
return args
|
||||
|
||||
Reference in New Issue
Block a user