diff options
| author | Ryan Snyder <ryan@vector35.com> | 2021-01-21 18:27:48 +0000 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2021-01-21 19:06:55 +0000 |
| commit | d3140edec185f47235b9e4642bdd56d6c585a341 (patch) | |
| tree | a61859c29e4e3539daea2b761bb1439d942beaf4 /rust/src/headless.rs | |
| parent | c0ddbf0c76d3f1bb7a2b2024f749afc8b9482575 (diff) | |
This is a combination of 23 commits, the work of Ryan Snyder:
Initial fresh repo
Add support for recent calling convention API updates and folds the binaryninjacore-sys crate directly into this one.
Add support for auto function analysis suppression
Finish moving binaryninjacore-sys back into this crate
Update for Symbol/Segment core API changes
Update for Symbol API cleanup
api: advance submodule reference, support Token changes
arch/lifting: support for flags in custom architectures
arch/lifting: support default flag write behaviors, handle more ops
build: enable headless binary support on MacOS via evil hack
bv: add BinaryView wrapper support, remove wrong comment
api: update to latest binja dev branch support
deps: bump dep versions
rust: bump to 2018 edition
api: bump to avoid cargo submodule brokenness
build: improve binaryninja path detection; enable linux linkhack
bv: stub for bv load settings
arch: fix flag related crash, minor llil update
api: update for recent changes
macos: disable linkhack briefly
Diffstat (limited to 'rust/src/headless.rs')
| -rw-r--r-- | rust/src/headless.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/rust/src/headless.rs b/rust/src/headless.rs new file mode 100644 index 00000000..e6b7c51c --- /dev/null +++ b/rust/src/headless.rs @@ -0,0 +1,68 @@ +use std::env; +use std::mem; +use std::os::raw; +use std::ffi::{OsStr, CString, CStr}; +use std::path::PathBuf; + +#[repr(C)] +struct DlInfo { + dli_fname: *const raw::c_char, + dli_fbase: *mut raw::c_void, + dli_sname: *const raw::c_char, + dli_saddr: *mut raw::c_void +} + +#[cfg(not(target_os = "windows"))] +fn binja_path() -> PathBuf { + use std::os::unix::ffi::OsStrExt; + + if let Ok(p) = env::var("BINJA_DIR") { + return PathBuf::from(p); + } + + extern { + fn dladdr(addr: *mut raw::c_void, info: *mut DlInfo) -> raw::c_int; + } + + unsafe { + let mut info: DlInfo = mem::uninitialized(); + + if dladdr(BNSetBundledPluginDirectory as *mut _, &mut info) == 0 { + panic!("Failed to find libbinaryninjacore path!"); + } + + if info.dli_fname.is_null() { + panic!("Failed to find libbinaryninjacore path!"); + } + + let path = CStr::from_ptr(info.dli_fname); + let path = OsStr::from_bytes(path.to_bytes()); + let mut path = PathBuf::from(path); + + path.pop(); + path + } +} + + +#[cfg(target_os = "windows")] +fn binja_path() -> PathBuf { + PathBuf::from(env::var("PROGRAMFILES").unwrap()).join("Vector35\\BinaryNinja\\") +} + +use binaryninjacore_sys::{BNSetBundledPluginDirectory, + BNInitCorePlugins, + BNInitUserPlugins, + BNInitRepoPlugins}; + +pub fn init() { + unsafe { + let path = binja_path().join("plugins").into_os_string(); + let path = CString::new(path.into_string().unwrap()).unwrap(); + + BNSetBundledPluginDirectory(path.as_ptr()); + BNInitCorePlugins(); + BNInitUserPlugins(); + BNInitRepoPlugins(); + } +} |
