summaryrefslogtreecommitdiff
path: root/rust/src/binaryview.rs
diff options
context:
space:
mode:
authorFabian Freyer <fabian.freyer@physik.tu-berlin.de>2022-01-28 01:36:26 +0100
committerKyleMiles <krm504@nyu.edu>2022-02-14 18:45:11 -0500
commit6cd49edb317112acc73f7caeb285f4134a472d72 (patch)
tree3fc1af20b46dcb33c1ba5490193a0226e112e839 /rust/src/binaryview.rs
parent181ad567199e5685578ecf7ad400257098c2e175 (diff)
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
Diffstat (limited to 'rust/src/binaryview.rs')
-rw-r--r--rust/src/binaryview.rs50
1 files changed, 50 insertions, 0 deletions
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<LinearDisassemblyLine> {
+ 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<LinearDisassemblyLine> {
+ 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<T: BinaryViewBase> BinaryViewExt for T {}