Skip to content

Commit

Permalink
Not all ELF files are for Linux (#55)
Browse files Browse the repository at this point in the history
This stops tagging all ELF files as 'runnable:linux' and instead
sets attempts to determine the most appropriate 'platform' and uses
'elf' as the extension.
  • Loading branch information
jasperla authored Jan 23, 2023
1 parent 821437d commit 3142429
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 15 additions & 1 deletion karton/classifier/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,22 @@ def zip_has_file(path: str) -> bool:
return sample_class

# Is ELF file?
elf_assoc = {
"linux": "(GNU/Linux)",
"freebsd": "(FreeBSD)",
"netbsd": "(NetBSD)",
"openbsd": "(SYSV)",
"solaris": "(Solaris)",
}
if magic.startswith("ELF"):
sample_class.update({"kind": "runnable", "platform": "linux"})
for platform, platform_full in elf_assoc.items():
if platform_full in magic:
sample_class.update(
{"kind": "runnable", "platform": platform, "extension": "elf"}
)
return sample_class

sample_class.update({"kind": "runnable", "extension": "elf"})
return sample_class

# Is PKG file?
Expand Down
5 changes: 3 additions & 2 deletions tests/test_classifier_runnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ def test_process_runnable_linux(self):
"quality": "high",
"kind": "runnable",
"mime": "application/x-executable",
"platform": "linux",
"extension": "elf",
"platform": "openbsd",
},
payload={
"sample": resource,
"tags": ["runnable:linux"],
"tags": ["runnable:openbsd:elf"],
"magic": magic,
},
)
Expand Down

0 comments on commit 3142429

Please sign in to comment.