Skip to content

Commit c7a8197

Browse files
committed
[Rust] Add Variable::to_register helper function
Makes it simpler to get the register from a variable (if it is a register variable)
1 parent 0320807 commit c7a8197

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

rust/src/variable.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![allow(unused)]
22

3+
use crate::architecture::{Architecture, CoreArchitecture, CoreRegister, RegisterId};
34
use crate::confidence::Conf;
45
use crate::function::{Function, Location};
56
use crate::rc::{CoreArrayProvider, CoreArrayProviderInner, Ref};
@@ -387,6 +388,16 @@ impl Variable {
387388
let raw = BNVariable::from(*self);
388389
unsafe { BNToVariableIdentifier(&raw) }
389390
}
391+
392+
pub fn to_register(&self, arch: CoreArchitecture) -> Option<CoreRegister> {
393+
match self.ty {
394+
VariableSourceType::RegisterVariableSourceType => {
395+
arch.register_from_id(RegisterId(self.storage as u32))
396+
}
397+
VariableSourceType::StackVariableSourceType => None,
398+
VariableSourceType::FlagVariableSourceType => None,
399+
}
400+
}
390401
}
391402

392403
impl From<BNVariable> for Variable {

0 commit comments

Comments
 (0)