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/src/command.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/src/command.rs')
| -rw-r--r-- | rust/examples/minidump/src/command.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/rust/examples/minidump/src/command.rs b/rust/examples/minidump/src/command.rs new file mode 100644 index 00000000..0b10c65a --- /dev/null +++ b/rust/examples/minidump/src/command.rs @@ -0,0 +1,44 @@ +use std::str; + +use log::{debug, error, info}; +use minidump::{Minidump, MinidumpMemoryInfoList}; + +use binaryninja::binaryview::{BinaryView, BinaryViewBase, BinaryViewExt}; + +use crate::view::DataBufferWrapper; + +pub fn print_memory_information(bv: &BinaryView) { + debug!("Printing memory information"); + if let Ok(minidump_bv) = bv.parent_view() { + if let Ok(read_buffer) = minidump_bv.read_buffer(0, minidump_bv.len()) { + let read_buffer = DataBufferWrapper::new(read_buffer); + if let Ok(minidump_obj) = Minidump::read(read_buffer) { + if let Ok(memory_info_list) = minidump_obj.get_stream::<MinidumpMemoryInfoList>() { + let mut memory_info_list_writer = Vec::new(); + match memory_info_list.print(&mut memory_info_list_writer) { + Ok(_) => { + if let Ok(memory_info_str) = str::from_utf8(&memory_info_list_writer) { + info!("{memory_info_str}"); + } else { + error!("Could not convert the memory information description from minidump into a valid string"); + } + } + Err(_) => { + error!("Could not get memory information from minidump"); + } + } + } else { + error!( + "Could not parse a valid MinidumpMemoryInfoList stream from the minidump" + ); + } + } else { + error!("Could not parse a valid minidump file from the parent binary view's data buffer"); + } + } else { + error!("Could not read data from parent binary view"); + } + } else { + error!("Could not get the parent binary view"); + } +} |
