本站动态:
首页 > 网络学院 > 操作系统 > DOS > 开发编程
一个“解码”程序
来源: 作者: 阅读: 发布时间:2005-04-02


经常会在网页上看到一些类似于%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;
}

上一篇:编程过把瘾:自己动手写操作系统

下一篇:下面没有链接了
内容导航:
访问者在接受本网站服务,表示访问者接受本站“网站声明

     评论人 评论内容 发表时间
发表评论
用户名: 密码:
验证码: 匿名发表
促销商品
进口DIP8转SOP8、SOIC8
·商品编号:
·品牌:
·库存:100
·价格: 200.00 70.00
特价三剑
·商品编号:
·品牌:
·库存:50
·价格: 420.00 280.00
SWORD
·商品编号:
·品牌:
·库存:50
·价格: 100.00 85.00