因此,我試圖將一個uint64_t的回傳地址寫入一個緩沖區,然后驗證正確的回傳地址是否被寫入正確的位置。下面是我的代碼。
uint64_t new_ret = ret - 8 - 32 - 32 - 1001 (ret_buffer_offset sizeof(shellcode));
printf("new_ret :%lu
", new_ret)。)
snprintf(&buffer[ret_buffer_offset], 8, "%s", new_ret) 。
//除錯代碼。
char buffer_debug[10] 。
uint64_t* buffer_uint = (uint64_t*)buffer_debug。
bzero(buffer_debug, 10)。
strncpy(buffer_debug, & buffer[ret_buffer_offset], 8)。
uint64_t ret_debug = *buffer_uint;
printf("ret debug: %lu
", ret_debug)。)
這兩個printfs應該輸出相同的東西,但是最下面的printf輸出了一個非常不同的數字。我不確定是我寫到緩沖區的方式不對,還是我獲取數值的方式有問題。這里的問題是什么?
謝謝你
uj5u.com熱心網友回復:
snprintf(&buffer[ret_buffer_offset], 8, "%s"/span>, new_ret) 。
buffer現在包含了原始值的字串表示法(或者至少是字串表示法的前8個位元組)。 然后你的代碼將這個字串的前8個位元組作為一個uint64_t的二進制序列進行解釋。 在除錯器中瀏覽這一大塊代碼,你會看到數值變化的確切位置。
我不確定這段代碼到底想做什么,但它似乎在做更多的復制和轉換。 如果你有一個指向你想要的值的指標,你應該可以做 memcpy(ptr, &new_ret, sizeof(new_ret)) 或者甚至可能做 *(uint64_t*)ptr = new_ret 如果你的平臺允許潛在的無符號的寫入行為。 要列印出用于除錯的值,你會使用printf("%"PRIu64, *(uint64_t*)ptr)。
uj5u.com熱心網友回復:
我喜歡使用union,但是如果你做一個char指標(char*)來指向uint64_t的地址就可以了。
使用指標將是:
uint64_t new_ret = ret - 8 - 32 - 32 - 1001 (ret_buffer_offset sizeof(shellcode));
buffer = (char*) &new_ret;
測驗下面的代碼,以使用union和pointer:
#include <stdio.h>
#include <stdint.h>
int main(){
union {
uint64_t u64。
char str[8] 。
} handler;
handler.u64 = 65;
printf("using union:
")。)
printf(" uint64: %ld
", handler.u64)。)
printf(" char*: %s
", handler.str)。)
uint64_t u64 = 65;
char *str = (char*)& u64;
printf("using pointer:
")。)
printf(" uint64: %ld
", u64)。)
printf(" char*: %s
", str)。)
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/315114.html
標籤:
