1、將如下代碼移植到你的c文件文章來源:http://www.zghlxwxcb.cn/news/detail-557758.html
#include <stdio.h>
#include <string.h>
char *strcat(char *dest, const char *src)
{
char *tmp = dest;
while (*dest)
dest++;
while ((*dest++ = *src++) != '\0');
return tmp;
}
static void i_to_string(char *buf, char x)
{
char shiwei = x /16;
char gewei = x %16;
buf[0] = ' ';
buf[1] = shiwei >= 10 ? (shiwei - 10 + 'a') : (shiwei + '0');
buf[2] = gewei >= 10 ? (gewei - 10 + 'a') : (gewei + '0');
buf[3] = 0;
}
#define PRINT_BUF_MAX (32)
#define TAG_STRING_MAX (32)
static void print_step_hex_data(void *tag, void *pbuf, uint32_t len)
{
int i;
char buf[PRINT_BUF_MAX*4 + TAG_STRING_MAX] = {0};
char temp_buf[4] = "HHH";
memcpy(buf, (char *)tag, sizeof(buf));
for (i=0;i<len;i++) {
if (i % 16 ==0) {
strcat(buf,"\n");
}
i_to_string(temp_buf, *((char *)pbuf + i)&0xff);
strcat(buf, temp_buf);
}
strcat(buf,"\n");
EMSG("%s", buf);
}
void print_hex_data(void *tag, void *pbuf, uint32_t len)
{
int i;
uint32_t block;
uint32_t remainder;
void *p;
char tag_buf[TAG_STRING_MAX + 6] = {0};
char tail_buf[6+4] = {0};
p = pbuf;
if (len<=PRINT_BUF_MAX) {
memcpy(tag_buf,tag,TAG_STRING_MAX);
strcat(tag_buf, " = ");
return print_step_hex_data(tag_buf, p, len);
} else {
block = len / PRINT_BUF_MAX;
remainder = len % PRINT_BUF_MAX;
for (i=0;i<block;i++) {
memcpy(tag_buf,tag,TAG_STRING_MAX);
tail_buf[0] = '[';
tail_buf[1] = i / 10 + '0';
tail_buf[2] = i % 10 + '0';
tail_buf[3] = ']';
tail_buf[4] = 0;
strcat(tag_buf, tail_buf);
print_step_hex_data(tag_buf, p, PRINT_BUF_MAX);
p = (char *)p + PRINT_BUF_MAX;
}
if (remainder) {
memcpy(tag_buf,tag,TAG_STRING_MAX);
tail_buf[0] = '[';
tail_buf[1] = i / 10 + '0';
tail_buf[2] = i % 10 + '0';
tail_buf[3] = ']';
tail_buf[4] = 0;
strcat(tag_buf, tail_buf);
print_step_hex_data(tag_buf, p, remainder);
}
}
}
2、 打印二進制的方法如下所示
print_hex_data("Cipher Data : ", tmp_buf, tmp_sz);
print_hex_data("Plaintext Data : ", out_buf, out_sz);文章來源地址http://www.zghlxwxcb.cn/news/detail-557758.html
到了這里,關(guān)于optee打印二進制的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!