summaryrefslogtreecommitdiff
path: root/rust/examples/dwarfexport/build.rs
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2023-02-10 13:19:07 -0500
committerKyleMiles <krm504@nyu.edu>2023-02-14 00:15:59 -0500
commitda48fde5958ad3eedcd3c4b82d7dc5b9428c9e93 (patch)
tree44678aef5f86e86a8841dc908a58f5cb00764767 /rust/examples/dwarfexport/build.rs
parent9e91eaf63aed340a2c0a61ad8f70e9a7883e3aba (diff)
Add DWARF Export
This plugin exports: - Functions - Addresses - Name - Return type - Argument names and types - Data Variables - Name - Tyoe - Address - Types - All types in a BNDB except for: - TypeClass::FunctionTypeClass - TypeClass::VarArgsTypeClass - TypeClass::ValueTypeClass Current MAJOR TODOs include: - Finish exporting all the types - Verify what we export can be imported by other toosl - Auto-detect settings for the initial interaction dialouge - Allow the functions to be more easily called in a headless mode - Local function variable names and types - All my todo comments in the code
Diffstat (limited to 'rust/examples/dwarfexport/build.rs')
-rw-r--r--rust/examples/dwarfexport/build.rs68
1 files changed, 68 insertions, 0 deletions
diff --git a/rust/examples/dwarfexport/build.rs b/rust/examples/dwarfexport/build.rs
new file mode 100644
index 00000000..5ba9bcde
--- /dev/null
+++ b/rust/examples/dwarfexport/build.rs
@@ -0,0 +1,68 @@
+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());
+ }
+}