def apps(device: frida.core.Device) -> list: props = ['identifier', 'name', 'pid'] def fmt(app): return '%s-%s' % (device.id, app.pid or app.identifier) wrap = info_wrap(props, fmt) try: apps = device.enumerate_applications(scope='full') except TypeError: raise RuntimeError( 'Your frida python package is out of date. Please upgrade it') except frida.TransportError: apps = device.enumerate_applications() return [wrap(app) for app in apps]
def apps(device: frida.core.Device) -> list: props = ['identifier', 'name', 'pid'] def wrap(app): obj = {prop: getattr(app, prop) for prop in props} obj['largeIcon'] = png.to_uri(app.get_large_icon()) obj['smallIcon'] = png.to_uri(app.get_small_icon()) return obj return [wrap(app) for app in device.enumerate_applications()]
def spawn_or_attach(device: frida.core.Device, bundle: str) -> frida.core.Session: try: app = next(app for app in device.enumerate_applications() if app.identifier == bundle) except StopIteration: raise ValueError('app "%s" not found' % bundle) if app.pid > 0: front = device.get_frontmost_application() if front and front.identifier == bundle: return device.attach(app.pid) raise RuntimeError( 'Unable to attach to "%s"(%d) as it is a background app.' % (bundle, app.pid)) devtype = device_type(device) if devtype == 'Android': module = 'libc.so' elif devtype == 'iOS': module = 'Foundation' else: raise RuntimeError('Unknown device type %s' % devtype) source = 'Module.ensureInitialized("%s"); rpc.exports.ok = function() { return true }' % module pid = device.spawn(bundle) session = device.attach(pid) device.resume(pid) script = session.create_script(source) script.load() MAX_RETRY = 5 for i in range(MAX_RETRY): try: time.sleep(0.2) if script.exports.ok(): break except: continue else: raise RuntimeError('Unable to create process') script.unload() return session