Skip to content

Instantly share code, notes, and snippets.

@bumaociyuan
Forked from susnmos/common.cy
Last active September 30, 2018 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumaociyuan/e777202a92b28382588ae4e8a83c1c68 to your computer and use it in GitHub Desktop.
Save bumaociyuan/e777202a92b28382588ae4e8a83c1c68 to your computer and use it in GitHub Desktop.
A script for cycript
(function(exports) {
// 打印按钮的action及其target
zxactionWithTargets = 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;
}
// 打印类的属性
zxtryPrintIvars = function tryPrintIvars(a){ var x={}; for(i in *a){ try{ x[i] = (*a)[i]; } catch(e){} } return x; }
// 打印类的方法
zxprintMethods = 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;
}
// 根据正则匹配需要的方法
zxmethodsMatching = function methodsMatching(cls, regexp) { return [[new Selector(m).type(cls), m] for (m in cls.prototype) if (!regexp || regexp.test(m))]; }
// 替换OC的已有方法
// 打印类的所有子类
zxallSubClass = function allSubClass(className) {
return [c for each (c in ObjectiveC.classes) if (class_getSuperclass(c) && [c isSubclassOfClass:className])]
}
})(exports);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment