|
经常会在网页上看到一些类似于%D6%D0%B9%FA 的字符,这是因为向WEB服务器提供非英文字符(如中文)时,都会以十六进制数传输,服务器会把它解码为实际字符(两个字符对应一个中文字符); 而有些网上木马病毒为了掩盖其真实意图也常常使用这种字符串(如前一阵子的about:blank病毒) 我写了一个小程序,输入码字符如:%D6%D0%B9%FA就可以得到真实字符串内容(如中国) #include <stdio.h> #include <stdlib.h>
int main(void) { unsigned int i=0,max=30; char* dest; dest=(char*)malloc(max); if(!dest)exit (1); printf("input your code string: "); while((dest =getchar())=='%') { if((dest[++i] =getchar()) >= 'A') dest = ((dest & 0xdf) - 'A') + 10; else dest = dest - '0'; if((dest[++i] =getchar()) >= 'A') dest = ((dest & 0xdf) - 'A') + 10; else dest = dest - '0'; dest[i/3]=dest +dest[i-1]*16; i++; if(i==max) { max+=max; dest=(char*)realloc(dest,max); if(!dest) exit(1); } } dest[i/3]='/0'; printf("this decode string is:%s/n",dest); free(dest); return 0; } |