吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 509|回复: 2
收起左侧

[讨论] Mac上注入程序修改原程序符号变量的初始值

[复制链接]
doorxp 发表于 2023-7-24 16:36
本帖最后由 doorxp 于 2023-7-24 16:47 编辑

Mac上注入程序修改原程序符号变量的初始值
直接上代码:
[C] 纯文本查看 复制代码
void *findSymbol(const char *symname, const struct mach_header_64 *mhp) {
    uint8_t *root = (uint8_t*)mhp;
    bool is64 = (mhp->cputype & CPU_ARCH_ABI64) == CPU_ARCH_ABI64;
    uint8_t *ptr = root + (is64 ? sizeof(struct mach_header_64) : sizeof(struct mach_header));

    void *ret = NULL;
    struct load_command *cmd = (struct load_command*)(ptr);
    struct load_command *end = (struct load_command*)((const uint8_t*)cmd + mhp->sizeofcmds);
       for (; cmd < end; cmd = (void *)((const uint8_t*)cmd + cmd->cmdsize)) {
       if (cmd->cmd == LC_SYMTAB) {
           struct symtab_command *stab = (struct symtab_command*)(cmd);
           struct nlist_64 *syms = (struct nlist_64*)((uintptr_t)root + stab->symoff);
           char *strs = (char*)((uintptr_t)root + stab->stroff);
            size_t n;
            for (n = 0; n < stab->nsyms; n++) {
               const char *name = &strs[syms[n].n_un.n_strx + 1];
               if(strcmp(symname, name) == 0) {
                   const uint64_t value = syms[n].n_value;
                   ret = (uint64_t *)(root + value);
               }
            }
       }
   }
   return ret;
}


举个例子:
[C] 纯文本查看 复制代码
//通过MbuInAutomatedQTestMode找到要修改的 lib
void *sym = dlsym(RTLD_DEFAULT,"MbuInAutomatedQTestMode");
if(sym == NULL) {return;}
Dl_info info;    NSLog(@"hook");
dladdr(sym, &info);
//找到的 lib 的起始地址:info.dli_fbase
//lib 中有个 _fRunningQtest 变量; 修改初始变量为 0x0;
int32_t *q = findSymbol("_fRunningQtest", info.dli_fbase);
if(q != NULL) {        *q = 0x0;    }
//lib 中有个 _fRunningAutomation 变量; 修改初始变量为 0x1;
int32_t *a = findSymbol("_fRunningAutomation", info.dli_fbase);
if(a != NULL) { *a = 0x1;  }

免费评分

参与人数 1热心值 +1 收起 理由
Indifference + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Indifference 发表于 2023-7-24 17:39
学习一下

免费评分

参与人数 1吾爱币 -8 收起 理由
RS水果 -8 本版块禁止灌水或回复与主题无关内容,违者重罚!

查看全部评分

kakazwh 发表于 2023-7-24 17:57
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 23:05

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表