找不到动态加载库的基地址或导出功能

问题描述

我能够检测何时使用System.loadLibrary加载库,但是Module.findBaseAddress返回null,而Module.enumerateExports不返回任何内容

这是我的代码

function processJniOnLoad(libraryName) {
    const funcSym = "JNI_OnLoad";
    const funcPtr = Module.findExportByName(libraryName,funcSym);

    const membase = Module.findBaseAddress(libraryName);
    console.log("Base address is " + membase);
    
    console.log("[+] Hooking " + funcSym + "() @ " + funcPtr + "...");

    Module.enumerateExports(libraryName,{ onMatch: function(e) { console.log("type " + e.type + " name of function = " + e.name + " " + e.address); },onComplete: function() { } });
}

function waitForLibLoading(libraryName) {
    var isLibLoaded = false;

    Interceptor.attach(Module.findExportByName(null,"android_dlopen_ext"),{
        onEnter: function (args) {
            var libraryPath = Memory.readCString(args[0]);
            if (libraryPath.includes(libraryName)) {
                console.log("[+] Loading library " + libraryPath + "...");
                isLibLoaded = true;
            }
        },onLeave: function (args) {
            if (isLibLoaded) {
                processJniOnLoad(libraryName);
                isLibLoaded = false;
            }
        }
    });
}

waitForLibLoading("library_name.so");

输出示例:

C:\just_a_path>python peton3.py
[+] Loading library /data/app/com.app_name.app-<random string>==/base.apk!/lib/arm64-v8a/library_name.so...
Base address is null
[+] Hooking JNI_OnLoad() @ null...

查看IDA中的“导出”选项卡,可以看到JNI_OnLoad已导出。

解决方法

这是因为发现JNI_OnLoad已被IDA导出时调用了JNI_OnLoad。 您可以尝试使用此方法HOOK JNI_OnLoad来分析JNI_OnLoad行为。
1.编写执行dlopen library_name.so以获得库句柄
2.使用dlsym获取JNI_OnLoad符号地址
3.使用inlinehook钩子符号地址。
4.做任何你想做的事。