File tree Expand file tree Collapse file tree 3 files changed +12
-7
lines changed
Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -106,7 +106,8 @@ where
106106 ) -> Option < LowLevelInstructionIndex > {
107107 use binaryninjacore_sys:: BNLowLevelILGetInstructionStart ;
108108 let loc: Location = loc. into ( ) ;
109- let arch = loc. arch . unwrap_or_else ( || * self . arch ( ) . as_ref ( ) ) ;
109+ // If the location does not specify an architecture, use the function's architecture.
110+ let arch = loc. arch . unwrap_or_else ( || self . arch ( ) ) ;
110111 let instr_idx =
111112 unsafe { BNLowLevelILGetInstructionStart ( self . handle , arch. handle , loc. addr ) } ;
112113 // `instr_idx` will equal self.instruction_count() if the instruction is not valid.
Original file line number Diff line number Diff line change @@ -47,11 +47,10 @@ impl MediumLevelILFunction {
4747 loc : L ,
4848 ) -> Option < MediumLevelInstructionIndex > {
4949 let loc: Location = loc. into ( ) ;
50- let arch = loc
51- . arch
52- . map ( |a| a. handle )
53- . unwrap_or_else ( std:: ptr:: null_mut) ;
54- let instr_idx = unsafe { BNMediumLevelILGetInstructionStart ( self . handle , arch, loc. addr ) } ;
50+ // If the location does not specify an architecture, use the function's architecture.
51+ let arch = loc. arch . unwrap_or_else ( || self . function ( ) . arch ( ) ) ;
52+ let instr_idx =
53+ unsafe { BNMediumLevelILGetInstructionStart ( self . handle , arch. handle , loc. addr ) } ;
5554 // `instr_idx` will equal self.instruction_count() if the instruction is not valid.
5655 if instr_idx >= self . instruction_count ( ) {
5756 None
Original file line number Diff line number Diff line change @@ -164,9 +164,14 @@ fn test_mlil_possible_values() {
164164 _ => panic ! ( "Expected SetVar" ) ,
165165 }
166166
167+ // As an aside, we also test to make sure `instruction_index_at` works.
168+ let instr_21_idx = mlil_function
169+ . instruction_index_at ( image_base + 0x0002af9a )
170+ . expect ( "Failed to get instruction index" ) ;
171+
167172 // 21 @ 0002af9a (MLIL_RET return (MLIL_VAR.d eax_2))
168173 let instr_21 = mlil_function
169- . instruction_from_index ( MediumLevelInstructionIndex ( 21 ) )
174+ . instruction_from_index ( instr_21_idx )
170175 . expect ( "Failed to get instruction" ) ;
171176 let lifted_instr_21 = instr_21. lift ( ) ;
172177 match lifted_instr_21. kind {
You can’t perform that action at this time.
0 commit comments