Search code examples
objective-ciospropertieshookcydia

What names are generated for property ivars without explicit declarations?


This question is related to hooking with Mobile Substrate, but as long as you know Objective-C you probably can help.

I've got this class that I dumped from UIKit. Here is a piece of it:

@interface UIStatusBarItem : NSObject {
     int _type;
}
@property(nonatomic, readonly, retain) int type;
@property(nonatomic, readonly, retain) int leftOrder;
@property(nonatomic, readonly, retain) int rightOrder;
@property(nonatomic, readonly, retain) int priority;

...

@end

Naturally, if i wanted to set int type to, for example, 16, I would do:

MSHookIvar<int>(self, "_type") = 16;

From then on, [self type] will return 16. This much I know.

My problem is that I don't know what the compiler "names" the int where the values for int leftOrder, int rightOrder, and int priority are stored. I tried:

MSHookIvar<int>(self, "leftOrder")

but that's incorrect and crashes the phone. All I really need to know is how these variables are auto-named if you don't specify it yourself. Thanks

Also, I hate to sound like a prick, but please don't respond with just "don't do this, it's not safe." I know it's not, and that's why most of my products are in Cydia and not the App Store =P


Solution

  • The backing ivars are typically named the same as the property. Without more details, I've no idea why that crashed. You can check at runtime what the names are, using property_getAttributes from the Objective C runtime (having used class_copyPropertyList to get the properties from a class).

    Also, not to sound too prickish myself, even in Cydia you shouldn't do fundamentally unsafe things. Software reliability for users is as important in a 3rd party app store as it is in the official one.