+
+// this highly-general hook replaces all previous attempts to protect SpringBoard from spurious code
+// the main purpose is to protect SpringBoard from non-Substrate "away view plug-ins" and "wee apps"
+
+const char *dylibs_[] = {
+ "/usr/lib",
+ "/System/Library/Frameworks",
+ "/System/Library/PrivateFrameworks",
+ "/System/Library/CoreServices",
+ "/System/Library/AccessibilityBundles",
+ NULL,
+};
+
+MSHook(void *, dlopen, const char *path, int mode) {
+ // we probably don't need this whitelist, but it has the nifty benefit of letting Cycript inject
+ // that said, older versions of iOS (before 3.1) will need a special case due to now shared cache
+
+ for (const char **dylib = dylibs_; *dylib != NULL; ++dylib) {
+ size_t length(strlen(*dylib));
+ if (strncmp(path, *dylib, length) != 0)
+ continue;
+ if (path[length] != '/')
+ continue;
+ goto load;
+ }
+
+ // if the file is not on disk, and isn't already loaded (LC_ID_DYLIB), it is in the shared cache
+ // files loaded from the shared cache are "trusted". ones that don't exist are clearly harmless.
+ // this allows us to load most of the dynamic functionality of SpringBoard without going nuts ;P
+
+ if (access(path, F_OK) == 0)
+ mode |= RTLD_NOLOAD;
+
+ load:
+ return _dlopen(path, mode);
+}
+
+