From 62714aca66b76e761a17bf254f38de59ca2555d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=AB=E3=82=A4=E3=83=80?= Date: Sat, 14 Dec 2024 10:25:01 +0900 Subject: [PATCH] WARP: Update build system to find binja dylibs on macOS --- plugins/warp/README.md | 11 +---------- plugins/warp/build.rs | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/plugins/warp/README.md b/plugins/warp/README.md index 732de15ba..15b126e86 100644 --- a/plugins/warp/README.md +++ b/plugins/warp/README.md @@ -41,13 +41,4 @@ Example: `./sigem mylibrary.a` or `./sigem ./all-libs/` Once its finished you should see a `.sbin` file next to the input file, this can be moved into the corresponding signature folder (see the [user docs](https://docs.binary.ninja/dev/annotation.html?h=install+path#signature-library) for more info) -If you encounter malloc errors or instability try and adjust the number of parallel threads using `RAYON_NUM_THREADS` environment variable (ex. `RAYON_NUM_THREADS=1 ./sigem mylib.a`) - -#### macOS - -If you are on macOS and the `sigem` binary fails to run due to missing `libbinaryninjacore.1.dylib`, you can set your [`DYLD_LIBRARY_PATH`](x-man-page://1/dyld) to include the `${DEP_BINARYNINJACORE_PATH}/Contents/MacOS/` directory. - -```sh -export DYLD_LIBRARY_PATH="${DYLD_LIBRARY_PATH}:${DEP_BINARYNINJACORE_PATH}/Contents/MacOS/" -./sigem --help -``` \ No newline at end of file +If you encounter malloc errors or instability try and adjust the number of parallel threads using `RAYON_NUM_THREADS` environment variable (ex. `RAYON_NUM_THREADS=1 ./sigem mylib.a`) \ No newline at end of file diff --git a/plugins/warp/build.rs b/plugins/warp/build.rs index 1239f000e..ccd9d6e8e 100644 --- a/plugins/warp/build.rs +++ b/plugins/warp/build.rs @@ -1,6 +1,7 @@ #![allow(unused_imports)] use std::path::PathBuf; use std::process::Command; +use std::path::Path; #[cfg(feature = "test")] fn compile_rust(file: PathBuf) -> bool { @@ -18,10 +19,49 @@ fn compile_rust(file: PathBuf) -> bool { } fn main() { - if let Some(link_path) = option_env!("BINARYNINJADIR") { + + let binja_base_dir = option_env!("DEP_BINARYNINJACORE_BASE_DIR").unwrap_or_else(|| { + // If the environment variable is not set, try the default locations from + // https://docs.binary.ninja/guide/#binary-path + + #[cfg(target_os = "macos")] + { + let default = "/Applications/Binary Ninja.app/"; + if Path::new(default).exists() { + return default + } + } + + #[cfg(target_os = "windows")] + { + let default = r"C:\Program Files\Vector35\BinaryNinja"; + if Path::new(default).exists() { + return default + } + // Nothing at default path, check user path + // TODO: Check %LOCALAPPDATA%\Vector35\BinaryNinja + if let Some(local_app_data) = std::env::var_os("LOCALAPPDATA") { + let user_path = Path::new(&local_app_data).join("Vector35").join("BinaryNinja"); + if default.exists() { + return user_path.to_str() + } + } + } + + panic!("DEP_BINARYNINJACORE_BASE_DIR must be set to the base directory of the Binary Ninja installation"); + }); + + if let link_path = binja_base_dir { println!("cargo::rustc-link-lib=dylib=binaryninjacore"); println!("cargo::rustc-link-search={}", link_path); + #[cfg(target_os = "macos")] + { + // On macOS the binaryninjacore dylib is in the MacOS directory + println!("cargo::rustc-link-search={}/Contents/MacOS", link_path); + println!("cargo::rustc-link-arg=-Wl,-rpath,{0}/Contents/MacOS,-L{0}/Contents/MacOS", link_path); + } + #[cfg(not(target_os = "windows"))] { println!("cargo::rustc-link-arg=-Wl,-rpath,{0},-L{0}", link_path);