Skip to content

Instantly share code, notes, and snippets.

@miticollo
Created April 30, 2023 02:48
Show Gist options
  • Save miticollo/9c7a7dd25770669232603ee5fb0d17c1 to your computer and use it in GitHub Desktop.
Save miticollo/9c7a7dd25770669232603ee5fb0d17c1 to your computer and use it in GitHub Desktop.
Python3 script containing a Frida script (as a string) with a child-gating feature, designed to run after device.resume(). Tested on iOS 16.3.1.
#!/usr/bin/env python3
import signal
import sys
import _frida
import frida
from frida.core import Session, Script, Device, ScriptMessage
def signal_handler(sig, frame):
print("Interrupted by Ctrl-C, stopping...")
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
def _on_message(message: ScriptMessage, data):
print(message)
def _on_child_added(child: _frida.Child):
script = None
if 'appex' in child.path:
session: Session = device.attach(child.pid)
script: Script = session.create_script(
"""\
recv('resume', function onMessage(message) {
// Your code to be executed after receiving the 'resume' message
const NSBundle = ObjC.classes.NSBundle;
const NSURL = ObjC.classes.NSURL;
send(NSBundle.bundleWithURL_(NSURL.fileURLWithPath_isDirectory_('/Applications/AppStore.app/', true)).objectForInfoDictionaryKey_('CFBundleIdentifier').toString());
})
"""
)
script.on("message", _on_message)
script.load()
device.resume(child.pid)
if 'appex' in child.path:
script.post({"type": "resume"})
device: Device = frida.get_usb_device()
device.on("child-added", _on_child_added)
device.attach(1).enable_child_gating()
while True:
signal.pause()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment