Skip to content

Commit

Permalink
update Session::load_with_option to the new API
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran authored and ElykDeer committed May 28, 2024
1 parent 53eed1f commit fce2681
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
9 changes: 4 additions & 5 deletions rust/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

use crate::{
binaryview,
metadata::Metadata,
rc::{self, Ref},
string::BnStrCompatible,
rc,
string::{BnStrCompatible, IntoJson},
};

use std::env;
Expand Down Expand Up @@ -146,11 +145,11 @@ impl Session {
/// let bv = headless_session.load_with_options("/bin/cat", true, Some(settings))
/// .expect("Couldn't open `/bin/cat`");
/// ```
pub fn load_with_options(
pub fn load_with_options<O: IntoJson>(
&self,
filename: &str,
update_analysis_and_wait: bool,
options: Option<Ref<Metadata>>,
options: Option<O>,
) -> Option<rc::Ref<binaryview::BinaryView>> {
crate::load_with_options(filename, update_analysis_and_wait, options)
}
Expand Down
11 changes: 5 additions & 6 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ const BN_INVALID_EXPR: usize = usize::MAX;
/// The main way to open and load files into Binary Ninja. Make sure you've properly initialized the core before calling this function. See [`crate::headless::init()`]
pub fn load<S: BnStrCompatible>(filename: S) -> Option<rc::Ref<binaryview::BinaryView>> {
let filename = filename.into_bytes_with_nul();
let options = "";

let handle = unsafe {
binaryninjacore_sys::BNLoadFilename(
filename.as_ref().as_ptr() as *mut _,
true,
std::ptr::null(),
options.as_ptr() as *mut core::ffi::c_char,
None,
)
};
Expand All @@ -216,15 +217,13 @@ pub fn load<S: BnStrCompatible>(filename: S) -> Option<rc::Ref<binaryview::Binar

/// The main way to open and load files (with options) into Binary Ninja. Make sure you've properly initialized the core before calling this function. See [`crate::headless::init()`]
///
/// <div class="warning">Your JSON needs to be compliant with RapidJSON's format, which basically means you just need to escape double quotes (\") and single quotes won't work.</div>
///
/// ```no_run
/// use binaryninja::{metadata::Metadata, rc::Ref};
/// use std::collections::HashMap;
///
/// let settings: Ref<Metadata> = HashMap::from([
/// ("analysis.linearSweep.autorun", false.into()),
/// ]).into();
///
/// let bv = binaryninja::load_with_options("/bin/cat", true, Some(settings))
/// let bv = binaryninja::load_with_options("/bin/cat", true, Some("{\"analysis.linearSweep.autorun\": false}"))
/// .expect("Couldn't open `/bin/cat`");
/// ```
pub fn load_with_options<S: BnStrCompatible, O: IntoJson>(
Expand Down
7 changes: 0 additions & 7 deletions rust/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,13 +710,6 @@ impl IntoJson for &Metadata {
}
}

impl IntoJson for Metadata {
type Output = BnString;
fn get_json_string(self) -> Result<BnString, ()> {
Metadata::get_json_string(&self)
}
}

impl IntoJson for Ref<Metadata> {
type Output = BnString;
fn get_json_string(self) -> Result<BnString, ()> {
Expand Down

0 comments on commit fce2681

Please sign in to comment.