美文网首页ios逆向
iOS逆向工具之class-dump(MacOS)介绍

iOS逆向工具之class-dump(MacOS)介绍

作者: 木子心语 | 来源:发表于2019-12-30 17:20 被阅读0次
    • 上一篇文章地址 iOS逆向工具之Cydia(iOS)介绍

    • 感兴趣的小伙伴请留言,我们互相交流一下.

    • 本篇文章将要介绍的工具是 class-dump,工具会放到群里面,方便大家下载.

    class-dump

    class-dump官网 github地址

    以上是两种下载方式,可以通过官网下载安装,也可以通过github下载后使用.

    • 如果你不想下载,可以到群文件中下载.

    • class-dump是什么?
      class-dump(类存储),用来dump目标对象的class信息的工具.

    • class-dump的特性是什么?
      它利用OC语言的runtime的特性,将存储在Mach-O文件中的头文件信息提取出来,并生成对应的.h文件.

    • 如果你完成了class-dump下载操作,我们接着打开下载的文件.

    class-dump dmg

    1 可以看到class-dump 可执行文件
    2 class-dump的版本已经更新到了3.5版本
    3 src文件:class-dump的编译源码
    4 github下载同样是class-dump编译源码

    • 我们如何使用class-dump?

    小伙伴有可能能遇到下面这个问题

    cp: /usr/bin/class-dump: Operation not permitted
    

    因为你选了路径是usr/bin ,如果遇到这个问题,我们可以换成路径为usr/local/bin中

    我们需要把class-dump可执行文件拷贝到/usr/local/bin文件中.

    • 我们拷贝完成后,我们在终端执行一下class-dump
    class-dump

    注意
    1 可以看到红框是配合class-dump 具体使用的参数
    2 如果你在执行class-dump的时候,提示权限不够
    3 你可以进行加权限: sudo chmod 777 /usr/local/bin/class-dump

    #import "ViewController.h"
    
    @interface ViewController ()
    
    @property (nonatomic,strong)UIButton *revealBtn;
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        
        [self.view addSubview:self.revealBtn];
    }
    
    -(UIButton*)revealBtn{
        if (!_revealBtn) {
            _revealBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            _revealBtn.frame = CGRectMake(100,100, 100,40);
            _revealBtn.backgroundColor = [UIColor redColor];
            [_revealBtn setTitle:@"测试" forState:UIControlStateNormal];
            [_revealBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }
        return _revealBtn;
    }
    
    @end
    
    • 我们只在项目ViewController 中添加上面的代码

    • 我们先看看TEST源码的头文件

    AppDelegate.h

    #import <UIKit/UIKit.h>
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    
    @property (strong, nonatomic) UIWindow *window;
    
    @end
    

    ViewController.h

    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController
    
    @end
    
    • 我们接下来打包项目,找到Mach-O文件


      TEST可执行文件
    • 我们找到了可执行文件后,我们拷贝到桌面
      执行下面的命令:

      class-dump 使用

    class-dump -s -S -H /Users/用户名/Desktop/TEST -o /Users/用户名/Desktop/TestHeader

    这个命令的意思是把可执行文件TEST中头文件dump后保存到TestHeader中

    • 我们执行一下看看
    执行完成
    我们看到执行成功了
    • 我们打开TestHeader文件看一下,文件夹里到底是什么?
    TestHeader

    我们可以看到,AppDelegate.h,ViewController.h等头文件.

    • 我们看下AppDelegate.h, ViewController.h文件中的源码

    AppDelegate.h

    #import "UIResponder.h"
    
    #import "UIApplicationDelegate.h"
    
    @class NSString, UIWindow;
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate>
    {
        UIWindow *_window;
    }
    
    - (void).cxx_destruct;
    - (_Bool)application:(id)arg1 didFinishLaunchingWithOptions:(id)arg2;
    - (void)applicationDidBecomeActive:(id)arg1;
    - (void)applicationDidEnterBackground:(id)arg1;
    - (void)applicationWillEnterForeground:(id)arg1;
    - (void)applicationWillResignActive:(id)arg1;
    - (void)applicationWillTerminate:(id)arg1;
    @property(retain, nonatomic) UIWindow *window; // @synthesize window=_window;
    
    // Remaining properties
    @property(readonly, copy) NSString *debugDescription;
    @property(readonly, copy) NSString *description;
    @property(readonly) unsigned long long hash;
    @property(readonly) Class superclass;
    
    @end
    

    ViewController.h

    #import "UIViewController.h"
    
    @class UIButton;
    
    @interface ViewController : UIViewController
    {
        UIButton *_revealBtn;
    }
    
    - (void).cxx_destruct;
    @property(retain, nonatomic) UIButton *revealBtn; // @synthesize revealBtn=_revealBtn;
    - (void)viewDidLoad;
    
    @end
    
    • TEST项目并不复杂,我们可以清晰的看到类中的控件及方法
      可以和上面的源码对比一下,我们使用了revealBtn,在dump的类中也能查看到.

    注意
    有没有发现,我们很容易的获取到了TEST项目中的头文件.
    这里总结一下
    1 我们项目创建的简单,导出的类也就清晰明了
    2 我们拿到可执行文件,我们通过自己打包的项目,我们可不是在AppStore下载的应用,你有可能忽略这一点,我们才dump很轻松.
    3 如果我们从AppStore下载的应用,我们应该通过砸壳后,才能使用可执行文件,然后接着class-dump可执行文件.
    4 我们下一篇文章要介绍砸壳工具的使用.
    5 如果没有执行成功,你需要配置一下class-dump环境.

    • class-dump帮我们排序后,头文件的可读性甚至变高了.
      我们这里分析自己的应用,同样可以分析其他应用,就像我上面说的,我们需要砸壳,才能看到应用的头文件.

    总结

    • class-dump的介绍,到这里介绍的差不多了.
    • 如果你很感兴趣,你可以自己搜索资料,了解更详细的class-dump.
    • 如果你想愿意分享更多class-dump资料,我可以把文章补充一下.
    • 下一篇文章将介绍应用砸壳工具.

    相关文章

      网友评论

        本文标题:iOS逆向工具之class-dump(MacOS)介绍

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