需要注入的key.dll的代码如下:
function HookProc(ncode,wparam,lparam:Integer):Integer;stdcall;
begin
  MessageBox(0,'sfsfasfsafsaf','fsf',0);
  Result:=CallNextHookEx(oldhook,ncode,wparam,lparam);
end;
procedure SetHook;export;
begin
  oldhook:=SetWindowsHookEx(WH_KEYBOARD,@HookProc,HInstance,0);
  MessageBox(0,PChar(inttostr(oldhook)),'sd',0);
end;
exports
  SetHook;
===========================================================================
运行后发现,key.dll确认已被注入到指定进程,key.dll的SetHook过程确实执行了,因为有一个对话框跳出并显示了一串数字,但是按键后却没有任何对话框跳出来,也就是说key.dll的HookProc函数并没有被调用,请问这是为什么?

解决方案 »

  1.   

    中间DLL的代码如下:
    procedure Load;
    var
      LibHd:THandle;
    begin
      Jumped:=True;
      LibHd:=LoadLibrary(PChar('D:\Program Files\Borland\Delphi7\Projects\hook\Jump\key.dll'));
      RealDLL:=GetProcAddress(LibHd,'SetHook');
      if @RealDLL<>nil then
      RealDLL
      else
      begin
        MessageBox(0,'f','dd',0);
        FreeLibrary(LibHd);
      end;
    end;function JumpProc(ncode:Integer;wparam:WPARAM;lparam:LPARAM):LRESULT;stdcall;
    var
      pid:Cardinal;
    begin
      if Jumped=False then
      begin
        ThreadHd:=CreateThread(nil,0,@Load,nil,0,pid);
        Jumped:=True;
      end;
      Result:=CallNextHookEx(JumpHook,ncode,wparam,lparam);
    end;procedure SetHook(ExpID:DWORD);stdcall;export;
    begin
      JumpHook:=SetWindowsHookEx(WH_GETMESSAGE,@JumpProc,HInstance,ExpID);
      Jumped:=False;
    end;