A
axfv
Unregistered / Unconfirmed
GUEST, unregistred user!
以下代码转自:ALGO RESEARCH CENTRE<br>感觉有点不劳而获,先SORRY了,我的C++停留在概念水平。。有几处实在看不明白。<br>//--------------------------------------------------------------------------- <br><br>#ifndef ApiHelperH <br>#define ApiHelperH <br><br>#include <windows.h> <br><br>//--------------------------------------------------------------------------- <br>#define OS2000_F1 0x55 <br>#define OS2000_F2 0x8b <br>#define OS2000_F3 0xec <br>#define OS2000_F4 0x56 <br>#define OS2000_F5 0x8b <br><br>#define OS2000_2_F1 0x8b <br>#define OS2000_2_F2 0xc0 <br>#define OS2000_2_F3 0x55 <br>#define OS2000_2_F4 0x8b <br>#define OS2000_2_F5 0xec <br><br>#define OS98_F1 0xe8 <br>#define OS98_F2 0x15 <br>#define OS98_F3 0xf6 <br>#define OS98_F4 0xff <br>#define OS98_F5 0xff <br><br>#define OSME_F1 <br>#define OSME_F2 <br>#define OSME_F3 <br>#define OSME_F4 <br>#define OSME_F5 <br><br>#define OSXP_F1 0x8b <br>#define OSXP_F2 0xff <br>#define OSXP_F3 0x55 <br>#define OSXP_F4 0x8b <br>#define OSXP_F5 0xec <br><br>typedef BOOL (WINAPI * SendMessageProc  ( HWND hWnd, UINT value, WPARAM wp, LPARAM lp <br><br>extern SendMessageProc _MySendMessage; <br>bool ProtectFunction(); <br><br>//--------------------------------------------------------------------------- <br>#endif <br> <br>代码: <br><br>//--------------------------------------------------------------------------- <br><br>#pragma hdrstop <br><br>#include "ApiHelper.h" <br>#include "Common.h" <br>#include "Log.h" <br><br>extern cLog * g_pLog; <br><br>SendMessageProc _MySendMessage; <br>SendMessageProc OldSendMessageFunc; <br>BYTE fnFuncEntry[255]; // 旧函数入口 <br><br>//--------------------------------------------------------------------------- <br>bool Func_2k() <br>{ <br> DWORD pp = (DWORD) OldSendMessageFunc; <br> DWORD pp1 = (DWORD) _MySendMessage; <br><br> fnFuncEntry[7] = 0xe9; // jump 指令 <br> int * p = (int*)(fnFuncEntry+8); <br> *p = pp - pp1 - 5; <br><br>#ifdef LOG <br> g_pLog->AddText( "// Protect function success....(Window2000)!" <br>#endif <br><br> return true; <br>} <br><br>//--------------------------------------------------------------------------- <br>bool Func_2k_2() <br>{ <br> DWORD pp = (DWORD) OldSendMessageFunc; <br> DWORD pp1 = (DWORD) _MySendMessage; <br><br> fnFuncEntry[9] = 0xe9; // jump 指令 <br> int * p = (int*)(fnFuncEntry+10); <br> *p = pp - pp1 - 5; <br><br>#ifdef LOG <br> g_pLog->AddText( "// Protect function success....(Window2000 V20050603)!" <br>#endif <br><br> return true; <br>} <br><br>//--------------------------------------------------------------------------- <br>bool Func_xp() <br>{ <br> DWORD pp = (DWORD) OldSendMessageFunc; <br> DWORD pp1 = (DWORD) _MySendMessage; <br><br> fnFuncEntry[6] = 0xe9; // jump 指令 <br> int * p = (int*)(fnFuncEntry+7); <br> *p = pp - pp1 - 5; <br><br>#ifdef LOG <br> g_pLog->AddText( "// Protect function success....(WindowsXP)!" <br>#endif <br><br> return true; <br>} <br><br>//--------------------------------------------------------------------------- <br>bool Func_98() <br>{ <br> DWORD pp = (DWORD) OldSendMessageFunc; <br> DWORD pp1 = (DWORD) _MySendMessage; <br><br> int * p = (int*)(fnFuncEntry + 1 // 重新计算出call的位置 <br> int offset = (DWORD)pp + *p + 5; <br><br> int jj = offset - pp1 - 5; <br><br> *p = jj; <br> offset = (DWORD)pp1 + *p + 5; <br><br> fnFuncEntry[5] = 0xe9; // 将后的面的指令改为一个jump <br> p = (int*) (fnFuncEntry + 6); <br> *p = pp - pp1 - 5; <br><br>#ifdef LOG <br> g_pLog->AddText( "// Protect function success....(Windows98)!" <br>#endif <br><br> return true; <br>} <br><br>//--------------------------------------------------------------------------- <br>bool ProtectFunction(  <br>{ <br><br> HMODULE hInst = LoadLibrary( "User32.dll" <br> OldSendMessageFunc = ( SendMessageProc  GetProcAddress( hInst, "SendMessageA" <br><br> if ( OldSendMessageFunc == NULL  <br> { <br> MessageBox( NULL, "Protect Win32 function failed.", "Warning", MB_OK <br> return false; <br> } <br><br> memcpy( fnFuncEntry, (BYTE*)OldSendMessageFunc, 50 <br><br> if ( fnFuncEntry[0] == 0xE9  // 发现已经修改过的指令 <br> { <br> MessageBox( NULL, "Protect Win32 function failed.(pls reset lineage client)", "Warning", MB_OK <br> return false; <br> } <br><br><br> DWORD dwAddress = reinterpret_cast<DWORD>(fnFuncEntry); <br> _MySendMessage = (SendMessageProc)dwAddress; <br><br> // ----------------- 2000 判断 <br> if ( (fnFuncEntry[0] == OS2000_F1) && <br> (fnFuncEntry[1] == OS2000_F2) && <br> (fnFuncEntry[2] == OS2000_F3) && <br> (fnFuncEntry[3] == OS2000_F4) && <br> (fnFuncEntry[4] == OS2000_F5)  <br> { <br> return Func_2k(); <br> } <br><br> // ----------------- 2000 判断 v2 <br> if ( (fnFuncEntry[0] == OS2000_2_F1) && <br> (fnFuncEntry[1] == OS2000_2_F2) && <br> (fnFuncEntry[2] == OS2000_2_F3) && <br> (fnFuncEntry[3] == OS2000_2_F4) && <br> (fnFuncEntry[4] == OS2000_2_F5)  <br> { <br> return Func_2k_2(); <br> } <br><br> // ----------------- 98 判断 <br> if ( (fnFuncEntry[0] == OS98_F1) && <br> (fnFuncEntry[1] == OS98_F2) && <br> (fnFuncEntry[2] == OS98_F3) && <br> (fnFuncEntry[3] == OS98_F4) && <br> (fnFuncEntry[4] == OS98_F5)  <br> { <br> return Func_98(); <br> } <br><br> // ----------------- xp 判断 <br> if ( (fnFuncEntry[0] == OSXP_F1) && <br> (fnFuncEntry[1] == OSXP_F2) && <br> (fnFuncEntry[2] == OSXP_F3) && <br> (fnFuncEntry[3] == OSXP_F4) && <br> (fnFuncEntry[4] == OSXP_F5)  <br> { <br> return Func_xp(); <br> } <br><br> MessageBox( NULL, "Your's os unprotected win32 api function.", "Warning", MB_OK <br><br> return true; <br>} <br><br>//--------------------------------------------------------------------------- <br><br>#pragma package(smart_init)