summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2024-12-14 12:52:23 -0500
committerMason Reed <mason@vector35.com>2024-12-14 12:52:23 -0500
commit5239ad6e8345e691fde31fd9f513fcf200e942aa (patch)
tree49863446efe7ae740faf34b2b674c91bc7461c4c /plugins
parent53b587d63833d43c46a228f1f58517d30f149709 (diff)
WARP: Attempt auto linking to core
This was missing as apparently some of this was written against the `rust_break_everything` branch.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/warp/build.rs57
1 files changed, 49 insertions, 8 deletions
diff --git a/plugins/warp/build.rs b/plugins/warp/build.rs
index 1239f000..18ac9231 100644
--- a/plugins/warp/build.rs
+++ b/plugins/warp/build.rs
@@ -1,7 +1,46 @@
#![allow(unused_imports)]
+use std::env;
use std::path::PathBuf;
use std::process::Command;
+#[cfg(target_os = "macos")]
+static LASTRUN_PATH: (&str, &str) = ("HOME", "Library/Application Support/Binary Ninja/lastrun");
+
+#[cfg(target_os = "linux")]
+static LASTRUN_PATH: (&str, &str) = ("HOME", ".binaryninja/lastrun");
+
+#[cfg(windows)]
+static LASTRUN_PATH: (&str, &str) = ("APPDATA", "Binary Ninja\\lastrun");
+
+// Check last run location for path to BinaryNinja; Otherwise check the default install locations
+fn link_path() -> PathBuf {
+ use std::io::prelude::*;
+ use std::io::BufReader;
+
+ let home = PathBuf::from(env::var(LASTRUN_PATH.0).unwrap());
+ let lastrun = PathBuf::from(&home).join(LASTRUN_PATH.1);
+
+ std::fs::File::open(lastrun)
+ .and_then(|f| {
+ let mut binja_path = String::new();
+ let mut reader = BufReader::new(f);
+
+ reader.read_line(&mut binja_path)?;
+ Ok(PathBuf::from(binja_path.trim()))
+ })
+ .unwrap_or_else(|_| {
+ #[cfg(target_os = "macos")]
+ return PathBuf::from("/Applications/Binary Ninja.app/Contents/MacOS");
+
+ #[cfg(target_os = "linux")]
+ return home.join("binaryninja");
+
+ #[cfg(windows)]
+ return PathBuf::from(env::var("PROGRAMFILES").unwrap())
+ .join("Vector35\\BinaryNinja\\");
+ })
+}
+
#[cfg(feature = "test")]
fn compile_rust(file: PathBuf) -> bool {
let out_dir = std::env::var_os("OUT_DIR").unwrap();
@@ -18,14 +57,16 @@ fn compile_rust(file: PathBuf) -> bool {
}
fn main() {
- if let Some(link_path) = option_env!("BINARYNINJADIR") {
- println!("cargo::rustc-link-lib=dylib=binaryninjacore");
- println!("cargo::rustc-link-search={}", link_path);
-
- #[cfg(not(target_os = "windows"))]
- {
- println!("cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}", link_path);
- }
+ // Use BINARYNINJADIR first for custom BN builds/configurations (BN devs/build server), fallback on defaults
+ let link_path = env::var("BINARYNINJADIR")
+ .map(PathBuf::from)
+ .unwrap_or_else(|_| link_path());
+ let link_path_str = link_path.to_str().unwrap();
+ println!("cargo::rustc-link-lib=dylib=binaryninjacore");
+ println!("cargo::rustc-link-search={}", link_path_str);
+ #[cfg(not(target_os = "windows"))]
+ {
+ println!("cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}", link_path_str);
}
#[cfg(feature = "test")]