我想获取一个类中的某个成员变量,但是它没有声明成属性,那该如何获取这个成员变量呢????求教大神!
取变量偏移然后强转
(id*)(isa+py)
MSHookIvar
什么意思啊。。。能说详细点吗,新手不太懂啊
取不到偏移量。。。我lldb和debugservicer一直不能成功
#import <substrate.h> // necessary
#import <Foundation/Foundation.h>
@interface TheClassYouAreHooking : NSObject {
NSString *_exampleVariable;
}
- (void)doSomething;
@end
NSString *_exampleVariableHooked;
%hook TheClassYouAreHooking
- (void)doSomething
{
// 'Hook' the variable
exampleVariableHooked = MSHookIvar<NSString *>(self, "_exampleVariable");
// The name of the hooked variable does not need to be the same
exampleVariableHooked = @"Hello World";
// You can do ANYTHING with the object Eg. [exampleVariableHooked release];
}
%end
找到了 ,好用,已经获取到了。 多谢 !!!
楼主,这…用KVC也可以存取吧。