Skip to content

Add Binary Similarity Python Bindings - #8385

Open
emesare wants to merge 3 commits into
devfrom
similarity/binary-similarity-python-bindings
Open

Add Binary Similarity Python Bindings#8385
emesare wants to merge 3 commits into
devfrom
similarity/binary-similarity-python-bindings

Conversation

@emesare

@emesare emesare commented Aug 3, 2026

Copy link
Copy Markdown
Member

Apart of https://github.com/Vector35/binaryninja/pull/1735 (Binary Similarity)

Adds the python bindings we depend on for user examples and python core unit tests

Depends on:

@emesare emesare added this to the Krypton milestone Aug 3, 2026
@plafosse
plafosse self-requested a review August 11, 2026 21:01
Comment thread python/similarity.py
return cls()

@classmethod
def for_node(cls, node_id: int) -> 'SimilaritySessionCompletionQuery':

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Type hint should be a defined type rather than an int

Comment thread python/similarity.py
class SimilarityEntityRef:
"""Identifies an entity within a session node."""

node_id: int

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

use a defined type instead of an int

Comment thread python/similarity.py
class SimilarityView:
"""A graph or linear view produced for a similarity result."""

group: str

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Use a defined type instead of str

Comment thread python/similarity.py
class SimilarityRenderContext:
"""Holds views used to display a similarity result."""

def __init__(self, handle=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I know were inconsistent here but define a type hint for the handle. Its super helpful and can help avoid crashes

Comment thread python/similarity.py
raise KeyError(f"'{value}' is not a valid similarity session resolver type")
return CoreSimilaritySessionResolverType(handle=resolver_type)

def __contains__(cls: '_SimilaritySessionResolverTypeMetaClass', name: object) -> bool:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

shouldn't this be self

Comment thread python/similarity.py
except KeyError:
return False

def get(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should this first param be self as its not a classmethod

Comment thread python/similarity.py
class DiffRenderer:
"""Renders functions with similarity range annotations."""

def __init__(self, handle=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

handle type hint

@plafosse

Copy link
Copy Markdown
Member

Did a quick review, nothing stood out to me as wrong. All of my comments are non-blocking nits:

  • Prefer named types rather than int/str
  • Ensure your handles have type hints.
  • You incremented the BN_MINIMUM_CORE_ABI_VERSION instead of the BN_CURRENT_CORE_ABI_VERSION

I didn't check the core PR and you may have already done this but you should add these objects to the ActiveObjectCounter if you haven't already and add a test which validate that we're not leaking these objects.

Actually one that confuses me and I don't know if its blocking or not

SimilarityProviderType.create returns Optional['SimilarityProvider']:

but SimilarityProviderType._create raises ValueError if it returns None that seems odd?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants