summaryrefslogtreecommitdiff
path: root/rust/src/architecture
diff options
context:
space:
mode:
authorBrandon Miller <brandon@vector35.com>2026-02-16 14:16:25 -0500
committerBrandon Miller <brandon@vector35.com>2026-02-16 14:16:25 -0500
commit2a4c7d5d89907497e029337bbaf6f7e467bcde98 (patch)
treec36bd1c4f3c477a5a8f7cce5f8ea5fd8a133d02f /rust/src/architecture
parentc9dbb48365bf1a0c5c06daa2234e21e64d9bc2f7 (diff)
Share context between BB recovery, lifing, and disassembly
Adds a GetInstructionTextWithContext callback to the architecture class that can be used to pass data from AnalyzeBasicBlocks. This same context is also supplied to LiftFunction and allows for supplying shared function and/or binary view level information across basic block analysis, function lifting, and disassembly text rendering
Diffstat (limited to 'rust/src/architecture')
-rw-r--r--rust/src/architecture/basic_block.rs32
1 files changed, 29 insertions, 3 deletions
diff --git a/rust/src/architecture/basic_block.rs b/rust/src/architecture/basic_block.rs
index 428a97a1..ac5ce774 100644
--- a/rust/src/architecture/basic_block.rs
+++ b/rust/src/architecture/basic_block.rs
@@ -1,4 +1,4 @@
-use crate::architecture::{CoreArchitecture, IndirectBranchInfo};
+use crate::architecture::{ArchitectureWithFunctionContext, CoreArchitecture, IndirectBranchInfo};
use crate::basic_block::BasicBlock;
use crate::function::{Function, Location, NativeBlock};
use crate::rc::Ref;
@@ -180,6 +180,34 @@ impl BasicBlockAnalysisContext {
self.inlined_unresolved_indirect_branches.insert(loc.into());
}
+ pub fn set_function_arch_context<A: ArchitectureWithFunctionContext>(
+ &mut self,
+ _arch: &A,
+ context: Box<A::FunctionArchContext>,
+ ) -> bool {
+ unsafe {
+ if !(*self.handle).functionArchContext.is_null() {
+ return false;
+ }
+ (*self.handle).functionArchContext = Box::into_raw(context) as *mut std::ffi::c_void;
+ }
+ true
+ }
+
+ pub fn get_function_arch_context<A: ArchitectureWithFunctionContext>(
+ &self,
+ _arch: &A,
+ ) -> Option<&A::FunctionArchContext> {
+ unsafe {
+ let ptr = (*self.handle).functionArchContext;
+ if ptr.is_null() {
+ None
+ } else {
+ Some(&*(ptr as *const A::FunctionArchContext))
+ }
+ }
+ }
+
/// Creates a new [`BasicBlock`] at the specified address for the given [`CoreArchitecture`].
///
/// After creating, you can add using [`BasicBlockAnalysisContext::add_basic_block`].
@@ -328,8 +356,6 @@ impl BasicBlockAnalysisContext {
if self.contextual_returns_dirty {
self.update_contextual_returns();
}
-
- unsafe { BNAnalyzeBasicBlocksContextFinalize(self.handle) };
}
}