Download and execute iOS code dynamically at runtime

独自空忆成欢 提交于 2019-12-05 01:19:07

问题


As an academic and mental exercise, how would one download a precompiled binary file and execute methods in it on an iOS device?

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.

Goal

  • Download http://someexample.com/MyCoolBinary.a
  • Save downloaded binary to device disk.
  • Call a known method that exists in the binary.

What I've tried

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)

Any examples or pointers on what kind of libraries this would work with would be appreciated.
Thanks.


回答1:


Try something like

void *uikit = dlopen("path_to_dylib", RTLD_LAZY);
id (*FunctionName)(id) = dlsym(uikit, "FunctionName");
FunctionName(arg1);
dlclose(uikit);

For more information you can read about dynamic loading here: http://en.wikipedia.org/wiki/Dynamic_loading



来源:https://stackoverflow.com/questions/23187911/download-and-execute-ios-code-dynamically-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!