Skip to content

Feature request: Publicize Rust API FFI conversion functions #6422

@comex

Description

@comex

What is the feature you'd like to have?
In the Rust API, the functionality to convert between the Rust wrapper types and the underlying C FFI types is currently marked pub(crate). I am requesting that it be made public in some form. This functionality includes from_raw, into_raw, inc_ref, the handle property (could be changed to a function), etc.

Is your feature request related to a problem?
While writing a Rust plugin, I ran into three different use cases where I needed to convert between Rust API wrappers and raw pointers to the C FFI types:

  1. Using binaryninjacore_sys to call functions that don't have a Rust wrapper yet (in my case, BNParseTypeString).
  2. Communicating with Python code that is using BN's Python API (example - not the best code but it works).
  3. Using a raw pointer as a hash map key (so that I can keep a per-object cache, but without keeping the object alive as would happen if I just used the wrapper type as the key).

Currently I am accomplishing all three by transmuting between the Rust wrapper types and raw pointers, but that is an abstraction violation. It would be better if I could use the proper APIs for this.

Are any alternative solutions acceptable?
In theory, you could obviate the need to drop down to the C API by providing the functionality natively. Respectively:

  1. Wrap all the missing functions.
  2. Add some kind of built-in Python object conversion functionality.
  3. Add some kind of 'unique ID' method or weak reference type.

But even then I think there would be use cases here and there for dropping down to the C API, e.g. interop with C or C++ code.

Metadata

Metadata

Assignees

Labels

Component: Rust APIIssue needs changes to the Rust APIEffort: TrivialIssue should take < 1 dayImpact: LowIssue is a papercut or has a good, supported workaround

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions