-
-
Save G5t4r/341c4703c34c6314f36d38c5cfdc804a to your computer and use it in GitHub Desktop.
A script for cycript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 打印按钮的action及其target | |
function actionWithTargets(button) { | |
var allTargets = [button allTargets].allObjects(); | |
if (!allTargets) { | |
return "is not a uicontrol" | |
} | |
var allShow = []; | |
for (var i = 0; i < allTargets.length; i++) { | |
var target = allTargets[i]; | |
var actions = [button actionsForTarget: target forControlEvent: UIControlEventTouchUpInside]; | |
allShow.push("actions:" + actions + " target:" + target); | |
} | |
return allShow; | |
} | |
// 打印类的属性 | |
function tryPrintIvars(a){ var x={}; for(i in *a){ try{ x[i] = (*a)[i]; } catch(e){} } return x; } | |
_ivarDescription: Prints all names and values of instance variables of a specified object | |
cy# [#0x5822600 _ivarDescription].toString() | |
// 遍历是否有弹框 | |
function findView(view) | |
{ | |
var sbvs = [view subviews]; | |
var num = [sbvs count]; | |
for (var i = 0; i < num; i++) | |
{ | |
var subview = sbvs[i]; | |
if([subview isKindOfClass:[_UIAlertControllerView class]]) | |
{ | |
return subview; | |
} | |
if([[subview subviews] count]>0) | |
{ | |
return findView(subview); | |
} | |
} | |
return nil; | |
} | |
//findView([UIApplication sharedApplication].keyWindow) | |
function allWin() { | |
return [UIApplication sharedApplication].windows | |
} | |
var allWindows=function () { | |
return allWin() | |
}() | |
function presentedVCForVC(presentedViewController) { | |
if ([presentedViewController isKindOfClass: [UINavigationController class]]) { | |
var topVC = presentedViewController.topViewController; | |
if (topVC.presentedViewController) { | |
return presentedVCForVC(topVC.presentedViewController); | |
} | |
return topVC; | |
} | |
if ([presentedViewController isKindOfClass: [UITabBarController class]]) { | |
var selectedVC = presentedViewController.selectedViewController; | |
return presentedVCForVC(selectedVC); | |
} | |
return presentedViewController; | |
} | |
// 获取对应UIWindow的当前控制器 | |
function currentWithWindow(win) { | |
if (!win.rootViewController) { | |
return "The window hadn't a root viewcontroller"; | |
} | |
return presentedVCForVC(win.rootViewController); | |
} | |
// 打印keyWindow上的当前的控制器 | |
function currentVCWithKeyWindow() { | |
return currentWithWindow([UIApplication sharedApplication].keyWindow) | |
} | |
// 打印类的方法 | |
function printMethods(className, isa) { | |
var count = new new Type("I"); | |
var classObj = (isa != undefined) ? objc_getClass(className).constructor : objc_getClass(className); | |
var methods = class_copyMethodList(classObj, count); | |
var methodsArray = []; | |
for(var i = 0; i < *count; i++) { | |
var method = methods[i]; | |
methodsArray.push({selector:method_getName(method), implementation:method_getImplementation(method)}); | |
} | |
free(methods); | |
return methodsArray; | |
} | |
// 根据正则匹配需要的方法 | |
function methodsMatching(cls, regexp) { return [[new Selector(m).type(cls), m] for (m in cls.prototype) if (!regexp || regexp.test(m))]; } | |
// 替换OC的已有方法 | |
// 打印类的所有子类 | |
function allSubClass(className) { | |
return [c for each (c in ObjectiveC.classes) if (class_getSuperclass(c) && [c isSubclassOfClass:className])] | |
} | |
// 加载framework | |
function loadFramework(fw) { | |
var h="/System/Library/",t="Frameworks/"+fw+".framework"; | |
[[NSBundle bundleWithPath:h+t]||[NSBundle bundleWithPath:h+"Private"+t] load]; | |
} | |
// 或者使用其他方法 | |
// include other .cy files | |
function include(fn) { | |
var t = [new NSTask init]; [t setLaunchPath:@"/usr/bin/cycript"]; [t setArguments:["-c", fn]]; | |
var p = [NSPipe pipe]; [t setStandardOutput:p]; [t launch]; [t waitUntilExit]; | |
var s = [new NSString initWithData:[[p fileHandleForReading] readDataToEndOfFile] encoding:4]; | |
return this.eval(s.toString()); | |
} | |
// CGGeometry | |
function CGPointMake(x, y) { return {0:x, 1:y}; } | |
function CGSizeMake(w, h) { return {0:w, 1:h}; } | |
function CGRectMake(x, y, w, h) { return {0:CGPointMake(x,y), 1:CGSizeMake(w, h)}; } | |
"Added common.cy to \""+NSProcessInfo.processInfo() .processName.toString()+"\" ("+NSProcessInfo.processInfo() .processIdentifier.toString()+")" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
//触发按钮点击事件
[UIButton_obj sendActionsForControlEvents:UIControlEventAllEvents];