From f47258c2b220d1d2e22106faf6f1fb73d70b75a0 Mon Sep 17 00:00:00 2001 From: ZERO-A-ONE Date: Wed, 20 Aug 2025 12:10:48 +0800 Subject: [PATCH] Fixed idaxml working in IDA 9.x --- .../IDAPro/Python/9xx/loaders/xml_loader.py | 9 ++------ .../IDAPro/Python/9xx/plugins/xml_exporter.py | 6 +----- .../IDAPro/Python/9xx/plugins/xml_importer.py | 11 ++++------ .../IDAPro/Python/9xx/python/idaxml.py | 21 ++++++++++++------- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/GhidraBuild/IDAPro/Python/9xx/loaders/xml_loader.py b/GhidraBuild/IDAPro/Python/9xx/loaders/xml_loader.py index 956e2abb32..5d2f3dd59f 100644 --- a/GhidraBuild/IDAPro/Python/9xx/loaders/xml_loader.py +++ b/GhidraBuild/IDAPro/Python/9xx/loaders/xml_loader.py @@ -31,11 +31,6 @@ import idaxml import idc import sys -if sys.version_info.major >= 3: - from idaxml import _exc_info - sys.exc_value = lambda: _exc_info()[1] - sys.exc_type = lambda: _exc_info()[0] - """ Loader functions """ @@ -96,10 +91,10 @@ def load_file(li, neflags, format): msg += "\nimporting multiple address spaces." print("\n" + msg) idc.warning(msg) - except: + except Exception as e: print("\nHouston, we have a problem!") msg = "***** Exception occurred: XML loader failed! *****" - print("\n" + msg + "\n", sys.exc_type, sys.exc_value) + print(f"\n{msg}\n{type(e).__name__}: {e}") print(event, element.tag, element.attrib) idc.warning(msg) finally: diff --git a/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py b/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py index 87d31ff163..317df68ebd 100644 --- a/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py +++ b/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py @@ -30,10 +30,6 @@ import idaxml import idc import sys -if sys.version_info.major >= 3: - from idaxml import _exc_info - sys.exc_value = lambda: _exc_info()[1] - sys.exc_type = lambda: _exc_info()[0] class XmlExporterPlugin(ida_idaapi.plugin_t): """ @@ -82,7 +78,7 @@ class XmlExporterPlugin(ida_idaapi.plugin_t): except: ida_kernwin.hide_wait_box() msg = "***** Exception occurred: XML Exporter failed! *****" - print("\n" + msg + "\n", sys.exc_type, sys.exc_value) + print(f"\n{msg}\n {type(e).__name__}: {e}") idc.warning(msg) finally: xml.cleanup() diff --git a/GhidraBuild/IDAPro/Python/9xx/plugins/xml_importer.py b/GhidraBuild/IDAPro/Python/9xx/plugins/xml_importer.py index 75da024c84..10e5958c40 100644 --- a/GhidraBuild/IDAPro/Python/9xx/plugins/xml_importer.py +++ b/GhidraBuild/IDAPro/Python/9xx/plugins/xml_importer.py @@ -24,16 +24,12 @@ The file idaxml.py must be placed in the IDA python directory. from __future__ import print_function import ida_idaapi +import ida_kernwin import ida_pro import idaxml import idc import sys -if sys.version_info.major >= 3: - from idaxml import _exc_info - sys.exc_value = lambda: _exc_info()[1] - sys.exc_type = lambda: _exc_info()[0] - class XmlImporterPlugin(ida_idaapi.plugin_t): """ XML Importer plugin class @@ -82,9 +78,10 @@ class XmlImporterPlugin(ida_idaapi.plugin_t): msg += "\nimporting multiple address spaces." print("\n" + msg) idc.warning(msg) - except: + except Exception as e: + ida_kernwin.hide_wait_box() msg = "***** Exception occurred: XML Importer failed! *****" - print("\n" + msg + "\n", sys.exc_type, sys.exc_value) + print(f"\n{msg}\n{type(e).__name__}: {e}") idc.warning(msg) finally: xml.cleanup() diff --git a/GhidraBuild/IDAPro/Python/9xx/python/idaxml.py b/GhidraBuild/IDAPro/Python/9xx/python/idaxml.py index d32fdba095..de39bff254 100644 --- a/GhidraBuild/IDAPro/Python/9xx/python/idaxml.py +++ b/GhidraBuild/IDAPro/Python/9xx/python/idaxml.py @@ -90,7 +90,8 @@ def is_ida_version_supported(): def get_struc(sid: int) -> Optional[ida_typeinf.tinfo_t]: try: - tif = ida_typeinf.tinfo_t(tid=sid) + tif = ida_typeinf.tinfo_t() + tif.get_type_by_tid(tid=sid) return tif if tif.is_udt() else None except ValueError: return None @@ -139,7 +140,8 @@ def get_struc_qty(): def get_enum_member_tid(eid: int, i: int) -> int: try: - tif = ida_typeinf.tinfo_t(tid=eid) + tif = ida_typeinf.tinfo_t() + tif.get_type_by_tid(tid=eid) except ValueError: return BADADDR edm = ida_typeinf.edm_t() @@ -152,7 +154,8 @@ def find_enum_member_serial(enum_id: int, member_value: int, member_name: str): Returns -1 on failure. """ try: - tif = ida_typeinf.tinfo_t(tid=enum_id) + tif = ida_typeinf.tinfo_t() + tif.get_type_by_tid(tid=enum_id) except ValueError: return -1 ei = ida_typeinf.enum_type_data_t() @@ -980,7 +983,9 @@ class XmlExporter(IdaXml): #if bf: # self.write_attribute(BIT_FIELD, "yes") regcmt = idc.get_enum_cmt(eid) - rptcmt = ida_typeinf.tinfo_t(tid=eid).get_type_rptcmt() + tif = ida_typeinf.tinfo_t() + tif.get_type_by_tid(tid=eid) + rptcmt = tif.get_type_rptcmt() has_children = ((idc.get_enum_size(eid) > 0) or (regcmt is not None) or (rptcmt is not None) or (ida_bytes.get_radix(eflags, 0) != 16) or @@ -2721,9 +2726,9 @@ class XmlImporter(IdaXml): if ea == BADADDR: idc.put_bookmark(addr, 0, 0, 0, slot, description) break - except Exception: + except Exception as e: msg = "** Exception occurred in import_bookmark **" - print("\n" + msg + "\n", sys.exc_type, sys.exc_value) + print(f"\n{msg}\n{type(e).__name__}: {e}") def import_cmts(self, element, sid, typ): @@ -3055,9 +3060,9 @@ class XmlImporter(IdaXml): register_vars = function.findall(REGISTER_VAR) for register_var in register_vars: self.import_register_var(register_var, func) - except Exception: + except Exception as e: msg = "** Exception occurred in import_function **" - print("\n" + msg + "\n", sys.exc_type, sys.exc_value) + print(f"\n{msg}\n{type(e).__name__}: {e}") def import_function_def(self, function_def):