diff --git a/ctypes_generation/def_parser.py b/ctypes_generation/def_parser.py index 42d4c84..0e85333 100644 --- a/ctypes_generation/def_parser.py +++ b/ctypes_generation/def_parser.py @@ -9,6 +9,8 @@ class WinDef(object): self.code = code def generate_ctypes(self): + if self.code[-1] == "L" and self.code[0].isdigit(): + self.code = self.code[:-1] return """{0} = make_flag("{0}", {1})""".format(self.name, self.code) class WinDefParser(Parser): diff --git a/ctypes_generation/definitions/defines/template.py b/ctypes_generation/definitions/defines/template.py index e9d55b2..e2a775e 100644 --- a/ctypes_generation/definitions/defines/template.py +++ b/ctypes_generation/definitions/defines/template.py @@ -1,5 +1,5 @@ import platform -from flag import make_flag +from .flag import make_flag bits = platform.architecture()[0] bitness = int(bits[:2]) diff --git a/ctypes_generation/definitions/flag.py b/ctypes_generation/definitions/flag.py index 18fb063..bbcf105 100644 --- a/ctypes_generation/definitions/flag.py +++ b/ctypes_generation/definitions/flag.py @@ -1,6 +1,6 @@ import sys -if sys.version_info.major == 3: +if sys.version_info.major >= 3: long = int diff --git a/ctypes_generation/definitions/functions/crypto_wintrust.txt b/ctypes_generation/definitions/functions/crypto_wintrust.txt index f86cfe0..c20f6c4 100644 --- a/ctypes_generation/definitions/functions/crypto_wintrust.txt +++ b/ctypes_generation/definitions/functions/crypto_wintrust.txt @@ -516,7 +516,6 @@ BOOL CryptMsgClose( HCRYPTMSG hCryptMsg ); - BOOL CryptEnumOIDFunction( DWORD dwEncodingType, LPCSTR pszFuncName, @@ -540,8 +539,4 @@ BOOL CryptGetOIDFunctionValue( BOOL CertCloseStore( HCERTSTORE hCertStore, DWORD dwFlags -); - -BOOL CryptMsgClose( - HCRYPTMSG hCryptMsg ); \ No newline at end of file diff --git a/ctypes_generation/definitions/ntstatus_template.py b/ctypes_generation/definitions/ntstatus_template.py index bb588e8..a047a41 100644 --- a/ctypes_generation/definitions/ntstatus_template.py +++ b/ctypes_generation/definitions/ntstatus_template.py @@ -1,5 +1,5 @@ import ctypes -from flag import Flag +from .flag import Flag class NtStatusException(WindowsError): ALL_STATUS = {} diff --git a/ctypes_generation/definitions/structures/template.py b/ctypes_generation/definitions/structures/template.py index 857efde..43236c2 100644 --- a/ctypes_generation/definitions/structures/template.py +++ b/ctypes_generation/definitions/structures/template.py @@ -2,7 +2,7 @@ import windows # Allow extended-struct to use windows/winproxy/... from ctypes import * from ctypes.wintypes import * -from flag import Flag, FlagMapper, FlagExatractor +from .flag import Flag, FlagMapper, FlagExatractor class EnumValue(Flag): def __new__(cls, enum_name, name, value): @@ -19,6 +19,9 @@ class EnumValue(Flag): def __getnewargs__(self, *args): return self.enum_name, self.name, int(self) +# Bypass bug https://bugs.python.org/issue29270 + +super_noissue = super class EnumType(DWORD): values = () @@ -26,16 +29,16 @@ class EnumType(DWORD): @property def value(self): - raw_value = super(EnumType, self).value + raw_value = super_noissue(EnumType, self).value return self.mapper.get(raw_value, raw_value) def __repr__(self): - raw_value = super(EnumType, self).value + raw_value = super_noissue(EnumType, self).value if raw_value in self.values: value = self.value return "<{0} {1}({2})>".format(type(self).__name__, value.name, hex(raw_value)) return "<{0}({1})>".format(type(self).__name__, hex(self.value)) # Sale: windef is hardcoded -import windef +from . import windef SZOID_MAPPER = FlagMapper(*(getattr(windef, x) for x in dir(windef) if x.startswith("szOID"))) diff --git a/ctypes_generation/definitions/winerror_template.py b/ctypes_generation/definitions/winerror_template.py index 74c626d..f41cdee 100644 --- a/ctypes_generation/definitions/winerror_template.py +++ b/ctypes_generation/definitions/winerror_template.py @@ -1,2 +1,2 @@ -from flag import make_flag, FlagMapper +from .flag import make_flag, FlagMapper diff --git a/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py b/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py index c048ace..078e43d 100644 --- a/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py +++ b/ctypes_generation/extended_structs/_LSA_UNICODE_STRING.py @@ -12,7 +12,7 @@ class _LSA_UNICODE_STRING(INITIAL_LSA_UNICODE_STRING): if getattr(self, "_target", None) is not None: #remote ctypes :D -> TRICKS OF THE YEAR raw_data = self._target.read_memory(self.Buffer, self.Length) return raw_data.decode("utf16") - size = self.Length / 2 + size = int(self.Length / 2) return (ctypes.c_wchar * size).from_address(self.Buffer)[:] @classmethod diff --git a/ctypes_generation/generate.py b/ctypes_generation/generate.py index f92f074..0b5c3e7 100644 --- a/ctypes_generation/generate.py +++ b/ctypes_generation/generate.py @@ -296,7 +296,7 @@ class CtypesGenerator(object): def emit_import_dependancies(self): for name in self.imported_name: - self.emitline("from {0} import *".format(name)) + self.emitline("from .{0} import *".format(name)) def copy_template(self): with open(self.template) as f: @@ -336,8 +336,8 @@ WINERROR_MODULE = "winerror" class DefineCtypesGenerator(CtypesGenerator): def after_emit_template(self): - self.emitline("from {0} import *".format(NTSTATUS_MODULE)) - self.emitline("from {0} import *".format(WINERROR_MODULE)) + self.emitline("from .{0} import *".format(NTSTATUS_MODULE)) + self.emitline("from .{0} import *".format(WINERROR_MODULE)) def generate_for_file(self, file): for define in file.data: @@ -626,7 +626,7 @@ class MetaFileGenerator(NoTemplatedGenerator): self.emitline(META_WALKER) for name, modname, exports in self.modules: - self.emitline("import {0} as {0}_module".format(modname)) + self.emitline("from . import {0} as {0}_module".format(modname)) self.emitline("{0}_walker = generate_walker({0}, {1}_module)".format(name, modname)) class ModuleGenerator(object):