有些程序(比如QQMusic)很郁闷 老是抢我的80端口(有时候需要架个简单的web服务器,发现80端口老被某些程序占用了,于是得先退出那个抢我端口的程序 然后再....很麻烦), 于是写了小Dll 在Dllentry hook bind. 判断sockaddr_in里面的 port是不是80 是80就返回-1
Hook,
先写五个nop jmp bind1
然后剩下一个jmp short 只要2byte,可以用cmpxchg原子操作了~
用原子操作cmpxchg ...
代码:
nop*5 bind: mov edi,edi ..........
代码:
format PE Dll \ on '%others%\stub.txt' include '%include%\win32ax.inc' WSAEADDRINUSE equ 0x00002740 entry $ push edi mov edi,[bind] sub edi,5 i VirtualProtect,edi,7,PAGE_EXECUTE_READWRITE,esp,eax pop eax mov byte[edi],0xE9 mov eax,bind1 sub eax,edi sub eax,5 mov dword[edi+1],eax mov cx,0xF9EB @@: cmpxchg word[edi+5],cx jnz @B xor eax,eax inc eax pop edi retn 4*3 bind1: mov eax,[esp+8] mov cx,80 xchg cl,ch cmp word[eax+2],cx je @F mov eax,[bind] inc eax inc eax jmp eax @@: i WSASetLastError,WSAEADDRINUSE or eax,-1 retn 4*3 data export export 'Export',\ bind1,'None' end data .fixups