https://github.com/leptos-null/loadorder
Understanding the load order of binaries with DYLD_INSERT_LIBRARIES
https://github.com/leptos-null/loadorder
darwin dyld mach-o macho
Last synced: 4 months ago
JSON representation
Understanding the load order of binaries with DYLD_INSERT_LIBRARIES
- Host: GitHub
- URL: https://github.com/leptos-null/loadorder
- Owner: leptos-null
- License: cc-by-4.0
- Created: 2018-08-23T22:35:36.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-17T21:28:56.000Z (over 6 years ago)
- Last Synced: 2025-01-19T17:24:11.728Z (5 months ago)
- Topics: darwin, dyld, mach-o, macho
- Language: Objective-C
- Size: 21.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## LoadOrder
When writing tweaks, it's important to understand "the order of initialization." Apple describes the order in the [+[NSObject load] documentation](https://developer.apple.com/documentation/objectivec/nsobject/1418815-load?language=objc).
This project includes an app, a framework linked against by the app, and a library loaded by [Substrate](http://www.cydiasubstrate.com). Each function and method is logged to `stdout`. The output is below:
```txt
+[LSTweakClass load]
void tweakConstructor()
+[LSFrameworkClass load]
void frameworkConstructor()
+[LSAppDelegate load]
void appConstructor()
int main(int, char **)
+[LSFrameworkClass initialize]
+[LSFrameworkClass exampleCallMeFromMain]
+[LSAppDelegate initialize]
```MobileSubstrate uses the `DYLD_INSERT_LIBRARIES` enviornment variable (more information availible in [dyld(1)](https://www.freebsd.org/cgi/man.cgi?query=dyld&apropos=0&sektion=0&manpath=Darwin+8.0.1%2Fppc&format=html)) to load itself into processes (which subsequently `dlopen(lib, RTLD_NOW)`s other libraries). The above output shows that libraries listed in `DYLD_INSERT_LIBRARIES` are initialized before the process that it's set for.
### Interesting Reading
[Blocking Code Injection on iOS and OS X](https://pewpewthespells.com/blog/blocking_code_injection_on_ios_and_os_x.html) ([mirror](./blocking_code_injection_on_ios_and_os_x.md))