QQ的尾巴

Meirtz昨天放暑假了,今天发来一截图,乍一看,说说的尾巴居然是iphone6,2!在Meirtz准备问那人是不是工程机时,我突然想起,iphone6,2不就是iPhone 5S的Model型号吗。

Meirtz发来的截图
Meirtz发来的截图

不过这倒是激起了我们想玩一玩QQ说说尾巴的兴趣。根据显示的字样,猜测应该是从sysctlbyname或者uname这两个函数的其中一个中获取的。

那么先Hook一下sysctlbyname看看。

Hook sysctlbyname

因为是C函数,所以我们用MSHookFunction来替换函数。

导入以下两个头文件

#import <substrate.h>
#import <sys/sysctl.h>

然后就是写我们的函数,判断一下请求的内容,如果是"hw.machine"的话,那么就把arg2赋值为"iPhone7,2"(随意猜想的下一代iPhone的Model型号)。

#pragma mark - MSHookFunction

static int (*orig_sysctlbyname)(const char *arg1, void * arg2, size_t * arg3, void * arg4, size_t arg5);
int repl_sysctlbyname(const char *arg1, void * arg2, size_t * arg3, void * arg4, size_t arg5);

int repl_sysctlbyname(const char *arg1, void * arg2, size_t * arg3, void * arg4, size_t arg5){

    NSLog(@"QQ Use sysctlbyname -> %s",arg1);

    if (strcmp(arg1, "hw.machine") == 0 && arg2 != NULL) {

                arg2 = "iPhone7,2";

                NSLog(@"Switch to iPhone7,2");

                return 0;

        }else if (strcmp(arg1, "hw.model") == 0 && arg2 != NULL){

                arg2 = "N63AP";

                NSLog(@"Switch to N63AP");

                return 0;

        }else return orig_sysctlbyname(arg1,arg2,arg3,arg4,arg5);

}

测试后,发现QQ有调用sysctlbyname,不过在选择尾巴的页面从iPod 5变成了ipod touch,看形式应该是调用了[[UIDevice currentDevice] model];

那么这个就用Objc的runtime特性来hook了。

#import <objc/runtime.h>

static IMP originalUIDeviceImplementation = NULL;

在原先的基础上,加几句Hook的,Hook之后返回的NSString姑且就写iPhone 6s吧XD

+ (void)load{

[super load];

    MSHookFunction(sysctlbyname, repl_sysctlbyname, &orig_sysctlbyname);

    Class originalUIDeviceClass = NSClassFromString(@"UIDevice");

Method originalUIDeviceMethod = class_getInstanceMethod(originalUIDeviceClass, @selector(model));

originalUIDeviceImplementation = method_getImplementation(originalUIDeviceMethod);

Method replacementUIDeviceMethod = class_getInstanceMethod(NSClassFromString(@"iPhonex_x"), @selector(repl_model));

method_exchangeImplementations(originalUIDeviceMethod, replacementUIDeviceMethod);

}

#pragma mark - objc runtime

- (NSString *)repl_model{

    NSLog(@"QQ Use UIDevice model");

    NSLog(@"Switch to iPhone Prototype");

    return@"iPhone 6s";

}

编译好之后,scp到touch上,用DYLD_INSERT_LIBRARYS注入,重启QQ之后,发说说测试成功。

源代码就托管到了Github上。

2 thoughts on “QQ的尾巴”

  1. 这个代码有点问题列,就是arg2是一个void的类型的数据,但是你返回的是一个 字符串。

  2. 翻github时看到了,有几个地方貌似有些错误。。
    我直接用arg2 = xxxxx;会没效果,用strcpy才行
    还有就是model的返回值直接返回iPhone就行了

Leave a Reply

Your email address will not be published. Required fields are marked *

three × 2 =