美文网首页
05_Cycript

05_Cycript

作者: 伶俐ll | 来源:发表于2020-08-15 19:22 被阅读0次

Cycript语法

一、Cycript的开启和关闭
  • 开启
    cycriptcycript -p 进程IDcycript -p 进程名称

ps(process status)命令可以列出系统当前的进程

  • 安装adv-cmds
    列出所有的进程
    ps –Aps aux
    搜索关键词
    ps –A | grep 关键词
  • 取消输入:Ctrl + C
  • 退出:Ctrl + D
  • 清屏:Command + R
二、Cycript的常用语法
  • UIApp[UIApplication sharedApplication]的简写
cy# [UIApplication sharedApplication]
#"<SMReaderApp: 0x147e22e50>"
cy# UIApp
#"<SMReaderApp: 0x147e22e50>"
  • 定义变量:var 变量名 = 变量值
cy# var app = UIApp.keyWindow 
#"<TQWindow: 0x147d22440; baseClass = UIWindow; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x1702577f0>; layer = <UIWindowLayer: 0x170223000>>"
cy# app.rootViewController 
#"<BaseViewController: 0x148032a00>"
  • 用内存地址获取对象:#内存地址
cy# UIApp
#"<SMReaderApp: 0x147e22e50>"
cy# #0x147e22e50.keyWindow 
#"<TQWindow: 0x147d22440; baseClass = UIWindow; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x1702577f0>; layer = <UIWindowLayer: 0x170223000>>"
cy# #0x147d22440.rootViewController 
#"<BaseViewController: 0x148032a00>"
  • 查看对象的所有成员变量:*对象
cy# *UIApp
{isa:SMReaderApp,_delegate:#"<SMReaderApp: 0x147e22e50>",_exclusiveTouchWindows:[NSSet setWithArray:@[]]],_event:#"<UIInternalEvent: 0x1702205c0>",
  • 递归打印view的所有子控件(跟LLDB一样的函数)
    view.recursiveDescription().toString()
cy#  UIApp.keyWindow.rootViewController.view.recursiveDescription() .toString()
"<UILayoutContainerView: 0x147e36250; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x17444c060>; layer = <CALayer: 0x170235a20>>\n   | <UINavigationTransitionView: 0x147d29f70; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x17423ab40>>\n   |    | <UIViewControllerWrapperView: 0x147e61de0; frame = (0 0; 375 667); autoresize = W+H;
  • 筛选出某种类型的对象
    choose(UIViewController)
    choose(UITableViewCell)
cy# choose(UIViewController)
[#"<StatusBarController: 0x147e354b0>",#"<PRRootMoveViewCtrl: 0x147e3a5c0>",#"<BookStoreTabPageViewCtrl: 0x147e55960>",#"<BookShelfCtrl: 0x147ed4500>",#"<BookPageViewCtrl: 0x149022730>",#"<LeftMenusViewCtrl: 0x147d3b100>",#"<BookPageViewCtrl: 0x147f429a0>",#"<UIInputWindowController: 0x148815200>",#"<BookShelfNavCtrl: 0x148919a00>",#"<BookPageNavigationCtrl: 0x148961e00>",#"<PRNavigationController: 0x148029200>",#"<BaseViewController: 0x148032a00>",#"<PRNavigationController: 0x148079200>",#"<BookPageNavigationCtrl: 0x14807cc00>",#"<BookPageNavigationCtrl: 0x14814da00>"]

封装Cycript

  • 我们可以将常用的Cycript代码封装在一个.cy文件中
  • exports参数名固定,用于向外提供接口
(function(exports) {
    // keyWindow
    exports.KeyWin = function() {
        return UIApp.keyWindow;
    };
    // 根控制器
    RootVc =  function() {
        return UIApp.keyWindow.rootViewController;
    };
})(exports);

存放和使用.cy文件

  • 将.cy文件存放到/usr/lib/cycript0.9目录下
zhanglingli@bogon ~ % scp -P 10010 ~/Desktop/mjcript-master/mjcript.cy root@localhost:/usr/lib/cycript0.9
mjcript.cy                                    100% 6178     1.8MB/s   00:00    
zhanglingli@bogon ~ % 
  • 在Cycript中引用.cy文件,并使用它提供的接口
cy# @import mjcript
{}
cy# MJAppId
@"com.book.yueliao"
cy# MJAppPath 
@"/private/var/mobile/Containers/Bundle/Application/60903954-D55C-46F3-A655-A1739CE983EE/YueLiao.app"
cy# MJKeyWin 
function () {return UIApp.keyWindow;}
cy# MJKeyWin ()
#"<TQWindow: 0x147d22440; baseClass = UIWindow; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x1702577f0>; layer = <UIWindowLayer: 0x170223000>>"
cy# MJR
MJRectMake  MJRootVc    
cy# MJRootVc ()
#"<BaseViewController: 0x148032a00>"

相关文章

  • 05_Cycript

    Cycript是Objective-C++、ES6(JavaScript)、Java等语法的混合物 可以用来探索、...

网友评论

      本文标题:05_Cycript

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