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

  • Implement a pure virtual method in Objective-C
  • How do I access my Application Delegate's window accessor method from another object?
  • Show method definition/description in Xcode 4
  • Accessing Method from other Classes Objective-C
  • Best method to get text to blink in iPhone OS?
  • Call a macro every time any method is called - Objective C
  • 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).

    Solutions Collect From Internet About “Objective C Method Swizzling using dynamic library”

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