Skip to content

Commit

Permalink
Merge pull request #2182 from yelhamer/process-name-interface-show-fe…
Browse files Browse the repository at this point in the history
…atures

scripts/show-features.py: use extractor.get_process_name() interface …
  • Loading branch information
mr-tz committed Jul 2, 2024
2 parents b617179 + fccb533 commit 1a44701
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
8 changes: 4 additions & 4 deletions scripts/show-features.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def print_dynamic_analysis(extractor: DynamicFeatureExtractor, args):
process_handles = tuple(extractor.get_processes())

if args.process:
process_handles = tuple(filter(lambda ph: ph.inner["name"] == args.process, process_handles))
if args.process not in [ph.inner["name"] for ph in args.process]:
process_handles = tuple(filter(lambda ph: extractor.get_process_name(ph) == args.process, process_handles))
if args.process not in [extractor.get_process_name(ph) for ph in process_handles]:
print(f"{args.process} not a process")
return -1

Expand Down Expand Up @@ -227,13 +227,13 @@ def print_static_features(functions, extractor: StaticFeatureExtractor):

def print_dynamic_features(processes, extractor: DynamicFeatureExtractor):
for p in processes:
print(f"proc: {p.inner.process_name} (ppid={p.address.ppid}, pid={p.address.pid})")
print(f"proc: {extractor.get_process_name(p)} (ppid={p.address.ppid}, pid={p.address.pid})")

for feature, addr in extractor.extract_process_features(p):
if is_global_feature(feature):
continue

print(f" proc: {p.inner.process_name}: {feature}")
print(f" proc: {extractor.get_process_name(p)}: {feature}")

for t in extractor.get_threads(p):
print(f" thread: {t.address.tid}")
Expand Down
26 changes: 19 additions & 7 deletions tests/test_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,21 @@ def get_script_path(s: str):
return str(CD / ".." / "scripts" / s)


def get_file_path():
def get_binary_file_path():
return str(CD / "data" / "9324d1a8ae37a36ae560c37448c9705a.exe_")


def get_report_file_path():
return str(
CD
/ "data"
/ "dynamic"
/ "cape"
/ "v2.4"
/ "fb7ade52dc5a1d6128b9c217114a46d0089147610f99f5122face29e429a1e74.json.gz"
)


def get_rules_path():
return str(CD / ".." / "rules")

Expand All @@ -48,12 +59,13 @@ def get_rule_path():
pytest.param("lint.py", ["-t", "create directory", get_rules_path()]),
# `create directory` rule has native and .NET example PEs
pytest.param("lint.py", ["--thorough", "-t", "create directory", get_rules_path()]),
pytest.param("match-function-id.py", [get_file_path()]),
pytest.param("show-capabilities-by-function.py", [get_file_path()]),
pytest.param("show-features.py", [get_file_path()]),
pytest.param("show-features.py", ["-F", "0x407970", get_file_path()]),
pytest.param("show-unused-features.py", [get_file_path()]),
pytest.param("capa_as_library.py", [get_file_path()]),
pytest.param("match-function-id.py", [get_binary_file_path()]),
pytest.param("show-capabilities-by-function.py", [get_binary_file_path()]),
pytest.param("show-features.py", [get_binary_file_path()]),
pytest.param("show-features.py", ["-F", "0x407970", get_binary_file_path()]),
pytest.param("show-features.py", ["-P", "MicrosoftEdgeUpdate.exe", get_report_file_path()]),
pytest.param("show-unused-features.py", [get_binary_file_path()]),
pytest.param("capa_as_library.py", [get_binary_file_path()]),
],
)
def test_scripts(script, args):
Expand Down

0 comments on commit 1a44701

Please sign in to comment.