(self, pid, script=None, print_debug_error=True)
Attach to pid
Attach to pid
Attach to pid
def attach(self, pid, script=None, print_debug_error=True):
        """ Attach to pid
        """
        if self.device is None:
            raise self.NoDeviceAssignedError('No Device assigned')

        if self._process is not None:
            self.detach()

        was_error = False
        error_msg = ''

        # for commandline arg
        if isinstance(pid, str):
            try:
                process = self.device.get_process(pid)
                pid = [process.pid, process.name]
            except frida.ProcessNotFoundError as error:
                raise Exception('Frida Error: ' + str(error))

        if isinstance(pid, list):
            if len(pid) > 1:
                name = pid[1]
            else:
                name = ''
            pid = pid[0]
        else:
            name = ''

        if not isinstance(pid, int):
            raise Exception('Error pid!=int')

        try:
            self._process = self.device.attach(pid)
            self._process.on('detached', self._on_detached)
            self._pid = pid
        except frida.ProcessNotFoundError:
            error_msg = 'Process not found (ProcessNotFoundError)'
            was_error = True
        except frida.ProcessNotRespondingError:
            error_msg = 'Process not responding (ProcessNotRespondingError)'
            was_error = True
        except frida.TimedOutError:
            error_msg = 'Frida timeout (TimedOutError)'
            was_error = True
        except frida.ServerNotRunningError:
            error_msg = 'Frida not running (ServerNotRunningError)'
            was_error = True
        except frida.TransportError:
            error_msg = 'Frida timeout was reached (TransportError)'
            was_error = True
        # keep for debug
        except Exception as error:  # pylint: disable=broad-except
            error_msg = error
            was_error = True

        if was_error:
            raise Exception(error_msg)

        self.onProcessAttached.emit([self.pid, name])
        self.load_script(script=script)
def attach ( self , pid , script = None , print_debug_error = True ) : if self . device is None : raise self . NoDeviceAssignedError ( 'No Device assigned' ) if self . _process is not None : self . detach ( ) was_error = False error_msg = '' # for commandline arg if isinstance ( pid , str ) : try : process = self . device . get_process ( pid ) pid = [ process . pid , process . name ] except frida . ProcessNotFoundError as error : raise Exception ( 'Frida Error: ' + str ( error ) ) if isinstance ( pid , list ) : if len ( pid ) > 1 : name = pid [ 1 ] else : name = '' pid = pid [ 0 ] else : name = '' if not isinstance ( pid , int ) : raise Exception ( 'Error pid!=int' ) try : self . _process = self . device . attach ( pid ) self . _process . on ( 'detached' , self . _on_detached ) self . _pid = pid except frida . ProcessNotFoundError : error_msg = 'Process not found (ProcessNotFoundError)' was_error = True except frida . ProcessNotRespondingError : error_msg = 'Process not responding (ProcessNotRespondingError)' was_error = True except frida . TimedOutError : error_msg = 'Frida timeout (TimedOutError)' was_error = True except frida . ServerNotRunningError : error_msg = 'Frida not running (ServerNotRunningError)' was_error = True except frida . TransportError : error_msg = 'Frida timeout was reached (TransportError)' was_error = True # keep for debug except Exception as error : # pylint: disable=broad-except error_msg = error was_error = True if was_error : raise Exception ( error_msg ) self . onProcessAttached . emit ( [ self . pid , name ] ) self . load_script ( script = script )