def activate(self, ctx): """ exec script to pop up python editor window """ g = globals() idaapi.IDAPython_ExecScript( os.path.join(file_dir, "xrk_pyeditor\\pyeditor.py"), g)
def monkey_patch_IDAPython_ExecScript(): """ This funtion wraps IDAPython_ExecScript to avoid having an empty string has a __file__ attribute of a module. See https://github.com/idapython/src/pull/23 """ # Test the behavior IDAPython_ExecScript see if it needs patching import sys, os fake_globals = {} idaapi.IDAPython_ExecScript(os.devnull, fake_globals, False) if "__file__" in fake_globals: # Monkey patch IDAPython_ExecScript original_IDAPython_ExecScript = idaapi.IDAPython_ExecScript def IDAPython_ExecScript_wrap(script, g, print_error=True): has_file = "__file__" in g try: original_IDAPython_ExecScript(script, g, print_error) finally: if not has_file and "__file__" in g: del g["__file__"] idaapi.IDAPython_ExecScript = IDAPython_ExecScript_wrap try: # Remove the empty strings on existing modules for mod_name in sys.modules: if hasattr(sys.modules[mod_name], "__file__") and \ bool(sys.modules[mod_name].__file__) is False: del sys.modules[mod_name].__file__ except RuntimeError: # Best effort here, let's not crash if something goes wrong pass
def load_script(self, bap, ea): idc.SetStatus(idc.IDA_STATUS_WORK) idaapi.IDAPython_ExecScript(bap.script.name, globals()) self._do_callbacks(ea) idc.Refresh() # do we really need to call this? idaapi.refresh_idaview_anyway() idc.SetStatus(idc.IDA_STATUS_READY)
def activate(self, ctx): """ execute script """ if not os.path.exists(self.py_script_path): warn("python script file not exists: %s" % self.py_script_path) else: g = globals() idaapi.IDAPython_ExecScript(self.py_script_path, g)
def runscript(script): """ Executes a script. This function is present for backward compatiblity. Please use idaapi.IDAPython_ExecScript() instead @param script: script path @return: Error string or None on success """ import idaapi return idaapi.IDAPython_ExecScript(script, globals())
def on_message(self, message): message = json.loads(message.decode("utf8")) if message["event"] == "set_workspace": path = message["path"] hooks.set_script_folder(path) print(f"[IDACode] Set workspace folder to {path}") elif message["event"] == "attach_debugger": start_debug_server() self.write_message({"event": "debugger_ready"}) elif message["event"] == "execute_script": script = message["path"] env = create_env() print(f"[IDACode] Executing {script}") idaapi.execute_sync( lambda: idaapi.IDAPython_ExecScript(script, env), idaapi.MFF_WRITE) else: print(f"[IDACode] Invalid event {message['event']}")
def rizzo_script(self): idaapi.IDAPython_ExecScript(self.script, globals())
help = pydoc.Helper(input=IDAPythonHelpPrompter(), output=sys.stdout) # Assign a default sys.argv sys.argv = [""] # Have to make sure Python finds our modules sys.path.append(_idaapi.idadir("python")) # Remove current directory from the top of the patch search if '' in sys.path: # On non Windows, the empty path is added sys.path.remove('') if os.getcwd() in sys.path: sys.path.remove(os.getcwd()) # ...and add it to the end if needed if not IDAPYTHON_REMOVE_CWD_SYS_PATH: sys.path.append(os.getcwd()) # Import all the required modules from idaapi import Choose, get_user_idadir, cvar, Choose2, Appcall, Form from idc import * from idautils import * import idaapi # Load the users personal init file userrc = os.path.join(get_user_idadir(), "idapythonrc.py") if os.path.exists(userrc): idaapi.IDAPython_ExecScript(userrc, globals()) # All done, ready to rock.
def activate(self, ctx): g = globals() idahome = os.path.join(ROOT_DIR, "Code editor") idaapi.IDAPython_ExecScript(os.path.join(idahome, "pyeditor.py"), g)
def finish(self, bap): idaapi.IDAPython_ExecScript(bap.script.name, globals()) idaapi.refresh_idaview_anyway() BapTaint._do_callbacks(self.kind) idc.Refresh()
def activate(self, ctx): g = globals() idahome = idaapi.idadir("python\\RECLASSIFY") idaapi.IDAPython_ExecScript(idahome + "\\analyzerWithRtti.py", g)
def activate(self, ctx): g = globals() script = os.path.join(idaapi.idadir("plugins"), "diaphora", "diaphora.py") idaapi.IDAPython_ExecScript(script, g)