diff options
| author | Cindy Xiao <git@cxiao.net> | 2023-02-11 11:25:38 -0800 |
|---|---|---|
| committer | Kyle Martin <krm504@nyu.edu> | 2023-02-20 10:45:04 -0500 |
| commit | 56996b0617c499178b463eb27973e7b12a056ffc (patch) | |
| tree | 9035cee98b515fa2946d5d115a9eac3768f9d8bc /rust/examples/minidump/build.rs | |
| parent | 9993345001464331697167349803235498218652 (diff) | |
Rust API : Add minidump example
Squashed commit message history:
Initial commit
chore: Add files from cargo new, Binary Ninja Rust API template
chore: Add README
feat: Add basic plugin registration code
feat: Add command to print memory information from minidump
I can't believe this actually worked the first time
feat: Set up registration of Minidump BinaryView type
Also set architecture based on contents of MinidumpSystemInfo stream in
the minidump.
feat: Perform basic segment mapping from MinidumpMemoryList, MinidumpMemory64List
feat: Read and apply memory segment protection info from MinidumpMemoryInfoList
feat: Log action to add segments at info level
docs: Update readme with build instructions, screenshot
style: Minor cleanup of types
refactor: Remove use of unwrap when parsing raw BaseRVA
docs: Add doc comments to view module
feat: More logging in print_memory_information command, remove unwrap
refactor: Add struct for representing memory protection flags
fix: Correct information about difference between MinidumpMemoryList, MinidumpMemory64List
MinidumpMemory64List is always used for "full dumps", i.e. dumps which
include the full process memory. It does not have to do with 64-bit
segments specifically.
docs: Clarify Windows-only support for now in README
fix: First try to find full dump memory in MinidumpMemory64List before looking for partial dump memory in MinidumpMemoryList
docs: Update README with examples of how to generate minidumps
feat: Parse module information in MinidumpModuleList, and add modules as sections
docs: Add information about unsupported features
docs: Update README with screenshots, explanation of memory map
docs: Update TODOs in BinaryViewBase impl
Rust Minidump example : Clippy appeasements; remove network dependency
Diffstat (limited to 'rust/examples/minidump/build.rs')
| -rw-r--r-- | rust/examples/minidump/build.rs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/rust/examples/minidump/build.rs b/rust/examples/minidump/build.rs new file mode 100644 index 00000000..5ba9bcde --- /dev/null +++ b/rust/examples/minidump/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()); + } +} |
