-
关注Ta
-
- 注册时间 2012-04-06
- 最后登录 2020-12-30
-
- 发帖288
- 在线146小时
- 精华1
- DB917
- 威望-3
- 保证金0
- 桃子0
- 鲜花0
- 鸡蛋0
-
访问TA的空间加好友用道具
|
—
本帖被 清风沐竹 执行压帖操作(2013-10-21)
—
这个没有窗口化,这个仅仅是解除鼠标限制的代码,要窗口化的朋友不用看了,以下是头文件: - #ifndef __APIHOOK
- #define __APIHOOK
- #include <windows.h>
- // APIHook类
- class APIHook
- {
- private:
- TCHAR m_szModName[256];
- char m_szProcName[256];
- PROC m_dwProcAddress;
- PROC m_dwNewProcAddress;
- byte *m_pBytesGoBack;
- byte m_bytesGoHookProc[5];
- bool m_bInitialed;
- bool m_bHooked;
- public:
- APIHook()
- {
- m_bInitialed = false;
- m_bHooked = false;
- }
- ~APIHook()
- {
-
- if ( m_bHooked )
- UnHook();
- }
-
- bool InitHook(TCHAR *szModName, const char *szProcName, PROC dwNewProcAddress)
- {
-
- if ( m_bHooked )
- UnHook();
- if ( szModName == NULL || szProcName == NULL )
- return false;
-
- HMODULE hMod = GetModuleHandle( szModName );
- if ( !hMod )
- {
- hMod = LoadLibrary( szModName );
- if ( !hMod )
- return false;
- }
-
- m_dwProcAddress = (PROC)GetProcAddress( hMod, szProcName );
- if ( m_dwProcAddress == 0 )
- {
- CloseHandle( hMod );
- return false;
- }
-
- strcpy( m_szModName, szModName );
- strcpy( m_szProcName, szProcName );
- m_dwNewProcAddress = dwNewProcAddress;
- m_bInitialed = true;
- return true;
- }
- bool Hook()
- {
-
- if ( !m_bInitialed )
- return false;
-
- if ( m_bHooked )
- UnHook();
-
- m_pBytesGoBack = (byte *)VirtualAlloc( NULL, 10, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE );
- if ( NULL == m_pBytesGoBack )
- return false;
- HANDLE hProcess = GetCurrentProcess();
-
- if ( !ReadProcessMemory(hProcess, (LPCVOID)m_dwProcAddress, m_pBytesGoBack, 5, NULL) )
- return false;
-
- m_pBytesGoBack[5] = 0xe9;
- int nDistance = (int)m_dwProcAddress - (int)m_pBytesGoBack - 5;
- memcpy( m_pBytesGoBack + 6, &nDistance, 4 );
-
- m_bytesGoHookProc[0] = 0xe9;
- nDistance = (int)m_dwNewProcAddress - (int)m_dwProcAddress - 5;
- memcpy( m_bytesGoHookProc + 1, &nDistance, 4 );
-
- if ( !WriteProcessMemory(hProcess, (LPVOID)m_dwProcAddress, m_bytesGoHookProc, 5, NULL) )
- return false;
- m_bHooked = true;
- return true;
- }
- void UnHook()
- {
- if ( m_bHooked )
- {
- HANDLE hProcess = GetCurrentProcess();
-
- if ( m_pBytesGoBack != NULL )
- {
-
- WriteProcessMemory(hProcess, (LPVOID)m_dwProcAddress, m_pBytesGoBack, 5, NULL);
- VirtualFree( m_pBytesGoBack, 0, MEM_RELEASE );
- m_pBytesGoBack = NULL;
- }
- m_bHooked = false;
- }
- }
-
-
- inline void CallOriginFunction(int &nRetValue, unsigned int nParamCount, ...)
- {
- if ( nParamCount > 0 )
- {
- LPVOID *pParamArray = new LPVOID[nParamCount];
-
- va_list params;
- va_start( params, nParamCount );
- for ( unsigned int i = 0; i < nParamCount; ++i )
- {
- pParamArray[nParamCount - i - 1] = (LPVOID)va_arg( params, LPVOID );
- }
- va_end( params );
-
- for ( unsigned int u = 0; u < nParamCount; ++u )
- {
- LPVOID param = pParamArray[u];
- __asm
- {
- push param
- }
- }
- delete[] pParamArray;
- }
- DWORD dwAddr = (DWORD)m_pBytesGoBack;
- int nRet = -1;
-
- __asm
- {
- call dwAddr
- mov nRet, eax
- }
- nRetValue = nRet;
- }
- PROC GetOriginFunction()
- {
- return m_dwProcAddress;
- }
- };
- #endif
以下是msimg32源文件:- // 头文件
- #include <Windows.h>
- #include "APIHOOKCLASS.H"
- #pragma comment(linker, "/EXPORT:vSetDdrawflag=_MsimgLib_vSetDdrawflag,@1")
- #pragma comment(linker, "/EXPORT:AlphaBlend=_MsimgLib_AlphaBlend,@2")
- #pragma comment(linker, "/EXPORT:DllInitialize=_MsimgLib_DllInitialize,@3")
- #pragma comment(linker, "/EXPORT:GradientFill=_MsimgLib_GradientFill,@4")
- #pragma comment(linker, "/EXPORT:TransparentBlt=_MsimgLib_TransparentBlt,@5")
- // 宏定义
- #define EXTERNC extern "C"
- #define NAKED __declspec(naked)
- #define EXPORT __declspec(dllexport)
- #define ALCPP EXPORT NAKED
- #define ALSTD EXTERNC EXPORT NAKED void __stdcall
- #define ALCFAST EXTERNC EXPORT NAKED void __fastcall
- #define ALCDECL EXTERNC NAKED void __cdecl
- APIHook hook;
- // MsimgLib 命名空间
- namespace MsimgLib
- {
- HMODULE m_hModule = NULL;
- DWORD m_dwReturn[5] = {0};
- inline BOOL WINAPI Load()
- {
- TCHAR tzPath[MAX_PATH];
- TCHAR tzTemp[MAX_PATH * 2];
- GetSystemDirectory(tzPath, MAX_PATH);
- lstrcat(tzPath, TEXT("\\msimg32"));
- m_hModule = LoadLibrary(tzPath);
- if (m_hModule == NULL)
- {
- wsprintf(tzTemp, TEXT("无法加载 %s,程序无法正常运行。"), tzPath);
- MessageBox(NULL, tzTemp, TEXT("MsimgLib"), MB_ICONSTOP);
- }
- return (m_hModule != NULL);
- }
-
- inline VOID WINAPI Free()
- {
- if (m_hModule)
- {
- FreeLibrary(m_hModule);
- }
- }
- FARPROC WINAPI GetAddress(PCSTR pszProcName)
- {
- FARPROC fpAddress;
- CHAR szProcName[16];
- TCHAR tzTemp[MAX_PATH];
- fpAddress = GetProcAddress(m_hModule, pszProcName);
- if (fpAddress == NULL)
- {
- if (HIWORD(pszProcName) == 0)
- {
- wsprintf(szProcName, "%d", pszProcName);
- pszProcName = szProcName;
- }
- wsprintf(tzTemp, TEXT("无法找到函数 %hs,程序无法正常运行。"), pszProcName);
- //MessageBox(NULL, tzTemp, TEXT("MsimgLib"), MB_ICONSTOP);
- ExitProcess(-2);
- }
- return fpAddress;
- }
- }
- using namespace MsimgLib;
- BOOL MyClipCursor(CONST RECT * lpRect)
- {
- int ret = FALSE;
- hook.CallOriginFunction(ret,1,NULL);
- return ret;
- }
- // 入口函数
- BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, PVOID pvReserved)
- {
- char szFileName[MAX_PATH] = { 0 };
- char szProcessName[MAX_COMPUTERNAME_LENGTH] = { 0 };
- if (dwReason == DLL_PROCESS_ATTACH)
- {
- GetModuleFileName(NULL,szFileName,MAX_PATH);
- int nStrLen = strlen(szFileName);
- for(int i = nStrLen; i > 0; i--)
- {
- if (szFileName[i] == '\\')
- {
- strcpy(szProcessName,&szFileName[i+1]);
- break;
- }
- }
- if (strcmp(szProcessName,"crossfire.exe") == 0)
- {
- if (hook.InitHook( TEXT("User32"), "ClipCursor", (PROC)MyClipCursor ) == false)
- {
- MessageBox(NULL, TEXT("msimg32 Init Faild!"), TEXT("MsimgLib"), MB_ICONSTOP);
- }
- ;
- ClipCursor(NULL);
- if (hook.Hook() == false)
- {
- MessageBox(NULL, TEXT("msimg32 Run Faild!"), TEXT("MsimgLib"), MB_ICONSTOP);
- }
- ClipCursor(NULL);
- };
- DisableThreadLibraryCalls(hModule);
- return Load();
- }
- else if (dwReason == DLL_PROCESS_DETACH)
- {
- Free();
- hook.UnHook();
- hook.~APIHook();
- }
- return TRUE;
- }
- ALCDECL MsimgLib_vSetDdrawflag(void)
- {
-
- __asm POP m_dwReturn[0 * TYPE long];
-
- GetAddress("vSetDdrawflag")();
-
- __asm JMP m_dwReturn[0 * TYPE long];
- }
- ALCDECL MsimgLib_AlphaBlend(void)
- {
-
- __asm POP m_dwReturn[1 * TYPE long];
-
- GetAddress("AlphaBlend")();
-
- __asm JMP m_dwReturn[1 * TYPE long];
- }
- ALCDECL MsimgLib_DllInitialize(void)
- {
-
- __asm POP m_dwReturn[2 * TYPE long];
-
- GetAddress("DllInitialize")();
-
- __asm JMP m_dwReturn[2 * TYPE long];
- }
- ALCDECL MsimgLib_GradientFill(void)
- {
-
- __asm POP m_dwReturn[3 * TYPE long];
-
- GetAddress("GradientFill")();
-
- __asm JMP m_dwReturn[3 * TYPE long];
- }
- ALCDECL MsimgLib_TransparentBlt(void)
- {
-
- __asm POP m_dwReturn[4 * TYPE long];
-
- GetAddress("TransparentBlt")();
-
- __asm JMP m_dwReturn[4 * TYPE long];
- }
附上完整源代码,vc6工程可直接编译。~ msimg32.rar[点击下载](9 K) 下载次数:31 累计下载获得 DB 58 刀附上已经编译好的dll,放入CF目录可直接解除窗口化鼠标限制,要写窗口化的朋友可以考虑把这个dll注入到crossfire.exe。 msimg32.rar[点击下载](16 K) 下载次数:37 累计下载获得 DB 68 刀结贴,收功。 元芳,你怎么看?
|