When writing tweaks, it's important to understand "the order of initialization." Apple describes the order in the +[NSObject load] documentation.
This project includes an app, a framework linked against by the app, and a library loaded by Substrate. Each function and method is logged to stdout
. The output is below:
+[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)) 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.