iOS逆向开发(三)----Clutch,dumpdecrypted,Theos-Tweak

iOS逆向开发(三)----Clutch,dumpdecrypted,Theos-Tweak

脱壳

我们知道上架到App Store的app都是通过加壳操作的,所谓加壳就是利用特殊的算法,对可执行文件的编码进行改变(比如压缩、加密),以达到保护程序代码的目的.我们要逆向别人的app,首先要脱壳,将未加密的可执行文件还原出来,脱壳主要有2种方法:硬脱壳、动态脱壳.主要工具有Clutch和dumpdecrypted.

Clutch

将下载好的Clutch,拷贝到iPhone的/usr/bin目录,如果在iPhone上执行Clutch指令,权限不够,赋予“可执行的权限”.

Snip20181101_33.png

1.Clutch -i 列出未脱壳的app

2.输入APP序号或者Bundle Id进行脱壳操作:Clutch -d APP序号或BundleId

Snip20181101_34.png

成功生成一个脱壳的ipa

Snip20181101_35.png

实际位置

Snip20181101_36.png

dumpdecrypted

下载源代码,然后在源代码目录执行make指令进行编译,获得dylib动态库文件,将dylib文件拷贝到iPhone上(如果是root用户,建议放/var/root目录),终端进入dylib所在的目录,使用环境变量DYLD_INSERT_LIBRARIES将dylib注入到需要脱壳的可执行文件(可执行文件路径可以通过ps -A查看获取): DYLD_INSERT_LIBRARIES=dumpdecrypted.dylib 可执行文件路径

Snip20181101_37.png

theos-tweak

先确保安装brew:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

利用brew安装签名工具ldid:brew install ldid

下载theos:git clone --recursive https://github.com/theos/theos.git ~/theos.

新建一个tweak项目,cd到一个项目文件夹:cd /Users/admin/Desktop/Tweak,然后nic.pl,

Snip20181104_41.png

选择11,填写Project Name 和要进行tweak的bundle ID 其它默认既可以.

Snip20181104_42.png

就新建成功一个Tweak项目,实现给微信添加一行,效果如图:

IMG_1928.PNG

填写编写Tweak.xm代码,用reveal,定位控制器为FindFriendEntryViewController,代码如下:


%hook  FindFriendEntryViewController

- (long long)numberOfSectionsInTableView:(id)arg1
{
    return %orig + 1;
}

- (long long)tableView:(id)arg1 numberOfRowsInSection:(long long)arg2
{
    if (arg2 == [self numberOfSectionsInTableView: arg1] - 1) {
        return 1;
    } else {
        return %orig;
    }
}

- (double)tableView:(id)arg1 heightForRowAtIndexPath:(id)arg2 
{
    if ([arg2 section] == [self numberOfSectionsInTableView: arg1] - 1) {
        return 44;
    } else {
        return %orig;
    }
}

- (id)tableView:(id)arg1 cellForRowAtIndexPath:(id)arg2 {
    if ([arg2 section] == [self numberOfSectionsInTableView: arg1] - 1) {
        
        UITableViewCell *cell = [arg1 dequeueReusableCellWithIdentifier:@"lj_cell"];
        if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"lj_cell"];
        cell.backgroundColor = [UIColor whiteColor];
        cell.textLabel.text = @"自动抢红包";
        cell.imageView.image = [UIImage imageWithContentsOfFile:@"/Library/Caches/LJWeChat/pic.png"];
        }
        UISwitch *switchView = [[UISwitch alloc] init];
        switchView.on = [[NSUserDefaults standardUserDefaults] boolForKey:@"lj_switch"];
        [switchView addTarget:self action:@selector(lj_switchValueDidChange:) forControlEvents:UIControlEventValueChanged];
        cell.accessoryView = switchView;
        return cell;
    } else {
        return %orig;
    }
}

%new
- (void)lj_switchValueDidChange:(UISwitch *)switchView {
    [[NSUserDefaults standardUserDefaults] setBool:switchView.isOn forKey:@"lj_switch"];
}

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

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

%end

然后进行make package,打包

Snip20181104_43.png

遇到问题如下:

![Snip20181104_38.png](https://upload-images.jianshu.io/upload_images/3529394-23b44c61e8a9c332.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

修theos路径下/makefiles/package/deb.mk的第六行,压缩方式为gzip,

安装make install,成功运行.

你可能感兴趣的:(iOS逆向开发(三)----Clutch,dumpdecrypted,Theos-Tweak)