1

我正在尝试在使用 Objective-C 制作的应用程序中调整一些方法。我收到此错误:

Symbol not found: _OBJC_CLASS_$_IASAvatarViewController

在 Hopper 中打开可执行文件后,我看到所有类都以前缀objc_class_代替。所以我试图调配的方法的类名是objc_class_IASAvatarViewController. 首先,我很想知道类标识符是如何变成这样的(某种名称修饰?)。其次,我想知道是否可以让我的 dylib 引用正确的标识符。

DylibTest.h:

#import <UIKit/UIKit.h>
#import <objc/runtime.h>

@interface IASBaseViewController : UIViewController

@end

@interface IASAvatarViewController : IASBaseViewController

@end

@interface IASAvatarViewController (Swizzle)

@end

DylibTest.m

#import "DylibTest.h"
#import <dlfcn.h>

@implementation IASAvatarViewController (Swizzle)

+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class class = [self class];

        SEL originalSelector = @selector(viewDidLoad);
        SEL swizzledSelector = @selector(xxx_viewDidLoad);

        Method originalMethod = class_getInstanceMethod(class, originalSelector);
        Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);

        BOOL didAddMethod =
        class_addMethod(class,
                    originalSelector,
                    method_getImplementation(swizzledMethod),
                    method_getTypeEncoding(swizzledMethod));

        if (didAddMethod) {
            class_replaceMethod(class,
                            swizzledSelector,
                            method_getImplementation(originalMethod),
                            method_getTypeEncoding(originalMethod));
        } else {
            method_exchangeImplementations(originalMethod, swizzledMethod);
        }
    });
 }


 - (void)xxx_viewDidLoad {
    [[[UIAlertView alloc] initWithTitle:@"Swizzled method" message:@"Ya swizzle" delegate:nil cancelButtonTitle:@"Yeah. Okay" otherButtonTitles:nil] show];

    [self xxx_viewDidLoad];
 }

 @end

以及带有 Objective-C 类的 Hopper 的屏幕截图: 霍珀的屏幕截图

编辑:获得足够的声誉可以直接发布图片。

Edit2: class-dump文件: http: //pastebin.com/DcUD5AL5

4

0 回答 0