含16进制的PHP源码解密

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
unsigned long HEX2DEC(const char *s)
{
        int i,t;
        unsigned long sum=0;
        for (i=0; s[i]; i++)
        {
                if ( (s[i]=='0' && s[i+1]=='x') || (s[i]=='\\' && s[i+1]=='x') )
                {    
                      i++;
                      continue; //0xff, \x64, 去前缀
                }
                if ( s[i]>='0' && s[i] <= '9' )
                        t = s[i]-'0';
                else if ( s[i]>='A' && s[i] <= 'F')
                        t = s[i]-'A'+10;
                else if ( s[i]>='a' && s[i]<='f' )
                        t = s[i]-'a'+10;
                else
                        break;
                sum=sum*16+t;
        }
        return sum;
}
int main(void)
{
         FILE *fd = fopen("d:/1.txt", "r");
         fseek(fd,0,SEEK_END);
         unsigned long s = ftell(fd);
         char *p = (char *)malloc(s);
         memset(p, 0, s );
         fseek(fd,0,SEEK_SET);
         fread( p, s, 1, fd);
         fclose(fd);
         // output
         char t[16]={0}, n[2]={0};
         fd = fopen("d:/2.txt", "w+");
         for ( unsigned int i=0; i<strlen(p); i++ )
         {        
              if ( p[i] == '\\' && p[i+1] == 'x' )
              {
                    sprintf(t, "%c%c", p[i+2], p[i+3]);
                    fputc(HEX2DEC(t),fd);
                    i += 3;
                    continue;
              }
              fputc(p[i], fd);
         }
         fclose(fd);
         free(p);
         return 0;
}

转载于:https://my.oschina.net/guyson/blog/233044

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值