使用动态库进行目标C方法混淆 [英] Objective C Method Swizzling using dynamic library

查看:141
本文介绍了使用动态库进行目标C方法混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习方法混乱.我已经在目标C中创建了一个程序,该程序仅在其类中调用一个方法.现在,我正在尝试使用DYLD_INSERT_LIBRARIES加载动态库,以便可以用在动态库中定义的新方法覆盖我的方法实现.目的是修改参数,然后调用原始函数调用.

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.

可以在 http://pastebin.com/a0b3qkgB 上找到程序代码. 有关动态库的代码,请访问 http://pastebin.com/Ndf6VdUt

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

我观察到的是,一旦"if(self == [Encryption class]){"行在动态库中执行,代码将显示类名,然后吐出奇怪的消息. 完成输出:

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.

目标是使用动态库(代码注入)覆盖目标C方法.

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

推荐答案

这是因为两个类具有相同的名称.只需将其重命名为EncryptionDylib或类似名称即可.

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

还要注意,ObjC方法应以小写字母开头,而不是大写字母(即-Encrypt:应为-encrypt:).

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

这篇关于使用动态库进行目标C方法混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆