Hash windows api method
为了控制shellcode 大小,总将api的名字用一个算法求得对应的一个Dword数(32位)
2的 32次方 可以表达4 294 967 296种可能。
网络常用的一个hash算法的c语言实现如下
#include <windows.h>
#include <stdio.h>
DWORD GetHash(char *fun_name)
{
DWORD digest=0;
while(*fun_name)
{
   digest=((digest<<25)|(digest>>7));
   digest+=*fun_name;
   fun_name++;
}
return digest;
}
void main()
{
DWORD hash;
hash=GetHash("MessageBoxA");
printf("result of hash is %.8x\n",hash);
}
基本算法就是 h=h<<25 | h>>7 +*fun_name

用汇编语言实现              
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:


一时间没有想明白ror   edx ,07h 为什么等于digest=((digest<<25)|(digest>>7))
好笨,昨天画了画明白了~
假如有这样一来一个32位二进制数
执行完digest<<25后把右边的7位移动到左边,然后右边七位补25个0
执行完digest>>7后把左边25位移动到右边,然后左边7位补0
把两个数或运算后 正好跟循环右移7位是相等的.