diff --git a/ctypes_generation/definitions/functions/winfunc.txt b/ctypes_generation/definitions/functions/winfunc.txt index cbbf195..d46a30b 100644 --- a/ctypes_generation/definitions/functions/winfunc.txt +++ b/ctypes_generation/definitions/functions/winfunc.txt @@ -33,10 +33,14 @@ HANDLE WINAPI CreateFileW( +/* +Flags is directly dereferenced if non-null on windows 10 +Let's assert it's a PVOID for now on +*/ NTSTATUS WINAPI LdrLoadDll( __in_opt LPCWSTR PathToFile, - __in_opt ULONG Flags, + __in_opt PVOID Flags, _In_ PUNICODE_STRING ModuleFileName, _Out_ PHANDLE ModuleHandle ); diff --git a/ctypes_generation/definitions/ntstatus_template.py b/ctypes_generation/definitions/ntstatus_template.py index a047a41..a301cdf 100644 --- a/ctypes_generation/definitions/ntstatus_template.py +++ b/ctypes_generation/definitions/ntstatus_template.py @@ -1,6 +1,9 @@ +import sys import ctypes from .flag import Flag +is_py3 = (sys.version_info.major >= 3) + class NtStatusException(WindowsError): ALL_STATUS = {} def __init__(self , code): @@ -11,8 +14,12 @@ class NtStatusException(WindowsError): self.code = x[0] self.name = x[1] self.descr = x[2] - x = ctypes.c_long(x[0]).value, x[1], x[2] - return super(NtStatusException, self).__init__(*x) + code_as_long = ctypes.c_long(x[0]).value + if is_py3: + vals = code_as_long, x[1], x[2], code_as_long + else: + vals = code_as_long, x[1], x[2] + return super(NtStatusException, self).__init__(*vals) def __str__(self): return "{e.name}(0x{e.code:x}): {e.descr}".format(e=self) diff --git a/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py b/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py index 078e43d..a9315c9 100644 --- a/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py +++ b/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py @@ -20,6 +20,11 @@ class _LSA_UNICODE_STRING(INITIAL_LSA_UNICODE_STRING): utf16_len = len(s) * 2 return cls(utf16_len, utf16_len, ctypes.cast(PWSTR(s), PVOID)) + @classmethod + def from_size(cls, size): + buffer = ctypes.create_string_buffer(size) + return cls(size, size, ctypes.cast(buffer, PVOID)) + def __repr__(self): return """<{0} "{1}" at {2}>""".format(type(self).__name__, self.str, hex(id(self)))