求助!如何获取某各类的成员变量???直接访问是null,急急急!

我想获取一个类中的某个成员变量,但是它没有声明成属性,那该如何获取这个成员变量呢????求教大神!

我对应的头文件是这样的:Tweak.xm里面这样引用:

取变量偏移然后强转

(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也可以存取吧。