From 56996b0617c499178b463eb27973e7b12a056ffc Mon Sep 17 00:00:00 2001 From: Cindy Xiao Date: Sat, 11 Feb 2023 11:25:38 -0800 Subject: 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 --- rust/examples/minidump/src/command.rs | 44 +++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 rust/examples/minidump/src/command.rs (limited to 'rust/examples/minidump/src/command.rs') 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::() { + 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"); + } +} -- cgit v1.3.1