@@ -529,6 +529,59 @@ static void test_arm64_pc_wrap(void)
529
529
OK (uc_close (uc ));
530
530
}
531
531
532
+ static void
533
+ test_arm64_mem_prot_regress_hook_mem (uc_engine * uc , uc_mem_type type ,
534
+ uint64_t address , int size , int64_t value , void * user_data )
535
+ {
536
+ // fprintf(stderr, "%s %p %d\n", (type == UC_MEM_WRITE) ? "UC_MEM_WRITE" : "UC_MEM_READ", (void *)address, size);
537
+ }
538
+
539
+ static bool
540
+ test_arm64_mem_prot_regress_hook_prot (uc_engine * uc , uc_mem_type type ,
541
+ uint64_t address , int size , int64_t value , void * user_data )
542
+ {
543
+ // fprintf(stderr, "%s %p %d\n", (type == UC_MEM_WRITE_PROT) ? "UC_MEM_WRITE_PROT" : ((type == UC_MEM_FETCH_PROT) ? "UC_MEM_FETCH_PROT" : "UC_MEM_READ_PROT"), (void *)address, size);
544
+ return false;
545
+ }
546
+
547
+ static bool
548
+ test_arm64_mem_prot_regress_hook_unm (uc_engine * uc , uc_mem_type type ,
549
+ uint64_t address , int size , int64_t value , void * user_data )
550
+ {
551
+ // fprintf(stderr, "%s %p %d\n", (type == UC_MEM_WRITE_UNMAPPED) ? "UC_MEM_WRITE_UNMAPPED" : ((type == UC_MEM_FETCH_UNMAPPED) ? "UC_MEM_FETCH_UNMAPPED" : "UC_MEM_READ_UNMAPPED"), (void *)address, size);
552
+ return false;
553
+ }
554
+
555
+ // https://github.com/unicorn-engine/unicorn/issues/2078
556
+ static void test_arm64_mem_prot_regress (void )
557
+ {
558
+ const uint8_t code [] = {
559
+ 0x08 , 0x40 , 0x5e , 0x78 , // ldurh w8, [x0, #-0x1c]
560
+ };
561
+
562
+ uc_engine * uc ;
563
+ OK (uc_open (UC_ARCH_ARM64 , UC_MODE_ARM , & uc ));
564
+
565
+ OK (uc_mem_map (uc , 0 , 0x4000 , UC_PROT_READ |UC_PROT_EXEC ));
566
+ OK (uc_mem_map (uc , 0x4000 , 0xC000 , UC_PROT_READ |UC_PROT_WRITE ));
567
+ OK (uc_mem_write (uc , 0 , code , sizeof (code )));
568
+ uc_hook hh_mem ;
569
+ OK (uc_hook_add (uc , & hh_mem , UC_HOOK_MEM_READ | UC_HOOK_MEM_WRITE , test_arm64_mem_prot_regress_hook_mem , NULL , 1 , 0 ));
570
+
571
+ uc_hook hh_prot ;
572
+ OK (uc_hook_add (uc , & hh_prot , UC_HOOK_MEM_READ_PROT | UC_HOOK_MEM_WRITE_PROT | UC_HOOK_MEM_FETCH_PROT , test_arm64_mem_prot_regress_hook_prot , NULL , 1 , 0 ));
573
+
574
+ uc_hook hh_unm ;
575
+ OK (uc_hook_add (uc , & hh_unm , UC_HOOK_MEM_READ_UNMAPPED | UC_HOOK_MEM_WRITE_UNMAPPED | UC_HOOK_MEM_FETCH_UNMAPPED , test_arm64_mem_prot_regress_hook_unm , NULL , 1 , 0 ));
576
+
577
+ const uint64_t value = 0x801b ;
578
+ OK (uc_reg_write (uc , UC_ARM64_REG_X0 , & value ));
579
+
580
+ OK (uc_emu_start (uc , 0 , sizeof (code ), 0 , 0 ));
581
+
582
+ OK (uc_close (uc ));
583
+ }
584
+
532
585
TEST_LIST = {{"test_arm64_until" , test_arm64_until },
533
586
{"test_arm64_code_patching" , test_arm64_code_patching },
534
587
{"test_arm64_code_patching_count" , test_arm64_code_patching_count },
@@ -544,4 +597,5 @@ TEST_LIST = {{"test_arm64_until", test_arm64_until},
544
597
test_arm64_block_invalid_mem_read_write_sync },
545
598
{"test_arm64_mmu" , test_arm64_mmu },
546
599
{"test_arm64_pc_wrap" , test_arm64_pc_wrap },
600
+ {"test_arm64_mem_prot_regress" , test_arm64_mem_prot_regress },
547
601
{NULL , NULL }};
0 commit comments