-
-
[原创]这玩意放着没用,丢了算了.
-
发表于:
2012-6-28 00:22
7509
-
#include <windows.h>
#pragma comment(linker,"/ENTRY:_WinMain@16");
#pragma comment(linker,"/ALIGN:512");
int decrypt(const void * src,size_t count,const void * dst)
{
unsigned char * psrc = (unsigned char *)src;
unsigned char * pdst = (unsigned char *)dst;
unsigned int Prob = (1 << 10);
unsigned int uiAny = 0;
unsigned int uiSom = 0xFFFFFFFF;
for(int i = 0; i < 4; i++)
{
uiAny = (uiAny << 8) | *psrc++;
}
while(count--)
{
unsigned char b = 0;
for (int j=0; j < 8; j++)
{
unsigned int u = (uiSom >> 11) * Prob;
if (uiAny < u)
{
uiSom = u;
Prob += ((1 << 11) - Prob) >> 5;
b += (0 << j);
}
else
{
uiSom -= u;
uiAny -= u;
Prob -= (Prob) >> 5;
b += (1 << j);
}
if (uiSom < (1 << 24))
{
uiAny = (uiAny << 8) | *psrc++;
uiSom <<= 8;
}
}
*pdst++ = b;
}
return (pdst - (unsigned char *)dst);
}
int encrypt(const void *src, size_t count, const void *dst)
{
unsigned char * psrc = (unsigned char *)src;
unsigned char * pdst = (unsigned char *)dst;
unsigned int last = 0;
unsigned int first = 0;
unsigned int Prob = 0x400;
unsigned int uiSom = 0xFFFFFFFF;
unsigned char cache = 0;
unsigned int index = 0;
unsigned int ShiftLow = 0;
while(count--)
{
unsigned char b = *psrc++;
for( int i = 0; i < 8; i++)
{
unsigned int u = Prob * (uiSom >> 11);
if ( (b >> i) & 1 )
{
ShiftLow += u;
first += (u >= ShiftLow ? 1:0);
uiSom -= u;
Prob -= Prob >> 5;
}
else
{
uiSom = Prob * (uiSom >> 11);
Prob += (0x800 - Prob) >> 5;
}
if ( uiSom >= 0x1000000 )
{
last = cache;
}
else
{
uiSom <<= 8;
if ( ShiftLow < 0xFF000000 || first )
{
for ( unsigned int j = cache; index; index-- )
{
*pdst++ = j + first;
j = -1;
}
last = ShiftLow >> 24;
cache = ShiftLow >> 24;
}
else
{
last = cache;
}
ShiftLow <<= 8;
first = 0;
++index;
}
}
}
for( unsigned int i = 0; i < 5; i++)
{
if ( ShiftLow < 0xFF000000)
{
*pdst++ = last + first;
last = ShiftLow >> 24;
}
ShiftLow <<= 8;
}
return (pdst - (unsigned char *)dst);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
char dst[0x100] = {0};
char src[0x100] = "LiuTaoTao 2007-07-28 Example --> by Worker";
int len = encrypt(src,lstrlen(src),dst);
memset(src,0x0,0x100);
decrypt(dst,len,src);
MessageBox(NULL,src,src,MB_ICONINFORMATION);
ExitProcess(0);
return 0;
}
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)