summaryrefslogtreecommitdiff
path: root/rust/src/variable.rs
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-05-30 19:16:46 -0400
committerMason Reed <mason@vector35.com>2025-05-30 19:17:10 -0400
commitc7a819799828e965b6c2afa7e8f39aecf1a5b9a7 (patch)
tree64916d1f0443cf91690a7b174a44b32cc3b7a5d2 /rust/src/variable.rs
parent032080750a88a1a437784b8c95cb1747aa907d0c (diff)
[Rust] Add `Variable::to_register` helper function
Makes it simpler to get the register from a variable (if it is a register variable)
Diffstat (limited to 'rust/src/variable.rs')
-rw-r--r--rust/src/variable.rs11
1 files changed, 11 insertions, 0 deletions
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<CoreRegister> {
+ match self.ty {
+ VariableSourceType::RegisterVariableSourceType => {
+ arch.register_from_id(RegisterId(self.storage as u32))
+ }
+ VariableSourceType::StackVariableSourceType => None,
+ VariableSourceType::FlagVariableSourceType => None,
+ }
+ }
}
impl From<BNVariable> for Variable {