iOS逆向开发-theos中的Makefile、代码中使用的库、资源文件导入配置

701 阅读3分钟

iOS逆向开发-theos安装配置使用简单说明

导语:补充说明一些theos使用的注意点,感觉网上关于逆向的很多资料都很老旧。希望刚学逆向的朋友们可以有点参考的东西。

配置Makefile文件

  • 创建完成theos项目,第一步就是配置Makefile文件
  1. 配置环境变量

由于每个项目都会使用连接到手机的环境变量,可以把环境变量放到 ~/.zprofile文件中

命令: open ~/.zprofile

//在.zprofile文件中配置好IP和端口
export THEOS_DEVICE_IP = localhost 
export THEOS_DEVICE_PORT = 10010

命令:source ~/.zprofile

Makefile中就不用配置连接手机的环境变量。

  • 在开发中要用到的很多配置是在Makefile中完成的
ARCHS = armv7 arm64 //指定架构

//导入动态库
project_FRAMEWORKS = 动态库
project_PRIVATE_FRAMEWORKS  = 私有动态库

导入动态库这里有个坑,我想导入UIKit,在网上看到的资料都是使用_FRAMEWORKS,但是实际在我的项目里死活读取不了UIKit,编译不能通过

使用_PRIVATE_FRAMEWORKS成功导入,不知道是不是版本问题

wechattweak_PRIVATE_FRAMEWORKS = UIKit


开发和资源导入

  • 网上很经典的给微信加两个cell,按照以前的看的demo,一堆报错,基本就是OC的对象类型不能通过编译,和导入UIKit的问题一起搞的一头乱码,终于成功编译安装。贴出代码供大家参考一下。因为刚开始学这个,如果发现有误,或者更好的解决方法,请一定要帮忙指出,谢谢。
tweak.x

#import <UIKit/UIKit.h> //除了在Makefile要导入UIKit,这里也要导入

#define FRUSERDEFAULTS [NSUserDefaults standardUserDefaults]
#define FRWeChatPath(path) @"/Library/PreferenceLoader/Preferences/FRWeChat/" #path

%hook FindFriendEntryViewController //导入需要hook的控制器

//声明一下类,才能使用self
@interface FindFriendEntryViewController

//声明一下方法,self调用方法才可以通过编译
- (long long)numberOfSectionsInTableView:(id)tableView;

@end

//%orig表示保持原方法的实现
- (long long)numberOfSectionsInTableView:(id)tableView
{
    return %orig + 1;
}

- (long long)tableView:(id)tableView numberOfRowsInSection:(long long)section
{
    if (section != [self numberOfSectionsInTableView:tableView] - 1)
    {
        return %orig;
    }
    
    return 2;
}

- (id)tableView:(id)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section != [self numberOfSectionsInTableView:tableView] - 1)
    {
         return %orig;
    }

    NSString *addCellID = (indexPath.row == 0) ? @"autoCellID" : @"exitCellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:addCellID];
         if (cell == nil) {
             cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:addCellID];
             cell.backgroundColor = [UIColor whiteColor];
             cell.imageView.image = [UIImage imageWithContentsOfFile:FRWeChatPath(skull.png)]; 
         }

     if (indexPath.row == 0) {

         cell.textLabel.text = @"自动抢红包";   

         UISwitch *st = [[UISwitch alloc] init];

         st.on = [FRUSERDEFAULTS boolForKey:@"fr_Switch_key"];

         [st addTarget:self action:@selector(clickSt:) forControlEvents:UIControlEventValueChanged];

         cell.accessoryView = st;

     }else if (indexPath.row == 1){
         cell.textLabel.text = @"退出微信";
     }

    return cell;
}

- (double)tableView:(id)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (indexPath.section != [self numberOfSectionsInTableView:tableView] - 1)
    {
        return %orig;
    }
    
    return 44;
}


- (void)tableView:(id)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (indexPath.section != [self numberOfSectionsInTableView:tableView] - 1)
     {
         %orig;
         return;
     }

     [tableView deselectRowAtIndexPath:indexPath animated:YES];

     if (indexPath.row)
     {
         // exit(0);//会卡顿

         abort();
     }
}

//添加新的方法要使用%new声明
%new
- (void)clickSt:(UISwitch *)st{
    [FRUSERDEFAULTS setBool:st.isOn forKey:@"fr_Switch_key"];
    [FRUSERDEFAULTS synchronize];
}

%end

  • 对比之前网上的demo主要是多了三个步骤
  1. 需要在Makefile文件中导入UIKit
  2. 在代码中导入UIKit
  3. 要使用self调用方法,需要声明类和被调用的方法才能通过编译
资源引入
  • 如果要使用图片之类的文件引入
  1. 创建一个layout文件夹放到项目的根目录

  2. 读取资源的路径说明:

如果文件直接放在layout中,安装到手机时,文件会被放到手机的~(home)目录中

相当于layout就是根目录,读取文件相对layout往下读取就可以了

文件最好不要直接放到layout中,创建一些文件夹区分资源

比如, 上面例子中的图片

路径:

/layout/Library/PreferenceLoader/Preferences/FRWeChat/skull.png

读取:

[UIImage imageWithContentsOfFile:@"/Library/PreferenceLoader/Preferences/FRWeChat/skull.png"];