Objective-C Swizzling Method Using Dynamic Library

I am trying to learn the swizzling method. I created a program in a C object that simply calls a method in its class. Now I am trying to load a dynamic library using DYLD_INSERT_LIBRARIES so that I can override the implementation of my method with the new method that is defined in my dynamic library. The goal is to change the argument and then call the original function call.

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

What I noticed, as soon as the line "if (self == [Encryption class]) {" is executed in the dynamic library, the code displays the class name and then spits a strange message. Full 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 what is wrong with the code. Any help would be appreciated.

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

+4
source share
1 answer

This is because both classes have the same name. Just rename the EncryptionDylib file or similar.

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

+1
source

Source: https://habr.com/ru/post/1400636/


All Articles