From 1840ce8bff3a93551535b57d590846ce46d89bf7 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 11 Feb 2025 14:47:50 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20support=20for=20IDA=20=E2=89=A5=209.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `get_inf_structure` was removed in IDA 9.0: https://docs.hex-rays.com/developer-guide/idapython/idapython-porting-guide-ida-9#removed-functions-9 --- idaref.py | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/idaref.py b/idaref.py index fb15649..1f305e7 100755 --- a/idaref.py +++ b/idaref.py @@ -78,7 +78,7 @@ def __init__(self, owner): self.loadArchitecture(self.getIdaArchitecture()) def create(self): - if find_widget(self.title) == None: + if find_widget(self.title) is None: if not idaapi.simplecustviewer_t.Create(self, self.title): print("Unable to open") return False @@ -163,18 +163,16 @@ def finish_populating_widget_popup(self, widget, popup): self.Show() - def update(): - if self.destroying == True: + def timer_callback(): + if self.destroying: return -1 else: if self.do_auto: self.update() - return 200 if "register_timer" in dir(idaapi): - idaapi.register_timer(200, update) - + idaapi.register_timer(200, timer_callback) self.is_loaded = True else: print("Sorry I can't support auto-refresh in your version of IDA.") @@ -197,7 +195,7 @@ def findManuals(self): if len(doc_opts) == 0: Warning("Couldn't find any databases in " + search_path) - return + return [] available = [] @@ -208,13 +206,15 @@ def findManuals(self): return available def askArchitecture(self, availList): + if not availList: + print("No available architectures found. Defaulting to x86-64.") + return "x86-64" prompt = ["What platform do you want to use?"] i = 1 for arch in availList: prompt.append("%d - %s" % (i, arch)) - i = i + 1 - + i += 1 sel = ask_long(1, "\n".join(prompt)) if sel is None: @@ -272,9 +272,11 @@ def loadArchitecture(self, name): return True def getIdaArchitecture(self): - inf = idaapi.get_inf_structure() - - return inf.procName + try: + return idaapi.inf_get_procname() + except AttributeError: + # Fallback for IDA < 9.0 + return idaapi.get_inf_structure().procName def OnClose(self): self.destroying = True @@ -306,14 +308,12 @@ def cleanInstruction(self, inst): def update(self, force=False): inst = self.cleanInstruction(print_insn_mnem(get_screen_ea())) - - if inst != self.last_inst or force == True: + if inst != self.last_inst or force: self.load_inst(inst) def load_inst(self, inst, wasLookup=False): inst = self.cleanInstruction(inst) - - if wasLookup == False: + if not wasLookup: self.last_inst = inst self.ClearLines() @@ -323,8 +323,7 @@ def load_inst(self, inst, wasLookup=False): if inst in self.inst_map: text = self.inst_map[inst] - - if len(text) > 0: + if text: self.AddLine(inst + ": " + text[0]) if len(text) > 1: for line in text[1:]: @@ -341,14 +340,13 @@ def OnPopupMenu(self, menu_id): self.update(True) elif menu_id == self.menu_lookup: inst = ask_str(self.last_inst, 0, "Instruction: ") - if inst != None: + if inst is not None: self.load_inst(inst, True) elif menu_id == self.menu_autorefresh: self.do_auto = not self.do_auto elif menu_id == self.change_arch: arch = self.askArchitecture(self.archs) - - if arch != None: + if arch is not None: self.loadArchitecture(arch) self.update(True) else: @@ -423,7 +421,7 @@ def _add_menus(self): def init(self): global initialized ret = idaapi.PLUGIN_SKIP - if initialized == False: + if not initialized: initialized = True self.ctxs = [] insref_g = None @@ -435,11 +433,9 @@ def init(self): def start(self, *args): global insref_g idaapi.msg("Starting IdaRef\n") - - if insref_g != None and find_widget(insref_g.title) == None: + if insref_g is not None and find_widget(insref_g.title) is None: self.stop() - - if insref_g == None: + if insref_g is None: insref_g = InstructionReference(self) else: print("IdaRef Already started") @@ -447,8 +443,7 @@ def start(self, *args): def stop(self, *args): global insref_g idaapi.msg("Stopping IdaRef\n") - - if insref_g != None: + if insref_g is not None: insref_g.destroy() insref_g = None else: