(self)
Runs the UpdateThread
Runs the UpdateThread
Runs the UpdateThread
def run(self):
        """Runs the UpdateThread
        """
        if self._adb is None:
            self.onError.emit('ADB not set')
            return

        if not self._adb.min_required:
            self.onError.emit('ADB MinRequired')
            return

        if not utils.is_connected():
            self.onError.emit('Not connected')
            return

        if self._frida_update_url is None or self._frida_update_url == '':
            self.onError.emit('Missing frida download url')
            return

        self.onStatusUpdate.emit('Downloading latest frida')

        try:
            if utils.is_connected():
                request = requests.get(self._frida_update_url, stream=True)
            else:
                self.onError.emit('Not connected')
                return
        except requests.ConnectionError:
            self.onError.emit('Failed to download latest frida')
            return

        # reset url
        self._frida_update_url = None

        if request is not None and request.status_code == 200:
            # write data to local file
            try:
                with open('frida.xz', 'wb') as frida_archive:
                    for chunk in request.iter_content(chunk_size=1024):
                        if chunk:
                            frida_archive.write(chunk)
            except EnvironmentError:
                self.onError.emit('Failed to write frida.xz')
                return

            # start extraction
            if os.path.exists('frida.xz'):
                self.onStatusUpdate.emit('Extracting latest frida')
                try:
                    with lzma.open('frida.xz') as frida_archive:
                        with open('frida-server', 'wb') as frida_binary:
                            frida_binary.write(frida_archive.read())

                    # remove downloaded archive
                    os.remove('frida.xz')
                except lzma.LZMAError:
                    self.onError.emit('Failed to extract frida.xz')
                    return
                except EnvironmentError:
                    self.onError.emit('Failed to write frida')
                    return
            else:
                self.onError.emit('Failed to open frida.xz')
                return

            self.onStatusUpdate.emit('Mounting devices filesystem')
            # mount system rw
            if self._adb.mount_system():
                self.onStatusUpdate.emit('Pushing to device')
                # push file to device
                self._adb.push('frida-server', '/sdcard/')
                self.onStatusUpdate.emit('Setting up and starting frida')
                # kill frida
                self._adb.kill_frida()

                _device_path = '/system/xbin'
                res = self._adb.su_cmd('ls ' + _device_path)
                if 'No such file or directory' in res:
                    # use /system/bin
                    _device_path = _device_path.replace('x', '')

                # copy file note: mv give sometimes a invalid id error
                self._adb.su_cmd('cp /sdcard/frida-server ' + _device_path + '/frida-server')
                # remove file
                self._adb.su_cmd('rm ' + _device_path + '/frida')  # remove old named file
                self._adb.su_cmd('rm /sdcard/frida-server')

                # just to make sure
                self._adb.su_cmd('chown root:root ' + _device_path + '/frida-server')
                # make it executable
                self._adb.su_cmd('chmod 06755 ' + _device_path + '/frida-server')

                # start it
                if self._adb.get_frida_version():
                    if not self._adb.start_frida():
                        self.onError.emit('Failed to start fridaserver on Device')
            else:
                print('failed to mount /system on device')

            # delete extracted file
            if os.path.exists('frida-server'):
                os.remove('frida-server')
        else:
            self.onError.emit('Failed to download latest frida! Error: %d' % request.status_code)
            return

        self.onFinished.emit()
def run ( self ) : if self . _adb is None : self . onError . emit ( 'ADB not set' ) return if not self . _adb . min_required : self . onError . emit ( 'ADB MinRequired' ) return if not utils . is_connected ( ) : self . onError . emit ( 'Not connected' ) return if self . _frida_update_url is None or self . _frida_update_url == '' : self . onError . emit ( 'Missing frida download url' ) return self . onStatusUpdate . emit ( 'Downloading latest frida' ) try : if utils . is_connected ( ) : request = requests . get ( self . _frida_update_url , stream = True ) else : self . onError . emit ( 'Not connected' ) return except requests . ConnectionError : self . onError . emit ( 'Failed to download latest frida' ) return # reset url self . _frida_update_url = None if request is not None and request . status_code == 200 : # write data to local file try : with open ( 'frida.xz' , 'wb' ) as frida_archive : for chunk in request . iter_content ( chunk_size = 1024 ) : if chunk : frida_archive . write ( chunk ) except EnvironmentError : self . onError . emit ( 'Failed to write frida.xz' ) return # start extraction if os . path . exists ( 'frida.xz' ) : self . onStatusUpdate . emit ( 'Extracting latest frida' ) try : with lzma . open ( 'frida.xz' ) as frida_archive : with open ( 'frida-server' , 'wb' ) as frida_binary : frida_binary . write ( frida_archive . read ( ) ) # remove downloaded archive os . remove ( 'frida.xz' ) except lzma . LZMAError : self . onError . emit ( 'Failed to extract frida.xz' ) return except EnvironmentError : self . onError . emit ( 'Failed to write frida' ) return else : self . onError . emit ( 'Failed to open frida.xz' ) return self . onStatusUpdate . emit ( 'Mounting devices filesystem' ) # mount system rw if self . _adb . mount_system ( ) : self . onStatusUpdate . emit ( 'Pushing to device' ) # push file to device self . _adb . push ( 'frida-server' , '/sdcard/' ) self . onStatusUpdate . emit ( 'Setting up and starting frida' ) # kill frida self . _adb . kill_frida ( ) _device_path = '/system/xbin' res = self . _adb . su_cmd ( 'ls ' + _device_path ) if 'No such file or directory' in res : # use /system/bin _device_path = _device_path . replace ( 'x' , '' ) # copy file note: mv give sometimes a invalid id error self . _adb . su_cmd ( 'cp /sdcard/frida-server ' + _device_path + '/frida-server' ) # remove file self . _adb . su_cmd ( 'rm ' + _device_path + '/frida' ) # remove old named file self . _adb . su_cmd ( 'rm /sdcard/frida-server' ) # just to make sure self . _adb . su_cmd ( 'chown root:root ' + _device_path + '/frida-server' ) # make it executable self . _adb . su_cmd ( 'chmod 06755 ' + _device_path + '/frida-server' ) # start it if self . _adb . get_frida_version ( ) : if not self . _adb . start_frida ( ) : self . onError . emit ( 'Failed to start fridaserver on Device' ) else : print ( 'failed to mount /system on device' ) # delete extracted file if os . path . exists ( 'frida-server' ) : os . remove ( 'frida-server' ) else : self . onError . emit ( 'Failed to download latest frida! Error: %d' % request . status_code ) return self . onFinished . emit ( )