我现在开个游戏game.exe然后GetModuleHandle("game.exe")但是返回值总是为NULL,为什么呢?
还请高手指教
还请高手指教
解决方案 »
- 急 command line error d2016 ,解决方法!!!
- VC中遍历程序中ToolBar工具栏图标
- 使用SkinMagic出现的问题
- 怎么能通过UDP把结构体发送过去,接受后并转换成结构体!!!急
- 请问,如何在树形控件的每个节点前加上“不同”图标(假设就两种图标)?
- 莫明其秒就成星星了,散分请客。
- error C2065: 'WSACreateEvent' : undeclared identifier,前段时间还是好的,今天却编不过啦,帮我啊
- 求教串口发送结构数据的问题
- Debug通过,而Release出错的问题
- 求高手,用MFC实现,具体操作一头雾水!具体要求...
- 怪问题求救: VB做的COM VC调用,解释模式正常, 编译成dll就出问题
- 读卡器读卡在什么情况下会损害卡,不停的读取会吗?
LPCTSTR lpModuleName
);
If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process.
我的想法是把GetModuleHandle("game.exe")写到dll中,然后写个程序把dll映射到游戏进程的地址空间内,然后用GetModuleHandle("game.exe")可以返回游戏进程的加载到地址空间的基地址吗?
#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不成功希望大家帮帮我,修改下这个程序
jony呢?把他揪出来问问。