Skip to content

Commit 631f281

Browse files
trumankemesare
andauthored
Pass arch to finalized LowLevelILFunction (#7729)
Co-authored-by: Mason Reed <mason@vector35.com>
1 parent d9ff403 commit 631f281

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

rust/src/low_level_il/function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl Ref<LowLevelILFunction<Mutable, NonSSA>> {
254254
unsafe {
255255
BNFinalizeLowLevelILFunction(self.handle);
256256
// Now that we have finalized return the function as is so the caller can reference the "finalized function".
257-
LowLevelILFunction::from_raw(self.handle).to_owned()
257+
LowLevelILFunction::from_raw_with_arch(self.handle, self.arch).to_owned()
258258
}
259259
}
260260
}

rust/tests/low_level_il.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use binaryninja::architecture::{ArchitectureExt, Intrinsic, Register};
1+
use binaryninja::architecture::{
2+
Architecture, ArchitectureExt, CoreArchitecture, Intrinsic, Register,
3+
};
24
use binaryninja::binary_view::BinaryViewExt;
35
use binaryninja::headless::Session;
46
use binaryninja::low_level_il::expression::{
@@ -8,7 +10,9 @@ use binaryninja::low_level_il::instruction::{
810
InstructionHandler, LowLevelILInstructionKind, LowLevelInstructionIndex,
911
};
1012
use binaryninja::low_level_il::operation::IntrinsicOutput;
11-
use binaryninja::low_level_il::{LowLevelILRegisterKind, LowLevelILSSARegisterKind, VisitorAction};
13+
use binaryninja::low_level_il::{
14+
LowLevelILMutableFunction, LowLevelILRegisterKind, LowLevelILSSARegisterKind, VisitorAction,
15+
};
1216
use std::path::PathBuf;
1317

1418
#[test]
@@ -349,3 +353,29 @@ fn test_llil_intrinsic() {
349353
_ => panic!("Expected Intrinsic"),
350354
}
351355
}
356+
357+
#[test]
358+
fn test_llil_unbacked_function_creation() {
359+
let _session = Session::new().expect("Failed to initialize session");
360+
let arch = CoreArchitecture::by_name("x86_64").unwrap();
361+
// Create an LLIL function backed by no Function.
362+
let llil = LowLevelILMutableFunction::new(arch, None);
363+
let (instr_len, _) = arch.instruction_llil(&[0x8b, 0xd9], 0x0, &llil).unwrap();
364+
assert_eq!(instr_len, 2);
365+
let llil = llil.finalized();
366+
367+
// Validate to make sure we can read the llil instruction for a non-backed LLIL function.
368+
let inst = llil
369+
.instruction_from_index(LowLevelInstructionIndex(0))
370+
.unwrap();
371+
let LowLevelILInstructionKind::SetReg(inst_operation) = inst.kind() else {
372+
panic!("Expected SetReg");
373+
};
374+
let LowLevelILExpressionKind::Reg(src_operation) = inst_operation.source_expr().kind() else {
375+
panic!("Expected Reg");
376+
};
377+
let src_reg = src_operation.source_reg();
378+
assert_eq!(src_reg.name(), "ecx");
379+
let dest_reg = inst_operation.dest_reg();
380+
assert_eq!(dest_reg.name(), "ebx");
381+
}

0 commit comments

Comments
 (0)