Add support for downloading unzipped samples.

pull/2/merge v1.11
Raphaël Vinot 2015-09-18 14:38:52 +02:00
parent a7c3d8869c
commit 11b3470167
2 changed files with 13 additions and 8 deletions

View File

@ -1,3 +1,3 @@
__version__ = '1.10'
__version__ = '1.11'
from .api import PyMISP

View File

@ -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):