再问三级跳的问题(30分)

  • 主题发起人 主题发起人 sy0116
  • 开始时间 开始时间
S

sy0116

Unregistered / Unconfirmed
GUEST, unregistred user!
中间DLL的代码如下:<br>procedure Load;<br>var<br> &nbsp;LibHd:THandle;<br>begin<br> &nbsp;Jumped:=True;<br> &nbsp;LibHd:=LoadLibrary(PChar('D:/Program Files/Borland/Delphi7/Projects/hook/Jump/key.dll'));<br> &nbsp;RealDLL:=GetProcAddress(LibHd,'SetHook');<br> &nbsp;if @RealDLL&lt;&gt;nil then<br> &nbsp;RealDLL<br> &nbsp;else<br> &nbsp;begin<br> &nbsp; &nbsp;MessageBox(0,'f','dd',0);<br> &nbsp; &nbsp;FreeLibrary(LibHd);<br> &nbsp;end;<br>end;<br><br>function JumpProc(ncode:Integer;wparam:WPARAM;lparam:LPARAM):LRESULT;stdcall;<br>var<br> &nbsp;pid:Cardinal;<br>begin<br> &nbsp;if Jumped=False then<br> &nbsp;begin<br> &nbsp; &nbsp;ThreadHd:=CreateThread(nil,0,@Load,nil,0,pid);<br> &nbsp; &nbsp;Jumped:=True;<br> &nbsp;end;<br> &nbsp;Result:=CallNextHookEx(JumpHook,ncode,wparam,lparam);<br>end;<br><br>procedure SetHook(ExpID:DWORD);stdcall;export;<br>begin<br> &nbsp;JumpHook:=SetWindowsHookEx(WH_GETMESSAGE,@JumpProc,HInstance,ExpID);<br> &nbsp;Jumped:=False;<br>end;<br><br>需要真正注入的key.dll的代码如下:<br>function HookProc(ncode,wparam,lparam:Integer):Integer;stdcall;<br>begin<br> &nbsp;MessageBox(0,'sfsfasfsafsaf','fsf',0);<br> &nbsp;Result:=CallNextHookEx(oldhook,ncode,wparam,lparam);<br>end;<br>procedure SetHook;export;<br>begin<br> &nbsp;oldhook:=SetWindowsHookEx(WH_KEYBOARD,@HookProc,HInstance,0);<br> &nbsp;MessageBox(0,PChar(inttostr(oldhook)),'sd',0);<br>end;<br>exports<br> &nbsp;SetHook;<br>===========================================================================<br>运行后发现,key.dll确认已被注入到指定进程,key.dll的SetHook过程确实执行了,因为有一个对话框跳出并显示了一串数字,但是按键后却没有任何对话框跳出来,也就是说key.dll的HookProc函数并没有被调用,请问这是为什么?
 
真是功夫不负有心人啊,乱搞了一天竟然找到了解决办法,只是不知道为什么,请各位高手指点:<br>把key.dll中SetHook的代码稍加修改,竟然加入一个死循环就可以了,实在不解:<br>procedure SetHook;stdcall;<br>var<br> &nbsp;i:Integer;<br>begin<br> &nbsp;oldhook:=SetWindowsHookEx(WH_KEYBOARD, HookProc, HInstance, 0);<br> &nbsp;while True do<br> &nbsp;begin<br> &nbsp; &nbsp;Sleep(100);<br> &nbsp; &nbsp;i:=i+0;<br> &nbsp;end;<br>end;
 
因为这是一个新建的线程,如果没有一个死循环或者一个获取消息的循环,这个线程在所有代码执行完成后,线程就会结束.
 
接受答案了.
 
后退
顶部