cycript 官方文档 http://www.cycript.org/manual/

Cycript 允许开发人员在 iOS 或 Mac OS X 上使用 objective - c++ 和 JavaScript 语法的混合工具来探索和修改运行的应用程序,通过一个具有语法高亮和标签完成功能的交互式控制台。(它还能在 Android 和 Linux 上独立运行,并提供对 Java 的访问,但没有注入。)

Cycript allows developers to explore and modify running applications on either iOS or Mac OS X using a hybrid of Objective-C++ and JavaScript syntax through an interactive console that features syntax highlighting and tab completion.
(It also runs standalone on Android and Linux and provides access to Java, but without injection.)

ssh 到手机后,启动 app 并且确保它在前台运行,然后执行

cycript -p WeChat

出现 cy# 提示符号表示成功。

常用操作

  • 显示 alert
    alertView = [[UIAlertView alloc] initWithTitle:@”test” message:@”Cycript” delegate:nil cancelButtonTitle:@”OK” otherButtonTitles:nil];
    [alertView show];

  • 查看当前控制器
    UIApp.keyWindow.rootViewController.visibleViewController

  • 获取 bundle info
    [[NSBundle mainBundle] infoDictionary].toString()

  • 显示 Controller 的层次结构
    _printHierarchy 是 UIViewController 的一个私有方法,你可以用它将 view controller 层次打印到控制台。
    [[[UIWindow keyWindow] rootViewController] _printHierarchy].toString()

  • 修改某个 label 的文字
    #0x1530cd5f0.text = @"111"

  • 修改某个 view 的 backgroundColor
    #0x1409777b0.backgroundColor = [UIColor redColor]

  • 打印 view 层级
    [[UIApp keyWindow] recursiveDescription].toString()

  • 打印层级树
    [[UIApp keyWindow] _autolayoutTrace].toString()

  • _ivarDescription 获取某个类的属性
    [choose(FixTitleColorButton)[0] _ivarDescription].toString()

  • _methodDescription
    [choose(FixTitleColorButton)[0] _methodDescription].toString()

  • 打印视图的响应者 [#0x12e5629f0 nextResponder]