Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to import-to-bn.py #2554

Open
as0ni opened this issue Jan 14, 2025 · 1 comment
Open

Updates to import-to-bn.py #2554

as0ni opened this issue Jan 14, 2025 · 1 comment
Labels
binary-ninja bug Something isn't working

Comments

@as0ni
Copy link

as0ni commented Jan 14, 2025

Description

The import-to-bn.py script does not support capa's current JSON output schema. This issue proposes several updates to improve compatibility.

Happy to implement if these updates look good.

Proposed Changes

Current (1)

else:
    path = binaryninja.interaction.get_open_filename_input("capa report:", "JSON (*.js *.json);;All Files (*)")

Update (1)

Convert the string returned by get_open_filename_input() to a Path object for compatibility with Path methods:

else:
    path = binaryninja.interaction.get_open_filename_input("capa report:", "JSON (*.js *.json);;All Files (*)")
    path = Path(path)

Current (2)

if rule["meta"]["scope"] != "function":
    continue

Update (2)

Align with the latest capa JSON schema:

if rule["meta"]["scopes"]["static"] != "function":
    continue

Current (3)

for va in rule["matches"].keys():
    va = int(va)
    rows.append((ns, name, va))

Update (3)

Align with the latest capa JSON schema:

for match in rule["matches"]:
    va = int(match[0]["value"])
    rows.append((ns, name, va))

Versions

Tested by producing JSON output with capa v8.0.1 and running updated import-to-bn.py using Binary Ninja 4.2.6455.

@williballenthin
Copy link
Collaborator

Great catches! Thanks for noticing and reporting the issues.

All your proposed solutions look good. We'd be happy to merge those in if you'll contribute them.

Thanks @as0ni!

@williballenthin williballenthin added bug Something isn't working binary-ninja labels Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binary-ninja bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants