def _find_local(self): """ Use local sources, e.g. input files of URLs and zip files, to import malware samples. """ sample_list = list() if self.opts.inputfile: for inputfile in self.opts.inputfile: with open(inputfile, 'rb') as handle: found_samples = process_simple_list(handle.read()) if not len(found_samples): logging.warning("Found no samples in local file %r", inputfile) else: logging.info("Found %d samples in local file %r", len(found_samples), inputfile) sample_list.extend(found_samples) if self.opts.zip: for zip_filename in self.opts.zip: handle = ZipFile(zip_filename, 'r') found_samples = list() for entry in handle.infolist(): url = '://'.join([os.path.basename(zip_filename), entry.filename]) found_samples.append( Namespace(url=url, url_sha1=hashstr(url, hashlib.sha1), _zip_handle=handle, _zip_filename=entry.filename, _read=lambda x: zip_tryopen(x._zip_handle, x._zip_filename).read(), source='zip')) if not len(found_samples): logging.warning("Found no samples in local zip file %r", zip_filename) else: logging.info("Found %d samples in local file %r", len(found_samples), zip_filename) sample_list.extend(found_samples) return sample_list