欢迎来到 嗅灵易学

零基础也能上手的脚本技术课,一对一答疑带你入门

对api 名字 hash的一点理解

对api 名字 hash的一点理解

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位是相等的.

注意:上传附件及图片大小不得大于30M。

⚠️ 版权声明:
本博客所有内容(含教程、源码、工具)仅供个人技术学习与研究交流使用,严禁商用、倒卖、二次分发及非法用途
未经作者书面授权,任何组织或个人不得转载、复制或用于其他平台,违者将追究相关责任。

0 0 0 举报
复制成功