各位大佬,Swift 可否逆向?

最近在开发中需要 hook 一下某个功能,发现是这样的:
image

一看就知道这个是 Swift 写的,应该如何 hook呢?

求大佬们指导??

这个主题类似:How to hook the swift functions by theos?

%hook ViewController

- (void)viewDidLoad {
    %orig;
    NSLog(@"VIEW DID LOAD");
}

%end

%ctor {
    %init(ViewController = objc_getClass("HookExampleApp.ViewController"));
}

static void (*orig_ViewController_randomFunction)(void) = NULL;

void hook_ViewController_randomFunction() {
   orig_ViewController_randomFunction();
   NSLog(@"Hooked random function");
}

%ctor {
    %init(ViewController = objc_getClass("HookExampleApp.ViewController"));
    MSHookFunction(MSFindSymbol(NULL, "__T014HookExampleApp14ViewControllerC14randomFunctionyyF"),
                   (void*)hook_ViewController_randomFunction,
                   (void**)&orig_ViewController_randomFunction);
}


getImplementation
setImplementation

6 个赞

这个是 DEBUG 模式吧,貌似在 RELEASE 模式就不行了。

我还发现使用真机的 RELEASE 模式下的调试,与从 App Store 下载的 Mach-O 文件中的符号,都是不一样的。很是费解…

Swift 符号重整之后 上App Store会strip

灭有符号你就按sub__来hook囖