@@ -815,6 +815,52 @@ static void test_armeb_be32_thumb2(void)
815
815
OK (uc_close (uc ));
816
816
}
817
817
818
+ static bool test_arm_mem_read_write_cb (uc_engine * uc , int type ,
819
+ uint64_t address , int size ,
820
+ int64_t value , void * user_data )
821
+ {
822
+ uint64_t * count = (uint64_t * )user_data ;
823
+ switch (type ) {
824
+ case UC_MEM_READ :
825
+ count [0 ]++ ;
826
+ break ;
827
+ case UC_MEM_WRITE :
828
+ count [1 ]++ ;
829
+ break ;
830
+ }
831
+
832
+ return 0 ;
833
+ }
834
+ static void test_arm_mem_hook_read_write (void )
835
+ {
836
+ uc_engine * uc ;
837
+ // ldr r1, [sp]
838
+ // str r1, [sp, #4]
839
+ // ldr r2, [sp, #4]
840
+ // str r2, [sp]
841
+ const char code [] = "\x00\x10\x9d\xe5\x04\x10\x8d\xe5\x04\x20\x9d\xe5\x00\x20\x8d\xe5" ;
842
+ uint32_t r_sp ;
843
+ r_sp = 0x9000 ;
844
+ uc_hook hk ;
845
+ uint64_t counter [2 ] = {0 , 0 };
846
+
847
+ uc_common_setup (& uc , UC_ARCH_ARM , UC_MODE_ARM , code , sizeof (code ) - 1 ,
848
+ UC_CPU_ARM_CORTEX_A15 );
849
+
850
+ uc_reg_write (uc , UC_ARM_REG_SP , & r_sp );
851
+ uc_mem_map (uc , 0x8000 , 1024 * 16 , UC_PROT_ALL );
852
+
853
+ OK (uc_hook_add (uc , & hk , UC_HOOK_MEM_READ , test_arm_mem_read_write_cb ,
854
+ counter , 1 , 0 ));
855
+ OK (uc_hook_add (uc , & hk , UC_HOOK_MEM_WRITE , test_arm_mem_read_write_cb ,
856
+ counter , 1 , 0 ));
857
+
858
+ OK (uc_emu_start (uc , code_start , code_start + sizeof (code ) - 1 , 0 , 0 ));
859
+
860
+ TEST_CHECK (counter [0 ] == 2 && counter [1 ] == 2 );
861
+ OK (uc_close (uc ));
862
+ }
863
+
818
864
TEST_LIST = {{"test_arm_nop" , test_arm_nop },
819
865
{"test_arm_thumb_sub" , test_arm_thumb_sub },
820
866
{"test_armeb_sub" , test_armeb_sub },
@@ -840,4 +886,5 @@ TEST_LIST = {{"test_arm_nop", test_arm_nop},
840
886
{"test_arm_context_save" , test_arm_context_save },
841
887
{"test_arm_thumb2" , test_arm_thumb2 },
842
888
{"test_armeb_be32_thumb2" , test_armeb_be32_thumb2 },
843
- {NULL , NULL }};
889
+ {"test_arm_mem_hook_read_write" , test_arm_mem_hook_read_write },
890
+ {NULL , NULL }};
0 commit comments