2014-01-18 85 views
1

我已經寫了一個if語句,比較兩個hex值,但是這個if表示值爲!=,即使它們是==! 。我可以看到它們是平等的,因爲我用printf打印它們的值!使用if語句比較兩個十六進制值

uint64_t sys_call_table_offset = 0xc033e7f4; 
uint64_t sys_call_func_ptr; 
uint64_t syscall_func_ptr[15] = { 0xc0107c30,//0->2 
            0xc0152ea0,//1->3 
            0xc0152fe0,//2->4 
            0xc0152220,//3->5 
            0xc0107d40,//4->11 
            0xc0151750,//5->12 
            0xc0132300,//6->23 
            0xc012dae0,//7->24 
            0xc01303a0,//8->37 
            0xc0165230,//9->54 
            0xc02086d0,//10->102 
            0xc0107c80,//11->120 
            0xc0165cb0,//12->141 
            0xc0124e50,//13->167 
            0xc0165e70,//14->220 
           }; 
int sys_num[15]={2,3,4,5,11,12,23,24,37,54,102,120,141,167,220}; 
int i; 
for(i = 0 ; i<15 ; i++) 
{ 
    vmi_read_32_va(vmi,sys_call_table_offset + (sys_num[i] * 0x4) , 0, &sys_call_func_ptr); 
    printf("sys_call_ptr = %x",sys_call_func_ptr); 
    printf("  sys_call_ptr = %x i=%d \n",syscall_func_ptr[i],i); 
    if(syscall_func_ptr[i]!= sys_call_func_ptr) 
    printf("Detected hooked system call!\n"); 
} 

這是printf的輸出:

sys_call_ptr = c0107c30 sys_call_ptr = c0107c30 i=0 
Detected hooked system call! 
sys_call_ptr = c0152ea0 sys_call_ptr = c0152ea0 i=1 
Detected hooked system call! 
sys_call_ptr = c0152fe0 sys_call_ptr = c0152fe0 i=2 
Detected hooked system call! 
sys_call_ptr = c0152220 sys_call_ptr = c0152220 i=3 
Detected hooked system call! 
sys_call_ptr = c0107d40 sys_call_ptr = c0107d40 i=4 
Detected hooked system call! 
sys_call_ptr = c0151750 sys_call_ptr = c0151750 i=5 
Detected hooked system call! 
sys_call_ptr = c0135b20 sys_call_ptr = c0132300 i=6 
Detected hooked system call! 
sys_call_ptr = c0135f30 sys_call_ptr = c012dae0 i=7 
Detected hooked system call! 
sys_call_ptr = c01303a0 sys_call_ptr = c01303a0 i=8 
Detected hooked system call! 
sys_call_ptr = c0165230 sys_call_ptr = c0165230 i=9 
Detected hooked system call! 
sys_call_ptr = c0209580 sys_call_ptr = c02086d0 i=10 
Detected hooked system call! 
sys_call_ptr = c0107c80 sys_call_ptr = c0107c80 i=11 
Detected hooked system call! 
sys_call_ptr = c0165cb0 sys_call_ptr = c0165cb0 i=12 
Detected hooked system call! 
sys_call_ptr = c0124e50 sys_call_ptr = c0124e50 i=13 
Detected hooked system call! 
sys_call_ptr = c0165e70 sys_call_ptr = c0165e70 i=14 
Detected hooked system call! 

回答

2

您需要"%lx"才能看到整個64位值? vmi_read_32_va填寫通過的&sys_call_func_ptr的整個64位? 如果不是,那麼你需要考慮32個垃圾位。

2

vmi_read_32_va需要一個指向uint32_t作爲最後一個參數,但你給它一個指針uint64_t,這是未初始化的,所以它只能填補32位它,其餘的有一個未定義的值(在大多數情況下不是0)。

您只打印4個LSB(%x),但會比較64位數字的全部8個字節。 如果您打印整個號碼(%llx),您將會看到區別。

+0

我改變的變量類型'uint32_t',現在它工作正常。 – Mjina

1

如果使用inttypes.h(如uint64_t)的類型,直接打印它們的方法是使用相同頭文件中定義的相應宏。

因此要打印uint64_t請使用PRIX64

uint64_t ui64 = (uint64_t)0xffff*0x10000*0x10000; 

... 

printf("0x"PRIX64" 0x"PRIX64"\n", ui64, ui64); 

將打印:

0xFFFF00000000 0xFFFF00000000 

64位計算機上的32位機器上,以及。

根據你的代碼會是這樣的:

printf("sys_call_ptr = "PRIX64, sys_call_func_ptr);