目录
-
- 获取对象(Getting objects)
- 获取成员变量(Getting ivars)
- 获取 BundleID(Getting bundle identifier)
- 获取方法(Getting methods)
- 列出所有子类(List all subclasses)
- 加载框架(Load frameworks)
- 包含其他 Cycript 文件(Include other Cycript files)
- 使用 NSLog(Using NSLog)
- 使用 CGGeometry 函数(Using CGGeometry functions)
- 使用 NSError(Using NSError)
- 将 Cycript 的输出写入到文件中(Writing Cycript output to file)
- 打印视图层级结构(Printing view hierarchy)
- Cycript 脚本(Cycript scripts)
- 基于 Cycript class-dump 的弱类转储
- 实用工具(Utils)
获取对象(Getting objects)
-
使用 choose 函数获取 Objective-C 对象(Objective-C objects using choose)
在 Cycript
0.9.502版本中引入并在此处记录的choose()函数,允许我们获取某个类所有的现有对象的数组
(hcg 注:简单地说,就是在内存的堆空间中查找指定的类及其子类的所有实例对象) -
使用地址获取 Objective-C 对象(Objective-C objects from addresses)
cy# var p = #0x8614390 cy# p ["<SKPaymentTransaction: 0x8613d80>"] -
获取 Javascript 变量(Javascript variables)
// 需要测试 cy# typedef int a; cy# for (x in this) if (x == 'a') system.print('yay');
获取成员变量(Getting ivars)
通常,只需要输入 *varName 即可:
cy# *controller
{
isa:"PrefsRootController",_contentView:"<UIView: 0x10bd70; frame = (0 0; 320 460); autoresize = W+H; layer = <CALayer: 0x150120>>",_navBar:...
有时,*varName 会不起作用:
cy# *UIApp
{
message:"hasProperty callback returned true for a property that doesn't exist.",name:"ReferenceError"}
此时,你可以这样做:
cy# [i for (i in *UIApp)]
["isa","_delegate","_touchMap","_exclusiveTouchWindows","_event",...
你也可以使用下面的 tryPrintIvars 函数获取尽可能多的成员变量以及它们的值:
function tryPrintIvars(a){
var x={
}; for(i in *a){
try{
x[i] = (*a)[i]; } catch(e){
} } return x; }
// 上面的代码经过整理后,如下所示:
function tryPrintIvars(a) {
var x={
};
for(i in *a) {
try {
x[i] = (*a)[i]; }
catch(e) {
}
}
return x;
}
tryPrintIvars 函数的使用示例:
cy# *a
{
message:"hasProperty callback returned true for a property that doesn't exist.",name:"ReferenceError"}
cy# tryPrintIvars(a)
{
isa:"SBWaveView",_layer:"<CALayer: 0x2a5160>",_tapInfo:null,_gestureInfo:null,_gestureRecognizers:...
获取 BundleID(Getting bundle identifier)
NSBundle.mainBundle.bundleIdentifier
获取方法(Getting methods)
下面的 printMethods 函数用于获取方法:
// @param.className 类名
// @param.isa 如果为 undefined,则打印对象方法。否则,打印类方法
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;
}
printMethods 函数的使用示例:
cy# printMethods("MailboxPrefsTableCell")
[{
selector:@selector(layoutSubviews),implementation:0x302bf2e9},{
selector:@selector(setCurrentMailbox:),implementation:0x302bee0d},...
你也可以只查看 isa 的 prototype 属性。例如,获取 rootViewController 的方法:
UIApp.keyWindow.rootViewController.isa.prototype
-
获取名称与特定正则表达式匹配的方法(Get methods matching particular RegExp)
function methodsMatching(cls, regexp) { return [[new Selector(m).type(cls), m] for (m in cls.prototype) if (!regexp || regexp.test(m))]; }// 上面的代码经过整理后,如下所示: function methodsMatching(cls, regexp) { return [ [new Selector(m).type(cls), m] for (m in cls.prototype) if (!regexp || regexp.test

本文详细介绍了Cycript中的关键功能,如获取Objective-C对象、成员变量操作、Bundle ID获取、方法查找、子类列举、框架加载、文件包含、NSLog使用等,是深入理解Cycript的强大工具指南。
最低0.47元/天 解锁文章
880

被折叠的 条评论
为什么被折叠?



