From f47258c2b220d1d2e22106faf6f1fb73d70b75a0 Mon Sep 17 00:00:00 2001 From: ZERO-A-ONE Date: Wed, 20 Aug 2025 12:10:48 +0800 Subject: [PATCH 1/4] 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): From 2484d2b548e2a3219add805d8be367f1124ae0ac Mon Sep 17 00:00:00 2001 From: ZERO-A-ONE Date: Wed, 20 Aug 2025 22:47:57 +0800 Subject: [PATCH 2/4] Update xml_exporter.py --- GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py b/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py index 317df68ebd..ced9bd968c 100644 --- a/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py +++ b/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py @@ -75,7 +75,7 @@ class XmlExporterPlugin(ida_idaapi.plugin_t): msg = "XML Export cancelled!" print("\n" + msg) idc.warning(msg) - except: + except Exception as e: ida_kernwin.hide_wait_box() msg = "***** Exception occurred: XML Exporter failed! *****" print(f"\n{msg}\n {type(e).__name__}: {e}") From a312aaabb1ed236f8ec21169c41b29c5e4e146ed Mon Sep 17 00:00:00 2001 From: ZERO-A-ONE Date: Wed, 20 Aug 2025 23:05:20 +0800 Subject: [PATCH 3/4] Update idaxml.py --- GhidraBuild/IDAPro/Python/9xx/python/idaxml.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/GhidraBuild/IDAPro/Python/9xx/python/idaxml.py b/GhidraBuild/IDAPro/Python/9xx/python/idaxml.py index de39bff254..5fe9e3e011 100644 --- a/GhidraBuild/IDAPro/Python/9xx/python/idaxml.py +++ b/GhidraBuild/IDAPro/Python/9xx/python/idaxml.py @@ -2206,6 +2206,9 @@ class XmlExporter(IdaXml): signedhex: Boolean indicating if hex representation of value is signed. """ + # Check if value is None and handle it gracefully + if value is None: + return if base == 10: temp = "%d" % value else: From 4bcb650313736a1484262f84ffa42b14dc690dce Mon Sep 17 00:00:00 2001 From: Ryan Kurtz Date: Thu, 21 Aug 2025 06:07:03 -0400 Subject: [PATCH 4/4] GP-5873: Certify --- .../IDAPro/Python/9xx/loaders/xml_loader.py | 26 +++++++++---------- .../IDAPro/Python/9xx/plugins/xml_exporter.py | 26 +++++++++---------- .../IDAPro/Python/9xx/plugins/xml_importer.py | 26 +++++++++---------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/GhidraBuild/IDAPro/Python/9xx/loaders/xml_loader.py b/GhidraBuild/IDAPro/Python/9xx/loaders/xml_loader.py index 5d2f3dd59f..d2676f4f82 100644 --- a/GhidraBuild/IDAPro/Python/9xx/loaders/xml_loader.py +++ b/GhidraBuild/IDAPro/Python/9xx/loaders/xml_loader.py @@ -1,17 +1,17 @@ ## ### -# IP: GHIDRA -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. ## #--------------------------------------------------------------------- # xmlldr.py - IDA XML loader diff --git a/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py b/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py index ced9bd968c..6c1dc4deec 100644 --- a/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py +++ b/GhidraBuild/IDAPro/Python/9xx/plugins/xml_exporter.py @@ -1,17 +1,17 @@ ## ### -# IP: GHIDRA -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. ## #--------------------------------------------------------------------- # xmlexp.py - IDA XML Exporter plugin diff --git a/GhidraBuild/IDAPro/Python/9xx/plugins/xml_importer.py b/GhidraBuild/IDAPro/Python/9xx/plugins/xml_importer.py index 10e5958c40..09ab053fc3 100644 --- a/GhidraBuild/IDAPro/Python/9xx/plugins/xml_importer.py +++ b/GhidraBuild/IDAPro/Python/9xx/plugins/xml_importer.py @@ -1,17 +1,17 @@ ## ### -# IP: GHIDRA -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# IP: GHIDRA +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. ## #--------------------------------------------------------------------- # xmlimp.py - IDA XML Importer plugin