A,CycriptIntroduction of grammar

  • Once you’re in Cycript debug mode from the previous article, you need to debug operations using scripting languages, such as: get the page controller, get object properties, manually call object methods, add your own UI to the page… And so on.

  • Cycript also has syntax examples to refer to.

    The command The results of
    UIApp Gets the Appdelegate object for the current App
    UIApp.keyWindow Gets the current keyWindow object
    UIWindow.keyWindow Gets the current keyWindow object
    var Define an object
    # memory address Object that gets the current memory address
    # memory address Object that gets the current memory address
    * object Gets all member variables of an object
    choose(UILabel) Find all uilabels for the current interface
  • After entering the Cycript debug environment, you can write OC, JS… Supported syntax, such as:

    • OC (which is a syntax format very, very similar to OC syntax) :

      cy# [UIApp description]
      @"<NMApplication: 0x113d4d710>"
      Copy the code

      UIApp is equal to UIApplication object, both written the same way, the abbreviation given by the script.

      cy# UIApp
      #"<NMApplication: 0x113d4d710>"
      Copy the code
    • JS:

      Cy# [for (x of [1,2,3]) x+1] [2,3,4]Copy the code

      .

Second,Define variables

  • NSString *name = @” DZM “is not supported

    $var Variable name = variable valueCopy the code
    ~ root# cycript -p neteasemusic // create variable window cy# var window = uiapp.keywindow #"<OTTouchObservingWindow: 0x10a65b610; baseClass = UIWindow; frame = (0 0; 320, 568); gestureRecognizers = <NSArray: 0x28043da10>; Layer = <UIWindowLayer: 0x280AF58A0 >>" // The output variable window is the same as uiApp. keyWindow. 0x10a65b610; baseClass = UIWindow; frame = (0 0; 320, 568); gestureRecognizers = <NSArray: 0x28043da10>; layer = <UIWindowLayer: 0x280af58a0>>"Copy the code

3. Get common objects (example)

  • UIApp is equal to UIApplication object.

    cy# [UIApp description]
    @"<NMApplication: 0x113d4d710>"
    Copy the code
    cy# UIApp
    #"<NMApplication: 0x113d4d710>"
    Copy the code
  • Get the keyWindow object (OTTouchObservingWindow is actually UIWindow, but converted internally in iOS after compilation).

    cy# UIApp.keyWindow #"<OTTouchObservingWindow: 0x10a65b610; baseClass = UIWindow; frame = (0 0; 320, 568); gestureRecognizers = <NSArray: 0x281ac01e0>; layer = <UIWindowLayer: 0x28146e0a0>>"Copy the code
  • To obtain a rootViewController.

    cy# UIApp.keyWindow.rootViewController
    #"<NMRootNavigationController: 0x10a8cd400>"
    Copy the code

4. Memory address access object

  • Obtain memory address 0x10a65b610 for keyWindow:

    cy# UIApp.keyWindow #"<OTTouchObservingWindow: 0x10a65b610; baseClass = UIWindow; frame = (0 0; 320, 568); gestureRecognizers = <NSArray: 0x281ac01e0>; layer = <UIWindowLayer: 0x28146e0a0>>"Copy the code

    This object can be accessed via the memory address with # 0x10A65b610, and you will see the same object as the one printed above:

    cy# #0x10a65b610 #"<OTTouchObservingWindow: 0x10a65b610; baseClass = UIWindow; frame = (0 0; 320, 568); gestureRecognizers = <NSArray: 0x28043da10>; layer = <UIWindowLayer: 0x280af58a0>>"Copy the code

    It is also possible to obtain the value of other attributes of this object as a memory address:

    cy# #0x10a65b610.rootViewController
    #"<NMRootNavigationController: 0x10a8cd400>"
    Copy the code

Five,ObjectiveC.classesGet all loaded OC classes

  • Objectivec. classes: You can think of it as listing all the.h headers or class objects, which lists all the classes that are currently loaded.

    Cy# objectivec.classes {// System classes __NSGenericDeallocHandler:__NSGenericDeallocHandler,_NSZombie_:_NSZombie_,__NSMessageBuilder:__NSMessageBuilder,..... // Custom class RMLog:RMLog,NMSearchShowCell,NMSearchPlaylistCell:NMSearchPlaylistCell,NMDjRadioPurchaseProgramCell:NMDjRadioPurchasePro gramCell,...... }Copy the code

    So iOS knows what it means, it’s all class names, custom classes, cells, things like that.

View all member variables of the object

  • It is often necessary later to know what member variables or attributes are in an object.

  • Just add an asterisk (*) before the object, for example: *UIApp:

    cy# *UIApp {isa:NSKVONotifying_NMApplication,_hasOverrideClient:0,_hasOverrideHost:0,_hasInputAssistantItem:0,_delegate:#"<NMAppDel egate: 0x2838b2010>",_event:#"<UIEvent: 0x2804cdce0>",_motionEvent:#"<UIMotionEvent: 0x2831b4d00> timestamp: 0 subtype: 0",_remoteControlEvent:#"<UIRemoteControlEvent: 0x28149b1c0>",_remoteControlEventObservers:1,_topLevelNibObjects:null,_networkResourcesCurrentlyLoadingCount:0,_hideNetw orkActivityIndicatorTimer:null,_editAlertController:null,_statusBar:#"<UIStatusBar: 0x10a863800; frame = (0 0; 20 320); opaque = NO; autoresize = W+BM; layer = <CALayer: 0x280a8ab20>>",_statusBarRequestedStyle:0,_statusBarWindow:#"<UIStatusBarWindow: 0x10a6561d0; frame = (0 0; 320, 568); opaque = NO; gestureRecognizers = <NSArray: 0x280438930>; . }Copy the code

    All of these attributes are separated by commas, and each comma is a member variable.

    Pick one out, such as a proxy property, preceded by the property name and followed by the value.

    _delegate:#"<NMAppDelegate: 0x2838b2010>"
    Copy the code

Seven, recursive printingViewAll child controls of

  • In iOS development, it is possible to recursively output all child controls of a given view in the form of a Po after the console LLDB break point.

    • grammarpo [self.view.window recursiveDescription]
    (lldb) po [self.view.window recursiveDescription] <UIWindow: 0x7f9f8b618460; frame = (0 0; 375, 667); gestureRecognizers = <NSArray: 0x60000077a1c0>; layer = <UIWindowLayer: 0x600000926de0>> | <UITransitionView: 0x7f9f8b719630; frame = (0 0; 375, 667); autoresize = W+H; layer = <CALayer: 0x60000093b300>> | | <UIDropShadowView: 0x7f9f8b71a060; frame = (0 0; 375, 667); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x60000093b280>> | | | <UIView: 0x7f9f8b719ef0; frame = (0 0; 375, 667); autoresize = W+H; layer = <CALayer: 0x60000093b2c0>> <UIWindow: 0x7f9f8b618460; frame = (0 0; 375, 667); gestureRecognizers = <NSArray: 0x60000077a1c0>; layer = <UIWindowLayer: 0x600000926de0>> | <UITransitionView: 0x7f9f8b719630; frame = (0 0; 375, 667); autoresize = W+H; layer = <CALayer: 0x60000093b300>> | | <UIDropShadowView: 0x7f9f8b71a060; frame = (0 0; 375, 667); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x60000093b280>> | | | <UIView: 0x7f9f8b719ef0; frame = (0 0; 375, 667); autoresize = W+H; layer = <CALayer: 0x60000093b2c0>>Copy the code

  • Recursively outputs child controls in Cycript using recursiveDescription.

    cy# [UIApp.keyWindow recursiveDescription]
    ......
    Copy the code
    cy# [UIApp.keyWindow recursiveDescription].toString()
    ......
    Copy the code

    Because the output is too much I will not post, as above in iOS, layer by layer listed. One is to recursively list all the child controls, one is to list the child controls into a string output, there is no difference between the two, is the difference in typography, can be.

Seven,chooseDeletes and selects an object of the specified type

  • Specify a class that is equal to or inherits from that class. Only those loaded into the cache will be listed.

  • For example, UIViewController, which is currently loaded into the cache is inherited or directly used by UIViewController.

    cy# choose(UIViewController)
    Copy the code

    Output:

    [#"<NMVoiceHomeViewController: 0x11a400200>",#"<NMSettingTabViewController: 0x11a404020>",#"<NMSingTabViewController: 0x11a407540>",#"<NMContainerViewController: 0x11a409ce0>",#"<NMContainerViewController: 0x11a414d60>",#"<NMMainViewController: 0x10a6d8780>",#"<NMContainerViewController: 0x10a5f5220>",#"<NMMineTabViewController: 0x10a5f6910>",#"<NMContainerViewController: 0x11a519390>",#"<NMContainerViewController: 0x11a52f3f0>",#"<NMTabBarController: 0x10b946000>",#"<NMNavigationController: 0x10b9a7000>",#"<NMNavigationController: 0x10b9cc400>",#"<NMNavigationController: 0x10b9d6c00>",#"<NMNavigationController: 0x10b9e0200>",#"<NMNavigationController: 0x10b9ea600>",#"<NMNavigationController: 0x10a83f400>",#"<NMRootNavigationController: 0x10a8cd400>",#"<NMNavigationController: 0x10a8e7200>",#"<NMNavigationController: 0x10a912a00>",#"<NMNavigationController: 0x10a919c00>",#"<NMNavigationController: 0x10a975800>"]

    These are the controllers that the current software has loaded into the cache and are inherited or equal to UIViewController

    Empty array if none, and debug mode if output crashes:

    cy# choose(UITableViewCell)
    []
    Copy the code
  • For example: Get the controller that is currently being displayed. This can be used in conjunction with the above property acquisition method and the iOS development controller acquisition method.

  • We will write a script that encapsulates this, after all, it will be very convenient to find the current controller, so that we know which file can be adjusted.