Skip to content

Commit

Permalink
Merge pull request #591 from kak-bo-che/bugfix/correct_mimetype_on_fi…
Browse files Browse the repository at this point in the history
…leobject

Previously file object was reporting the libmagic description of a file
  • Loading branch information
Rafiot authored Jun 15, 2020
2 parents 23d732e + 17ebfe8 commit 96aeaf7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pymisp/tools/fileobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def generate_attributes(self):
self.add_attribute('sha512', value=sha512(self.__data).hexdigest())
self.add_attribute('malware-sample', value=self.__filename, data=self.__pseudofile)
if HAS_MAGIC:
self.add_attribute('mimetype', value=magic.from_buffer(self.__data))
self.add_attribute('mimetype', value=magic.from_buffer(self.__data, mime=True))
if HAS_PYDEEP:
self.add_attribute('ssdeep', value=pydeep.hash_buf(self.__data).decode())

Expand Down
16 changes: 16 additions & 0 deletions tests/test_fileobject.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest
import json
from pymisp.tools import FileObject
import pathlib


class TestFileObject(unittest.TestCase):
def test_mimeType(self):
file_object = FileObject(filepath=pathlib.Path(__file__))
attributes = json.loads(file_object.to_json())['Attribute']
mime = next(attr for attr in attributes if attr['object_relation'] == 'mimetype')
# was "Python script, ASCII text executable"
self.assertEqual(mime['value'], 'text/x-python')

0 comments on commit 96aeaf7

Please sign in to comment.