Skip to content

Commit 587a7fd

Browse files
committed
[Rust] Add misc documentation
1 parent 2372ab8 commit 587a7fd

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

rust/src/architecture.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,34 @@ pub trait Architecture: 'static + Sized + AsRef<CoreArchitecture> {
123123

124124
fn associated_arch_by_addr(&self, addr: u64) -> CoreArchitecture;
125125

126+
/// Returns the [`InstructionInfo`] at the given virtual address with `data`.
127+
///
128+
/// The [`InstructionInfo`] object should always fill the proper length and branches if not, the
129+
/// next instruction will likely be incorrect.
126130
fn instruction_info(&self, data: &[u8], addr: u64) -> Option<InstructionInfo>;
131+
127132
fn instruction_text(
128133
&self,
129134
data: &[u8],
130135
addr: u64,
131136
) -> Option<(usize, Vec<InstructionTextToken>)>;
137+
138+
// TODO: Why do we need to return a boolean here? Does `None` not represent the same thing?
139+
/// Appends arbitrary low-level il instructions to `il`.
140+
///
141+
/// If `None` is returned, no instructions were appended and the data is invalid. If `Some` is returned,
142+
/// the instructions consumed length is returned (necessary for variable length instruction decoding).
132143
fn instruction_llil(
133144
&self,
134145
data: &[u8],
135146
addr: u64,
136147
il: &LowLevelILMutableFunction,
137148
) -> Option<(usize, bool)>;
138149

150+
/// Performs basic block recovery and commits the results to the function analysis.
151+
///
152+
/// NOTE: Only implement this method if function-level analysis is required. Otherwise, do not
153+
/// implement to let default basic block analysis take place.
139154
fn analyze_basic_blocks(
140155
&self,
141156
function: &mut Function,
@@ -147,7 +162,7 @@ pub trait Architecture: 'static + Sized + AsRef<CoreArchitecture> {
147162
}
148163

149164
/// Fallback flag value calculation path. This method is invoked when the core is unable to
150-
/// recover flag use semantics, and resorts to emitting instructions that explicitly set each
165+
/// recover the flag using semantics and resorts to emitting instructions that explicitly set each
151166
/// observed flag to the value of an expression returned by this function.
152167
///
153168
/// This function *MUST NOT* append instructions that have side effects.
@@ -166,11 +181,10 @@ pub trait Architecture: 'static + Sized + AsRef<CoreArchitecture> {
166181
Some(get_default_flag_write_llil(self, role, op, il))
167182
}
168183

169-
/// Determines what flags need to be examined in order to attempt automatic recovery of the
170-
/// semantics of this flag use.
184+
/// Determines what flags need to be examined to attempt automatic recovery of the flag uses semantics.
171185
///
172-
/// If automatic recovery is not possible, the `flag_cond_llil` method will be invoked to give
173-
/// this `Architecture` implementation arbitrary control over the expression to be evaluated.
186+
/// If automatic recovery is not possible, the [`Architecture::flag_cond_llil`] method will be invoked
187+
/// to give this [`Architecture`] implementation arbitrary control over the expression to be evaluated.
174188
fn flags_required_for_flag_condition(
175189
&self,
176190
_condition: FlagCondition,
@@ -485,6 +499,12 @@ impl Architecture for CoreArchitecture {
485499
}
486500
}
487501

502+
/// Performs basic block recovery and commits the results to the function analysis.
503+
///
504+
/// NOTE: Only implement this method if function-level analysis is required. Otherwise, do not
505+
/// implement to let default basic block analysis take place.
506+
///
507+
/// NOTE: The default implementation exists in C++ here: <https://github.com/Vector35/binaryninja-api/blob/dev/defaultabb.cpp>
488508
fn analyze_basic_blocks(
489509
&self,
490510
function: &mut Function,

rust/src/binary_view.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,11 @@ pub trait BinaryViewExt: BinaryViewBase {
13221322
}
13231323
}
13241324

1325+
/// This list contains the analysis entry function, and functions like init_array, fini_array,
1326+
/// and TLS callbacks etc.
1327+
///
1328+
/// We see `entry_functions` as good starting points for analysis, these functions normally don't
1329+
/// have internal references. Exported functions in a dll/so file are not included.
13251330
fn entry_point_functions(&self) -> Array<Function> {
13261331
unsafe {
13271332
let mut count = 0;
@@ -1706,6 +1711,9 @@ pub trait BinaryViewExt: BinaryViewBase {
17061711
}
17071712
}
17081713

1714+
/// Retrieve the metadata as the type `T`.
1715+
///
1716+
/// Fails if the metadata does not exist, or if the metadata failed to coerce to type `T`.
17091717
fn get_metadata<T>(&self, key: &str) -> Option<Result<T>>
17101718
where
17111719
T: for<'a> TryFrom<&'a Metadata>,
@@ -2235,6 +2243,9 @@ pub trait BinaryViewExt: BinaryViewBase {
22352243
}
22362244
}
22372245

2246+
/// Retrieve the string that falls on a given virtual address.
2247+
///
2248+
/// NOTE: This returns discovered strings and is therefore governed by `analysis.limits.minStringLength` and other settings.
22382249
fn string_at(&self, addr: u64) -> Option<BNStringReference> {
22392250
let mut str_ref = BNStringReference::default();
22402251
let success = unsafe { BNGetStringAtAddress(self.as_ref().handle, addr, &mut str_ref) };

rust/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ pub fn license_count() -> i32 {
555555

556556
/// Set the license that will be used once the core initializes. You can reset the license by passing `None`.
557557
///
558-
/// If not set the normal license retrieval will occur:
558+
/// If not set, the normal license retrieval will occur:
559559
/// 1. Check the BN_LICENSE environment variable
560560
/// 2. Check the Binary Ninja user directory for license.dat
561561
#[cfg(not(feature = "demo"))]
@@ -623,14 +623,15 @@ pub fn add_optional_plugin_dependency(name: &str) {
623623
unsafe { BNAddOptionalPluginDependency(raw_name.as_ptr()) };
624624
}
625625

626-
// Provide ABI version automatically so that the core can verify binary compatibility
626+
/// Exported function to tell the core what core ABI version this plugin was compiled against.
627627
#[cfg(not(feature = "no_exports"))]
628628
#[no_mangle]
629629
#[allow(non_snake_case)]
630630
pub extern "C" fn CorePluginABIVersion() -> u32 {
631631
plugin_abi_version()
632632
}
633633

634+
/// Exported function to tell the core what UI ABI version this plugin was compiled against.
634635
#[cfg(not(feature = "no_exports"))]
635636
#[no_mangle]
636637
pub extern "C" fn UIPluginABIVersion() -> u32 {

rust/src/llvm.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! LLVM functionality exposed by the core.
2+
//!
3+
//! Also see [`crate::demangle::demangle_llvm`].
4+
15
use binaryninjacore_sys::{
26
BNLlvmServicesAssemble, BNLlvmServicesAssembleFree, BNLlvmServicesDisasmInstruction,
37
BNLlvmServicesInit,

0 commit comments

Comments
 (0)