Skip to content

Commit

Permalink
ELF support
Browse files Browse the repository at this point in the history
  • Loading branch information
c-urly committed Mar 14, 2024
1 parent 2da66f0 commit 1b75077
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion floss/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
KILOBYTE = 1024
MEGABYTE = 1024 * KILOBYTE
MAX_FILE_SIZE = 16 * MEGABYTE
SUPPORTED_FILE_MAGIC = {b"MZ"}
SUPPORTED_FILE_MAGIC = {b"MZ",b"\x7fELF"}
MIN_STRING_LENGTH = 4
MAX_STRING_LENGTH = 2048

Expand Down
16 changes: 13 additions & 3 deletions floss/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class StringType(str, Enum):
TIGHT = "tight"
DECODED = "decoded"

class FileType():
PE = False
ELF = False

class WorkspaceLoadError(ValueError):
pass
Expand Down Expand Up @@ -364,9 +367,13 @@ def is_supported_file_type(sample_file_path: Path):
:return: True if file type is supported, False otherwise
"""
with sample_file_path.open("rb") as f:
magic = f.read(2)
magic = f.read(4)

if magic in SUPPORTED_FILE_MAGIC:
FileType.ELF = True
return True
elif magic[:2] in SUPPORTED_FILE_MAGIC:
FileType.PE = True
return True
else:
return False
Expand Down Expand Up @@ -398,7 +405,8 @@ def load_vw(
else:
vw = viv_utils.getWorkspace(str(sample_path), analyze=False, should_save=False)

viv_utils.flirt.register_flirt_signature_analyzers(vw, list(map(str, sigpaths)))
if not FileType.ELF:
viv_utils.flirt.register_flirt_signature_analyzers(vw, list(map(str, sigpaths)))

vw.analyze()

Expand Down Expand Up @@ -555,14 +563,16 @@ def main(argv=None) -> int:
return 0

static_runtime = get_runtime_diff(interim)
if not is_supported_file_type(sample):
logger.error("FileType not Supported")

# set language configurations
selected_lang = Language(args.language)
if selected_lang == Language.DISABLED:
results.metadata.language = ""
results.metadata.language_version = ""
results.metadata.language_selected = ""
else:
elif FileType.PE:
lang_id, lang_version = identify_language_and_version(sample, static_strings)

if selected_lang == Language.UNKNOWN:
Expand Down

0 comments on commit 1b75077

Please sign in to comment.