| 发表于:2007-09-05 16:10:197楼 得分:0 |
在dll中加上这一句#pragma comment(linker, "/section:share,rws ") 还有你的这一句lresult callback myproc(int ncode, wparam wparam, lparam lparam) { messagebox(null, "fun ", "fun ",0); return (callnexthookex(hk, ncode, wparam, lparam)); } 改了吧,不然,嘿嘿。。。 改了的代码贴一下: dll代码 #include "stdafx.h " #include <windows.h> #pragma data_seg( "share ") handle hinst=null; hhook hk=null; #pragma data_seg() #pragma comment(linker, "/section:share,rws ") lresult callback myproc(int ncode, wparam wparam, lparam lparam); bool apientry dllmain( handle hmodule, dword ul_reason_for_call, lpvoid lpreserved ) { hinst = hmodule; return true; } _declspec (dllexport) bool sethook(dword threadid) { if(threadid) { hk=setwindowshookex(wh_getmessage,myproc,(hinstance)hinst,0); if(hk) { messagebox(null, "hook success ", "ok ",mb_ok); return 0; } else return 0; } else { messagebox(null, "dll即将从记事本进程空间中撤出! ", "dll ", mb_iconinformation + mb_ok); return unhookwindowshookex(hk); } } lresult callback myproc(int ncode, wparam wparam, lparam lparam) { messagebox(null, "fun ", "fun ",0); return (callnexthookex(hk, ncode, wparam, lparam)); } exe代码: typedef bool ( *myhook)(dword threadid) ; int main(int argc, char* argv[]) { startupinfo stat; process_information proce; memset(&stat,0,sizeof(stat)); stat.cb=sizeof(stat); myhook myhookh; hmodule h_mod= loadlibrary( "e:\\code\\injectdll\\debug\\injectdll.dll "); if(h_mod) { myhookh=(myhook)(getprocaddress(h_mod, "?sethook@@yahk@z ")); bool hret=createprocess(null, "c:\\windows\\system32\\notepad.exe ",null,null,false,0,null,null,&stat,&proce); if(hret) { char szmsg[max_path]; sprintf(szmsg, "%d ",proce.dwprocessid); myhookh(proce.dwthreadid); messagebox(null,szmsg, "ok ",mb_ok); } else messagebox(null, "wrong ", "err ",mb_ok); return 0; } return 0; } | | |
|