I'm trying to swizzle some methods in an application made with Objective-C. I'm getting this error:
Symbol not found: _OBJC_CLASS_$_IASAvatarViewController
After opening the executable in Hopper, I see that all of the classes are prefixed with objc_class_
instead. So the class name of the method I'm trying to swizzle is objc_class_IASAvatarViewController
. First off, I'm dying to know how the class identifiers have turned out that way (some sort of name mangling?). And second, I'd like to know if it's possible to have my dylib reference the correct identifier.
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
And a screen shot of Hopper with the Objective-C classes:
Edit: Got enough reputation to directly post image.
Edit2: class-dump
of the file: http://pastebin.com/DcUD5AL5