

def restore_files(self, name=None, backup=None, files=None, strip=None, archive='zip', password=None, agent=None):
    'See :func:`burpui.misc.backend.interface.BUIbackend.restore_files`'
    if ((not name) or (not backup) or (not files)):
        return (None, 'At least one argument is missing')
    if (not self.stripbin):
        return (None, "Missing 'strip' binary")
    if (not self.burpbin):
        return (None, "Missing 'burp' binary")
    flist = json.loads(files)
    if password:
        (tmphandler, tmpfile) = tempfile.mkstemp()
    tmpdir = tempfile.mkdtemp(prefix=self.tmpdir)
    if ('restore' not in flist):
        return (None, 'Wrong call')
    if os.path.isdir(tmpdir):
        shutil.rmtree(tmpdir)
    full_reg = ''
    for restore in flist['restore']:
        reg = ''
        if (restore['folder'] and (restore['key'] != '/')):
            reg += (('^' + re.escape(restore['key'])) + '/|')
        else:
            reg += (('^' + re.escape(restore['key'])) + '$|')
        full_reg += reg
    cmd = [self.burpbin, '-C', quote(name), '-a', 'r', '-b', quote(str(backup)), '-r', full_reg.rstrip('|'), '-d', tmpdir]
    if password:
        if (not self.burpconfcli):
            return (None, 'No client configuration file specified')
        tmpdesc = os.fdopen(tmphandler, 'w+')
        with open(self.burpconfcli) as fileobj:
            shutil.copyfileobj(fileobj, tmpdesc)
        tmpdesc.write('encryption_password = {}\n'.format(password))
        tmpdesc.close()
        cmd.append('-c')
        cmd.append(tmpfile)
    elif self.burpconfcli:
        cmd.append('-c')
        cmd.append(self.burpconfcli)
    if (strip and strip.isdigit() and (int(strip) > 0)):
        cmd.append('-s')
        cmd.append(strip)
    self._logger('debug', cmd)
    proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    (out, _) = proc.communicate()
    status = proc.wait()
    if password:
        os.remove(tmpfile)
    self._logger('debug', out)
    self._logger('debug', 'command returned: %d', status)
    if (('zstrm inflate error: -3' in out) and ('transfer file returning: -1' in out)):
        status = 1
        out = 'encrypted'
    if (status not in [0, 2]):
        return (None, out)
    zip_dir = tmpdir.rstrip(os.sep)
    zip_file = (zip_dir + '.zip')
    if os.path.isfile(zip_file):
        os.remove(zip_file)
    zip_len = (len(zip_dir) + 1)
    stripping = True
    test_strip = True
    with BUIcompress(zip_file, archive, self.zip64) as zfh:
        for (dirname, _, files) in os.walk(zip_dir):
            for filename in files:
                path = os.path.join(dirname, filename)
                if test_strip:
                    test_strip = False
                    otp = None
                    try:
                        otp = subprocess.check_output([self.stripbin, '-p', '-i', path])
                    except subprocess.CalledProcessError as exc:
                        self._logger('debug', "Stripping failed on '{}': {}".format(path, str(exc)))
                    if (not otp):
                        stripping = False
                if (stripping and os.path.isfile(path)):
                    self._logger('debug', 'stripping file: %s', path)
                    shutil.move(path, (path + '.tmp'))
                    status = subprocess.call([self.stripbin, '-i', (path + '.tmp'), '-o', path])
                    if (status != 0):
                        os.remove(path)
                        shutil.move((path + '.tmp'), path)
                        stripping = False
                        self._logger('debug', 'Disable stripping since this file does not seem to embed VSS headers')
                    else:
                        os.remove((path + '.tmp'))
                entry = path[zip_len:]
                zfh.append(path, entry)
    shutil.rmtree(tmpdir)
    return (zip_file, None)

dataset/ETHPy150Open ziirish/burp-ui/burpui/misc/backend/burp1.py Burp.restore_files/original