From 11b3470167285b46282736c0a3dba97d5d3c910e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 18 Sep 2015 14:38:52 +0200 Subject: [PATCH] Add support for downloading unzipped samples. --- pymisp/__init__.py | 2 +- pymisp/api.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pymisp/__init__.py b/pymisp/__init__.py index 592d0af..50c04af 100644 --- a/pymisp/__init__.py +++ b/pymisp/__init__.py @@ -1,3 +1,3 @@ -__version__ = '1.10' +__version__ = '1.11' from .api import PyMISP diff --git a/pymisp/api.py b/pymisp/api.py index 2f94a92..25e1ed5 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -572,14 +572,19 @@ class PyMISP(object): for f in result['result']: decoded = base64.b64decode(f['base64']) zipped = BytesIO(decoded) - archive = zipfile.ZipFile(zipped) try: - # New format - unzipped = BytesIO(archive.open(f['md5'], pwd='infected').read()) - except KeyError: - # Old format - unzipped = BytesIO(archive.open(f['filename'], pwd='infected').read()) - details.append([f['event_id'], f['filename'], unzipped]) + archive = zipfile.ZipFile(zipped) + try: + # New format + unzipped = BytesIO(archive.open(f['md5'], pwd='infected').read()) + except KeyError: + # Old format + unzipped = BytesIO(archive.open(f['filename'], pwd='infected').read()) + details.append([f['event_id'], f['filename'], unzipped]) + except zipfile.BadZipfile: + # In case the sample isn't zipped + details.append([f['event_id'], f['filename'], zipped]) + return True, details def download_last(self, last):