简体   繁体   中英

Objective C Method Swizzling using dynamic library

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).

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 (ie -Encrypt: should be -encrypt:).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM