From f8ce286894446ee244bf403d9336c75fcce89b4c Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Wed, 10 Jul 2019 22:19:38 +0100 Subject: [PATCH] Add downloading progress when retrieving PDBs. --- volatility/framework/symbols/windows/mspdb.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/volatility/framework/symbols/windows/mspdb.py b/volatility/framework/symbols/windows/mspdb.py index 5fd88b040..805608029 100644 --- a/volatility/framework/symbols/windows/mspdb.py +++ b/volatility/framework/symbols/windows/mspdb.py @@ -866,6 +866,20 @@ class PdbReader: class PdbRetreiver: + def get_report_hook(self, progress_callback, url): + """Returns a report hook that converts output into a progress_callback""" + + if progress_callback is None: + return lambda x, y, z: None + + def report_hook(chunk_num, chunk_size, total_size): + if total_size < 0: + progress_callback(50, "Downloading {}".format(url)) + else: + progress_callback(chunk_num * chunk_size * 100 / total_size, "Downloading {}".format(url)) + + return report_hook + def retreive_pdb(self, guid: str, file_name: str, progress_callback: constants.ProgressCallback = None) -> Optional[str]: vollog.info("Download PDB file...") @@ -875,11 +889,10 @@ class PdbRetreiver: result = None for suffix in [file_name[:-1] + '_', file_name]: - if progress_callback is not None: - progress_callback(50, "Downloading {}".format(url + suffix)) try: vollog.debug("Attempting to retrieve {}".format(url + suffix)) - result, _ = request.urlretrieve(url + suffix) + reporthook = self.get_report_hook(progress_callback, url) + result, _ = request.urlretrieve(url + suffix, reporthook = reporthook) except request.HTTPError as excp: vollog.debug("Failed with {}".format(excp)) if result: