diff --git a/examples/pyqt/paint_over_navbar.py b/examples/pyqt/paint_over_navbar.py index 938f22e..1bca746 100644 --- a/examples/pyqt/paint_over_navbar.py +++ b/examples/pyqt/paint_over_navbar.py @@ -57,8 +57,8 @@ class painter_t(QtCore.QObject): painter.setRenderHints(QtGui.QPainter.Antialiasing) pxl, is_vertical = ida_kernwin.get_navband_pixel(ea) if pxl >= 0: - x = (self.target.width() / 2) if is_vertical else pxl - y = pxl if is_vertical else (self.target.height() / 2) + x = (self.target.width() // 2) if is_vertical else pxl + y = pxl if is_vertical else (self.target.height() // 2) painter.setPen(color) painter.setBrush(color) painter.drawEllipse(QtCore.QPoint(x, y), radius, radius) diff --git a/idapython.script b/idapython.script index fc2848f..1b587d8 100644 --- a/idapython.script +++ b/idapython.script @@ -15,6 +15,7 @@ global: PyW_ShowCbErr; PyW_SizeVecToPyList; PyW_UvalVecToPyList; + PyW_StrVecToPyList; PyW_TryGetAttrString; PyW_TryImportModule; PyW_register_compiled_form; diff --git a/idapython_implib.def b/idapython_implib.def index d273f0c..223fa81 100644 --- a/idapython_implib.def +++ b/idapython_implib.def @@ -6,6 +6,7 @@ EXPORTS PyW_GetStringAttr PyW_SizeVecToPyList PyW_UvalVecToPyList + PyW_StrVecToPyList PyW_IsSequenceType PyW_ObjectToString PyW_PyListToEaVec diff --git a/out_of_tree/parsed_notifications.zip b/out_of_tree/parsed_notifications.zip index e9d8a23..6e54678 100644 Binary files a/out_of_tree/parsed_notifications.zip and b/out_of_tree/parsed_notifications.zip differ diff --git a/python/init.py b/python/init.py index 976b9f9..384010b 100644 --- a/python/init.py +++ b/python/init.py @@ -16,6 +16,20 @@ import os import sys import time import warnings +import os +import os.path + +if os.name == 'nt' and \ + sys.version_info.major == 3 and \ + sys.version_info.minor >= 11: + # Python 3.11 has a bug with DLLs directory missing from sys.path + # so add it if it's not there + base = sys.base_exec_prefix + dllspath = os.path.join(base, sys.platlibdir) + if os.path.exists(dllspath) and dllspath not in sys.path: + i = sys.path.index(base) if base in sys.path else len(sys.path) + sys.path.insert(i, dllspath) + # Prepare sys.path so loading of the shared objects works lib_dynload = os.path.join( @@ -107,10 +121,20 @@ sys.stdout = sys.stderr = IDAPythonStdOut() # Initialize the help, with our own stdin wrapper, that'll query the user # ----------------------------------------------------------------------- import pydoc -class IDAPythonHelpPrompter: +class IDAPythonHelpPrompter(object): def readline(self): return ida_kernwin.ask_str('', 0, 'Help topic?') -help = pydoc.Helper(input = IDAPythonHelpPrompter(), output = sys.stdout) + +class IDAPythonHelp(pydoc.Helper): + def __init__(self): + super().__init__(input = IDAPythonHelpPrompter(), output = sys.stdout) + def help(self, *args): + try: + return super().help(*args) + except ImportError as e: + print(e) + +help = IDAPythonHelp() # Assign a default sys.argv sys.argv = [""] diff --git a/pywraps.cpp b/pywraps.cpp index 2e3af77..5c8b645 100644 --- a/pywraps.cpp +++ b/pywraps.cpp @@ -100,6 +100,18 @@ ref_t ida_export PyW_UvalVecToPyList(const uvalvec_t &vec) return ref_t(py_list); } +//------------------------------------------------------------------------- +ref_t ida_export PyW_StrVecToPyList(const qstrvec_t &vec) +{ + size_t n = vec.size(); + PYW_GIL_CHECK_LOCKED_SCOPE(); + newref_t py_list(PyList_New(n)); + for ( size_t i = 0; i < n; ++i ) + PyList_SetItem(py_list.o, i, PyUnicode_from_qstring(vec[i])); + return ref_t(py_list); + +} + //------------------------------------------------------------------------- static Py_ssize_t pyvar_walk_list( const ref_t &py_list, diff --git a/pywraps.hpp b/pywraps.hpp index e07be82..caa8f60 100644 --- a/pywraps.hpp +++ b/pywraps.hpp @@ -489,6 +489,7 @@ idaman Py_ssize_t ida_export pyvar_walk_list( // Converts a vector to a Python list object idaman ref_t ida_export PyW_SizeVecToPyList(const sizevec_t &vec); idaman ref_t ida_export PyW_UvalVecToPyList(const uvalvec_t &vec); +idaman ref_t ida_export PyW_StrVecToPyList(const qstrvec_t &vec); // Converts a Python list, to a vector of the given type. // An exception will be raised in case: diff --git a/pywraps/py_kernwin_choose.py b/pywraps/py_kernwin_choose.py index fdc9a25..3ba0069 100644 --- a/pywraps/py_kernwin_choose.py +++ b/pywraps/py_kernwin_choose.py @@ -103,6 +103,18 @@ class Choose(object): ALL_CHANGED = 1 SELECTION_CHANGED = 2 + # to construct `forbidden_cb` + CHOOSE_HAVE_INIT = 0x0001 + CHOOSE_HAVE_GETICON = 0x0002 + CHOOSE_HAVE_GETATTR = 0x0004 + CHOOSE_HAVE_INS = 0x0008 + CHOOSE_HAVE_DEL = 0x0010 + CHOOSE_HAVE_EDIT = 0x0020 + CHOOSE_HAVE_ENTER = 0x0040 + CHOOSE_HAVE_REFRESH = 0x0080 + CHOOSE_HAVE_SELECT = 0x0100 + CHOOSE_HAVE_ONCLOSE = 0x0200 + class UI_Hooks_Trampoline(UI_Hooks): def __init__(self, v): UI_Hooks.__init__(self) diff --git a/pywraps/py_registry.hpp b/pywraps/py_registry.hpp index 86dffa5..0a35d15 100644 --- a/pywraps/py_registry.hpp +++ b/pywraps/py_registry.hpp @@ -7,21 +7,15 @@ static PyObject *_py_reg_subkey_children(const char *name, bool subkeys) { PYW_GIL_CHECK_LOCKED_SCOPE(); - PyObject *result = nullptr; qstrvec_t children; SWIG_PYTHON_THREAD_BEGIN_ALLOW; - if ( reg_subkey_children(&children, name, subkeys) ) - { - result = PyList_New(children.size()); - if ( result != nullptr ) - for ( size_t i = 0, n = children.size(); i < n; ++i ) - PyList_SET_ITEM(result, i, PyUnicode_FromString(children[i].c_str())); - } + bool ok = reg_subkey_children(&children, name, subkeys); SWIG_PYTHON_THREAD_END_ALLOW; - if ( result == nullptr ) + if ( !ok ) Py_RETURN_NONE; - else - return result; + ref_t result = PyW_StrVecToPyList(children); + result.incref(); + return result.o; } //