Merge branch 'GP-5873_ryanmkurtz_PR-8450_ZERO-A-ONE_ida9' (Closes #8450)

This commit is contained in:
Ryan Kurtz 2025-08-21 06:08:09 -04:00
commit 09e625f5fe
4 changed files with 63 additions and 67 deletions

View file

@ -1,17 +1,17 @@
## ### ## ###
# IP: GHIDRA # IP: GHIDRA
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
## ##
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# xmlldr.py - IDA XML loader # xmlldr.py - IDA XML loader
@ -31,11 +31,6 @@ import idaxml
import idc import idc
import sys 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 Loader functions
""" """
@ -96,10 +91,10 @@ def load_file(li, neflags, format):
msg += "\nimporting multiple address spaces." msg += "\nimporting multiple address spaces."
print("\n" + msg) print("\n" + msg)
idc.warning(msg) idc.warning(msg)
except: except Exception as e:
print("\nHouston, we have a problem!") print("\nHouston, we have a problem!")
msg = "***** Exception occurred: XML loader failed! *****" 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) print(event, element.tag, element.attrib)
idc.warning(msg) idc.warning(msg)
finally: finally:

View file

@ -1,17 +1,17 @@
## ### ## ###
# IP: GHIDRA # IP: GHIDRA
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
## ##
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# xmlexp.py - IDA XML Exporter plugin # xmlexp.py - IDA XML Exporter plugin
@ -30,10 +30,6 @@ import idaxml
import idc import idc
import sys 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): class XmlExporterPlugin(ida_idaapi.plugin_t):
""" """
@ -79,10 +75,10 @@ class XmlExporterPlugin(ida_idaapi.plugin_t):
msg = "XML Export cancelled!" msg = "XML Export cancelled!"
print("\n" + msg) print("\n" + msg)
idc.warning(msg) idc.warning(msg)
except: except Exception as e:
ida_kernwin.hide_wait_box() ida_kernwin.hide_wait_box()
msg = "***** Exception occurred: XML Exporter failed! *****" 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) idc.warning(msg)
finally: finally:
xml.cleanup() xml.cleanup()

View file

@ -1,17 +1,17 @@
## ### ## ###
# IP: GHIDRA # IP: GHIDRA
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
## ##
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# xmlimp.py - IDA XML Importer plugin # xmlimp.py - IDA XML Importer plugin
@ -24,16 +24,12 @@ The file idaxml.py must be placed in the IDA python directory.
from __future__ import print_function from __future__ import print_function
import ida_idaapi import ida_idaapi
import ida_kernwin
import ida_pro import ida_pro
import idaxml import idaxml
import idc import idc
import sys 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): class XmlImporterPlugin(ida_idaapi.plugin_t):
""" """
XML Importer plugin class XML Importer plugin class
@ -82,9 +78,10 @@ class XmlImporterPlugin(ida_idaapi.plugin_t):
msg += "\nimporting multiple address spaces." msg += "\nimporting multiple address spaces."
print("\n" + msg) print("\n" + msg)
idc.warning(msg) idc.warning(msg)
except: except Exception as e:
ida_kernwin.hide_wait_box()
msg = "***** Exception occurred: XML Importer failed! *****" 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) idc.warning(msg)
finally: finally:
xml.cleanup() xml.cleanup()

View file

@ -90,7 +90,8 @@ def is_ida_version_supported():
def get_struc(sid: int) -> Optional[ida_typeinf.tinfo_t]: def get_struc(sid: int) -> Optional[ida_typeinf.tinfo_t]:
try: 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 return tif if tif.is_udt() else None
except ValueError: except ValueError:
return None return None
@ -139,7 +140,8 @@ def get_struc_qty():
def get_enum_member_tid(eid: int, i: int) -> int: def get_enum_member_tid(eid: int, i: int) -> int:
try: try:
tif = ida_typeinf.tinfo_t(tid=eid) tif = ida_typeinf.tinfo_t()
tif.get_type_by_tid(tid=eid)
except ValueError: except ValueError:
return BADADDR return BADADDR
edm = ida_typeinf.edm_t() 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. Returns -1 on failure.
""" """
try: try:
tif = ida_typeinf.tinfo_t(tid=enum_id) tif = ida_typeinf.tinfo_t()
tif.get_type_by_tid(tid=enum_id)
except ValueError: except ValueError:
return -1 return -1
ei = ida_typeinf.enum_type_data_t() ei = ida_typeinf.enum_type_data_t()
@ -980,7 +983,9 @@ class XmlExporter(IdaXml):
#if bf: #if bf:
# self.write_attribute(BIT_FIELD, "yes") # self.write_attribute(BIT_FIELD, "yes")
regcmt = idc.get_enum_cmt(eid) 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 has_children = ((idc.get_enum_size(eid) > 0) or
(regcmt is not None) or (rptcmt is not None) or (regcmt is not None) or (rptcmt is not None) or
(ida_bytes.get_radix(eflags, 0) != 16) or (ida_bytes.get_radix(eflags, 0) != 16) or
@ -2201,6 +2206,9 @@ class XmlExporter(IdaXml):
signedhex: Boolean indicating if hex representation of signedhex: Boolean indicating if hex representation of
value is signed. value is signed.
""" """
# Check if value is None and handle it gracefully
if value is None:
return
if base == 10: if base == 10:
temp = "%d" % value temp = "%d" % value
else: else:
@ -2721,9 +2729,9 @@ class XmlImporter(IdaXml):
if ea == BADADDR: if ea == BADADDR:
idc.put_bookmark(addr, 0, 0, 0, slot, description) idc.put_bookmark(addr, 0, 0, 0, slot, description)
break break
except Exception: except Exception as e:
msg = "** Exception occurred in import_bookmark **" 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): def import_cmts(self, element, sid, typ):
@ -3055,9 +3063,9 @@ class XmlImporter(IdaXml):
register_vars = function.findall(REGISTER_VAR) register_vars = function.findall(REGISTER_VAR)
for register_var in register_vars: for register_var in register_vars:
self.import_register_var(register_var, func) self.import_register_var(register_var, func)
except Exception: except Exception as e:
msg = "** Exception occurred in import_function **" 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): def import_function_def(self, function_def):