Skip to content

Commit

Permalink
More rust cleanup
Browse files Browse the repository at this point in the history
- Added main thread handler api
- Register a headless main thread handler by default in initialization
- Refactor QualifiedName to be properly owned
- Loosened some type constraints on some apis involving QualifiedName
- Fixed some apis that were crashing due to incorrect param types
- Removed extern crate cruft for log crate
- Simplified headless initialization using more wrapper apis
- Fixed segments leaking because of no ref wrapper, see BinaryViewExt::segment_at
- Added rstest to manage headless init in unit tests
- Added some more unit tests
- Refactored demangler api to be more ergonomic
- Fixed minidump plugin not building
  • Loading branch information
emesare committed Jan 4, 2025
1 parent 43e5fb7 commit e3d59cc
Show file tree
Hide file tree
Showing 30 changed files with 1,220 additions and 909 deletions.
2 changes: 1 addition & 1 deletion plugins/minidump/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use binaryninja::binaryview::{BinaryView, BinaryViewBase, BinaryViewExt};

pub fn print_memory_information(bv: &BinaryView) {
debug!("Printing memory information");
if let Ok(minidump_bv) = bv.parent_view() {
if let Some(minidump_bv) = bv.parent_view() {
if let Ok(read_buffer) = minidump_bv.read_buffer(0, minidump_bv.len()) {
if let Ok(minidump_obj) = Minidump::read(read_buffer.get_data()) {
if let Ok(memory_info_list) = minidump_obj.get_stream::<MinidumpMemoryInfoList>() {
Expand Down
2 changes: 1 addition & 1 deletion plugins/minidump/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl MinidumpBinaryView {
}

fn init(&self) -> BinaryViewResult<()> {
let parent_view = self.parent_view()?;
let parent_view = self.parent_view().ok_or(())?;
let read_buffer = parent_view.read_buffer(0, parent_view.len())?;

if let Ok(minidump_obj) = Minidump::read(read_buffer.get_data()) {
Expand Down
171 changes: 104 additions & 67 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ rayon = { version = "1.8", optional = true }
binaryninjacore-sys = { path = "binaryninjacore-sys" }

[dev-dependencies]
rstest = "0.23.0"
rstest = "0.24.0"
tempfile = "3"
8 changes: 4 additions & 4 deletions rust/examples/demangler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ impl CustomDemangler for TestDemangler {
_arch: &CoreArchitecture,
name: &str,
_view: Option<Ref<BinaryView>>,
) -> Result<(Option<Ref<Type>>, QualifiedName), ()> {
) -> Option<(QualifiedName, Option<Ref<Type>>)> {
match name {
"test_name" => Ok((Some(Type::bool()), QualifiedName::from(vec!["test_name"]))),
"test_name2" => Ok((None, QualifiedName::from(vec!["test_name2", "aaa"]))),
_ => Err(()),
"test_name" => Some((QualifiedName::from(vec!["test_name"]), Some(Type::bool()))),
"test_name2" => Some((QualifiedName::from(vec!["test_name2", "aaa"]), None)),
_ => None,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rust/src/architecture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ where
return expr.index.0;
}
} else {
warn!(
log::warn!(
"unable to unpack flag write op: {:?} with {} operands",
op,
operands.len()
Expand Down
Loading

1 comment on commit e3d59cc

@emesare
Copy link
Member Author

@emesare emesare commented on e3d59cc Jan 5, 2025

Choose a reason for hiding this comment

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

because we got rid of the workspace in api/rust we can .gitignore the Cargo.lock in there

Please sign in to comment.