1- use binaryninja:: architecture:: { ArchitectureExt , Intrinsic , Register } ;
1+ use binaryninja:: architecture:: {
2+ Architecture , ArchitectureExt , CoreArchitecture , Intrinsic , Register ,
3+ } ;
24use binaryninja:: binary_view:: BinaryViewExt ;
35use binaryninja:: headless:: Session ;
46use binaryninja:: low_level_il:: expression:: {
@@ -8,7 +10,9 @@ use binaryninja::low_level_il::instruction::{
810 InstructionHandler , LowLevelILInstructionKind , LowLevelInstructionIndex ,
911} ;
1012use 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+ } ;
1216use 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