本帖最后由 海风月影 于 2014-11-9 21:42 编辑
保护手段:特殊版的编译器,clang.exe cm.c,生成出来的bin,就是比赛用的
编译方式:普通编译器也可以编译,注释掉一行编译选项:cl.exe cm.c即可
下面放的源码是跨平台的,其实也可以做个Android版本,不过为了降低难度,只做了Windows版本
把源码里面关于Windows平台代码注释去掉,编译出来,就是比赛放出去的版本
说明一下,你们自己的编译器如果报错,注释掉下面一行就行了
// 这行是特殊版编译器的选项,普通编译器编译,注释掉就行了
#pragma obfuscate on
源码如下://#include <windows.h>
#include <stdio.h>
#include <math.h>
#define PI 3.141592653589793238462643383279
#define EPLISON 0.00001
#define R1 -0.1666665668e+0
#define R2 0.8333025139e-2
#define R3 -0.1980741872e-3
#define R4 0.2601903036e-5
#define INVSPI 0.31830988618379067153776752674508
#define HALFPI (PI / 2)
#define C1 3.140625
#define C2 9.67653589793e-4
#define hashkey1 0xB4B2F8C2
#define hashkey2 0x2FF54B62
#define hashkey3 0x9639CE42
#define hashkey4 0x58ECCC20
// 这行是特殊版编译器的选项,普通编译器编译,注释掉就行了
#pragma obfuscate on
char key[50] = {0}; //48位的key
char name[35] = "";
int vaild();
int main(int argc, char *argv[])
{
//HANDLE hd = GetStdHandle(STD_OUTPUT_HANDLE);
//SetConsoleTitle("52Pojie CrackMe Contest 2014");
//SetConsoleTextAttribute(hd, 0xF);
printf(" 52Pojie CrackMe Contest 2014\n");
printf(" [url]http://www.52pojie.cn[/url]\n\n");
printf(" Author: 海风月影\n\n");
printf("Useage: \n cm [name] [key]\n");
printf("\n");
if(argc < 2)
{
printf("Please Input Name (length = [3, 32]): ");
scanf("%32s", name);
printf("Please Input Key (length = 48): ");
scanf("%48s", key);
printf("\n\n\n");
}
else
{
strncpy(name, argv[1], 32);
strncpy(key, argv[2], 48);
}
printf("Your name: %s\nYour key: %s\nChecking...", name, key);
//SetConsoleTextAttribute(hd, 12);
vaild();
//SetConsoleTextAttribute(hd, 0xF);
{
char tmp[6] = {'D', 'o', 'n', 'e', '!', 0};
printf("\n%s\n", tmp);
}
getchar();
return 0;
}
int vaild()
{
unsigned int namelen;
unsigned int keylen;
unsigned char *pk;
unsigned int k;
unsigned int hash1 = 0;
unsigned int hash2 = 0;
unsigned int hash3 = 0;
unsigned int hash4 = 0;
float y;
float y1;
float y2;
float y3;
double x0;
float x1;
float x2;
float x4;
float *x;
unsigned int *xx;
unsigned int crc32;
unsigned char *lpData;
unsigned int i, j;
unsigned int n;
unsigned int sign;
unsigned int crcTable[256];
float xn, f, g, rg, result;
unsigned int rem;
unsigned int root;
unsigned int divisor;
unsigned int a;
unsigned short *d;
int B, C;
unsigned int ddd[6];
char szGood[12];
namelen = strlen(name);
keylen = strlen(key);
if (namelen < 3 || namelen > 32 || keylen != 48)
{
return 6;
}
szGood[5] = 'c';
for(i = 0; i < namelen; i++)
{
hash1 += hash1 * name[i] * (name[i] << 1) + hashkey1;
hash2 += hash2 * name[i] * (name[i] >> 2) + hashkey2;
hash3 += hash3 * name[i] * (name[i] << 3) + hashkey3;
hash4 += hash4 * name[i] * (name[i] << 5) + hashkey4;
}
hash1 = ((hash1 & 0x00FFFFFF) ^ (unsigned int)0x3E000000);
hash2 = ((hash2 & 0x00FFFFFF) ^ (unsigned int)0x3F000000);
hash3 = ((hash3 & 0x00FFFFFF) ^ (unsigned int)0x40000000);
szGood[7] = '!';
for(i = 0; i < keylen; i+= 8)
sscanf((char*)&key[i], "%08X", &ddd[i / 8]);
szGood[8] = '\x0';
for( i = 0; i < 256; i ++ )
{
crc32 = i;
for( j = 0; j < 8; j ++ )
{
if(crc32 & 1)
crc32 = (crc32 >> 1) ^ 0xEDB88320UL;
else
crc32 >>= 1;
}
crcTable[i] = crc32;
}
szGood[4] = 'e';
crc32 = ~hash4;
lpData = &ddd;
for(i = 0; i < 24; i ++)
{
crc32 = (crc32 >> 8) ^ crcTable[ (crc32 ^ lpData[i]) & 0xFF ];
}
szGood[3] = 'r';
crc32 = ~crc32;
for(i = 0; i < 6; i ++)
{
ddd[i] ^= crc32;
}
szGood[6] = 't';
xx = (unsigned int*)&y2;
y1 = 0.0;
x0 = 1.0;
y2 = x0;
x1 = *(float*)&ddd[0];
x2 = *(float*)&ddd[1];
x4 = x1;
for(i = 1; i <= 100000; i++)
{
sign = (x4 < 0);
x4 = sign?(-x4):x4;
n = (int) ((x4 * INVSPI) + 0.5);
xn = (double) n;
sign ^= n % 2;
f = (x4 - xn * C1) - xn * C2;
g = f * f;
rg = (((R4 * g + R3) * g + R2) * g + R1) * g;
result = f + f * rg;
result = sign ? -result : result;
y1 += result / i;
x0 *= x2;
y2 += x0;
x4 += x1;
}
x = (float*)&hash1;
if(fabs(*x - y1) > EPLISON || fabs(y2 - *(float*)&hash2) > EPLISON)
{
szGood[1] = '\x0';
return 3;
}
szGood[0] = 'C';
x0 = 1.0;
y3 = 0.0;
x1 = *(float*)&ddd[2];
x4 = x1;
for(i = 1; i < 8000; i++)
{
x4 = (x4 > 0)?(x4):(-x4);
n = (int) (((x4 + HALFPI) * INVSPI) + 0.5);
xn = (double)n - 0.5;
sign = n % 2;
f = (x4 - xn * C1) - xn * C2;
g = f * f;
rg = (((R4 * g + R3) * g + R2) * g + R1) * g;
result = f + f * rg;
result = sign ? -result : result;
y3 += x0 * result / (i * i);
x0 = -x0;
x4 += x1;
}
y3 = y3 * 4 + PI * PI / 3 * 2;
x = (float*)&hash3;
if(fabs(*x - y3) > EPLISON)
{
szGood[0] = '\x0';
return 1;
}
k = 0;
szGood[1] = 'o';
d = (unsigned short*)&ddd[4];
for(i = 0; i < 4; i++)
{
B = (int)d[i];
if(B >= 0x8000)
{
B = (B * 2) & 0xFFFF;
C = B + 1;
}
else
C = B + 2;
rem = 0;
root = 0;
divisor = 0;
a = C * C - B * B;
for(j = 0; j < 16; j++)
{
root <<= 1;
rem = ((rem << 2) + (a >> 30));
a <<= 2;
divisor = (root << 1) + 1;
if(divisor <= rem)
{
rem -= divisor;
root ++;
}
}
k = k | ((unsigned char)(root - 3)) << (i * 8);
}
if(k == hash4)
{
szGood[2] = 'r';
;;;
printf("%s", szGood);
;
}
;
return 2;
}
|