def _update_name(self): name = decode(self.info.get("name")) if name and name != decode(self.info.get("url")): self.pyfile.name = name else: name = decode(self.pyfile.name) self.log_info(self._("Link name: {}").format(name))
def parse_packages(self, start_node): return [ ( base64.b64decode(decode(node.getAttribute("name"))), self.parse_links(node), ) for node in start_node.getElementsByTagName("package") ]
def parse_domains(self, list): _re = re.compile( r"^(?:https?://)?(?:www\.)?(?:\w+\.)*((?:(?:\d{1,3}\.){3}\d{1,3}|[\w\-^_]{3,63}(?:\.[a-zA-Z]{2,}){1,2})(?:\:\d+)?)", re.I | re.U, ) domains = [ decode(domain).strip().lower() for url in list for domain in _re.findall(url) ] return self.replace_domains(uniquify(domains))
def list(self, password=None): command = "vb" if self.fullpath else "lb" p = self.call_cmd(command, "-v", self.filename, password=password) out, err = (r.strip() if r else "" for r in p.communicate()) if "Cannot open" in err: raise ArchiveError(self._("Cannot open file")) if err: #: Only log error at this point self.log_error(err) result = set() if not self.fullpath and self.VERSION.startswith("5"): # NOTE: Unrar 5 always list full path for filename in decode(out).splitlines(): filename = os.path.join(self.dest, os.path.basename(filename.strip())) if os.path.isfile(filename): result.add( os.path.join(self.dest, os.path.basename(filename))) else: if self.fullpath: for filename in decode(out).splitlines(): # Unrar fails to list all directories for some archives filename = filename.strip() while filename: fabs = os.path.join(self.dest, filename) if fabs not in result: result.add(fabs) filename = os.path.dirname(filename) else: break else: for filename in decode(out).splitlines(): result.add(os.path.join(self.dest, filename.strip())) self.files = list(result) return self.files
def render_footer(self, line): """ prints out the input line with input. """ println(line, "") line += 1 println(line, white(" Input: ") + decode(self.input)) # clear old output if line < self.last_lowest_line: for i in range(line + 1, self.last_lowest_line + 1): println(i, "") self.last_lowest_line = line # set cursor to position print(f"\033[{self.inputline};0H")
def decrypt_file(self, key): """ Decrypts and verifies checksum to the file at 'last_download'. """ k, iv, meta_mac = MegaCrypto.get_cipher_key(key) ctr = Cryptodome.Util.Counter.new( 128, initial_value=((iv[0] << 32) + iv[1]) << 64) cipher = Cryptodome.Cipher.AES.new(MegaCrypto.a32_to_str(k), Cryptodome.Cipher.AES.MODE_CTR, counter=ctr) self.pyfile.set_status("decrypting") self.pyfile.set_progress(0) file_crypted = os.fsdecode(self.last_download) file_decrypted = file_crypted.rsplit(self.FILE_SUFFIX)[0] try: f = open(file_crypted, mode="rb") df = open(file_decrypted, mode="wb") except IOError as exc: self.fail(exc) encrypted_size = os.path.getsize(file_crypted) checksum_activated = self.config.get("enabled", default=False, plugin="Checksum") check_checksum = self.config.get("check_checksum", default=True, plugin="Checksum") cbc_mac = (MegaCrypto.Checksum(key) if checksum_activated and check_checksum else None) progress = 0 for chunk_start, chunk_size in MegaCrypto.get_chunks(encrypted_size): buf = f.read(chunk_size) if not buf: break chunk = cipher.decrypt(buf) df.write(chunk) progress += chunk_size self.pyfile.set_progress((100 // encrypted_size) * progress) if checksum_activated and check_checksum: cbc_mac.update(chunk) self.pyfile.set_progress(100) f.close() df.close() self.log_info(self._("File decrypted")) os.remove(file_crypted) if checksum_activated and check_checksum: file_mac = cbc_mac.digest() if file_mac == meta_mac: self.log_info( self. _('File integrity of "{}" verified by CBC-MAC checksum ({})' ).format( self.pyfile.name.rsplit(self.FILE_SUFFIX)[0], meta_mac)) else: self.log_warning( self. _('CBC-MAC checksum for file "{}" does not match ({} != {})' ).format( self.pyfile.name.rsplit(self.FILE_SUFFIX)[0], file_mac, meta_mac)) self.checksum_failed(file_decrypted, self._("Checksums do not match")) self.last_download = decode(file_decrypted)