Skip to content

Commit e9904f2

Browse files
committed
[Rust] Add LowLevelILSSARegisterKind::id helper
The partial register id is the "main" id so we return that, whereas the full register id is not.
1 parent 6728415 commit e9904f2

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

rust/src/low_level_il.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,13 @@ impl<R: ArchReg> LowLevelILSSARegisterKind<R> {
189189
| LowLevelILSSARegisterKind::Partial { version, .. } => version,
190190
}
191191
}
192+
193+
pub fn id(&self) -> RegisterId {
194+
match *self {
195+
LowLevelILSSARegisterKind::Full { kind, .. } => kind.id(),
196+
LowLevelILSSARegisterKind::Partial { partial_reg, .. } => partial_reg.id(),
197+
}
198+
}
192199
}
193200

194201
#[derive(Copy, Clone, Debug)]

rust/src/low_level_il/function.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,11 @@ impl<M: FunctionMutability> LowLevelILFunction<M, SSA> {
267267
reg: LowLevelILSSARegisterKind<R>,
268268
) -> Vec<LowLevelILInstruction<'_, M, SSA>> {
269269
use binaryninjacore_sys::BNGetLowLevelILSSARegisterUses;
270-
let register_id = match reg {
271-
LowLevelILSSARegisterKind::Full { kind, .. } => kind.id(),
272-
LowLevelILSSARegisterKind::Partial { partial_reg, .. } => partial_reg.id(),
273-
};
274270
let mut count = 0;
275271
let instrs = unsafe {
276272
BNGetLowLevelILSSARegisterUses(
277273
self.handle,
278-
register_id.into(),
274+
reg.id().into(),
279275
reg.version() as usize,
280276
&mut count,
281277
)
@@ -295,14 +291,10 @@ impl<M: FunctionMutability> LowLevelILFunction<M, SSA> {
295291
reg: &LowLevelILSSARegisterKind<R>,
296292
) -> Option<LowLevelILInstruction<'_, M, SSA>> {
297293
use binaryninjacore_sys::BNGetLowLevelILSSARegisterDefinition;
298-
let register_id = match reg {
299-
LowLevelILSSARegisterKind::Full { kind, .. } => kind.id(),
300-
LowLevelILSSARegisterKind::Partial { partial_reg, .. } => partial_reg.id(),
301-
};
302294
let instr_idx = unsafe {
303295
BNGetLowLevelILSSARegisterDefinition(
304296
self.handle,
305-
register_id.into(),
297+
reg.id().into(),
306298
reg.version() as usize,
307299
)
308300
};
@@ -315,12 +307,8 @@ impl<M: FunctionMutability> LowLevelILFunction<M, SSA> {
315307
&self,
316308
reg: &LowLevelILSSARegisterKind<R>,
317309
) -> Option<RegisterValue> {
318-
let register_id = match reg {
319-
LowLevelILSSARegisterKind::Full { kind, .. } => kind.id(),
320-
LowLevelILSSARegisterKind::Partial { partial_reg, .. } => partial_reg.id(),
321-
};
322310
let value = unsafe {
323-
BNGetLowLevelILSSARegisterValue(self.handle, register_id.into(), reg.version() as usize)
311+
BNGetLowLevelILSSARegisterValue(self.handle, reg.id().into(), reg.version() as usize)
324312
};
325313
if value.state == BNRegisterValueType::UndeterminedValue {
326314
return None;

0 commit comments

Comments
 (0)