├── README.md ├── LICENSE ├── md.cy └── MS.cy /README.md: -------------------------------------------------------------------------------- 1 | # MDCycript 2 | cycript demo for MonkeyDev 3 | 4 | [通过MonkeyDev加载网络或者自己的cy脚本](http://www.alonemonkey.com/2018/04/20/monkeydev-cycript/) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Alone_Monkey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /md.cy: -------------------------------------------------------------------------------- 1 | (function(utils) { 2 | 3 | utils.constants = { 4 | APPID: NSBundle.mainBundle.bundleIdentifier, 5 | APPPATH: NSBundle.mainBundle.bundlePath, 6 | APPHOME: NSHomeDirectory(), 7 | APPDOC: NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0], 8 | APPLIBRARY: NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0], 9 | APPCACHE: NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0] 10 | }; 11 | 12 | utils.pviews = function(){ 13 | return UIApp.keyWindow.recursiveDescription().toString(); 14 | }; 15 | 16 | utils.pvcs = function(){ 17 | return UIWindow.keyWindow().rootViewController._printHierarchy().toString(); 18 | }; 19 | 20 | utils.rp = function(target){ 21 | var result = "" + target.toString(); 22 | while(target.nextResponder){ 23 | result += "\n" + target.nextResponder.toString(); 24 | target = target.nextResponder; 25 | } 26 | return result; 27 | }; 28 | 29 | utils.pactions = function(target){ 30 | var result = ''; 31 | var objs = target.allTargets.allObjects(); 32 | for(var i = 0; i < objs.length; i++){ 33 | var actions = [target actionsForTarget:objs[i] forControlEvent:0]; 34 | result += objs[i] + " " + [actions componentsJoinedByString:@","]; 35 | } 36 | return result; 37 | } 38 | 39 | for(var k in utils.constants) { 40 | Cycript.all[k] = utils.constants[k]; 41 | } 42 | 43 | for(var k in utils) { 44 | if(utils.hasOwnProperty(k)) { 45 | var f = utils[k]; 46 | if(typeof f === 'function') { 47 | Cycript.all[k] = f; 48 | } 49 | } 50 | } 51 | })(exports); 52 | -------------------------------------------------------------------------------- /MS.cy: -------------------------------------------------------------------------------- 1 | /* Cydia Substrate - Powerful Code Insertion Platform 2 | * Copyright (C) 2008-2015 Jay Freeman (saurik) 3 | */ 4 | 5 | (function(ms) { 6 | 7 | let GetLibraryPath = function() { 8 | let handle = dlopen(NULL, RTLD_NOLOAD); 9 | if (handle == null) 10 | return null; 11 | 12 | try { 13 | let CYListenServer = dlsym(handle, "CYListenServer"); 14 | if (CYListenServer == null) 15 | return null; 16 | 17 | let info = new Dl_info; 18 | if (dladdr(CYListenServer, info) == 0) 19 | return null; 20 | 21 | let path = info->dli_fname; 22 | let slash = path.lastIndexOf('/'); 23 | if (slash == -1) 24 | return null; 25 | 26 | path = path.substr(0, slash); 27 | 28 | GetLibraryPath = function() { 29 | return path; 30 | }; 31 | 32 | return GetLibraryPath(); 33 | } finally { 34 | dlclose(handle); 35 | } 36 | }; 37 | 38 | var libcycript = dlopen(GetLibraryPath() + "/libcycript.dylib", RTLD_NOLOAD); 39 | if (libcycript == null) { 40 | return; 41 | } 42 | 43 | var libsubstrate = dlopen(GetLibraryPath() + "/libsubstrate.dylib", RTLD_GLOBAL | RTLD_LAZY); 44 | if (libsubstrate == null) { 45 | return; 46 | } 47 | 48 | extern "C" void *MSGetImageByName(const char *); 49 | extern "C" void *MSFindSymbol(void *, const char *); 50 | extern "C" void MSHookFunction(void *, void *, void **); 51 | extern "C" void MSHookMessageEx(Class, SEL, void *, void **); 52 | 53 | var slice = Array.prototype.slice; 54 | 55 | ms.HookFunction = function(func, hook, old) { 56 | var type = typeid(func); 57 | 58 | var pointer; 59 | if (old == null || typeof old === "undefined") 60 | pointer = null; 61 | else { 62 | pointer = new (typedef void **); 63 | *old = function() { return type(*pointer).apply(null, arguments); }; 64 | } 65 | 66 | MSHookFunction(func.valueOf(), type(hook), pointer); 67 | }; 68 | 69 | ms.HookMessage = function(isa, sel, imp, old) { 70 | var type = sel.type(isa); 71 | 72 | var pointer; 73 | if (old == null || typeof old === "undefined") 74 | pointer = null; 75 | else { 76 | pointer = new (typedef void **); 77 | *old = function() { return type(*pointer).apply(null, [this, sel].concat(slice.call(arguments))); }; 78 | } 79 | 80 | MSHookMessageEx(isa, sel, type(function(self, sel) { return imp.apply(self, slice.call(arguments, 2)); }), pointer); 81 | }; 82 | 83 | for(var k in ms) { 84 | if(ms.hasOwnProperty(k)) { 85 | var f = ms[k]; 86 | if(typeof f === 'function') { 87 | Cycript.all[k] = f; 88 | } 89 | } 90 | } 91 | 92 | })(exports); 93 | --------------------------------------------------------------------------------