From c7a819799828e965b6c2afa7e8f39aecf1a5b9a7 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Fri, 30 May 2025 19:16:46 -0400 Subject: [Rust] Add `Variable::to_register` helper function Makes it simpler to get the register from a variable (if it is a register variable) --- rust/src/variable.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'rust/src/variable.rs') diff --git a/rust/src/variable.rs b/rust/src/variable.rs index 1921f950..dd7f4cf5 100644 --- a/rust/src/variable.rs +++ b/rust/src/variable.rs @@ -1,5 +1,6 @@ #![allow(unused)] +use crate::architecture::{Architecture, CoreArchitecture, CoreRegister, RegisterId}; use crate::confidence::Conf; use crate::function::{Function, Location}; use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Ref}; @@ -387,6 +388,16 @@ impl Variable { let raw = BNVariable::from(*self); unsafe { BNToVariableIdentifier(&raw) } } + + pub fn to_register(&self, arch: CoreArchitecture) -> Option { + match self.ty { + VariableSourceType::RegisterVariableSourceType => { + arch.register_from_id(RegisterId(self.storage as u32)) + } + VariableSourceType::StackVariableSourceType => None, + VariableSourceType::FlagVariableSourceType => None, + } + } } impl From for Variable { -- cgit v1.3.1