From 01774be48bf278f18329aaebefc0682d68de2e2c Mon Sep 17 00:00:00 2001 From: Arnaud Diederen Date: Mon, 6 Jul 2020 09:56:31 +0200 Subject: [PATCH] Backported fixes --- out_of_tree/parsed_notifications.zip | Bin 4298622 -> 4298622 bytes pydoc_injections2.txt | 9 +++++---- pydoc_injections3.txt | 18 ++++++++++-------- pywraps/py_idaapi.py | 17 ++++++++++++++--- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/out_of_tree/parsed_notifications.zip b/out_of_tree/parsed_notifications.zip index 876b6c97f3e3ad4435171c5c987149a15735556e..ee169113a0dd2c9c7066a693d20e2a8d472125cb 100644 GIT binary patch delta 299 zcmW;HIZgrr7(n4TEH1+cBFZ8tJBlF6CYypM@CY1ZYKwm+p@Pa=n7<*^9K!-nF%1R8 z7m6>he)}KC*keBOo4>|%G5I|7`_HyAUn+VeYKZzo{h|TUpy;vaiRh{5nW!lmTB=pG zecScU-Pjh+5k>?Th~g44T;UpVB#=Z3H%KFcTihXw9P%ijh!V=E;2saC;t@5}@q`AR o@q#8=XrqHJUeQAz0}L_38{StNdmIZNjyz}Vdd_6!IUlpgKS4*3k^lez delta 297 zcmW;HxpF}P7(n3(SqRr2AqWynh(v4=Tkr%P=hi9yYetn!3NxNSW&Xx^8jqm6jm9_> z-<3{_~M-4X3s>+St~37B~V&YmSxx diff --git a/pydoc_injections2.txt b/pydoc_injections2.txt index 36e43fd..0c32577 100644 --- a/pydoc_injections2.txt +++ b/pydoc_injections2.txt @@ -16921,7 +16921,8 @@ class Hexrays_Hooks(__builtin__.object) | | func_printed(self, *args) | Function text has been generated. Plugins may modify the text in - | 'cfunc_t::sv' . + | 'cfunc_t::sv' . The text uses regular color codes (see 'lines.hpp' ) + | COLOR_ADDR is used to store pointers to ctree elements. | | func_printed(self, cfunc) -> int | @param cfunc (C++: cfunc_t *) @@ -17102,9 +17103,9 @@ class Hexrays_Hooks(__builtin__.object) | Decompiled text is ready. | | text_ready(self, vu) -> int - | @param vu: This event can be used to modify the output text (sv). The - | text uses regular color codes (see lines.hpp) COLOR_ADDR is - | used to store pointers to ctree elements (C++: vdui_t *) + | @param vu: This event can be used to modify the output text (sv). + | Obsolete. Please use hxe_func_printed instead. (C++: + | vdui_t *) | | unhook(self, *args) | unhook(self) -> bool diff --git a/pydoc_injections3.txt b/pydoc_injections3.txt index a32025e..9c86103 100644 --- a/pydoc_injections3.txt +++ b/pydoc_injections3.txt @@ -16894,7 +16894,8 @@ class Hexrays_Hooks(builtins.object) | | func_printed(self, *args) -> 'int' | Function text has been generated. Plugins may modify the text in - | 'cfunc_t::sv' . + | 'cfunc_t::sv' . The text uses regular color codes (see 'lines.hpp' ) + | COLOR_ADDR is used to store pointers to ctree elements. | | func_printed(self, cfunc) -> int | @param cfunc (C++: cfunc_t *) @@ -17075,9 +17076,9 @@ class Hexrays_Hooks(builtins.object) | Decompiled text is ready. | | text_ready(self, vu) -> int - | @param vu: This event can be used to modify the output text (sv). The - | text uses regular color codes (see lines.hpp) COLOR_ADDR is - | used to store pointers to ctree elements (C++: vdui_t *) + | @param vu: This event can be used to modify the output text (sv). + | Obsolete. Please use hxe_func_printed instead. (C++: + | vdui_t *) | | unhook(self, *args) -> 'bool' | unhook(self) -> bool @@ -17139,7 +17140,8 @@ class __cbhooks_t(Hexrays_Hooks) | | func_printed(self, *args) | Function text has been generated. Plugins may modify the text in - | 'cfunc_t::sv' . + | 'cfunc_t::sv' . The text uses regular color codes (see 'lines.hpp' ) + | COLOR_ADDR is used to store pointers to ctree elements. | | func_printed(self, cfunc) -> int | @param cfunc (C++: cfunc_t *) @@ -17215,9 +17217,9 @@ class __cbhooks_t(Hexrays_Hooks) | Decompiled text is ready. | | text_ready(self, vu) -> int - | @param vu: This event can be used to modify the output text (sv). The - | text uses regular color codes (see lines.hpp) COLOR_ADDR is - | used to store pointers to ctree elements (C++: vdui_t *) + | @param vu: This event can be used to modify the output text (sv). + | Obsolete. Please use hxe_func_printed instead. (C++: + | vdui_t *) | | ---------------------------------------------------------------------- | Data and other attributes defined here: diff --git a/pywraps/py_idaapi.py b/pywraps/py_idaapi.py index 01d371e..5fd26ee 100644 --- a/pywraps/py_idaapi.py +++ b/pywraps/py_idaapi.py @@ -466,9 +466,20 @@ def IDAPython_ExecScript(script, g, print_error=True): g[FILE_ATTR] = script try: - with open(script) as fin: - code = compile(fin.read(), script, 'exec') - exec(code, g) + with open(script, "rb") as fin: + raw = fin.read() + encoding = "UTF-8" # UTF-8 by default: https://www.python.org/dev/peps/pep-3120/ + + # Look for a 'coding' comment + encoding_pat = re.compile(r'\s*#.*coding[:=]\s*([-\w.]+).*') + for line in raw.decode("ASCII", errors='replace').split("\n"): + match = encoding_pat.match(line) + if match: + encoding = match.group(1) + break + + code = compile(raw.decode(encoding), script, 'exec') + exec(code, g) PY_COMPILE_ERR = None except Exception as e: PY_COMPILE_ERR = "%s\n%s" % (str(e), traceback.format_exc())