@@ -1342,6 +1342,48 @@ static void test_x86_unaligned_access(void)
1342
1342
1343
1343
OK (uc_close (uc ));
1344
1344
}
1345
+
1346
+ static void test_x86_64_unaligned_access (void ){
1347
+ uc_engine * uc ;
1348
+ uc_hook hook ;
1349
+ char code [] = {
1350
+ "\x48\x89\x01" // mov qword ptr [rcx],rax
1351
+ "\x48\x8b\x00" // mov rax,qword ptr [rax]
1352
+ "\xcc"
1353
+ };
1354
+ uint64_t r_rax = LEINT64 (0x2fffff );
1355
+ uint64_t r_rcx = LEINT64 (0x2fffff );
1356
+ struct writelog_t write_log [10 ];
1357
+ struct writelog_t read_log [10 ];
1358
+ memset (write_log , 0 , sizeof (write_log ));
1359
+ memset (read_log , 0 , sizeof (read_log ));
1360
+ uc_common_setup (& uc , UC_ARCH_X86 , UC_MODE_64 , code , sizeof (code ) - 1 );
1361
+ OK (uc_mem_map (uc , 0x200000 , 0x200000 , UC_PROT_ALL ));
1362
+ OK (uc_hook_add (uc , & hook , UC_HOOK_MEM_WRITE ,
1363
+ test_x86_unaligned_access_callback , write_log , 1 , 0 ));
1364
+ OK (uc_hook_add (uc , & hook , UC_HOOK_MEM_READ ,
1365
+ test_x86_unaligned_access_callback , read_log , 1 , 0 ));
1366
+
1367
+ OK (uc_reg_write (uc , UC_X86_REG_RAX , & r_rax ));
1368
+ OK (uc_reg_write (uc , UC_X86_REG_RCX , & r_rcx ));
1369
+
1370
+ OK (uc_emu_start (uc , code_start , code_start + sizeof (code ) - 1 , 0 , 2 ));
1371
+
1372
+ TEST_CHECK (write_log [0 ].addr == 0x2fffff );
1373
+ TEST_CHECK (write_log [0 ].size == 8 );
1374
+ TEST_CHECK (write_log [1 ].size == 0 );
1375
+
1376
+ TEST_CHECK (read_log [0 ].addr == 0x2fffff );
1377
+ TEST_CHECK (read_log [0 ].size == 8 );
1378
+ TEST_CHECK (read_log [1 ].size == 0 );
1379
+
1380
+ uint64_t b ;
1381
+ OK (uc_mem_read (uc , 0x2fffff , & b , 8 ));
1382
+ TEST_CHECK (b == 0x2fffff );
1383
+
1384
+ OK (uc_close (uc ));
1385
+
1386
+ }
1345
1387
#endif
1346
1388
1347
1389
static bool test_x86_lazy_mapping_mem_callback (uc_engine * uc , uc_mem_type type ,
@@ -2019,6 +2061,8 @@ TEST_LIST = {
2019
2061
{"test_x86_invalid_vex_l" , test_x86_invalid_vex_l },
2020
2062
#if !defined (TARGET_READ_INLINED ) && defined (BOOST_LITTLE_ENDIAN )
2021
2063
{"test_x86_unaligned_access" , test_x86_unaligned_access },
2064
+ {"test_x86_64_unaligned_access" , test_x86_64_unaligned_access },
2065
+
2022
2066
#endif
2023
2067
{"test_x86_lazy_mapping" , test_x86_lazy_mapping },
2024
2068
{"test_x86_16_incorrect_ip" , test_x86_16_incorrect_ip },
0 commit comments