首页
社区
课程
招聘
[原创] 自實現Linker加載so-Android安全:续貂
发表于: 2025-5-17 22:50 1550

[原创] 自實現Linker加載so-Android安全:续貂

2025-5-17 22:50
1550

大佬的原帖在这里:https://bbs.kanxue.com/thread-282316.htm


原函数

soinfo* Utils::get_soinfo(const char* so_name)

在我的运行环境中,从maps获取的nglinker的so_addr为NULL,无法继续。


后修改如下(代码没有优化):

long *findsobase(long *soheader, const char *soname) {
    typedef uint64_t _QWORD;

    _QWORD * result;
    long* base;
    long* soinfo;
    int  n=0;
    for (result = reinterpret_cast<uint64_t *>(*(_QWORD *) soheader);
            result; result = (_QWORD *)result[5] ){
        if(*(_QWORD *) ((int64_t) result + 408) != 0
                && strcmp(reinterpret_cast<const char *>(*(_QWORD *) ((int64_t) result + 408)), soname)==0)
        {
            base= reinterpret_cast<long *>(*(_QWORD *) ((char *) result + 16));
            long* size= reinterpret_cast<long *>(*(_QWORD *) ((char *) result + 24));
            long* load_bias= reinterpret_cast<long *>(*(_QWORD *) ((char *) result + 256));
            const char* name= reinterpret_cast<const char *>(*(_QWORD *) ((int64_t) result + 408));
            soinfo= reinterpret_cast<long *>(result);
            break;
        }
    }

    return soinfo;
}

soinfo* Utils::get_soinfo(const char* so_name) {
    char line[1024];
    int *start, *end;
    long* base;
    int n = 1;
    FILE *fp = fopen("/proc/self/maps", "r");
    while (fgets(line, sizeof(line), fp)) {
        if (strstr(line, "linker64")) {
            if (n == 1) {
                start = reinterpret_cast<int *>(strtoul(strtok(line, "-"), NULL, 16));
                end = reinterpret_cast<int *>(strtoul(strtok(NULL, " "), NULL, 16));

            } else {
                strtok(line, "-");
                end = reinterpret_cast<int *>(strtoul(strtok(NULL, " "), NULL, 16));
            }
            n++;
        }
    }
    // findsym("/system/bin/linker64", "__dl__ZL6solist");
    // objdump -t linker64 | grep solist
    int soheaderoff = 0x113980;
    long *soheader = reinterpret_cast<long *>((char *) start + soheaderoff);

    return reinterpret_cast<soinfo *>(findsobase(soheader, so_name));
}

调试通过


[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2025-5-17 22:51 被土豆花开编辑 ,原因:
收藏
免费 4
支持
分享
最新回复 (1)
雪    币: 116
活跃值: (2758)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
你的AndroidManifest.xml文件加这个属性【android:extractNativeLibs="true"】应该就能找到nglinker的地址了
2025-5-19 09:21
1
游客
登录 | 注册 方可回帖
返回