越狱检测函数 getenv("DYLD_INSERT_LIBRARIES") 不知该如何Hook

  • (IBAction)btn4:(id)sender {

    char *env = getenv(“DYLD_INSERT_LIBRARIES”);

    NSString string_content = [NSString alloc] initWithCString:(const char)env
    encoding:NSUTF8StringEncoding];

    if ([string_content isEqualToString:@"/Library/MobileSubstrate/MobileSubstrate.dylib"])
    {
    NSLog(@“已经越狱”);
    }
    else
    {
    NSLog(@“还未越狱”);

    }
    }

上面是我根据网上一些检测机器是否越狱的方法,自己写的代码,我想Hook getenv 这个API,
使得返回值不为 “/Library/MobileSubstrate/MobileSubstrate.dylib”
达到欺骗为越狱的效果 但是 HOOK getenv 这个API的 Tweak 代码不知道该怎么写

参考CydiaSubstrate的官方文档

#include <substrate.h>

char *(*old_getenv)(const char * str);

char *getenv_getenv(const char * str)
{
return old_getenv(str);
}

%ctor
{
MSHookFunction((void *)getenv,(void *)getenv_getenv, (void **)old_getenv);
}

这个是我的代码,能编译打包安装,但是其他程序加载就会退出,不知道是不是我的写法不对

MSHookFunction(&connect, &newConnect, &oldConnect); 如果我用 & 而不用 (void *) 编译不过去。

问题找到了,少了一个 &
错误 MSHookFunction((void *)getenv,(void *)getenv_getenv, (void **)old_getenv);

正确 MSHookFunction((void *)getenv,(void *)getenv_getenv, (void **)&old_getenv);

改成

MSHookFunction((void *)getenv, (void *)getenv_getenv, (void **)&old_getenv);

试试;
另外,你的getenv_getenv里NSLog一下,看看有没有输出,就知道有没有hook上了

已经HOOK上了,未越狱的机器返回值为NULL,我把值返回为NULL,就骗过去了。

哥们有联系方式么