7.3节Frida中main.py源码enumerate_modules无法找到

在执行书上【7.3Frida实战应用】的 main.py文件时,执行到 main()方法第四步:“4.枚举某个进程加载的模块信息”,出现错误,错误代码:
“File “/Users/zh/Documents/frida-learn-python27/ios/main.py”, line 99, in listModulesoOfProcess moduels = session.enumerate_modules()
AttributeError: ‘Session’ object has no attribute ‘enumerate_modules’”。

其他1到5步,执行都没问题。环境是python2.7,使用的工具是pycharm。Mac上frida版本是12.6.18

请教如何解决,如何能枚举枚举某个进程加载的模块信息?

Convenience APIs in bindings

Something that seemed like a great idea at the time was having our language bindings provide some convenience APIs on the Session object. The thinking was that simple use-cases that only need to enumerate loaded modules and perhaps a few memory ranges, to then read or write memory, wouldn’t have to load their own agent. So both our Python and our Node.js bindings did this behind the scenes for you.

Back then it was somewhat tedious to communicate with an agent as the rpc API didn’t exist, but even so, it was a bad design decision. The JS APIs are numerous and not all can be exposed without introducing new layers of complexity. Another aspect is that every language binding would have to duplicate such convenience APIs, or we would have to add core APIs that bindings could expose. Both are terrible options, and cause confusion by blurring the lines, ultimately confusing people new to Frida. Granted, it did make things easier for some very simple use-cases, like memory dumping tools, but for everybody else it just added bloat and confusion.

These APIs are now finally gone from our Python and Node.js bindings. The other bindings are unaffected as they didn’t implement any such convenience APIs.

简单翻译就是 frida 12 之后移除了 python 库 session 相关的 api。你需要在 js 里调用 Process.enumerateModules()

感谢 ChiChou 提供思路,下面代码可以打印出所有modules:

    var modules = Process.enumerateModules();
    for(var i = i; i < modules.length; i++ ) {
        console.log(JSON.stringify(modules[i]));
    }