iOS 逆向常用代码片段

1、在导航条上添加按钮

UINavigationItem *navigatItem = [self performSelector:@selector(navigationItem)];

UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"群助手" style:UIBarButtonItemStylePlain target:self action:@selector(pushViewController)];

navigatItem.rightBarButtonItem = rightBarButtonItem;

2、判断是非为好友

 CContact *contact = self.arrData[indexPath.row];
 NSString *m_nsNickName = contact.m_nsNickName;

 Ivar m_uiFriendSceneIvar = class_getInstanceVariable(objc_getClass("CContact"), "m_uiFriendScene");
 ptrdiff_t m_uiFriendSceneOffset = ivar_getOffset(m_uiFriendSceneIvar);
unsigned char *stuffBytes = (unsigned char *)(__bridge void *)contact;
NSUInteger m_uiFriendScene = * ((NSUInteger *)(stuffBytes + m_uiFriendSceneOffset));

cell.textLabel.text = m_nsNickName; 

if (m_uiFriendScene == 0) {
     cell.detailTextLabel.text = @"非好友";
} else {
     cell.detailTextLabel.text = @"好友";
}

3、添加一个按钮

UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-80, 74, 70, 70)];
    [btn setTitle:@"上传群" forState:UIControlStateNormal];
[btn setBackgroundColor:kColor_Green];
btn.layer.cornerRadius = 35.0f;
[btn addTarget:self action:@selector(upLoadGroupChat) forControlEvents:UIControlEventTouchUpInside];
[((UIViewController *)self).view addSubview:btn];

4、调用多个参数的方法

SEL startSendVerifyMsg = @selector(startForSendVerifyMsg:parentView:verifyMsg:);
NSMethodSignature *signature = [[CContactVerify class] instanceMethodSignatureForSelector:startSendVerifyMsg];

NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:CContactVerify];
[invocation setSelector:startSendVerifyMsg];
[invocation setArgument:&wrap atIndex:2];
[invocation setArgument:&view atIndex:3];
[invocation setArgument:&msg atIndex:4];
[invocation invoke];

5、遍历字典

    //返回的参数
    NSDictionary *responseObject = [[[NSString alloc] initWithData:arg1.retText.buffer encoding:NSUTF8StringEncoding] JSONDictionary];  

    for (NSInteger i=0; i.count; i++) {
        NSString *key = responseObject.allKeys[i];
        NSString *value = responseObject.allValues[i];
        NSLog(@"%@:%@",key, value);

    }

6、微信判断是否是自己发送的消息

//接收消息
- (void)AsyncOnAddMsg:(NSString *)fromUser MsgWrap:(CMessageWrap* )wrap{
    %orig;
    if ([%c(CMessageWrap) isSenderFromMsgWrap:wrap] == YES) {
        NSLog(@"自己发的消息");
        return;
   }
}

7、打开某个指定的APP

 Class CLSApplicationWorkspace = objc_getClass("LSApplicationWorkspace");
    NSObject * workspace = [CLSApplicationWorkspace performSelector:@selector(defaultWorkspace)];
    [workspace performSelector:@selector(openApplicationWithBundleID:) withObject:@"com.alimama.moon"];

8、判断是否为我的好友

%hook ContactInfoViewController

- (void)viewDidLoad
{
    %orig;

    BOOL isFriend = [self isInMyContactList];
    if (isFriend) {
        NSLog(@"是我的好友");
    } else {
        NSLog(@"不是我的好友");
    }
}

%end

9、获取对象所属的类名

例如我们已知事例对象A *a;

我们可以通过下面的语句获取这个对象的所属类名。

[NSString stringWithUTF8String:object_getClassName(a)]

你可能感兴趣的:(iOS逆向)