summaryrefslogtreecommitdiff
path: root/rust/examples/template
diff options
context:
space:
mode:
Diffstat (limited to 'rust/examples/template')
-rw-r--r--rust/examples/template/Cargo.toml16
-rw-r--r--rust/examples/template/README.md19
-rw-r--r--rust/examples/template/build.rs68
-rw-r--r--rust/examples/template/src/main.rs40
4 files changed, 0 insertions, 143 deletions
diff --git a/rust/examples/template/Cargo.toml b/rust/examples/template/Cargo.toml
deleted file mode 100644
index f571c46d..00000000
--- a/rust/examples/template/Cargo.toml
+++ /dev/null
@@ -1,16 +0,0 @@
-[package]
-name = "template"
-version = "0.1.0"
-edition = "2021"
-
-# Uncomment this if you're writing a plugin (plugins are shared objects loaded by the core):
-# [lib]
-# crate-type = ["cdylib"]
-
-# You can point at the BinaryNinja dependency in one of two ways, via path:
-[dependencies]
-binaryninja = {path="../../"}
-
-# Or directly at the git repo:
-# [dependencies]
-# binaryninja = {git = "https://github.com/Vector35/binaryninja-api.git", branch = "dev"}
diff --git a/rust/examples/template/README.md b/rust/examples/template/README.md
deleted file mode 100644
index 1466ef24..00000000
--- a/rust/examples/template/README.md
+++ /dev/null
@@ -1,19 +0,0 @@
-# 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
-
-Enable
-```
-[lib]
-crate-type = ["cdylib"]
-```
-in `Cargo.toml`.
-
-## 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.
diff --git a/rust/examples/template/build.rs b/rust/examples/template/build.rs
deleted file mode 100644
index 5ba9bcde..00000000
--- a/rust/examples/template/build.rs
+++ /dev/null
@@ -1,68 +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/src/main.rs b/rust/examples/template/src/main.rs
deleted file mode 100644
index 4a1bab2c..00000000
--- a/rust/examples/template/src/main.rs
+++ /dev/null
@@ -1,40 +0,0 @@
-use binaryninja::architecture::Architecture;
-use binaryninja::binaryview::{BinaryViewBase, BinaryViewExt};
-
-// Standalone executables need to provide a main function for rustc
-// Plugins should refer to `binaryninja::command::*` for the various registration callbacks.
-fn main() {
- // This loads all the core architecture, platform, etc plugins
- // Standalone executables probably need to call this, but plugins do not
- println!("Loading plugins...");
- let headless_session = binaryninja::headless::Session::new();
-
- // Your code here...
- println!("Loading binary...");
- let bv = headless_session
- .load("/bin/cat")
- .expect("Couldn't open `/bin/cat`");
-
- println!("Filename: `{}`", bv.file().filename());
- println!("File size: `{:#x}`", bv.len());
- println!("Function count: {}", bv.functions().len());
-
- for func in &bv.functions() {
- println!(" `{}`:", func.symbol().full_name());
- for basic_block in &func.basic_blocks() {
- // TODO : This is intended to be refactored to be more nice to work with soon(TM)
- for addr in basic_block.as_ref() {
- print!(" {} ", addr);
- if let Some((_, tokens)) = func.arch().instruction_text(
- bv.read_buffer(addr, func.arch().max_instr_len())
- .unwrap()
- .get_data(),
- addr,
- ) {
- tokens.iter().for_each(|token| print!("{}", token.text()));
- println!();
- }
- }
- }
- }
-}