Skip to content

Commit 5cf6ee5

Browse files
committed
More rust cleanup
- Add extra info to README.md - Refactor components api - Add components unit test
1 parent b495bbe commit 5cf6ee5

File tree

5 files changed

+148
-92
lines changed

5 files changed

+148
-92
lines changed

rust/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ These bindings are still actively under development. Compatibility _will_ break
1313
It is encouraged that you reference a specific commit to avoid having your plugin/application break when the API changes.
1414
To specify a specific commit see the cargo documentation [here](https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#choice-of-commit).
1515

16+
If you are worried about breaking changes avoid modules with warnings about instability!
17+
1618
**MSRV**: The Rust version specified in the `Cargo.toml`.
1719

1820
## Example

rust/src/binary_view.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use binaryninjacore_sys::*;
2525

2626
use crate::architecture::{Architecture, CoreArchitecture};
2727
use crate::basic_block::BasicBlock;
28-
use crate::component::{Component, ComponentBuilder, IntoComponentGuid};
28+
use crate::component::{Component, IntoComponentGuid};
2929
use crate::confidence::Conf;
3030
use crate::data_buffer::DataBuffer;
3131
use crate::debuginfo::DebugInfo;
@@ -1422,39 +1422,35 @@ pub trait BinaryViewExt: BinaryViewBase {
14221422
.collect()
14231423
}
14241424

1425-
fn component_by_guid<S: BnStrCompatible>(&self, guid: S) -> Option<Component> {
1425+
fn component_by_guid<S: BnStrCompatible>(&self, guid: S) -> Option<Ref<Component>> {
14261426
let name = guid.into_bytes_with_nul();
14271427
let result = unsafe {
14281428
BNGetComponentByGuid(
14291429
self.as_ref().handle,
14301430
name.as_ref().as_ptr() as *const c_char,
14311431
)
14321432
};
1433-
NonNull::new(result).map(|h| unsafe { Component::from_raw(h) })
1433+
NonNull::new(result).map(|h| unsafe { Component::ref_from_raw(h) })
14341434
}
14351435

1436-
fn root_component(&self) -> Option<Component> {
1436+
fn root_component(&self) -> Option<Ref<Component>> {
14371437
let result = unsafe { BNGetRootComponent(self.as_ref().handle) };
1438-
NonNull::new(result).map(|h| unsafe { Component::from_raw(h) })
1438+
NonNull::new(result).map(|h| unsafe { Component::ref_from_raw(h) })
14391439
}
14401440

1441-
fn component_builder(&self) -> ComponentBuilder {
1442-
ComponentBuilder::new_from_raw(self.as_ref().handle)
1443-
}
1444-
1445-
fn component_by_path<P: BnStrCompatible>(&self, path: P) -> Option<Component> {
1441+
fn component_by_path<P: BnStrCompatible>(&self, path: P) -> Option<Ref<Component>> {
14461442
let path = path.into_bytes_with_nul();
14471443
let result = unsafe {
14481444
BNGetComponentByPath(
14491445
self.as_ref().handle,
14501446
path.as_ref().as_ptr() as *const c_char,
14511447
)
14521448
};
1453-
NonNull::new(result).map(|h| unsafe { Component::from_raw(h) })
1449+
NonNull::new(result).map(|h| unsafe { Component::ref_from_raw(h) })
14541450
}
14551451

14561452
fn remove_component(&self, component: &Component) -> bool {
1457-
unsafe { BNRemoveComponent(self.as_ref().handle, component.as_raw()) }
1453+
unsafe { BNRemoveComponent(self.as_ref().handle, component.handle.as_ptr()) }
14581454
}
14591455

14601456
fn remove_component_by_guid<P: IntoComponentGuid>(&self, guid: P) -> bool {

rust/src/collaboration.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The collaboration API is **unstable** and as such will undergo breaking changes in the near future!
2+
13
mod changeset;
24
mod file;
35
mod folder;

0 commit comments

Comments
 (0)