本文整理汇总了Python中frida.get_device方法的典型用法代码示例。如果您正苦于以下问题:Python frida.get_device方法的具体用法?Python frida.get_device怎么用?Python frida.get_device使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类frida
的用法示例。
在下文中一共展示了frida.get_device方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def start(self):
'''
Attach or spawn to an application with Frida
:return:
'''
logging.debug("Frida:start()")
device = frida.get_device(self.device.device_id)
spawn = self.configuration.getboolean('spawn_app')
if (spawn):
pid = device.spawn([self.module.application.package])
session = device.attach(pid)
else:
pid = device.get_process(self.module.application.package).pid
session = device.attach(pid)
self.script = session.create_script(open(f"{dirname}frida_scripts/_agent.js").read())
self.script.on('message', self.on_message)
self.script.load()
if (spawn):
device.resume(pid)
示例2: connect
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def connect(self):
"""Connect to Frida Server."""
session = None
try:
env = Environment()
self.clean_up()
env.run_frida_server()
device = frida.get_device(get_device(), settings.FRIDA_TIMEOUT)
pid = device.spawn([self.package])
device.resume(pid)
logger.info('Spawning %s', self.package)
time.sleep(2)
session = device.attach(pid)
except frida.ServerNotRunningError:
logger.warning('Frida server is not running')
self.connect()
except frida.TimedOutError:
logger.error('Timed out while waiting for device to appear')
except (frida.ProcessNotFoundError,
frida.TransportError,
frida.InvalidOperationError):
pass
except Exception:
logger.exception('Error Connecting to Frida')
try:
if session:
script = session.create_script(self.get_script())
script.on('message', self.frida_response)
script.load()
sys.stdin.read()
script.unload()
session.detach()
except Exception:
logger.exception('Error Connecting to Frida')
示例3: _update_device
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def _update_device(self, device_id):
try:
self.device = frida.get_device(device_id)
self.proc_list.device = self.device
self.spawn_list.device = self.device
except frida.TimedOutError:
self.device = None
except frida.InvalidArgumentError:
self.device = None
示例4: _on_device_changed
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def _on_device_changed(self, index):
device = None
device_id = self._devices_combobox.itemData(index)
if device_id:
try:
device = frida.get_device(device_id)
except:
return
if device:
self._device_id = device.id
self._check_device(device)
self.onDeviceChanged.emit(self._device_id)
示例5: _on_devices_finished
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def _on_devices_finished(self):
if self._devices:
if len(self._devices) > 1:
self._devices_combobox.clear()
self._devices_combobox.setVisible(True)
self.update_label.setText('Please select the Device: ')
for device in self._devices:
self._devices_combobox.addItem(device['name'], device['id'])
else:
self._devices_combobox.setVisible(False)
try:
device = frida.get_device(self._devices[0]['id'])
self._check_device(device)
except:
pass
示例6: start
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def start(self, args):
self.dwarf.onScriptDestroyed.connect(self.stop)
if not args.device:
self.dwarf.device = self.frida_device
else:
self.dwarf.device = frida.get_device(id=args.device)
if args.any == '':
self._device_window.onSelectedProcess.connect(self._on_proc_selected)
self._device_window.onSpawnSelected.connect(self._on_spawn_selected)
self._device_window.onClosed.connect(self._on_device_dialog_closed)
self._device_window.show()
else:
if args.pid > 0:
print('* Trying to attach to {0}'.format(args.pid))
try:
self.dwarf.attach(args.pid, args.script, False)
print('* Dwarf attached to {0}'.format(args.pid))
except Exception as e: # pylint: disable=broad-except
print('-failed-')
print('Reason: ' + str(e))
print('Help: you can use -sp to force spawn')
self.stop()
exit(0)
else:
print('* Trying to spawn {0}'.format(args.any))
try:
_pid = self.dwarf.spawn(args.any, args=args.args, script=args.script)
print('* Dwarf attached to {0}'.format(_pid))
except Exception as e: # pylint: disable=broad-except
print('-failed-')
print('Reason: ' + str(e))
self.stop()
exit(0)
示例7: disable_secure_flag
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def disable_secure_flag(device, pkg_name, activity_name):
js_code = get_js_hook("disable_secure_flag.js")
device = frida.get_device(device.get_serial_no())
session = device.attach(pkg_name)
script = session.create_script(js_code)
script.on("message", message_callback)
script.load()
script.exports.disablesecureflag(activity_name)
示例8: attach_spawn_target
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def attach_spawn_target(args, user_script=None):
if not args.target and not args.device:
print('missing session type. use -t local|android|ios|remote to define the session type'
' or specify a device id with --device')
exit(0)
if args.any is None or args.any == '':
print('missing file or package name to attach')
exit(0)
device = None
try:
if args.device:
device = frida.get_device(id=args.device)
else:
session_type = args.target.lower()
if session_type == 'local':
device = frida.get_local_device()
elif session_type == 'android' or session_type == 'ios':
device = frida.get_usb_device(5)
elif session_type == 'remote':
device = frida.get_remote_device()
except Exception as e:
print('failed to get frida device')
print(e)
if device is not None:
try:
# parse target as pid
args.pid = int(args.any)
except ValueError:
args.pid = 0
if args.pid > 0:
print('* Trying to attach to {0}'.format(args.pid))
try:
attach(args, device)
print('* Dwarf attached to {0}'.format(args.pid))
except Exception as e: # pylint: disable=broad-except
print('-failed-')
print('Reason: ' + str(e))
print('Help: you can use -sp to force spawn')
exit(0)
else:
print('* Trying to spawn {0}'.format(args.any))
try:
_pid = spawn(args, device, user_script)
print('* Dwarf attached to {0}'.format(_pid))
except Exception as e: # pylint: disable=broad-except
print('-failed-')
print('Reason: ' + str(e))
exit(0)
sys.stdin.read()
示例9: run
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def run(self, bv, function=None):
device_id = self.settings.get_string("frida.device_id")
if device_id:
device = None
try:
device = frida.get_device(device_id, timeout=3)
except frida.TimedOutError:
log.log_error("Frida Plugin: Failed to find device. Please try reconnecting device or select another from the device menu.")
return
frida_processes = device.enumerate_processes()
try:
last_process = bv.query_metadata("frida_plugin_process_name")
except KeyError:
last_process = self.settings.get_string("frida.process_name")
processes = []
processes_reorder = []
for process in frida_processes:
if process.name == last_process:
processes.insert(0, f'{process.name}-{process.pid}')
processes_reorder.insert(0, process)
else:
processes.append(f'{process.name}-{process.pid}')
processes_reorder.append(process)
choice_f = ChoiceField("Processes", processes)
get_form_input([choice_f], "Attach Frida to Process")
if choice_f.result != None:
self.settings.set_string("frida.process_name", processes_reorder[choice_f.result].name)
bv.store_metadata("frida_plugin_process_name", str(processes_reorder[choice_f.result].name))
process = processes_reorder[choice_f.result]
self.frida_session = device.attach(process.pid)
log.log_info("Frida Plugin: Successfully connected to device.")
filename = os.path.split(bv.file.filename)[-1].split('.')[0] + '.'
self.module_name = filename
for addr, intercept in list(self.intercepts.items()):
if intercept.is_enabled:
intercept.set_module_name(self.module_name)
intercept.start(self.frida_session.create_script(intercept.to_frida_script()))
else:
log.log_error("Frida Plugin: No device set. Please select from tools menu.")
示例10: run
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def run(self, bv, function=None):
device_id = self.settings.get_string("frida.device_id")
if device_id:
device = None
try:
device = frida.get_device(device_id, timeout=3)
except frida.TimedOutError:
log.log_error("Frida Plugin: Failed to find device. Please try reconnecting device or select another from the device menu.")
return
# Generate ui for reading binary name to spawn
cmd_line = TextLineField('Command line')
choice_field = ChoiceField("Start Process", [bv.file.original_filename, "Command line"])
ret = get_form_input([choice_field,cmd_line], "Start Process")
if not ret:
log.log_info("No binary to spawn specified.")
return
if choice_field.result == 1:
# Select choice is to read textlinefiled
print(choice_field.result)
self.binary_name = cmd_line.result
log.log_info(f"Binary is {self.binary_name}.")
else:
self.binary_name = bv.file.original_filename
# Begin running process
frida_pid = device.spawn(self.binary_name)
log.log_info(f'Spawned process pid: {frida_pid}')
self.frida_session = device.attach(frida_pid)
self.settings.set_string("frida.process_name", self.binary_name)
bv.store_metadata("frida_plugin_process_name", self.binary_name)
log.log_info(f'{self.binary_name}')
log.log_info("Frida Plugin: Successfully connected to device.")
filename = os.path.split(bv.file.filename)[-1].split('.')[0]
self.module_name = filename
log.log_info(f'Applying intercepts {filename}')
for addr, intercept in list(self.intercepts.items()):
log.log_debug(f'Intercept debug: {intercept.to_frida_script()}')
if intercept.is_enabled:
intercept.set_module_name(self.module_name)
intercept.start(self.frida_session.create_script(intercept.to_frida_script()))
device.resume(frida_pid)
else:
log.log_error("Frida Plugin: No device set. Please select from tools menu.")
示例11: _try_start
# 需要导入模块: import frida [as 别名]
# 或者: from frida import get_device [as 别名]
def _try_start(self):
if self._device is not None:
return
if self._device_id is not None:
try:
self._device = frida.get_device(self._device_id)
except:
self._update_status("Device '%s' not found" % self._device_id)
self._exit(1)
return
elif self._device_type is not None:
self._device = find_device(self._device_type)
if self._device is None:
return
elif self._host is not None:
self._device = frida.get_device_manager().add_remote_device(self._host)
else:
self._device = frida.get_local_device()
self._device.on('output', self._schedule_on_output)
self._device.on('lost', self._schedule_on_device_lost)
if self._target is not None:
spawning = True
try:
target_type, target_value = self._target
if target_type == 'file':
argv = target_value
if not self._quiet:
self._update_status("Spawning `%s`..." % " ".join(argv))
self._spawned_pid = self._device.spawn(argv)
self._spawned_argv = argv
attach_target = self._spawned_pid
else:
attach_target = target_value
if not self._quiet:
self._update_status("Attaching...")
spawning = False
self._session = self._device.attach(attach_target)
if self._enable_jit:
self._session.enable_jit()
if self._enable_debugger:
self._session.enable_debugger()
if self._enable_jit:
self._print("Chrome Inspector server listening on port 9229\n")
else:
self._print("Duktape debugger listening on port 5858\n")
self._session.on('detached', self._schedule_on_session_detached)
except Exception as e:
if spawning:
self._update_status("Failed to spawn: %s" % e)
else:
self._update_status("Failed to attach: %s" % e)
self._exit(1)
return
self._start()
self._started = True