美文网首页逆向工程
iOS逆向:Theos与Tweak基础篇

iOS逆向:Theos与Tweak基础篇

作者: 码小菜 | 来源:发表于2020-06-30 15:38 被阅读0次

目录
一,环境配置
二,实战练习:SpringBoard(桌面)
三,实战练习:喜马拉雅
四,实战练习:微信

一,环境配置

1,安装签名工具ldid
  • 成功
  • 报错
  • 解决

1>sudo chown -R `whoami`:admin /usr/local/bin
2>sudo chown -R `whoami`:admin /usr/local/share

2,修改环境变量
  • 编辑配置文件:vim ~/.bash_profile
  • 在文件中加入两行: export THEOS=~/theosexport PATH=$THEOS/bin:$PATH
  • 让修改立即生效:source ~/.bash_profile
  • 查看是否生效:echo $THEOSecho $PATH
3,配置theos
  • 下载:git clone --recursive https://github.com/theos/theos.git $THEOS
  • 修改~/theos/makefiles/package/deb.mk文件

1>将_THEOS_PLATFORM_DPKG_DEB_COMPRESSION的值修改为gzip

2>将1替换为2

1,$(ECHO_NOTHING)COPYFILE_DISABLE=1 $(FAKEROOT) -r $(_THEOS_PLATFORM_DPKG_DEB) -Z$(_THEOS_PLATFORM_DPKG_DEB_COMPRESSION) -z$(THEOS_PLATFORM_DEB_COMPRESSION_LEVEL) -b "$(THEOS_STAGING_DIR)" "$(_THEOS_DEB_PACKAGE_FILENAME)"$(ECHO_END)
2,$(ECHO_NOTHING)COPYFILE_DISABLE=1 $(FAKEROOT) -r dpkg-deb -Zgzip -b "$(THEOS_STAGING_DIR)" "$(_THEOS_DEB_PACKAGE_FILENAME)" $(STDERR_NULL_REDIRECT)$(ECHO_END)

二,实战练习:SpringBoard(桌面)

1,目标:移除红色标记
2,查询所需信息
  • 查询AppId
  • 查询控件所属类
  • 查询需要hook的方法

1>用ps -A找到可执行文件

2>用class-dump导出所有.h文件

3>在SBIconParallaxBadgeView.h文件中找到有效的方法

3,新建tweak项目
  • sbTweak:项目名称
  • com.yj.sb:项目bundleId
  • com.apple.springboard:桌面APP的bundleId
4,在Makefile文件中添加环境变量
  • THEOS_DEVICE_IP:本机IP
  • THEOS_DEVICE_PORT:本机与iPhone通信的端口
5,在Tweak.x文件中编写hook代码
6,编译,打包和安装
  • 编译
  • 打包
  • 安装(会自动重启SpringBoard
7,安装成功
  • 爱思助手
  • Cydia
8,最终效果

三,实战练习:喜马拉雅

1,目标:移除暂停时出现的广告
2,查询所需信息
  • 查询AppId
  • 查询控件所属类
  • 查询需要hook的方法
3,新建tweak项目
4,在.bash_profile文件中添加环境变量(避免每个项目都添加一次)
5,在Tweak.x文件中编写hook代码
6,编译,打包和安装
7,最终效果

四,实战练习:微信

1,目标:在发现页添加两个功能
2,hook代码
#define YJSwitchKey       @"yj_switch_key"
#define YJUserDefaults    NSUserDefaults.standardUserDefaults
// 该路径需要与iPhone上的一致,这样图片就能存储到iPhone上对应路径下
#define YJImagePath(name) [NSString stringWithFormat:@"/Library/Caches/YJWechat/%@", name]

@interface FindFriendEntryViewController
// 必须提前声明,否则调用此方法会报错
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
@end

%hook FindFriendEntryViewController

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // %orig表示调用原始的方法
    return %orig + 1;
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section {
    NSInteger totalSection = [self numberOfSectionsInTableView:tableView];
    // 如果section不是新增的,就直接使用原始方法的实现
    if (section != totalSection - 1) {
        return %orig;
    }
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger totalSection = [self numberOfSectionsInTableView:tableView];
    if (indexPath.section != totalSection - 1) {
        return %orig;
    }
    
    NSString *identifier = @"YJCustomCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:identifier];
        cell.backgroundColor = UIColor.whiteColor;
        // 加载本地图片
        cell.imageView.image = [UIImage imageWithContentsOfFile:YJImagePath(@"skull")];
    }
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"自动抢红包";
        UISwitch *sw = [[UISwitch alloc] init];
        // 获取switch的状态
        sw.on = [YJUserDefaults boolForKey:YJSwitchKey];
        cell.accessoryView = sw;

        [sw addTarget:self
               action:@selector(yj_switchChanged:)
     forControlEvents:UIControlEventValueChanged];
    } else {
        cell.textLabel.text = @"退出微信";
        cell.accessoryView = nil;
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger totalSection = [self numberOfSectionsInTableView:tableView];
    if (indexPath.section != totalSection - 1) {
        return %orig;
    }
    return 56;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSInteger totalSection = [self numberOfSectionsInTableView:tableView];
    if (indexPath.section != totalSection - 1) {
        %orig;
        return;
    }
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 1) {
        // 终止进程
        abort();
    }
}

%new // 表示此方法是新增的方法
- (void)yj_switchChanged:(UISwitch *)sw {
    // 保存switch的状态
    [YJUserDefaults setBool:sw.isOn forKey:YJSwitchKey];
    [YJUserDefaults synchronize];
}

%end
3,图片位置
  • 项目中
  • iPhone中
4,最终效果
本文章仅供学习交流,如有侵权,请联系删除,谢谢!

相关文章

网友评论

    本文标题:iOS逆向:Theos与Tweak基础篇

    本文链接:https://www.haomeiwen.com/subject/hfylfktx.html