summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2021-06-29 11:35:06 -0400
committerKyleMiles <krm504@nyu.edu>2021-06-29 14:00:21 -0400
commit70be4645d30c8017524ae2b444ac7e0c0a8448a6 (patch)
tree3bdad671acaa346b2c893448fba7c4908363cfbd
parentf388a25624c5860c45f6e002577a2c283002ce47 (diff)
Rust API : No longer update to latest cargo nightly; Add link args back to -sys to reduce build errors
-rw-r--r--.gitignore2
-rw-r--r--CMakeLists.txt2
-rw-r--r--rust/README.md30
-rw-r--r--rust/binaryninjacore-sys/build.rs63
-rw-r--r--rust/examples/basic_script/CMakeLists.txt16
-rw-r--r--rust/examples/basic_script/Cargo.lock353
-rw-r--r--rust/examples/dwarfdump/build.rs67
-rw-r--r--rust/examples/flowgraph/build.rs67
-rw-r--r--rust/examples/template/CMakeLists.txt89
-rw-r--r--rust/examples/template/README.md12
10 files changed, 460 insertions, 241 deletions
diff --git a/.gitignore b/.gitignore
index 18784fc3..b755ba2f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -63,7 +63,7 @@ Makefile
# Make
python/examples/binaryninja/
-python/plugins/
+python/plugins/
python/types/
suite/binaryninja/
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b575f864..dfc4797d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,6 +4,8 @@ project(binaryninjaapi)
option(BN_API_BUILD_EXAMPLES "Builds example plugins" OFF)
+set(CARGO_API_VERSION nightly-2021-06-27)
+
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
if (MSVC)
message(FATAL_ERROR "Binary Ninja is 64-bit only (try -G \"${CMAKE_GENERATOR} Win64\")")
diff --git a/rust/README.md b/rust/README.md
index 39b5e9b0..815b449b 100644
--- a/rust/README.md
+++ b/rust/README.md
@@ -4,7 +4,7 @@
> :warning: **These bindings are in a very early beta, only have partial support for the core APIs and are still actively under development. Compatibility _will_ break and conventions _will_ change! They are being used for core Binary Ninja features however, so we expect much of what is already there to be reliable enough to build on, just don't be surprised if your plugins/scripts need to hit a moving target.**
-> :warning: This project requires **Rust Nightly** to build with those fancy linker arguments
+> :warning: This project requires **Rust Nightly** to build with those fancy linker arguments - most recent tested version: `cargo 1.55.0-nightly (9233aa06c 2021-06-22)`
## Dependencies
@@ -16,7 +16,33 @@ Rust **Nightly**
## How to use
-See [`examples/template`](examples/template).
+See [`examples/template`](examples/template) for more details.
+
+### To write a plugin:
+
+`Cargo.toml`:
+```
+[lib]
+crate-type = ["cdylib"]
+
+[dependencies]
+binaryninja = {git = "https://github.com/Vector35/binaryninja-api.git", branch = "dev"}
+```
+
+See the `./examples/`. Plugin registration commands are in `binaryninja::command::*`
+
+
+### To write a standalone executable:
+
+`Cargo.toml`:
+```
+[dependencies]
+binaryninja = { git = "https://github.com/Vector35/binaryninja-api.git", branch = "dev"}
+```
+
+All standalone binaries should call both `binaryninja::headless::init()` and `binaryninja::headless::shutdown()`.
+All standalone binaries need to provide a `build.rs`.
+See [`examples/template`](examples/template) for details.
---
diff --git a/rust/binaryninjacore-sys/build.rs b/rust/binaryninjacore-sys/build.rs
index 38f8d208..13de448f 100644
--- a/rust/binaryninjacore-sys/build.rs
+++ b/rust/binaryninjacore-sys/build.rs
@@ -6,12 +6,75 @@ use std::io::BufRead;
use std::io::BufReader;
use std::path::PathBuf;
+#[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::*;
+
+ let home = PathBuf::from(env::var(LASTRUN_PATH.0).unwrap());
+ let lastrun = PathBuf::from(&home).join(LASTRUN_PATH.1);
+
+ 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\\");
+ })
+}
+
fn main() {
println!("cargo:rerun-if-changed=../../binaryninjacore.h");
//Cargo's output directory
let out_dir = env::var("OUT_DIR").unwrap();
+ let link_path = env::var("BINARYNINJADIR")
+ .map(PathBuf::from)
+ .unwrap_or_else(|_| link_path());
+
+ // Linux builds of binaryninja ship with libbinaryninjacore.so.1 in the
+ // application folder and no symlink. The linker will attempt to link with
+ // libbinaryninjacore.so. Since this is likely going to fail, we detect this
+ // ahead of time and create an appropriately named symlink inside of OUT_DIR
+ // and add it to the library search path.
+ #[cfg(target_os = "linux")]
+ {
+ let symlink_target = PathBuf::from(&out_dir).join("libbinaryninjacore.so");
+ if !link_path.join("libbinaryninjacore.so").exists() && !symlink_target.exists() {
+ use std::os::unix::fs;
+ fs::symlink(
+ link_path.join("libbinaryninjacore.so.1"),
+ PathBuf::from(&out_dir).join("libbinaryninjacore.so"),
+ )
+ .expect("failed to create required symlink");
+ }
+ println!("cargo:rustc-link-search={}", out_dir);
+ }
+
+ println!("cargo:rustc-link-lib=binaryninjacore");
+ println!("cargo:rustc-link-search={}", link_path.to_str().unwrap());
+
let current_line = "#define BN_CURRENT_UI_ABI_VERSION ";
let minimum_line = "#define BN_MINIMUM_UI_ABI_VERSION ";
let mut current_version = "0".to_string();
diff --git a/rust/examples/basic_script/CMakeLists.txt b/rust/examples/basic_script/CMakeLists.txt
index 51adb923..cb44180b 100644
--- a/rust/examples/basic_script/CMakeLists.txt
+++ b/rust/examples/basic_script/CMakeLists.txt
@@ -29,7 +29,7 @@ add_custom_target(test_headless ALL DEPENDS ${OUTPUT_PATH})
add_dependencies(test_headless binaryninjaapi)
find_program(RUSTUP_PATH rustup REQUIRED HINTS ~/.cargo/bin)
-set(INSTALL_UPDATE_NIGHTLY ${RUSTUP_PATH} install nightly)
+set(RUSTUP_COMMAND ${RUSTUP_PATH} run ${CARGO_API_VERSION} cargo build)
if(APPLE)
if(UNIVERSAL)
@@ -43,13 +43,12 @@ if(APPLE)
add_custom_command(
OUTPUT ${OUTPUT_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
COMMAND ${CMAKE_COMMAND} -E env
MACOSX_DEPLOYMENT_TARGET=10.14 LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build --target=aarch64-apple-darwin ${CARGO_OPTS}
+ ${RUSTUP_COMMAND} --target=aarch64-apple-darwin ${CARGO_OPTS}
COMMAND ${CMAKE_COMMAND} -E env
MACOSX_DEPLOYMENT_TARGET=10.14 LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build --target=x86_64-apple-darwin ${CARGO_OPTS}
+ ${RUSTUP_COMMAND} --target=x86_64-apple-darwin ${CARGO_OPTS}
COMMAND cp ${AARCH64_LIB_PATH} ${OUTPUT_PATH}-aarch
COMMAND cp ${X86_64_LIB_PATH} ${OUTPUT_PATH}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
@@ -63,10 +62,9 @@ if(APPLE)
add_custom_command(
OUTPUT ${OUTPUT_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
COMMAND ${CMAKE_COMMAND} -E env
MACOSX_DEPLOYMENT_TARGET=10.14 LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build --target=x86_64-apple-darwin ${CARGO_OPTS}
+ ${RUSTUP_COMMAND} --target=x86_64-apple-darwin ${CARGO_OPTS}
COMMAND cp ${X86_64_LIB_PATH} ${OUTPUT_PATH}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
@@ -74,20 +72,18 @@ if(APPLE)
elseif(WIN32)
add_custom_command(
OUTPUT ${OUTPUT_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
COMMAND ${CMAKE_COMMAND} -E env
LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build ${CARGO_OPTS}
+ ${RUSTUP_COMMAND} ${CARGO_OPTS}
COMMAND cp ${TARGET_DIR}/${OUTPUT_FILE} ${OUTPUT_PATH}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
else()
add_custom_command(
OUTPUT ${OUTPUT_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
COMMAND ${CMAKE_COMMAND} -E env
LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build ${CARGO_OPTS}
+ ${RUSTUP_COMMAND} ${CARGO_OPTS}
COMMAND cp ${TARGET_DIR}/${OUTPUT_FILE} ${OUTPUT_PATH}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
diff --git a/rust/examples/basic_script/Cargo.lock b/rust/examples/basic_script/Cargo.lock
new file mode 100644
index 00000000..36be9636
--- /dev/null
+++ b/rust/examples/basic_script/Cargo.lock
@@ -0,0 +1,353 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "aho-corasick"
+version = "0.7.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
+name = "ansi_term"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi",
+]
+
+[[package]]
+name = "basic_script"
+version = "0.1.0"
+dependencies = [
+ "binaryninja",
+]
+
+[[package]]
+name = "binaryninja"
+version = "0.1.0"
+dependencies = [
+ "binaryninjacore-sys",
+ "libc",
+ "log",
+]
+
+[[package]]
+name = "binaryninjacore-sys"
+version = "0.1.0"
+dependencies = [
+ "bindgen",
+]
+
+[[package]]
+name = "bindgen"
+version = "0.58.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0f8523b410d7187a43085e7e064416ea32ded16bd0a4e6fc025e21616d01258f"
+dependencies = [
+ "bitflags",
+ "cexpr",
+ "clang-sys",
+ "clap",
+ "env_logger",
+ "lazy_static",
+ "lazycell",
+ "log",
+ "peeking_take_while",
+ "proc-macro2",
+ "quote",
+ "regex",
+ "rustc-hash",
+ "shlex",
+ "which",
+]
+
+[[package]]
+name = "bitflags"
+version = "1.2.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
+
+[[package]]
+name = "cexpr"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27"
+dependencies = [
+ "nom",
+]
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "clang-sys"
+version = "1.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "853eda514c284c2287f4bf20ae614f8781f40a81d32ecda6e91449304dfe077c"
+dependencies = [
+ "glob",
+ "libc",
+ "libloading",
+]
+
+[[package]]
+name = "clap"
+version = "2.33.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
+dependencies = [
+ "ansi_term",
+ "atty",
+ "bitflags",
+ "strsim",
+ "textwrap",
+ "unicode-width",
+ "vec_map",
+]
+
+[[package]]
+name = "env_logger"
+version = "0.8.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "17392a012ea30ef05a610aa97dfb49496e71c9f676b27879922ea5bdf60d9d3f"
+dependencies = [
+ "atty",
+ "humantime",
+ "log",
+ "regex",
+ "termcolor",
+]
+
+[[package]]
+name = "glob"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
+
+[[package]]
+name = "hermit-abi"
+version = "0.1.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "humantime"
+version = "2.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
+
+[[package]]
+name = "lazy_static"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+
+[[package]]
+name = "lazycell"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
+
+[[package]]
+name = "libc"
+version = "0.2.94"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e"
+
+[[package]]
+name = "libloading"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6f84d96438c15fcd6c3f244c8fce01d1e2b9c6b5623e9c711dc9286d8fc92d6a"
+dependencies = [
+ "cfg-if",
+ "winapi",
+]
+
+[[package]]
+name = "log"
+version = "0.4.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
+dependencies = [
+ "cfg-if",
+]
+
+[[package]]
+name = "memchr"
+version = "2.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
+
+[[package]]
+name = "nom"
+version = "5.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
+dependencies = [
+ "memchr",
+ "version_check",
+]
+
+[[package]]
+name = "peeking_take_while"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.26"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec"
+dependencies = [
+ "unicode-xid",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "regex"
+version = "1.4.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2a26af418b574bd56588335b3a3659a65725d4e636eb1016c2f9e3b38c7cc759"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.6.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
+
+[[package]]
+name = "rustc-hash"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
+
+[[package]]
+name = "shlex"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "42a568c8f2cd051a4d283bd6eb0343ac214c1b0f1ac19f93e1175b2dee38c73d"
+
+[[package]]
+name = "strsim"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
+
+[[package]]
+name = "termcolor"
+version = "1.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
+name = "textwrap"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
+dependencies = [
+ "unicode-width",
+]
+
+[[package]]
+name = "unicode-width"
+version = "0.1.8"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
+
+[[package]]
+name = "unicode-xid"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
+
+[[package]]
+name = "vec_map"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
+
+[[package]]
+name = "version_check"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
+
+[[package]]
+name = "which"
+version = "3.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d011071ae14a2f6671d0b74080ae0cd8ebf3a6f8c9589a2cd45f23126fe29724"
+dependencies = [
+ "libc",
+]
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-util"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/rust/examples/dwarfdump/build.rs b/rust/examples/dwarfdump/build.rs
deleted file mode 100644
index 7ad93884..00000000
--- a/rust/examples/dwarfdump/build.rs
+++ /dev/null
@@ -1,67 +0,0 @@
-use std::env;
-use std::fs::File;
-use std::io::BufReader;
-use std::path::PathBuf;
-
-#[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::*;
-
- let home = PathBuf::from(env::var(LASTRUN_PATH.0).unwrap());
- let lastrun = PathBuf::from(&home).join(LASTRUN_PATH.1);
-
- 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\\");
- })
-}
-
-fn main() {
- // Use BINARYNINJADIR first for custom BN builds/configurations (BN devs/build server), fallback on defaults
- let install_path = env::var("BINARYNINJADIR")
- .map(PathBuf::from)
- .unwrap_or_else(|_| link_path());
-
- #[cfg(target_os = "linux")]
- println!(
- "cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-l:libbinaryninjacore.so.1",
- install_path.to_str().unwrap(),
- install_path.to_str().unwrap(),
- );
-
- #[cfg(target_os = "macos")]
- println!(
- "cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-lbinaryninjacore",
- install_path.to_str().unwrap(),
- install_path.to_str().unwrap(),
- );
-
- #[cfg(target_os = "windows")]
- {
- println!("cargo:rustc-link-lib=binaryninjacore");
- println!("cargo:rustc-link-search={}", install_path.to_str().unwrap());
- }
-}
diff --git a/rust/examples/flowgraph/build.rs b/rust/examples/flowgraph/build.rs
deleted file mode 100644
index 7ad93884..00000000
--- a/rust/examples/flowgraph/build.rs
+++ /dev/null
@@ -1,67 +0,0 @@
-use std::env;
-use std::fs::File;
-use std::io::BufReader;
-use std::path::PathBuf;
-
-#[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::*;
-
- let home = PathBuf::from(env::var(LASTRUN_PATH.0).unwrap());
- let lastrun = PathBuf::from(&home).join(LASTRUN_PATH.1);
-
- 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\\");
- })
-}
-
-fn main() {
- // Use BINARYNINJADIR first for custom BN builds/configurations (BN devs/build server), fallback on defaults
- let install_path = env::var("BINARYNINJADIR")
- .map(PathBuf::from)
- .unwrap_or_else(|_| link_path());
-
- #[cfg(target_os = "linux")]
- println!(
- "cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-l:libbinaryninjacore.so.1",
- install_path.to_str().unwrap(),
- install_path.to_str().unwrap(),
- );
-
- #[cfg(target_os = "macos")]
- println!(
- "cargo:rustc-link-arg=-Wl,-rpath,{},-L{},-lbinaryninjacore",
- install_path.to_str().unwrap(),
- install_path.to_str().unwrap(),
- );
-
- #[cfg(target_os = "windows")]
- {
- println!("cargo:rustc-link-lib=binaryninjacore");
- println!("cargo:rustc-link-search={}", install_path.to_str().unwrap());
- }
-}
diff --git a/rust/examples/template/CMakeLists.txt b/rust/examples/template/CMakeLists.txt
deleted file mode 100644
index a06a5af6..00000000
--- a/rust/examples/template/CMakeLists.txt
+++ /dev/null
@@ -1,89 +0,0 @@
-cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
-
-project(test_headless)
-
-file(GLOB PLUGIN_SOURCES
- ${PROJECT_SOURCE_DIR}/Cargo.toml
- ${PROJECT_SOURCE_DIR}/src/*.rs)
-
-file(GLOB API_SOURCES
- ${PROJECT_SOURCE_DIR}/../../../binaryninjacore.h
- ${PROJECT_SOURCE_DIR}/../../binaryninjacore-sys/build.rs
- ${PROJECT_SOURCE_DIR}/../../binaryninjacore-sys/Cargo.toml
- ${PROJECT_SOURCE_DIR}/../../binaryninjacore-sys/src/*
- ${PROJECT_SOURCE_DIR}/../../Cargo.toml
- ${PROJECT_SOURCE_DIR}/../../src/*.rs)
-
-if(CMAKE_BUILD_TYPE MATCHES Debug)
- set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/debug)
- set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target)
-else()
- set(TARGET_DIR ${PROJECT_BINARY_DIR}/target/release)
- set(CARGO_OPTS --target-dir=${PROJECT_BINARY_DIR}/target --release)
-endif()
-set(PLUGIN_PATH ${TARGET_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
-
-add_custom_target(test_headless ALL DEPENDS ${PLUGIN_PATH})
-add_dependencies(test_headless binaryninjaapi)
-
-find_program(RUSTUP_PATH rustup REQUIRED HINTS ~/.cargo/bin)
-set(INSTALL_UPDATE_NIGHTLY ${RUSTUP_PATH} install nightly)
-
-if(APPLE)
- if(UNIVERSAL)
- if(CMAKE_BUILD_TYPE MATCHES Debug)
- set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/debug/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/debug/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- else()
- set(AARCH64_LIB_PATH ${PROJECT_BINARY_DIR}/target/aarch64-apple-darwin/release/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- endif()
-
- add_custom_command(
- OUTPUT ${PLUGIN_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
- COMMAND ${CMAKE_COMMAND} -E env
- MACOSX_DEPLOYMENT_TARGET=10.14 LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build --target=aarch64-apple-darwin ${CARGO_OPTS}
- COMMAND ${CMAKE_COMMAND} -E env
- MACOSX_DEPLOYMENT_TARGET=10.14 LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build --target=x86_64-apple-darwin ${CARGO_OPTS}
- COMMAND mkdir -p ${TARGET_DIR}
- COMMAND lipo -create ${AARCH64_LIB_PATH} ${X86_64_LIB_PATH} -output ${PLUGIN_PATH}
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
- else()
- if(CMAKE_BUILD_TYPE MATCHES Debug)
- set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/debug/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- else()
- set(X86_64_LIB_PATH ${PROJECT_BINARY_DIR}/target/x86_64-apple-darwin/release/${CMAKE_STATIC_LIBRARY_PREFIX}test_headless${CMAKE_SHARED_LIBRARY_SUFFIX})
- endif()
-
- add_custom_command(
- OUTPUT ${PLUGIN_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
- COMMAND ${CMAKE_COMMAND} -E env
- MACOSX_DEPLOYMENT_TARGET=10.14 LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build --target=x86_64-apple-darwin ${CARGO_OPTS}
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
- endif()
-elseif(WIN32)
- add_custom_command(
- OUTPUT ${PLUGIN_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
- COMMAND ${CMAKE_COMMAND} -E env
- LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build ${CARGO_OPTS}
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
-else()
- add_custom_command(
- OUTPUT ${PLUGIN_PATH}
- COMMAND ${INSTALL_UPDATE_NIGHTLY}
- COMMAND ${CMAKE_COMMAND} -E env
- LIBCLANG_PATH=${LLVM_PATH}/lib LLVM_VERSION=${LLVM_VERSION} BINARYNINJADIR=${BN_CORE_OUTPUT_DIR}
- ${RUSTUP_PATH} run nightly cargo build ${CARGO_OPTS}
- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
- DEPENDS ${PLUGIN_SOURCES} ${API_SOURCES})
-endif()
diff --git a/rust/examples/template/README.md b/rust/examples/template/README.md
index f10f89c8..998a9cd2 100644
--- a/rust/examples/template/README.md
+++ b/rust/examples/template/README.md
@@ -1,17 +1,19 @@
+# Template
+
[The only official method of providing linker arguments to a crate is through that crate's `build.rs`](https://github.com/rust-lang/cargo/issues/9554), thus this template.
Please see `Cargo.toml` for further configuration options.
-### Plugins
+## Plugins
Enable
```
[lib]
crate-type = ["cdylib"]
```
-in Cargo.toml`
-
-### Standalone executables
+in `Cargo.toml`.
-All standalone executables should call both `binaryninja::headless::init()` and `binaryninja::headless::shutdown()`.
+## Standalone executables
+All standalone executables should call both `binaryninja::headless::init()` and `binaryninja::headless::shutdown()` (see [`src/main.rs`](src/main.rs)).
+Standalone executables will fail to link if you do not provide a `build.rs`. The one provided here should work.