Cycript Tricks

From iPhone Development Wiki
Revision as of 01:50, 3 November 2009 by Kimcha (talk | contribs)

Printing Ivars

Often just typing *varName works:

cy# *controller
{isa:"PrefsRootController",_contentView:"<UIView: 0x10bd70; frame = (0 0; 320 460); autoresize = W+H; layer = <CALayer: 0x150120>>",_navBar:...
cy#

Sometimes it does not...

cy# *UIApp
{message:"hasProperty callback returned true for a property that doesn't exist.",name:"ReferenceError"}

then you can do:

cy# [i for (i in *UIApp)]
["isa","_delegate","_touchMap","_exclusiveTouchWindows","_event",...

You may use this function to get as much ivar values as possible:

function tryPrintIvars(a){ var x={}; for(i in *a){ try{ x[i] = (*a)[i]; } catch(e){} } return x; }

To use:

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:...


Printing Methods

Function to get the methods:

function printMethods(className) { var count = new new Type("I"); var theClass = objc_getClass(className); var methods = class_copyMethodList(theClass, count); var methodsArray = []; for(var i = 0; i < *count; i++) { var method = methods[i]; var methodDict = {}; methodDict['selector'] = method_getName(method); methodDict['implementation'] =  method_getImplementation(method); methodsArray[i] = methodDict; } return methodsArray; }


cy# printMethods("MailboxPrefsTableCell")

[{selector:@selector(layoutSubviews),implementation:0x302bf2e9},{selector:@selector(setCurrentMailbox:),implementation:0x302bee0d},{selector:@selector(setEnabled:),implementation:0x302beead},{selector:@selector(dealloc),implementation:0x302bef2d},{selector:@selector(setMailbox:),implementation:0x302bf179},{selector:@selector(setMailboxType:),implementation:0x302bf26d},{selector:@selector(_setupMailboxIconForImage:),implementation:0x302bef89},{selector:@selector(initWithStyle:reuseIdentifier:),implementation:0x302bf021}]

cy# 


Making vars point to objects

var x = new Instance(0xdeadbabe)

cy# var p = new Instance(0x8614390)
cy# p
["<SKPaymentTransaction: 0x8613d80>"]