汇编做的dll 堆栈不平衡
来源:百度知道 编辑:UC知道 时间:2024/06/24 17:03:20
; -----------------------------------------------
; Proc Name: GetProcAddr
; Usage: Get the address of a function. Actually, User can call 'LoadLibrary' & 'GetProcAddress' to take the place of this function.
; Parameters: szDllName, dword, a long pointer to a zero-ended string recording the name of lib
; szProcName, dword, a long pointer to a zero-ended string recording the name of function
; Return Value: if the function successfully acquire the address, the address is returned via eax. Otherwise zero will be put into eax.
; -----------------------------------------------???
invoke LoadLibrary, szDllName
.if eax
push szProcName
push eax
call GetProcAddress
.else
mov eax, FALSE
.endif
ret
GetProcAddr Endp
代码很简单,就是做了两个api的工作
调用是用vb,其中st
我想应该是你的LoadLibrary这个API用错的缘故。
以下是MSDN中对LoadLibrary的解释
HMODULE WINAPI LoadLibrary(
LPCTSTR lpFileName
);
传给它的参数是个指向字符串常量的指针,所以你应该这样写
invoke LoadLibrary,addr szDllName
如果szDllName是个全局变量的话,应写为:
invoke LoadLibrary,offset szDllName
还有堆栈都是向下增长的,所以APIHOOK.dll:10001039 push dword ptr [ebp+8]
这样的压栈肯定是有问题的
希望对你能有所帮助~
补充:
如果szDllName 不是常量的话,那就不能用LoadLibrary这么调用了。
人家MSDN说的很明白,参数是个字符串指针常量,你如果传个dword变量,那这个
API怎么能正常工作呢,你自然也得不到dll的句柄了(换言之返回值eax不会正确)。
我觉得应该这样写:
.386
.model flat, stdcall
option casemap:none
include windows.inc
include kernel32.inc ;具体参见MSDN中LoadLibrary 的Requirements
includelib kernel32.lib
.data?
;数据段略
.const
szDllName db 'user32.dll',0
.code
GetProcAddr proc uses ebx,ebp,edi,esi
local szProcName