Start iOS app with DYLD_PRINT_STATISTICS=YES

Hi guys. How to pass custom environment variables to iOS UI app?
For example, DYLD_PRINT_STATISTICS=YES

  1. I’ve tried open package from Cydia (com.conradkramer.open):
    root# DYLD_PRINT_STATISTICS=YES open com.facebook.Facebook
    But unfortunately DYLD_PRINT_STATISTICS just prints stats on ‘open’ process itself, not on the com.facebook.Facebook.

  2. Direct launching from terminal is not possible too (returns ‘Killed: 9’)
    root# DYLD_PRINT_STATISTICS=YES /private/var/containers/Bundle/Application/B06C0DE7-57FD-4CB2-8E5D-FC685F0FBB6B/Facebook.app/Facebook

  3. There are SpringBoardServices-functions to launch apps programmatically, like SBSLaunchApplicationWithIdentifier, SBSLaunchApplicationWithIdentifierAndLaunchOptions, SBSLaunchApplicationForDebugging. But they are undocumented and I don’t know how to pass env vars to them (if ever possible).

  4. There is idevicedebug (on the computer side). I tried it too:
    mac$ devicedebug --env DYLD_PRINT_STATISTICS=YES run com.facebook.Facebook
    Out of luck too. It crashes with ERROR: failed to get the task for process 10517. Seems that host-side idevicedebug cannot be used to debug sandboxed and fairpayed apps.

Can anybody help?

From my understanding here, all spawning process is actually a call to POSIX_SPAWN, which is documented and allows you to pass env.

I suggest RE SpringBoard related services to see how SB uses the aforementioned API, and inject a hook there

Of course there are definitely easier methods, however since I have no experience with this, the aforementioned advice is all I have now.

An alternative way would be looking at how MobileSubstrate achieved this. Because MS also works by setting env you should be able to get a hint or two from there

Thank you very much for cool advice! CydiaSubstrate sources are the way to go!