本文主要是介绍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<responseObject.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 逆向常用代码片段的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!