在某论坛下了个IDA,打开报错No module name “imp”,这是由于高版本python已经移除了imp,新版使用import importlib。
1、打开文件D:\IDA_Pro_7.7\python\3\ida_idaapi.py
2、替换import imp 为 import importlib。
3、替换IDAPython_LoadProcMod函数代码:
def IDAPython_LoadProcMod(path, g, print_error=True):r"""Load processor module."""path = _utf8_native(path)pname = g['__name__'] if g and "__name__" in g else '__main__'parent = sys.modules[pname]path_dir, path_fname = os.path.split(path)procmod_name = os.path.splitext(path_fname)[0]procobj = Nonefp = Nonetry:# fp, pathname, description = imp.find_module(procmod_name, [path_dir])# procmod = imp.load_module(procmod_name, fp, pathname, description)module_spec = importlib.util.spec_from_file_location(procmod_name, os.path.join(path_dir, procmod_name + ".py"))if module_spec is None:raise ImportError(f"Module {procmod_name} could not be found in {path_dir}")procmod = importlib.util.module_from_spec(module_spec)module_spec.loader.exec_module(procmod)sys.modules[procmod_name] = procmodif parent:setattr(parent, procmod_name, procmod)# export attrs from parent to processor moduleparent_attrs = getattr(parent, '__all__',(attr for attr in dir(parent) if not attr.startswith('_')))for pa in parent_attrs:setattr(procmod, pa, getattr(parent, pa))# instantiate processor objectif getattr(procmod, 'PROCESSOR_ENTRY', None):procobj = procmod.PROCESSOR_ENTRY()PY_COMPILE_ERR = Noneexcept Exception as e:PY_COMPILE_ERR = "%s\n%s" % (str(e), traceback.format_exc())if print_error:print(PY_COMPILE_ERR)finally:if fp:fp.close()return (PY_COMPILE_ERR, procobj)