Esempio n. 1
0
    def _on_dwarf_isupdate(self):
        if not utils.is_connected():
            return

        self.update_bar.setVisible(True)
        self.setFixedHeight(self.height() + self.update_bar.height())
        self.onIsNewerVersion.emit()
Esempio n. 2
0
    def _update_dwarf(self):
        path_to_version = os.path.join(self._base_path, os.pardir, os.pardir,
                                       'VERSION')
        if not os.path.exists(path_to_version):
            if utils.is_connected():
                try:
                    # file exists in dwarf >2.0.0 wich means update from 1.x to 2.x
                    request = requests.get(
                        'https://raw.githubusercontent.com/iGio90/Dwarf/master/VERSION'
                    )
                    if request.ok:
                        utils.show_message_box(
                            'This update will break your Dwarf installation!\nSee GitHub for more infos'
                        )
                        from PyQt5.QtCore import QUrl
                        from PyQt5.QtGui import QDesktopServices
                        QDesktopServices.openUrl(
                            QUrl('https://github.com/iGio90/Dwarf'))
                        return
                except:
                    pass

        self._update_thread = DwarfUpdateThread(self)
        self._update_thread.on_finished.connect(self._update_finished)
        if not self._update_thread.isRunning():
            self._update_thread.start()
Esempio n. 3
0
 def _open_cache(self, path, url, _json=True):
     data = None
     now = time.time()
     if os.path.exists(path):
         with open(path, 'r') as f:
             data = json.load(f)
             last_update = data['updated']
             data = data['data']
             if now - last_update < 60 * 15:
                 return data
     if utils.is_connected():
         try:
             r = requests.get(url)
         except:
             return data
         if r is None or r.status_code != 200:
             return data
         if _json:
             try:
                 data = r.json()
             except:
                 return None
         else:
             data = r.text
         with open(path, 'w') as f:
             f.write(json.dumps({
                 'updated': now,
                 'data': data
             }))
     return data
Esempio n. 4
0
    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()