首页
社区
课程
招聘
[原创]关于 idaapi.require 不能重新 reload 整个 Package 的解决办法
发表于: 2024-8-2 18:28 1845

[原创]关于 idaapi.require 不能重新 reload 整个 Package 的解决办法

2024-8-2 18:28
1845

今天看了下 require 函数,发现并没有直接重新加载 Package 下所有的 module,稍微改了下,配合 qscript 无缝衔接。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import importlib
import inspect
import sys
 
import idaapi
 
 
def require ( modulename, package = None ):
    frame_obj, filename, line_number, function_name, lines, index = inspect.stack () [ 1 ]
    importer_module = inspect.getmodule ( frame_obj )
    if importer_module is None:
        importer_module = sys.modules [ '__main__' ]
 
    if modulename in sys.modules:
        del sys.modules [ modulename ]
 
    modules_to_reload = [ modulename ]
    for name, module in list ( sys.modules.items () ):
        if name.startswith ( modulename + "." ):
            modules_to_reload.append ( name )
            del sys.modules [ name ]
 
    m = importlib.import_module ( modulename, package )
    setattr ( importer_module, modulename, m )
    for mod_name in modules_to_reload:
        importlib.import_module ( mod_name, package )
 
    return m
 
class Plugin ( idaapi.plugin_t ):
    flags = idaapi.PLUGIN_FIX
    comment = ""
    help = ""
    wanted_name = ""
    wanted_hotkey = ""
 
    def init ( self ):
        return idaapi.PLUGIN_OK
 
    def run ( self, arg ):
        self.term ()
        require ( 'You Pakcage Name' )
        self.init ()
        asg.test ()
        return 0
 
    def term ( self ):
        pass
 
 
def PLUGIN_ENTRY ():
    return Plugin ()
最后于 2024-8-2 19:04 被天下有敌编辑 ,原因:
收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 10
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
2
没懂,这个是干啥用的,先收藏了,方便以后学习
2024-8-2 18:56
0
游客
登录 | 注册 方可回帖
返回
//