void hexStringToByte(const char *hex_string,size_t hex_len,unsigned char **bytes,size_t *byte_len)
{
size_t loop,i,out_len=0;
BYTE *out_bs = NULL;
int temp=0x10;
const char limits[] = {'0','9',0,'a','f',0xa,'A','F',0xa};
if(hex_len == 0){
return;
}
*bytes = calloc((size_t)hex_len,sizeof (BYTE));
out_bs = *bytes;
for(loop = 0;loop<hex_len;loop++){
char hex_char = hex_string[loop];
for(i=0;i<=6;i+=3){
if(hex_char >= limits[i] && hex_char <= limits[i+1]){
temp = temp | (BYTE)(hex_char-limits[i]+limits[i+2]);
if(temp & 0x100){
out_bs[out_len] = temp&0xff;
++out_len;
temp = 0x10;
}else{
temp <<= 4;
}
break;
}
}
}
realloc(out_bs,(size_t)out_len);
*byte_len = out_len;
}
网友评论