fix: properly use lief on a file

pull/995/head
Raphaël Vinot 2023-05-12 11:58:38 +02:00
parent 1a83f7edef
commit 5f698a1247
4 changed files with 22 additions and 20 deletions

16
poetry.lock generated
View File

@ -2175,18 +2175,18 @@ files = [
[[package]]
name = "platformdirs"
version = "3.5.0"
version = "3.5.1"
description = "A small Python package for determining appropriate platform-specific dirs, e.g. a \"user data dir\"."
category = "dev"
optional = false
python-versions = ">=3.7"
files = [
{file = "platformdirs-3.5.0-py3-none-any.whl", hash = "sha256:47692bc24c1958e8b0f13dd727307cff1db103fca36399f457da8e05f222fdc4"},
{file = "platformdirs-3.5.0.tar.gz", hash = "sha256:7954a68d0ba23558d753f73437c55f89027cf8f5108c19844d4b82e5af396335"},
{file = "platformdirs-3.5.1-py3-none-any.whl", hash = "sha256:e2378146f1964972c03c085bb5662ae80b2b8c06226c54b2ff4aa9483e8a13a5"},
{file = "platformdirs-3.5.1.tar.gz", hash = "sha256:412dae91f52a6f84830f39a8078cecd0e866cb72294a5c66808e74d5e88d251f"},
]
[package.extras]
docs = ["furo (>=2023.3.27)", "proselint (>=0.13)", "sphinx (>=6.1.3)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)"]
docs = ["furo (>=2023.3.27)", "proselint (>=0.13)", "sphinx (>=6.2.1)", "sphinx-autodoc-typehints (>=1.23,!=1.23.4)"]
test = ["appdirs (==1.4.4)", "covdefaults (>=2.3)", "pytest (>=7.3.1)", "pytest-cov (>=4)", "pytest-mock (>=3.10)"]
[[package]]
@ -3290,14 +3290,14 @@ files = [
[[package]]
name = "types-redis"
version = "4.5.5.1"
version = "4.5.5.2"
description = "Typing stubs for redis"
category = "dev"
optional = false
python-versions = "*"
files = [
{file = "types-redis-4.5.5.1.tar.gz", hash = "sha256:0193d0522cccd6d46e9e17b811c30fc407e1800e0381da0e95f5c9239bdca58b"},
{file = "types_redis-4.5.5.1-py3-none-any.whl", hash = "sha256:569b9795618c95d5f8fad2156dceb622614162761b4382892b99c519c378f776"},
{file = "types-redis-4.5.5.2.tar.gz", hash = "sha256:2fe82f374d9dddf007deaf23d81fddcfd9523d9522bf11523c5c43bc5b27099e"},
{file = "types_redis-4.5.5.2-py3-none-any.whl", hash = "sha256:bf8692252038dbe03b007ca4fde87d3ae8e10610854a6858e3bf5d01721a7c4b"},
]
[package.dependencies]
@ -3720,4 +3720,4 @@ virustotal = ["validators"]
[metadata]
lock-version = "2.0"
python-versions = "^3.8"
content-hash = "a072a1aec4e97c24b7c7bdec6b01273a3abf43b3e73ba5ac87ef1f27338ebe18"
content-hash = "112c8019bd1ee10c0c3fe5883e6e6a68985087a4f3de808b3035cc4568e6c6bf"

@ -1 +1 @@
Subproject commit 3d736c427ce376eac7c623068325cfce05269f3e
Subproject commit a605792844d13cdd2f8b8825f4bd0dc85e5c5f6c

View File

@ -37,21 +37,23 @@ def make_binary_objects(filepath: Optional[str] = None, pseudofile: Optional[Byt
if HAS_LIEF and (filepath or (pseudofile and filename)):
if filepath:
lief_parsed = lief.parse(filepath=filepath)
print(lief_parsed)
elif pseudofile and filename:
lief_parsed = lief.parse(raw=pseudofile.getvalue(), name=filename)
if isinstance(lief_parsed, lief.lief_errors):
logger.warning('Got an error parsing the file: {lief_parsed}')
elif isinstance(lief_parsed, lief.PE.Binary):
return make_pe_objects(lief_parsed, misp_file, standalone, default_attributes_parameters)
elif isinstance(lief_parsed, lief.ELF.Binary):
return make_elf_objects(lief_parsed, misp_file, standalone, default_attributes_parameters)
elif isinstance(lief_parsed, lief.MachO.Binary):
return make_macho_objects(lief_parsed, misp_file, standalone, default_attributes_parameters)
else:
logger.critical(f'Unexpected type from lief: {type(lief_parsed)}')
else:
logger.critical('You need either a filepath, or a pseudofile and a filename.')
lief_parsed = None
if isinstance(lief_parsed, lief.lief_errors):
logger.warning('Got an error parsing the file: {lief_parsed}')
elif isinstance(lief_parsed, lief.PE.Binary):
return make_pe_objects(lief_parsed, misp_file, standalone, default_attributes_parameters)
elif isinstance(lief_parsed, lief.ELF.Binary):
return make_elf_objects(lief_parsed, misp_file, standalone, default_attributes_parameters)
elif isinstance(lief_parsed, lief.MachO.Binary):
return make_macho_objects(lief_parsed, misp_file, standalone, default_attributes_parameters)
else:
logger.critical(f'Unexpected type from lief: {type(lief_parsed)}')
if not HAS_LIEF:
logger.warning('Please install lief, documentation here: https://github.com/lief-project/LIEF')
return misp_file, None, []

View File

@ -81,7 +81,7 @@ ipython = [
jupyterlab = "^3.6.3"
types-requests = "^2.30.0.0"
types-python-dateutil = "^2.8.19.13"
types-redis = "^4.5.5.1"
types-redis = "^4.5.5.2"
types-Flask = "^1.1.6"
pytest-cov = "^4.0.0"