小谷禿頭合集微信
今天又是接近逆向的一天~markdown
今天準備來個案例:在某信
的設置界面,注入UI
(爲了之後的自動搶紅包
來個前奏~)ide
首先咱們看下效果圖post
不管是
正向
仍是逆向
開發,咱們寫代碼以前,都要縷一波思路:咱們的目的就是在設置界面增長UI
學習
上一篇博客已經說了
Monkey
和Logos
,咱們正好來用一波。測試
咱們使用的是8.0.2的微信包
。(固然你可使用最新的8.0.5
的,咱們應該是同樣的)ui
WeChat
,運行Monkey
viewDebug
定位控制器的名稱爲:NewSettingViewController
WCTableView
,咱們要找到他的數據源(dataSource)
,因此咱們先看下能夠知道:
datasource=<WCTableViewManager: 0x282ba8db0>
atom
class-dump
獲取微信
的H文件
,sublime
打開以後尋找WCTableViewManager
WCTableViewManager
裏面有section組
和tableView
的代理方法響應鏈條
,找到設置界面咱們已經找到了設置界面,能夠經過
class-dump
.經過頭文件查看他的方法spa
#import <UIKit/UIKit.h>
#define XGDefaults [NSUserDefaults standardUserDefaults]
#define XGSWITCHKEY @"XGSWITCHKEY"
#define XGTEXTKEY @"XGTEXTKEY"
@interface WCTableViewManager : NSObject
//在class-dump中的方法。我要調用,因此copy過來~
@property(retain, nonatomic) NSMutableArray *sections;
- (long long)numberOfSectionsInTableView:(UITableView *)tableView;
@end
//因爲用到self,須要知道self的定位
@interface MMUIViewController : UIViewController
@end
@interface NewSettingViewController : MMUIViewController
@end
%hook WCTableViewManager
//要hook的方法~ 滑動時,鍵盤迴收
- (void)scrollViewWillBeginDragging:(id)arg1{
%orig;
//肯定是在設置界面
if([MSHookIvar <UITableView *>(self,"_tableView").nextResponder.nextResponder isKindOfClass:%c(NewSettingViewController)]){
[MSHookIvar <UITableView *>(self,"_tableView") endEditing:YES];
}
}
//自定義textfield方法
%new
-(void)xg_textFieldDidChangeValue:(NSNotification *)notification{
UITextField *textField = (UITextField *)[notification object];
[XGDefaults setValue:textField.text forKey:XGTEXTKEY];
[XGDefaults synchronize];
[MSHookIvar <UITableView *>(self,"_tableView") reloadData];
}
//自定義switch開關方法
%new
-(void)xg_switchChang:(UISwitch *)switchView{
[XGDefaults setBool:switchView.isOn forKey:XGSWITCHKEY];
[XGDefaults synchronize];
[MSHookIvar <UITableView *>(self,"_tableView") reloadData];
}
//cell設置
- (id)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
// NSLog(@"indexPath:%ld,section:%ld",indexPath,[indexPath section]);
//若是在設置界面而且是最後一組。設置cell
if([tableView.nextResponder .nextResponder isKindOfClass:%c(NewSettingViewController)] && ([indexPath section] == [self numberOfSectionsInTableView:tableView]-1)){
UITableViewCell * cell = nil;
//笑臉UI SWICH開關
if([indexPath row] == 0){
static NSString * swCell = @"SWCELL";
cell = [tableView dequeueReusableCellWithIdentifier:swCell];
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:nil];
}
cell.textLabel.text = @"逆向開始!!";
UISwitch * switchView = [[UISwitch alloc] init];
switchView.on = [XGDefaults boolForKey:XGSWITCHKEY];
[switchView addTarget:self action:@selector(xg_switchChang:) forControlEvents:(UIControlEventValueChanged)];
cell.accessoryView = switchView;
cell.imageView.image = [UIImage imageNamed:([XGDefaults boolForKey:XGSWITCHKEY] == 1) ? @"unlocked" : @"locked"];
}else if([indexPath row] == 1){
static NSString * waitCell = @"UICELL";
cell = [tableView dequeueReusableCellWithIdentifier:waitCell];
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:nil];
}
cell.textLabel.text = @"增長個小UI!";
//首先設置一個輸入框的大小
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 80, 30)];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(xg_textFieldDidChangeValue:) name:UITextFieldTextDidChangeNotification object:textField];
textField.text = [XGDefaults valueForKey:XGTEXTKEY];
//咱們經過class-dump中header能夠知道,cell有一個- (void)setAccessoryView:(id)arg1;方法
[cell setAccessoryView:textField];
cell.imageView.image = [UIImage imageNamed:@"1003_filled"];
}
cell.backgroundColor = [UIColor whiteColor];
return cell;
}else{
return %orig;
}
}
//每組有多少行
- (long long)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//若是在設置界面而且是最後一組。增長2行
if([tableView.nextResponder .nextResponder isKindOfClass:%c(NewSettingViewController)] && (section == [self numberOfSectionsInTableView:tableView]-1)){
return 2;
}else{
return %orig;
}
}
// 多少組 .nextResponder .nextResponder
- (long long)numberOfSectionsInTableView:(UITableView *)tableView {
//能夠判斷是在設置界面
if([tableView.nextResponder .nextResponder isKindOfClass:%c(NewSettingViewController)]){
return %orig + 1;
}else{
return %orig;
}
}
//行高
- (double)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//若是在設置界面而且是最後一組。設置行高~
if([tableView.nextResponder .nextResponder isKindOfClass:%c(NewSettingViewController)] && ([indexPath section] == [self numberOfSectionsInTableView:tableView]-1)){
return 44;
}else{
return %orig;
}
}
%end
//因爲咱們增長了一個textfield控件,想象一下,鍵盤談起的話,會遮擋視圖因此咱們能夠處理下(固然,能夠能夠不處理,只是個界面遮擋的問題,不過對於有點小小強迫症的我來講,仍是要處理下)
//要作的2件事,,一、鍵盤談起,tableview,上移!二、滑動tableview,鍵盤迴收
%hook NewSettingViewController
//彈出
%new
- (void)xg_keyboardWillShow:(NSNotification *)notification{
UIView * view = self.view;
CGRect keyBoardRect=[notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
view.frame = CGRectMake(0, -keyBoardRect.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height );
}
//消失
%new
- (void)xg_keyboardWillHide:(NSNotification *)notification{
UIView * view = self.view;
view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
}
// hook 方法,增長通知~
- (void)viewDidLoad{
%orig;
//監聽鍵盤的彈出和消失
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(xg_keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(xg_keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
%end
複製代碼
某信
有風險,慎觸~ 😆3d
這篇博客主要是爲自動搶紅包
作個準備,要不一下代碼太多兄弟研究的時候就很差預覽了~
兄弟們要是試的話,用大號測試。到時候能夠解封(因爲有被封的風險)
咱們就是研究下他的技術,學習一下,因此沒有什麼問題的
此次注入UI沒有寫什麼功能,因此比較簡單些。最後,兄得們,我去加班了~ (公司總是下班以前來工做!!😿)