iOS逆向安防從入門到禿頭--某信app界面注入UI

小谷禿頭合集微信

今天又是接近逆向的一天~markdown

  • 今天準備來個案例:在某信的設置界面,注入UI(爲了之後的自動搶紅包來個前奏~)ide

  • 首先咱們看下效果圖post

0.png

1. 準備工做

不管是正向仍是逆向開發,咱們寫代碼以前,都要縷一波思路:咱們的目的就是在設置界面增長UI學習

1.1. 定位設置界面

上一篇博客已經說了MonkeyLogos,咱們正好來用一波。測試

  • 咱們使用的是8.0.2的微信包。(固然你可使用最新的8.0.5的,咱們應該是同樣的)ui

    1. 咱們重籤WeChat,運行Monkey
    1. 咱們能夠用viewDebug定位控制器的名稱爲:NewSettingViewController

1.png

    1. 並且咱們也能夠觀察到界面是一個WCTableView,咱們要找到他的數據源(dataSource),因此咱們先看下

2.png

能夠知道:datasource=<WCTableViewManager: 0x282ba8db0>atom

    1. class-dump 獲取微信H文件,sublime打開以後尋找WCTableViewManager

3.png

    1. 發現WCTableViewManager裏面有section組tableView的代理方法

4.png

    1. 咱們查看有多少使用WCTableViewManager管理的

5.png

    1. 咱們能夠肯定,其中一個是設置界面:咱們能夠經過響應鏈條,找到設置界面

6.png

2. UI注入

咱們已經找到了設置界面,能夠經過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
複製代碼
  • 實物圖走上一波

7.png

3. 總結

  • 某信有風險,慎觸~ 😆3d

  • 這篇博客主要是爲自動搶紅包作個準備,要不一下代碼太多兄弟研究的時候就很差預覽了~

  • 兄弟們要是試的話,用大號測試。到時候能夠解封(因爲有被封的風險)

  • 咱們就是研究下他的技術,學習一下,因此沒有什麼問題的

  • 此次注入UI沒有寫什麼功能,因此比較簡單些。最後,兄得們,我去加班了~ (公司總是下班以前來工做!!😿)

相關文章
相關標籤/搜索