我现在开个游戏game.exe然后GetModuleHandle("game.exe")但是返回值总是为NULL,为什么呢?
还请高手指教
 
  

解决方案 »

  1.   

    game.exe是你另外创建的进程吧?如果是这样的话,当然会失败,GetModuleHandle只能获取调用GetModuleHandle的进程的进程空间中的模块的句柄……你可以用GetLastError来看看到底是什么错误
      

  2.   

    HMODULE GetModuleHandle(
      LPCTSTR lpModuleName
    );
    If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process.
      

  3.   

    用CreateProcess创建进程,可以在最后一个参数中获得该进程的句柄,然后可以操作该进程了
      

  4.   

    是啊!
    我的想法是把GetModuleHandle("game.exe")写到dll中,然后写个程序把dll映射到游戏进程的地址空间内,然后用GetModuleHandle("game.exe")可以返回游戏进程的加载到地址空间的基地址吗?
      

  5.   

    #include <windows.h>
    #include <imagehlp.h>
    #include <iostream.h>
    #include "api.h"
    HHOOK old;int WINAPI MessageMy(
      HWND hWnd,          // handle of owner window
      LPCTSTR lpText,     // address of text in message box
      LPCTSTR lpCaption,  // address of title of message box
      UINT uType          // style of message box
    );
    void FindApi(HMODULE h);
    void SetHook();
    typedef int (WINAPI *fnnew)(HWND hWnd, LPCTSTR lpText,LPCTSTR lpCaption, UINT uType);
    int WINAPI MessageMy(
      HWND hWnd,          // handle of owner window
      LPCTSTR lpText,     // address of text in message box
      LPCTSTR lpCaption,  // address of title of message box
      UINT uType          // style of message box
    )
    {
    cout<<"123\n";
    return 0;
    }
    fnnew fn=(fnnew)MessageMy;//指向自定义的函数
    void FindApi(HMODULE h) //hook msg.exe进程的api
    {
      HMODULE h=GetModuleHandle("msg.exe");//获取要修改进程的模块
      if(h==NULL)
       MessageBox(NULL,"//","//",0);  
      PROC p=GetProcAddress(GetModuleHandle("user32.dll"),"MessageBoxA"); //获取调用系统的MessageBoxA的地址
      ULONG size;
      PCSTR name="USER32.dll";
      PIMAGE_IMPORT_DESCRIPTOR import=(PIMAGE_IMPORT_DESCRIPTOR)ImageDirectoryEntryToData(h,TRUE,IMAGE_DIRECTORY_ENTRY_IMPORT,&size);//查找msg.exe进程的输入节并hook这个进程中的MessageBoxA函数
      
      for(;import->Name;import++)
      {
        PSTR name1=(PSTR)((PBYTE)h+import->Name);
    if(lstrcmpiA(name,name1)==0)
      break;
      }
      if(import->Name==0)
       return;
      PIMAGE_THUNK_DATA pThunk=(PIMAGE_THUNK_DATA) ((PBYTE)h+import->FirstThunk);
      
      for(;pThunk->u1.Function;pThunk++)
      {
       PROC *p1=(PROC*) &pThunk->u1.Function;
       BOOL found=(*p1==p);
       if(found)
            pThunk->u1.Function=(PDWORD)fn;  }}
    HMODULE x;
    LRESULT CALLBACK GetMsgProc(
      int code,       // hook code
      WPARAM wParam,  // removal flag
      LPARAM lParam   // address of structure with message
    )
    {
        x=GetModuleHandle("msg.exe");
       if(x!=NULL)
       FindApi(x);  return CallNextHookEx(old,code,wParam,lParam);
    }
    void SetHook()
    {
        
    old=SetWindowsHookEx(WH_GETMESSAGE,GetMsgProc,GetModuleHandle("api.dll"),0);//对所有进程安装钩子!
    }msg文件代码是#include <windows.h>
    int WINAPI WinMain(
      HINSTANCE hInstance,  // handle to current instance
      HINSTANCE hPrevInstance,  // handle to previous instance
      LPSTR lpCmdLine,      // pointer to command line
      int nCmdShow          // show state of window
    )
    {
       MessageBox(NULL,"外挂","努力学习",0);
    }
    这个是我写的程序准备hook,msg的MessageBox,但是hook不成功希望大家帮帮我,修改下这个程序
      

  6.   

    这个我不懂……jony饼子呢?这个问他好了……
      

  7.   

    在外部可以用OpenProcess,如果dll已经挂到game.exe中了,用GetModuleHandle(NULL)就行了
      

  8.   

    同意楼上的问题。看dll中有没有挂game.exe
    jony呢?把他揪出来问问。