A list,

  • Every time you debug Cycript, you need to type a lot of debugging instructions, which can be wrapped into a.cy script file and referenced.

  • Once Cycript is installed, there is a Cycript folder on the jailbroken phone, which can be viewed through iFunBox, or through a terminal connected to the phone:

    • iFunBoxTo viewcycriptfolder

    • The terminal connects to the mobile phone to view informationcycriptfolder
    The iPhone: ~ root# CD/usr/lib/cycript0.9 iPhone: / usr/lib/cycript0.9 root# ls com/orgCopy the code
    • The.cy script is stored in the cycript0.9 folder. You can use the remote copy of the script you wrote before, or drag it into the folder using the @import XXX command.

    • This is just a shortcut, but when you have a lot of scripts, it’s better to put them in the com folder. If you open the com folder, that’s where the author keeps his.xy files. You can create a folder to store your.cy files, but the import method is slightly different. You can use this method at the bottom of the article, and you can use the above method for simple tests.

Two, encapsulation cases

  • Create a test.cy file that contains javascript, OC C++… writing

  • Add/subtract methods, attributes, BundleID obtained from OC:

    (function(exports) {
      exports.age = 10;
      exports.sum = function (a, b) {
        return a + b;
      };
      exports.minus = function (a, b) {
        return a - b;
      };
      exports.appID = [NSBundle mainBundle].bundleIdentifier;
      exports.rootVC = function () {
        return UIApp.keyWindow.rootViewController;
      }
    })(exports)
    Copy the code
  • Exports you can understand that it is an object passed in during runtime that you now need to add properties or methods to.

  • Then you can copy it remotely or drag it from iFunBox to the /usr/lib/cycript0.9 folder on your phone

    dengzemiaodeMacBook-Pro:~ dengzemiao$ scp -P 10010 /Users/dengzemiao/Desktop/Project/ios/video/test/test.cy Root @ localhost: / usr/lib/cycript0.9 test. The cy 100% 126 45.1 KB/s 00:00 dengzemiaodeMacBook - Pro: ~ dengzemiao $Copy the code

  • Then go into Cycript debug mode and use it via @import test import

    Dengzemiaodemacbook-pro: SSH Dengzemiao $sh login.sh iPhone:~ root# sycript -p neteasemusic  @import test {age:10,sum:function (t,e){return t+e},minus:function (t,e){return T - e}, appID: @ "com.net help ease. Cloudmusic rootVC: function () {return UIApp. KeyWindow. RootViewController}} / / that introducing the successful, Cy# @import test {} Cy# test.sum(1,2) 3 cy# test.age 10 cy# test.appid @"com.netease.cloudmusic" cy# test.rootvc () #"<NMRootNavigationController: 0x12a97e200>"Copy the code
  • If the following error occurs:

    cy# @import test [1322] _krncall(task_for_pid) =5 [1322] MachObject.cpp[108]: _krncall(task_info) =10000003 [1322] DarwinInjector.cpp[73]: _assert(MSGetTaskInfo(info, task))[DarwinInjector.cpp:73] *** _assert(status == 0):.. /Inject.cpp(143):InjectLibraryCopy the code

    Solution:

    1, delete the imported into the mobile phone before the test. The cy file to import, actually also can not delete directly covered, but after I here cover or cache problems, by removing had to avoid, measuring behind the cover is no problem, may be write wrong, in short not cover will be delete afresh again came to try).

    2. Exit the mobile phone debugging APP and open it again (because you do not restart the APP, the old test.cy may have cache files and cannot be cleared).

    3. Exit Cycript debug mode and re-enter debug mode after the APP is reopened.

    4. Use @import test again.

  • Note: If the script file has been modified, or the script file has a bug adjustment and is re-imported to the phone, you need to follow the above steps.

Global functions and attributes

  • The above are used as object attributes. After the @import test is imported, you need to use the test. XXX method to use it.

  • How to define a global function or property that can be imported without using the point-and-export syntax? Simply write the method or property name.

    (function(exports) {
      age = 10;
      sum = function (a, b) {
        return a + b;
      };
      minus = function (a, b) {
        return a - b;
      };
      appID = [NSBundle mainBundle].bundleIdentifier;
      rootVC = function () {
        return UIApp.keyWindow.rootViewController;
      }
    })(exports)
    Copy the code
    // iPhone:~ root# cycript -p neteasemusic Cy# @import test {} Cy# sum function (t,e){return t+e} cy# sum function (t,e){return t-e} cy# sum function (t,e){return t-e} cy# age 10 cy# appID @"com.netease.cloudmusic"Copy the code
  • If not, delete the test.cy file and import it again. Sometimes cache clearing may be delayed.

4. Save the script filecomDirectories (easier to manage if you have a lot of script files)

  • Cycript0.9 is the root directory for storing scripts in cycript0.9. You can use @import test to import scripts in cycript0.9.

    • Previous path:Cycript0.9 > test. Cy
    • Now path:Cycript0.9 > com > DZM > test.cy
  • Create the DZM folder under /usr/lib/cycript0.9/com on the cli of the mobile phone or iFunBox.

    The iPhone: ~ root# CD/usr/lib/cycript0.9 / com iPhone: / usr/lib/cycript0.9 / com root# mkdir DZM iPhone: / usr/lib/cycript0.9 / com root# ls dzm/ saurik/Copy the code

  • PC upload command will need to adjust the path, before is/usr/lib/cycript0.9 folder, now need to switch to/usr/lib/cycript0.9 / com/DZM:

    $SCP - 10010 P/Users/dengzemiao/Desktop/Project/ios/video/test/test. The cy root @ localhost: / usr/lib/cycript0.9 / com/DZMCopy the code
  • @import com.dzm.test: @import com.dzm.test:

    ~ root# cycript -p neteasemusic // Import the script cy# @import com.dzm.test {} // Use the same cy# appID as before @"com.netease.cloudmusic" cy# age 10 cy#Copy the code

    Cycript0.9 uses @import test as a root directory. Now, in /com/dzm/test.cy, you only need to cache. Just connect @import com.dzm.test.

  • DZMCycript script (encapsulate the common shortcut functions, will be added later)