用汇编语言实现
xor edx,edx ;ebx equals zero
mov esi,offset funcname ;get the start of api name string
1oop:
Movsz eax,byte prt[esi] ;get one byte from name string to eax
cmp al,ah ;if we get zero then Exit
jz Exit
ror edx ,07h ;this statement equals digest=((digest<<25)|(digest>>7));
add edx,eax ; this statement equals digest+=*fun_name;
add esi,1 ; ask esi to point to the next byte
jmp 1oop
Exit:
1.看编译器安装目录中库文件代码中的rotl.c,我同样用VC6试验了,同样的函数无论如何优化总是不能只得到一条汇编指令。
/***
*unsigned _rotl(val, shift) - int rotate left
*
*Purpose:
* Performs a rotate left on an unsigned integer.
*
* [Note: The _lrotl entry is based on the assumption
* that sizeof(int) == sizeof(long).]
*Entry:
* unsigned val: value to rotate
* int shift: number of bits to shift by
*
*Exit:
* returns rotated value
*
*Exceptions:
* None.
*
*******************************************************************************/
unsigned long __cdecl _lrotl (
unsigned long val,
int shift
)
{
return( (unsigned long) _rotl((unsigned) val, shift) );
}
unsigned __cdecl _rotl (
unsigned val,
int shift
)
{
register unsigned hibit; /* non-zero means hi bit set */
register unsigned num = val; /* number to rotate */
shift &= 0x1f; /* modulo 32 -- this will also make
negative shifts work */
while (shift--) {
hibit = num & 0x80000000; /* get high bit */
num <<= 1; /* shift left one bit */
if (hibit)
num |= 1; /* set lo bit if hi bit was set */
}