我是 C 的新手,所以我为任何“明显的问题”道歉。
我正在尝试在缓冲区中搜索一组十六进制值。我试图将它放入一个函数中,因为我将不得不搜索它们的多组。
这是我到目前为止的代码:
#define bin_buff_size (1024 * 1500)
unsigned char *bin_buff;
int i, hex_location, reset_i, hex_i, fix_location_1, buff_size;
unsigned char hex_string_search_1[] = {0x5e, 0x00, 0x75, 0x0d, 0x68, 0xb4, 0x2c, 0x63};
<other code here>
int get_location_from_buffer(unsigned char *needle, unsigned char *haystack, size_t haystack_size) {
// Find the location of the hex-values in the buffer
for (i = 0; i < haystack_size; i++) {
// Reset hex_value because I will need to do this for multiple sets of hex values
for (reset_i = 0; reset_i <= 7; reset_i++) {
hex_value[reset_i] = 0x00;
}
// Set hex_value equal to the next section of the haystack
for (hex_i = 0; hex_i <= 7; hex_i++) {
hex_value[hex_i] = haystack[i + hex_i];
printf("hex_value[%i] = %s\n",hex_i,hex_value[hex_i]); // Print the resulting hex-value for this sub-location
}
printf("hex_value = %s\n",hex_value); // Print the entire hex_value
// Check if needle equals haystack, and if so, return the resulting location
if (needle == hex_value){
printf("Found the first value at %i", i);
}else{
printf("Havent found the first value yet!\n");
}
}
return i;
}
fix_location_1 = get_location_from_buffer(hex_string_search_1, bin_buff, buff_size);
我遇到的问题是这是我的输出:
hex_value[0] = (null)
hex_value[1] = (null)
hex_value[2] = (null)
hex_value[3] = (null)
hex_value[4] = (null)
hex_value[5] = (null)
hex_value[6] = (null)
hex_value[7] = (null)
hex_value =
Havent found the first value yet!
<The above is repeated multiple times>
它看起来像这一行:
hex_value[hex_i] = haystack[i + hex_i];
实际上并没有像我想的那样从缓冲区中提取数据。有人能指出我做错了什么吗?