Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

## master (unreleased)
- main: add initial elf files support

### New Features

Expand Down
2 changes: 1 addition & 1 deletion capa/features/extractors/viv/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def extract_file_import_names(vw, file_path):
"""
for va, _, _, tinfo in vw.getImports():
# vivisect source: tinfo = "%s.%s" % (libname, impname)
modname, impname = tinfo.split(".")
modname, impname = tinfo.split(".", 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
modname, impname = tinfo.split(".", 1)
modname, _, impname = tinfo.partition(".")

if is_viv_ord_impname(impname):
# replace ord prefix with #
impname = "#%s" % impname[len("ord") :]
Expand Down
4 changes: 4 additions & 0 deletions capa/features/extractors/viv/insn.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ def extract_insn_api_features(f, bb, insn):
for name in capa.features.extractors.helpers.generate_symbols(dll, symbol):
yield API(name), insn.va

# if jump leads to an ENDBRANCH instruction, skip it
if f.vw.getByteDef(target)[1].startswith(b"\xf3\x0f\x1e"):
target += 4

target = capa.features.extractors.viv.helpers.get_coderef_from(f.vw, target)
if not target:
return
Expand Down
9 changes: 5 additions & 4 deletions capa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

RULES_PATH_DEFAULT_STRING = "(embedded rules)"
SIGNATURES_PATH_DEFAULT_STRING = "(embedded signatures)"
SUPPORTED_FILE_MAGIC = set([b"MZ"])
SUPPORTED_FILE_MAGIC = (b"MZ", b"\x7fELF")
BACKEND_VIV = "vivisect"
BACKEND_SMDA = "smda"
EXTENSIONS_SHELLCODE_32 = ("sc32", "raw32")
Expand Down Expand Up @@ -240,8 +240,8 @@ def is_supported_file_type(sample: str) -> bool:
Return if this is a supported file based on magic header values
"""
with open(sample, "rb") as f:
magic = f.read(2)
if magic in SUPPORTED_FILE_MAGIC:
magic = f.read(4)
if magic.startswith(SUPPORTED_FILE_MAGIC):
return True
else:
return False
Expand Down Expand Up @@ -414,7 +414,7 @@ def get_workspace(path, format, sigpaths):

# don't analyze, so that we can add our Flirt function analyzer first.
vw = viv_utils.getWorkspace(path, analyze=False, should_save=False)
elif format == "pe":
elif format in {"pe", "elf"}:
vw = viv_utils.getWorkspace(path, analyze=False, should_save=False)
elif format == "sc32":
# these are not analyzed nor saved.
Expand Down Expand Up @@ -668,6 +668,7 @@ def install_common_args(parser, wanted=None):
formats = [
("auto", "(default) detect file type automatically"),
("pe", "Windows PE file"),
("elf", "Executable and Linkable Format"),
("sc32", "32-bit shellcode"),
("sc64", "64-bit shellcode"),
("freeze", "features previously frozen by capa"),
Expand Down