Skip to content

Commit

Permalink
WARP: Update build system to find binja dylibs on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberkaida committed Dec 14, 2024
1 parent e2cfbbd commit c5d3abc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
11 changes: 1 addition & 10 deletions plugins/warp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
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`)
42 changes: 41 additions & 1 deletion plugins/warp/build.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,10 +19,49 @@ fn compile_rust(file: PathBuf) -> bool {
}

fn main() {
if let Some(link_path) = option_env!("BINARYNINJADIR") {

let binja_base_dir: &str = 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 user_path.exists() {
return user_path.to_str().unwrap()
}
}
}

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);
Expand Down

0 comments on commit c5d3abc

Please sign in to comment.