c源码
/* adler32.c -- compute the Adler-32 checksum of a data stream
* Copyright (C) 1995-2004 Mark Adler
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#define ZLIB_INTERNAL
#include "zlib.h"
#define BASE 65521UL /* largest prime smaller than 65536 */
#define NMAX 5552
/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
#define DO16(buf) DO8(buf,0); DO8(buf,8);
/* use NO_DIVIDE if your processor does not do division in hardware */
#ifdef NO_DIVIDE
# define MOD(a) \
do { \
if (a >= (BASE << 16)) a -= (BASE << 16); \
if (a >= (BASE << 15)) a -= (BASE << 15); \
if (a >= (BASE << 14)) a -= (BASE << 14); \
if (a >= (BASE << 13)) a -= (BASE << 13); \
if (a >= (BASE << 12)) a -= (BASE << 12); \
if (a >= (BASE << 11)) a -= (BASE << 11); \
if (a >= (BASE << 10)) a -= (BASE << 10); \
if (a >= (BASE << 9)) a -= (BASE << 9); \
if (a >= (BASE << 8)) a -= (BASE << 8); \
if (a >= (BASE << 7)) a -= (BASE << 7); \
if (a >= (BASE << 6)) a -= (BASE << 6); \
if (a >= (BASE << 5)) a -= (BASE << 5); \
if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \
if (a >= BASE) a -= BASE; \
} while (0)
# define MOD4(a) \
do { \
if (a >= (BASE << 4)) a -= (BASE << 4); \
if (a >= (BASE << 3)) a -= (BASE << 3); \
if (a >= (BASE << 2)) a -= (BASE << 2); \
if (a >= (BASE << 1)) a -= (BASE << 1); \
if (a >= BASE) a -= BASE; \
} while (0)
#else
# define MOD(a) a %= BASE
# define MOD4(a) a %= BASE
#endif
/* ========================================================================= */
uLong ZEXPORT adler32(adler, buf, len)
uLong adler;
const Bytef *buf;
uInt len;
{
unsigned long sum2;
unsigned n;
/* split Adler-32 into component sums */
sum2 = (adler >> 16) & 0xffff;
adler &= 0xffff;
/* in case user likes doing a byte at a time, keep it fast */
if (len == 1) {
adler += buf[0];
if (adler >= BASE)
adler -= BASE;
sum2 += adler;
if (sum2 >= BASE)
sum2 -= BASE;
return adler | (sum2 << 16);
}
/* initial Adler-32 value (deferred check for len == 1 speed) */
if (buf == Z_NULL)
return 1L;
/* in case short lengths are provided, keep it somewhat fast */
if (len < 16) {
while (len--) {
adler += *buf++;
sum2 += adler;
}
if (adler >= BASE)
adler -= BASE;
MOD4(sum2); /* only added so many BASE's */
return adler | (sum2 << 16);
}
/* do length NMAX blocks -- requires just one modulo operation */
while (len >= NMAX) {
len -= NMAX;
n = NMAX / 16; /* NMAX is divisible by 16 */
do {
DO16(buf); /* 16 sums unrolled */
buf += 16;
} while (--n);
MOD(adler);
MOD(sum2);
}
/* do remaining bytes (less than NMAX, still just one modulo) */
if (len) { /* avoid modulos if none remaining */
while (len >= 16) {
len -= 16;
DO16(buf);
buf += 16;
}
while (len--) {
adler += *buf++;
sum2 += adler;
}
MOD(adler);
MOD(sum2);
}
/* return recombined sums */
return adler | (sum2 << 16);
}
/* ========================================================================= */
uLong ZEXPORT adler32_combine(adler1, adler2, len2)
uLong adler1;
uLong adler2;
z_off_t len2;
{
unsigned long sum1;
unsigned long sum2;
unsigned rem;
/* the derivation of this formula is left as an exercise for the reader */
rem = (unsigned)(len2 % BASE);
sum1 = adler1 & 0xffff;
sum2 = rem * sum1;
MOD(sum2);
sum1 += (adler2 & 0xffff) + BASE - 1;
sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
if (sum1 > BASE) sum1 -= BASE;
if (sum1 > BASE) sum1 -= BASE;
if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
if (sum2 > BASE) sum2 -= BASE;
return sum1 | (sum2 << 16);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
反编译源码
//----- (10088260) --------------------------------------------------------
unsigned int __cdecl sub_10088260(unsigned int a1, unsigned __int8 *a2, unsigned int a3)
{
unsigned int v3; // ebx
unsigned int v4; // ecx
unsigned int v5; // edi
unsigned int v6; // eax
int v7; // edx
int v8; // ecx
unsigned __int8 *v10; // esi
int v11; // eax
unsigned int v12; // esi
int v13; // edx
unsigned int v14; // ecx
unsigned int v15; // edi
unsigned int v16; // ecx
unsigned int v17; // edi
unsigned int v18; // ecx
unsigned int v19; // edi
unsigned int v20; // ecx
unsigned int v21; // edi
unsigned int v22; // ecx
unsigned int v23; // edi
unsigned int v24; // ecx
unsigned int v25; // edi
unsigned int v26; // ecx
int v27; // edi
unsigned int v28; // ecx
int v29; // edi
unsigned int v30; // ecx
int v31; // edi
int v32; // ecx
int v33; // edi
int v34; // ecx
int v35; // edi
int v36; // ecx
int v37; // edi
int v38; // ecx
int v39; // edi
int v40; // ecx
int v41; // edi
int v42; // ecx
int v43; // eax
int v44; // edi
unsigned int v45; // edx
unsigned int v46; // ecx
unsigned int v47; // edi
unsigned int v48; // ecx
unsigned int v49; // edi
unsigned int v50; // ecx
unsigned int v51; // edi
unsigned int v52; // ecx
unsigned int v53; // edi
unsigned int v54; // ecx
unsigned int v55; // edi
unsigned int v56; // ecx
unsigned int v57; // edi
unsigned int v58; // ecx
int v59; // edi
unsigned int v60; // ecx
int v61; // edi
unsigned int v62; // ecx
int v63; // edi
int v64; // ecx
int v65; // edi
int v66; // ecx
int v67; // edi
int v68; // ecx
int v69; // edi
int v70; // ecx
int v71; // edi
int v72; // ecx
int v73; // edi
int v74; // ecx
int v75; // eax
int v76; // edi
int v77; // eax
unsigned int v78; // [esp+10h] [ebp+8h]
v3 = a3;
v4 = (unsigned __int16)a1;
v5 = HIWORD(a1);
if ( a3 == 1 )
{
v6 = (unsigned __int16)a1 + *a2;
v7 = v6 - 65521;
if ( v6 < 0xFFF1 )
v7 = (unsigned __int16)a1 + *a2;
v8 = v7 + v5 - 65521;
if ( v7 + v5 < 0xFFF1 )
v8 = v7 + v5;
return v7 | (v8 << 16);
}
else
{
v10 = a2;
if ( a2 )
{
if ( a3 >= 0x10 )
{
if ( a3 >= 0x15B0 )
{
v78 = a3 / 0x15B0;
do
{
v3 -= 5552;
v13 = 347;
do
{
v14 = *v10 + v4;
v15 = v14 + v5;
v16 = v10[1] + v14;
v17 = v16 + v15;
v18 = v10[2] + v16;
v19 = v18 + v17;
v20 = v10[3] + v18;
v21 = v20 + v19;
v22 = v10[4] + v20;
v23 = v22 + v21;
v24 = v10[5] + v22;
v25 = v24 + v23;
v26 = v10[6] + v24;
v27 = v26 + v25;
v28 = v10[7] + v26;
v29 = v28 + v27;
v30 = v10[8] + v28;
v31 = v30 + v29;
v32 = v10[9] + v30;
v33 = v32 + v31;
v34 = v10[10] + v32;
v35 = v34 + v33;
v36 = v10[11] + v34;
v37 = v36 + v35;
v38 = v10[12] + v36;
v39 = v38 + v37;
v40 = v10[13] + v38;
v41 = v40 + v39;
v42 = v10[14] + v40;
v43 = v10[15];
v44 = v42 + v41;
v10 += 16;
v4 = v43 + v42;
v5 = v4 + v44;
--v13;
}
while ( v13 );
v4 %= 0xFFF1u;
v5 %= 0xFFF1u;
--v78;
}
while ( v78 );
}
if ( v3 )
{
if ( v3 >= 0x10 )
{
v45 = v3 >> 4;
do
{
v3 -= 16;
v46 = *v10 + v4;
v47 = v46 + v5;
v48 = v10[1] + v46;
v49 = v48 + v47;
v50 = v10[2] + v48;
v51 = v50 + v49;
v52 = v10[3] + v50;
v53 = v52 + v51;
v54 = v10[4] + v52;
v55 = v54 + v53;
v56 = v10[5] + v54;
v57 = v56 + v55;
v58 = v10[6] + v56;
v59 = v58 + v57;
v60 = v10[7] + v58;
v61 = v60 + v59;
v62 = v10[8] + v60;
v63 = v62 + v61;
v64 = v10[9] + v62;
v65 = v64 + v63;
v66 = v10[10] + v64;
v67 = v66 + v65;
v68 = v10[11] + v66;
v69 = v68 + v67;
v70 = v10[12] + v68;
v71 = v70 + v69;
v72 = v10[13] + v70;
v73 = v72 + v71;
v74 = v10[14] + v72;
v75 = v10[15];
v76 = v74 + v73;
v10 += 16;
v4 = v75 + v74;
v5 = v4 + v76;
--v45;
}
while ( v45 );
}
for ( ; v3; --v3 )
{
v77 = *v10++;
v4 += v77;
v5 += v4;
}
v4 %= 0xFFF1u;
v5 %= 0xFFF1u;
}
return v4 | (v5 << 16);
}
else
{
if ( a3 )
{
do
{
v11 = *v10++;
v4 += v11;
v5 += v4;
--v3;
}
while ( v3 );
}
v12 = v4 - 65521;
if ( v4 < 0xFFF1 )
v12 = v4;
return v12 | ((v5 + 15 * (v5 / 0xFFF1)) << 16);
}
}
else
{
return 1;
}
}
}
// 10088260: too many cbuild loops