Ninjaprawn (talk | contribs) (Created the page) |
m (Unnecessary change inconsistent with standard) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
This page is dedicated to the use of the MSHookIvar function, included in | This page is dedicated to the use of the MSHookIvar function, included in [[Cydia Substrate]], to modify instance variables. This function is meant to be used when one can't get an instance variable through instance methods. | ||
== Header definition == | |||
= | <source lang="cpp"> | ||
template <typename Type_> | |||
static inline Type_ &MSHookIvar(id self, const char *name); | |||
</source> | |||
Used like this: | |||
<code>type ivar = MSHookIvar<type>(object, ivar_name);</code> | |||
Where: | |||
# <tt>type</tt> is a primitive type (int, char, struct CGRect, a pointer or a reference to), a C++ class or an Objective-C class (NSObject *, UILabel *). | |||
# <tt>object</tt> is the variable that contains the target instance variable. | |||
# <tt>ivar_name</tt> is a '''C string''', not an Objective-C string (so no @ sign). | |||
== Example usage == | |||
<source lang="logos"> | |||
// Given a private class | |||
@interface SBIconController : NSObject { | |||
SBIconContentView *_contentView; | |||
} | |||
+ (id)sharedInstance; | |||
@end | |||
// In some block of code: | |||
{ | |||
... | |||
SBIconController *iconController = [%c(SBIconController) sharedInstance]; | |||
SBIconContentView *contentView = MSHookIvar<SBIconContentView *>(iconController, "_contentView"); | |||
// Would return the same as [[%c(SBIconController) sharedInstance] contentView]; | |||
... | |||
} | |||
</source> |
Latest revision as of 03:02, 11 April 2016
This page is dedicated to the use of the MSHookIvar function, included in Cydia Substrate, to modify instance variables. This function is meant to be used when one can't get an instance variable through instance methods.
Header definition
template <typename Type_>
static inline Type_ &MSHookIvar(id self, const char *name);
Used like this:
type ivar = MSHookIvar<type>(object, ivar_name);
Where:
- type is a primitive type (int, char, struct CGRect, a pointer or a reference to), a C++ class or an Objective-C class (NSObject *, UILabel *).
- object is the variable that contains the target instance variable.
- ivar_name is a C string, not an Objective-C string (so no @ sign).
Example usage
// Given a private class
@interface SBIconController : NSObject {
SBIconContentView *_contentView;
}
+ (id)sharedInstance;
@end
// In some block of code:
{
...
SBIconController *iconController = [%c(SBIconController) sharedInstance];
SBIconContentView *contentView = MSHookIvar<SBIconContentView *>(iconController, "_contentView");
// Would return the same as [[%c(SBIconController) sharedInstance] contentView];
...
}