Objective C Method Swizzling using dynamic library

有些话、适合烂在心里 提交于 2019-12-06 04:14:29

问题


I am trying to learn method swizzling. I have created a program in objective C which just calls a method within its class. Now my I am trying to load a dynamic library using DYLD_INSERT_LIBRARIES so I can override my method implementation with new method which is defined in my dynamic library. The aim is to modify the argument and then call the original function call.

Program code is available at http://pastebin.com/a0b3qkgB The code for dynamic library is available at http://pastebin.com/Ndf6VdUt

What I have observed that as soon as line "if (self == [Encryption class]) {" gets executed in dynamic library, the code display the class name and then spit weird message. Complete Output:

Test-IPhone:~ root# DYLD_INSERT_LIBRARIES="./evil7.dylib" ./new
objc[324]: Class Encryption is implemented in both /private/var/root/evil7.dylib and /private/var/root/./new. One of the two will be used. Which one is undefined.
Inside load function
objc[324]: Encryption: 
Trace/BPT trap

I am not sure whats wrong with the code. Any help would be appreciated.

The objective is to override objective C methods using dynamic library (code Injection).


回答1:


This is because both classes have the same name. Simply rename the one to be EncryptionDylib, or similar.

Also note that ObjC methods should start with a lowercase letter, not an uppercase (i.e. -Encrypt: should be -encrypt:).



来源:https://stackoverflow.com/questions/9638815/objective-c-method-swizzling-using-dynamic-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!