Skip to content

Commit

Permalink
features: add BinExport2 declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
williballenthin authored and mike-hunhoff committed Jun 10, 2024
1 parent 76a4a58 commit 89ebfe6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
5 changes: 4 additions & 1 deletion capa/features/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,10 @@ def get_value_str(self):
# other candidates here: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types
ARCH_I386 = "i386"
ARCH_AMD64 = "amd64"
ARCH_AARCH64 = "aarch64"
# dotnet
ARCH_ANY = "any"
VALID_ARCH = (ARCH_I386, ARCH_AMD64, ARCH_ANY)
VALID_ARCH = (ARCH_I386, ARCH_AMD64, ARCH_ANY, ARCH_AARCH64)


class Arch(Feature):
Expand Down Expand Up @@ -459,6 +460,7 @@ def evaluate(self, features: "capa.engine.FeatureSet", short_circuit=True):
FORMAT_AUTO = "auto"
FORMAT_SC32 = "sc32"
FORMAT_SC64 = "sc64"
FORMAT_BINEXPORT2 = "binexport2"
FORMAT_CAPE = "cape"
FORMAT_FREEZE = "freeze"
FORMAT_RESULT = "result"
Expand All @@ -470,6 +472,7 @@ def evaluate(self, features: "capa.engine.FeatureSet", short_circuit=True):
FORMAT_DOTNET,
FORMAT_FREEZE,
FORMAT_RESULT,
FORMAT_BINEXPORT2,
}
DYNAMIC_FORMATS = {
FORMAT_CAPE,
Expand Down
23 changes: 13 additions & 10 deletions capa/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
FORMAT_FREEZE,
FORMAT_UNKNOWN,
Format,
)
), FORMAT_BINEXPORT2

EXTENSIONS_SHELLCODE_32 = ("sc32", "raw32")
EXTENSIONS_SHELLCODE_64 = ("sc64", "raw64")
EXTENSIONS_BINEXPORT2 = ("BinExport", "BinExport2")
EXTENSIONS_DYNAMIC = ("json", "json_", "json.gz")
EXTENSIONS_ELF = "elf_"
EXTENSIONS_FREEZE = "frz"
Expand Down Expand Up @@ -105,15 +106,8 @@ def get_format_from_extension(sample: Path) -> str:
format_ = get_format_from_report(sample)
elif sample.name.endswith(EXTENSIONS_FREEZE):
format_ = FORMAT_FREEZE
return format_


def get_auto_format(path: Path) -> str:
format_ = get_format(path)
if format_ == FORMAT_UNKNOWN:
format_ = get_format_from_extension(path)
if format_ == FORMAT_UNKNOWN:
raise UnsupportedFormatError()
elif sample.name.endswith(EXTENSIONS_BINEXPORT2):
format_ = FORMAT_BINEXPORT2
return format_


Expand All @@ -136,6 +130,15 @@ def get_format(sample: Path) -> str:
return FORMAT_UNKNOWN


def get_auto_format(path: Path) -> str:
format_ = get_format(path)
if format_ == FORMAT_UNKNOWN:
format_ = get_format_from_extension(path)
if format_ == FORMAT_UNKNOWN:
raise UnsupportedFormatError()
return format_


@contextlib.contextmanager
def redirecting_print_to_tqdm(disable_progress):
"""
Expand Down

0 comments on commit 89ebfe6

Please sign in to comment.