From 6cd49edb317112acc73f7caeb285f4134a472d72 Mon Sep 17 00:00:00 2001 From: Fabian Freyer Date: Fri, 28 Jan 2022 01:36:26 +0100 Subject: rust: add linearview and related APIs This should include everything required to retrieve linear disassembly for a function. * add `highest_address` method to `Function` * add `DisassemblySettings` * add text getter for `InstructionTextToken` * add `LinearViewObject`, `LinearViewCursor` * add decompilation example --- rust/src/binaryview.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'rust/src/binaryview.rs') diff --git a/rust/src/binaryview.rs b/rust/src/binaryview.rs index 00069c15..6d52fa88 100644 --- a/rust/src/binaryview.rs +++ b/rust/src/binaryview.rs @@ -29,6 +29,8 @@ use crate::fileaccessor::FileAccessor; use crate::filemetadata::FileMetadata; use crate::flowgraph::FlowGraph; use crate::function::{Function, NativeBlock}; +use crate::linearview::LinearDisassemblyLine; +use crate::linearview::LinearViewCursor; use crate::platform::Platform; use crate::section::{Section, SectionBuilder}; use crate::segment::{Segment, SegmentBuilder}; @@ -774,6 +776,54 @@ pub trait BinaryViewExt: BinaryViewBase { fn remove_user_data_tag(&self, addr: u64, tag: &Tag) { unsafe { BNRemoveUserDataTag(self.as_ref().handle, addr, tag.handle) } } + + /// Retrieves a list of the next disassembly lines. + /// + /// `get_next_linear_disassembly_lines` retrieves an [Array] over [LinearDisassemblyLine] objects for the + /// next disassembly lines, and updates the [LinearViewCursor] passed in. This function can be called + /// repeatedly to get more lines of linear disassembly. + /// + /// # Arguments + /// * `pos` - Position to start retrieving linear disassembly lines from + fn get_next_linear_disassembly_lines( + &self, + pos: &mut LinearViewCursor, + ) -> Array { + let mut result = unsafe { Array::new(std::ptr::null_mut(), 0, ()) }; + + while result.len() == 0 { + result = pos.lines(); + if !pos.next() { + return result; + } + } + + result + } + + /// Retrieves a list of the next disassembly lines. + /// + /// `get_previous_linear_disassembly_lines` retrieves an [Array] over [LinearDisassemblyLine] objects for the + /// previous disassembly lines, and updates the [LinearViewCursor] passed in. This function can be called + /// repeatedly to get more lines of linear disassembly. + /// + /// # Arguments + /// * `pos` - Position to start retrieving linear disassembly lines from + fn get_previous_linear_disassembly_lines( + &self, + pos: &mut LinearViewCursor, + ) -> Array { + let mut result = unsafe { Array::new(std::ptr::null_mut(), 0, ()) }; + while result.len() == 0 { + if !pos.previous() { + return result; + } + + result = pos.lines(); + } + + result + } } impl BinaryViewExt for T {} -- cgit v1.3.1