在运行时动态下载并执行iOS代码 [英] Download and execute iOS code dynamically at runtime
问题描述
作为学术和心理练习,如何在iOS设备上下载预编译的二进制文件并在其中执行方法?
As an academic and mental exercise, how would one download a precompiled binary file and execute methods in it on an iOS device?
据我所知,这违反了Apple的许可协议第3.2.2节,但我要求提供个人项目并了解有关iOS运行时的更多信息。
I understand this violates Apple's License Agreement, section 3.2.2, but I am asking for personal projects and to learn more about the iOS runtime.
目标
- 下载 http://someexample.com/MyCoolBinary.a
- 将下载的二进制文件保存到设备磁盘。
- 调用二进制文件中存在的已知方法。
我是什么已经尝试了
我没有尝试任何具体的东西,但我想可以按照......的方式做一些事情。 p>
I haven't attempted anything concrete, but I would imagine that it would be possible to do something along the lines of...
void *myDownloadedLibrary = dlopen("/path/to/newly/downloaded/framework/MyCoolBinary.framework")
dlsym(myDownloadedLibrary)
任何关于哪种库可以使用的示例或指针都将不胜感激。< br>
谢谢。
Any examples or pointers on what kind of libraries this would work with would be appreciated.
Thanks.
推荐答案
尝试类似
void *uikit = dlopen("path_to_dylib", RTLD_LAZY);
id (*FunctionName)(id) = dlsym(uikit, "FunctionName");
FunctionName(arg1);
dlclose(uikit);
有关详细信息,请参阅此处的动态加载:
http://en.wikipedia.org/wiki/Dynamic_loading
For more information you can read about dynamic loading here: http://en.wikipedia.org/wiki/Dynamic_loading
这篇关于在运行时动态下载并执行iOS代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!