mirror of
https://github.com/hakril/PythonForWindows
synced 2026-06-08 14:31:45 +00:00
ctypes_generation now generate py3.6 compatible code :)
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import platform
|
||||
from flag import make_flag
|
||||
from .flag import make_flag
|
||||
|
||||
bits = platform.architecture()[0]
|
||||
bitness = int(bits[:2])
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import sys
|
||||
|
||||
if sys.version_info.major == 3:
|
||||
if sys.version_info.major >= 3:
|
||||
long = int
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
);
|
||||
@@ -1,5 +1,5 @@
|
||||
import ctypes
|
||||
from flag import Flag
|
||||
from .flag import Flag
|
||||
|
||||
class NtStatusException(WindowsError):
|
||||
ALL_STATUS = {}
|
||||
|
||||
@@ -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")))
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
from flag import make_flag, FlagMapper
|
||||
from .flag import make_flag, FlagMapper
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user