WINDOWS的程序都是基于消息的,有这样的程序吗?还是游戏做了手脚?

解决方案 »

  1.   

    我写的 DLL 代码如下,请大家看看,那里有问题呀:
    Library KEYHOOK ;uses
      Windows,
      UnitHOOK in 'UnitHOOK.pas';exports // 定义输出函数
      InstallKeyBoardHook ,
      UnInstallKeyBoardHook ;begin // DLL 初始化部分end.另一个单元文件:
    unit UnitHOOK ;interfaceuses
      Windows , Messages;const
      HOOK_MEM_FILENAME='SAMPLE KEY_HOOK_MEM_FILE' ;
      My_user32 = 'USER32.DLL'  ;type
      TShared=record
        ThreadID : Cardinal ;
      end ;
      PShared=^TShared ;  //模拟键盘--只能模拟键盘
      TMy_keybd_event=procedure(bVk: Byte; bScan: Byte; dwFlags, dwExtraInfo: DWORD); stdcall;//external My_user32 name 'keybd_event' ;
      //模拟鼠标--只能模拟鼠标
      TMy_mouse_event=procedure(dwFlags, dx, dy, dwData, dwExtraInfo: DWORD); stdcall;// external; user32 name 'mouse_event';
      //模拟键盘与鼠标--键盘鼠标都能模拟
      TMy_SendInput=function(cInputs: UINT; var pInputs: TInput; cbSize: Integer): UINT; stdcall;// external My_user32 name 'SendInput';var
      MemFile : THandle ;
      HHook : Thandle ;
      Shared : PShared ;  function HookProcKeyBoard(Code: Integer; wParam: WPARAM ; lParam: LPARAM):LRESULT;stdcall;
      Procedure InstallKeyBoardHook ; Stdcall ; export ;
      Procedure UnInstallKeyBoardHook ; Stdcall ; export ;implementationtype
      TCustom_Input = Array[0..2] of TInput ;
    var
      H_Module : THandle ;
      My_keybd_event : TMy_keybd_event ;
      My_mouse_event : TMy_mouse_event ;
      My_SendInput : TMy_SendInput ;Procedure Custom_SendInput(VK : Cardinal) ; //模拟按键
    var
      Input : TCustom_Input ;
    begin
      Input[0].Itype := INPUT_KEYBOARD ;
      Input[0].ki.wVk := VK ;
      Input[0].ki.wScan := MapVirtualKey(VK,0) ;
      Input[0].ki.dwFlags := 0 ;
      Input[0].ki.time := GetTickCount ;
      Input[0].ki.dwExtraInfo := 0 ;  Input[1].Itype := INPUT_KEYBOARD ;
      Input[1].ki.wVk := VK ;
      Input[1].ki.wScan := MapVirtualKey(VK,0) ;
      Input[1].ki.dwFlags := KEYEVENTF_KEYUP ;
      Input[1].ki.time := GetTickCount ;
      Input[1].ki.dwExtraInfo := 0 ;  My_SendInput(1,Input[0],Sizeof(TInput)) ;
      My_SendInput(1,Input[1],Sizeof(TInput))
    end ;Procedure Custom_keybd_event(VK : Cardinal) ; //模拟按键
    begin
      My_keybd_event(VK,MapVirtualKey(VK,0),0,0) ;                 //模拟按键
      My_keybd_event(VK,MapVirtualKey(VK,0),KEYEVENTF_KEYUP,0) ;   //模拟放键
      KEYEVENTF_EXTENDEDKEY
    end ;Procedure Custom_SendMessage(VK : Cardinal) ; //模拟按键
    var
      HForegroundWindow : Thandle ;
      HSub_ForegroundWindow : Thandle ;
    begin
      HForegroundWindow := Windows.GetForegroundWindow ;
      HSub_ForegroundWindow := Windows.FindWindowEx(HForegroundWindow,0,'Afx:400000:b:10011:6:0',nil) ;
      Windows.SendMessage(HSub_ForegroundWindow,Messages.WM_KEYDOWN,VK,$00000001) ;
      Windows.SendMessage(HSub_ForegroundWindow,Messages.WM_KEYUP,VK,$00000001) ;
    end ;// 键盘回调函数处理...
    function HookProcKeyBoard(Code: Integer; wParam: WPARAM ; lParam: LPARAM):LRESULT;
    const
      KeyPressMask = $80000000 ;
    var
      VK : Cardinal ;
    begin
      Result := 0 ;
      if Code < 0 then
        Result := CallNextHookEx(HHook,Code,wParam,lParam)
      else if Code = HC_ACTION then
      begin
        if (lParam and KeyPressMask) = 0 then
        begin
          if wParam = VK_F12 then  //启动键
          begin
            VK := Ord('A') ;
            Custom_keybd_event(VK) ;
          end ;
        end ;
        Result := CallNextHookEx(HHook,Code,wParam,lParam) ;
      end
      else if Code = HC_NOREMOVE then
      begin
        Result := CallNextHookEx(HHook,Code,wParam,lParam) ;
      end ;
    end;// 设置键盘钩子过滤函数
    Procedure InstallKeyBoardHook ;
    begin
      HHook:=SetWindowsHookEx(WH_KEYBOARD,@HookProcKeyBoard,HInstance,0) ;
      if hHook = 0 then
        Exit ;
    end ;//撤消键盘钩子过滤函数
    Procedure UnInstallKeyBoardHook ;  
    begin
      UnHookWindowsHookEx(HHook) ;
      hHook:=0;
    end ;Initialization
    begin
      MemFile:=OpenFileMapping(FILE_MAP_WRITE,False,HOOK_MEM_FILENAME);  // 通过建立内存映象文件以共享内存
      if MemFile=0 then
        MemFile:=CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,SizeOf(TShared),HOOK_MEM_FILENAME) ;
      Shared := MapViewOfFile(MemFile,File_MAP_WRITE,0,0,SizeOf(TShared)) ;  H_Module := Windows.LoadLibrary(My_user32) ;
      @My_keybd_event := Windows.GetProcAddress(H_Module,'keybd_event') ;
      @My_mouse_event := Windows.GetProcAddress(H_Module,'mouse_event') ;
      @My_SendInput := Windows.GetProcAddress(H_Module,'SendInput') ;
    end ;Finalization
    begin
      if hHook <> 0 then
        UnInstallKeyBoardHook ;
      UnMapViewOfFile(Shared) ;  // 释放内存映象文件
      CloseHandle(MemFile) ;     // 关闭映象文件
      Windows.FreeLibrary(H_Module) ;
    end ;end.
    我的代码如上,请大家帮我看看那里有问题?是什么原因?模拟键盘不成功?
      

  2.   

    我也是新手
    我自己做了个千年外挂,因为菜目前没能分析出千年的封包,所以只是简单的挂钩
    send API并替换成攻击封包,在替换前必须产生一个被替换封包,我是把按F12换
    武功所产生的封包替换成攻击怪物封包的,按键部分原理如下:
    var
    clienthwd:HWND;
    begin
    clienthwd:=getforegroundwindow();//得到当前窗口句柄(也就是是千年)
    postmessage(edithwd,wm_keydown,VK_F12,0); //模拟向千年窗口发送按下F12键消息 
    postmessage(edithwd,wm_keyup,VK_F12,0);  //模拟向千年窗口发送弹起F12键消息 
    sleep(500);
    end;