Skip to content

Commit 0af8344

Browse files
committed
Fix HighLevelILInstruction CoreArrayProvider using instr index instead of expr index
1 parent 8cc5a88 commit 0af8344

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

rust/src/high_level_il/instruction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ unsafe impl CoreArrayProviderInner for HighLevelILInstruction {
10681068

10691069
unsafe fn wrap_raw<'a>(raw: &'a Self::Raw, context: &'a Self::Context) -> Self::Wrapped<'a> {
10701070
context
1071-
.instruction_from_index(HighLevelInstructionIndex(*raw))
1071+
.instruction_from_expr_index(HighLevelExpressionIndex(*raw))
10721072
.unwrap()
10731073
}
10741074
}

rust/tests/high_level_il.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use binaryninja::binary_view::BinaryViewExt;
1+
use binaryninja::binary_view::{BinaryViewBase, BinaryViewExt};
22
use binaryninja::headless::Session;
33
use binaryninja::high_level_il::{
44
HighLevelExpressionIndex, HighLevelILInstructionKind, HighLevelInstructionIndex,
@@ -37,3 +37,27 @@ fn test_hlil_info() {
3737
_ => panic!("Expected Ret"),
3838
}
3939
}
40+
41+
#[test]
42+
fn test_hlil_var_info() {
43+
let _session = Session::new().expect("Failed to initialize session");
44+
let out_dir = env!("OUT_DIR").parse::<PathBuf>().unwrap();
45+
let view = binaryninja::load(out_dir.join("atox.obj")).expect("Failed to create view");
46+
47+
let function = view
48+
.function_at(&view.default_platform().unwrap(), view.start() + 0x28600)
49+
.unwrap();
50+
let hlil_function = function.high_level_il(false).unwrap();
51+
52+
for v in hlil_function.variables().iter() {
53+
let defs = hlil_function.variable_definitions(v).to_vec();
54+
if v.index != 0 {
55+
// Make sure non-param vars have a def site
56+
assert!(defs.len() > 0)
57+
}
58+
let _ = hlil_function.variable_uses(v).to_vec();
59+
for ssa_var in hlil_function.ssa_variables(&v).iter() {
60+
let _ = hlil_function.ssa_variable_uses(ssa_var).to_vec();
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)