def zip_do_zip(azip, afile): """ azip:ZipFile, afile:source archive(s) name """ # test if encrypted try: azip.testzip() except RuntimeError as e: if 'encrypted' in str(e): log_encrypted(BF_ZIP, afile) return else: log_error(str(e), afile) # iterate directly over file names for member in azip.namelist(): # sort directories out if member.endswith('/'): continue # check file name filename = os.path.basename(member).lower() res = RGX_INFILENAME.search(filename) if res: log_secret(res.group(), afile + ':' + member) # check file content, calling other modules data = azip.read(member) (ftype, supported) = type_data(data, member) if supported: if ftype in ENCRYPTED: log_encrypted(ftype, member) else: do_data(ftype, data, afile + ':' + member)
def zip_do_zip(azip, afile): """ azip:ZipFile, afile:source archive(s) name """ # test if encrypted try: azip.testzip() except RuntimeError as e: if 'encrypted' in str(e): log_encrypted(BF_ZIP, afile) return else: log_error(str(e), afile) # iterate directly over file names for member in azip.namelist(): # sort directories out if member.endswith('/'): continue # check file name filename = os.path.basename(member).lower() res = RGX_INFILENAME.search(filename) if res: log_secret(res.group(), afile+':'+member) # check file content, calling other modules data = azip.read(member) (ftype, supported) = type_data(data, member) if supported: if ftype in ENCRYPTED: log_encrypted(ftype, member) else: do_data(ftype, data, afile+':'+member)
def bzip2_do_bzip2(abzip2, afile): """abzip2: raw bytes, afile: source file name""" try: data = bz2.decompress(abzip2) except (IOError, ValueError) as e: log_error(str(e), afile) return (ftype, supported) = type_data(data) if supported: # strip any .bz2 extension (root, ext) = os.path.splitext(afile) if ext.lower() == '.bz2': do_data(ftype, data, afile+':'+root) else: do_data(ftype, data, afile)
def bzip2_do_bzip2(abzip2, afile): """abzip2: raw bytes, afile: source file name""" try: data = bz2.decompress(abzip2) except (IOError, ValueError) as e: log_error(str(e), afile) return (ftype, supported) = type_data(data) if supported: # strip any .bz2 extension (root, ext) = os.path.splitext(afile) if ext.lower() == '.bz2': do_data(ftype, data, afile + ':' + root) else: do_data(ftype, data, afile)
def gz_do_gz(agz, afile): """agz:GzipFile, afile:source file name""" try: data = agz.read() except IOError as e: log_error(str(e), afile) return (ftype, supported) = type_data(data) if supported: # strip any .gz extension (root, ext) = os.path.splitext(afile) if ext.lower() == '.gz': do_data(ftype, data, afile+':'+root) else: do_data(ftype, data, afile)
def gz_do_gz(agz, afile): """agz:GzipFile, afile:source file name""" try: data = agz.read() except IOError as e: log_error(str(e), afile) return (ftype, supported) = type_data(data) if supported: # strip any .gz extension (root, ext) = os.path.splitext(afile) if ext.lower() == '.gz': do_data(ftype, data, afile + ':' + root) else: do_data(ftype, data, afile)
def tar_do_tar(atar, afile): """ atar:TarFile, afile:source archive(s) name """ # iterate over TarInfo's for member in atar.getmembers(): # only process files if not member.isfile(): continue # check file name filename = os.path.basename(member.name).lower() res = RGX_INFILENAME.search(filename) if res: log_secret(res.group(), afile + ':' + member.name) # check file content, calling other modules data = atar.extractfile(member).read() (ftype, supported) = type_data(data, member.name) if supported: if ftype in ENCRYPTED: log_encrypted(ftype, member.name) else: do_data(ftype, data, afile + ':' + member.name)