VC++6.0远程调用Call

VC++6.0远程调用Call

转载:http://wodeball.blog.163.com/blog/static/69365999201242293613680/

好久没来了,心情不好,又来到这熟悉又怀念的地方,伴我快一年多的地方,真的很感谢伴我渡过孤独的大半年。 
又看到喜欢的VC++,VC++这块一直很少有人发表,可能高手都忙吧。今天没事就发下我以前的远程调用Call。 
有不好的地方希望大家可以指正交流。 

typedef struct ParamData    //参数结构 
{ 
    long Param1; 
    long Param2; 
    DWORD Param3; 
    DWORD Param4; 
}ParamData,*Paramp; 
 
//************************************************************************************** 
//函数名:InfusionFunc 
//功能  :封装远程注入的函数 
//参数 1:进程ID  
//参数 2:被注入函数指针<函数名>  
//参数 3:参数  
//参数 4:参数长度  
//************************************************************************************** 
void InfusionFunc(DWORD dwProcId,LPVOID mFunc, LPVOID Param, DWORD ParamSize)  
{  
    HANDLE hProcess;//远程句柄 
    LPVOID mFuncAddr;//申请函数内存地址         
    LPVOID ParamAddr;//申请参数内存地址 
    HANDLE hThread;    //线程句柄 
    DWORD NumberOfByte; //辅助返回值 
    CString str;     
    //打开被注入的进程句柄     
    hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcId); 
    //申请内存 
    mFuncAddr = VirtualAllocEx(hProcess,NULL,128,MEM_COMMIT,PAGE_EXECUTE_READWRITE); 
    ParamAddr = VirtualAllocEx(hProcess,NULL,ParamSize,MEM_COMMIT,PAGE_EXECUTE_READWRITE); 
    //写内存  
    WriteProcessMemory(hProcess,mFuncAddr,mFunc,128, &NumberOfByte);     
    WriteProcessMemory(hProcess,ParamAddr,Param,ParamSize, &NumberOfByte); 
    //创建远程线程 
    hThread = CreateRemoteThread(hProcess,NULL,0,(LPTHREAD_START_ROUTINE)mFuncAddr, 
        ParamAddr,0,&NumberOfByte); 
    WaitForSingleObject(hThread, INFINITE); //等待线程结束 
    //释放申请有内存 
    VirtualFreeEx(hProcess,mFuncAddr,128,MEM_RELEASE); 
    VirtualFreeEx(hProcess,ParamAddr,ParamSize,MEM_RELEASE);     
    //释放远程句柄 
    CloseHandle(hThread);  
    CloseHandle(hProcess);  
}  
 
//************************************************************************************** 
//函数名:CallAddhp 
//功能  :调用加血Call 
//************************************************************************************** 
void  CallAddhp ()  
{  
    DWORD dwAddr = 0x00452E98;  
    _asm 
    {         
        pushad  
        mov eax,dword ptr DS:[0x456D68]  
        mov edx,0x00453028 
        call dwAddr  
        popad  
    } 
}   
 
//************************************************************************************** 
//函数名:CallAddhp 
//功能  :调用加法计算Call 
//************************************************************************************** 
void CallAdd(LPVOID lParam) 
{ 
    ParamData * lp; 
    lp=(ParamData *)lParam; 
    long lp1=(long)lp->Param1; 
    long lp2=(long)lp->Param2; 
    DWORD dwAddr = 0x45992C;  
    _asm 
    { 
        pushad 
        pushad  
        push lp2 
        push lp1 
        mov eax,dword ptr DS:[0x461CF8] 
        push eax 
        call dwAddr  
        popad  
    } 
} 

下面是调用实例 

//一例:调用无参Call 
void CInfusionFunDlg::OnButton4()  
{ 
    // TODO: Add your control notification handler code here     
    DWORD ProcessId=NULL; 
    HWND hWnd = ::FindWindow(NULL,"游戏找CALL练习实例one"); //窗口标题取句柄 
    GetWindowThreadProcessId(hWnd,&ProcessId); 
    if(ProcessId==NULL) 
   { ::AfxMessageBox(
"未找到进程");
   }
else {     InfusionFunc(ProcessId,CallAddhp,NULL,NULL); } } //二例:调用有参Call void CInfusionFunDlg::OnButtonAdd() { // TODO: Add your control notification handler code here DWORD ProcessId=NULL; HWND hWnd = ::FindWindow(NULL,"F8 CALL 01"); //窗口标题取句柄 GetWindowThreadProcessId(hWnd,&ProcessId); ParamData CallParam; CallParam.Param1 = atoi(m_edit1_text); CallParam.Param2 = atoi(m_edit2_text); if(ProcessId==NULL)
   { ::AfxMessageBox(
"未找到进程");
  }
else {     InfusionFunc(ProcessId,CallAdd,&CallParam,sizeof(CallParam)); } }

 

posted @ 2013-06-13 12:37  DageKing  阅读(1058)  评论(2编辑  收藏  举报