Add special error handling for NtQuerySystemInformation

This commit is contained in:
Clement Rouault
2015-09-16 17:40:35 +02:00
parent 09a5724ea0
commit c05be85eb4
3 changed files with 13 additions and 3 deletions
+2
View File
@@ -17,6 +17,7 @@ if bitness() == 32:
winstructs.PEXCEPTION_POINTERS = winstructs.PEXCEPTION_POINTERS32
winstructs.SYSTEM_MODULE = winstructs.SYSTEM_MODULE32
winstructs.SYSTEM_MODULE_INFORMATION = winstructs.SYSTEM_MODULE_INFORMATION32
else:
winstructs.CONTEXT = winstructs.CONTEXT64
winstructs.PCONTEXT = winstructs.PCONTEXT64
@@ -26,6 +27,7 @@ else:
winstructs.PEXCEPTION_POINTERS = winstructs.PEXCEPTION_POINTERS64
winstructs.SYSTEM_MODULE = winstructs.SYSTEM_MODULE64
winstructs.SYSTEM_MODULE_INFORMATION = winstructs.SYSTEM_MODULE_INFORMATION64
from . import winfuncs
+2 -1
View File
@@ -469,4 +469,5 @@ KEY_WOW64_RES = Flag("KEY_WOW64_RES", ( 0x0300 ))
KEY_READ = Flag("KEY_READ", ( ( STANDARD_RIGHTS_READ|KEY_QUERY_VALUE|KEY_ENUMERATE_SUB_KEYS|KEY_NOTIFY ) & ( ~SYNCHRONIZE ) ))
KEY_WRITE = Flag("KEY_WRITE", ( ( STANDARD_RIGHTS_WRITE|KEY_SET_VALUE|KEY_CREATE_SUB_KEY ) & ( ~SYNCHRONIZE ) ))
KEY_EXECUTE = Flag("KEY_EXECUTE", ( ( KEY_READ ) & ( ~SYNCHRONIZE ) ))
KEY_ALL_ACCESS = Flag("KEY_ALL_ACCESS", ( ( STANDARD_RIGHTS_ALL|KEY_QUERY_VALUE|KEY_SET_VALUE|KEY_CREATE_SUB_KEY|KEY_ENUMERATE_SUB_KEYS|KEY_NOTIFY|KEY_CREATE_LINK ) & ( ~SYNCHRONIZE ) ))
KEY_ALL_ACCESS = Flag("KEY_ALL_ACCESS", ( ( STANDARD_RIGHTS_ALL|KEY_QUERY_VALUE|KEY_SET_VALUE|KEY_CREATE_SUB_KEY|KEY_ENUMERATE_SUB_KEYS|KEY_NOTIFY|KEY_CREATE_LINK ) & ( ~SYNCHRONIZE ) ))
STATUS_INFO_LENGTH_MISMATCH = Flag("STATUS_INFO_LENGTH_MISMATCH", ( 0xC0000004 ))
+9 -2
View File
@@ -202,7 +202,6 @@ GetThreadId = TransparentKernel32Proxy("GetThreadId")
def CreateFileA(lpFileName, dwDesiredAccess, dwShareMode=0, lpSecurityAttributes=None, dwCreationDisposition=OPEN_EXISTING, dwFlagsAndAttributes=FILE_ATTRIBUTE_NORMAL, hTemplateFile=None):
return CreateFileA.ctypes_function(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)
# This kind of function could be fully done by using paramflags
@Kernel32Proxy("VirtualAlloc")
def VirtualAlloc(lpAddress=0, dwSize=NeededParameter, flAllocationType=MEM_COMMIT, flProtect=PAGE_EXECUTE_READWRITE):
return VirtualAlloc.ctypes_function(lpAddress, dwSize, flAllocationType, flProtect)
@@ -374,7 +373,15 @@ def DeviceIoControl(hDevice, dwIoControlCode, lpInBuffer, nInBufferSize=None, lp
def NtWow64ReadVirtualMemory64(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead=None):
return NtWow64ReadVirtualMemory64.ctypes_function(hProcess, lpBaseAddress, lpBuffer, nSize, lpNumberOfBytesRead)
@NtdllProxy('NtQuerySystemInformation')
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 == STATUS_INFO_LENGTH_MISMATCH and args[1] is None:
return args
raise Kernel32Error("{0} failed with NTStatus {1)".format(func_name, hex(result)))
@NtdllProxy('NtQuerySystemInformation', ntquerysysteminformation_error_check)
def NtQuerySystemInformation(SystemInformationClass, SystemInformation=None, SystemInformationLength=0, ReturnLength=NeededParameter):
if SystemInformation is not None and SystemInformation == 0:
SystemInformationLength = ctypes.sizeof(SystemInformation)