typedef struct _RemotePara//参数结构
{
char pMessageBox[102];
DWORD dwMessageBox;
DWORD dwProcessHook; //installhook函数的地址
}RemotePara;
--------------------------------------------------------------------------------------------------------------------------------------------------

void *pRemoteThread =::VirtualAllocEx(hWnd,0,THREADSIZE,MEM_COMMIT| MEM_RESERVE,PAGE_EXECUTE_READWRITE);
if(!pRemoteThread)
//return 0;
MessageBox(NULL,"2","2",MB_OK);
if(!::WriteProcessMemory(hWnd,pRemoteThread,&ThreadProc,THREADSIZE,0))
//return 0;
MessageBox(NULL,"3","3",MB_OK);

//再付值
RemotePara myRemotePara;
::ZeroMemory(&myRemotePara,sizeof(RemotePara));
HINSTANCE hKernel32 = ::LoadLibrary ("kernel32.dll");//Kernal32
HINSTANCE hProcessHook = ::LoadLibrary ("D:\\vctest\\spy\\InsertDLL\\HideProc\\ProcessHook.dll");//ProcessHook  myRemotePara.dwMessageBox =(DWORD) ::GetProcAddress (hKernel32 , "LoadLibraryA");
strcat(myRemotePara.pMessageBox,"D:\\vctest\\spy\\InsertDLL\\HideProc\\ProcessHook.dll"); myRemotePara.dwProcessHook=(DWORD) ::GetProcAddress (hProcessHook , "installhook");//installhook
//dll是个钩子程序,installl为安装钩子的函数
//写进目标进程
RemotePara *pRemotePara =(RemotePara *) ::VirtualAllocEx (hWnd ,0,sizeof(RemotePara),MEM_COMMIT,PAGE_READWRITE);//注意申请空间时的页面属性
if(!pRemotePara)
//return 0;
MessageBox(NULL,"4","4",MB_OK);
if(!::WriteProcessMemory (hWnd ,pRemotePara,&myRemotePara,sizeof myRemotePara,0))
//return 0;
MessageBox(NULL,"5","5",MB_OK);

//启动线程
HANDLE hThread = ::CreateRemoteThread (hWnd ,0,0,(DWORD (__stdcall *)(void *))pRemoteThread ,pRemotePara,0,&byte_write);
if(!hThread){
//return 0;
MessageBox(NULL,"6","6",MB_OK);
}
------------------------------------------------------------------------------------------------------------------------------
执行线程DWORD __stdcall ThreadProc (RemotePara *lpPara){
//可以成功注入DLL
typedef int (__stdcall *MLoadlibaryA)(LPCTSTR);//定义MessageBox函数
MLoadlibaryA myLoadlibaryA;
myLoadlibaryA =(MLoadlibaryA) lpPara->dwMessageBox ;//得到函数入口地址
myLoadlibaryA(lpPara->pMessageBox);//call
/*****************************************************/
//不好使,我在别的程序中测试了我的DLL完全好用,是个钩子程序,installl为安装钩子的函数
typedef BOOL (__stdcall *MInstallHookA)();//定义MessageBox函数
MInstallHookA myInstallHookA;
myInstallHookA =(MInstallHookA) lpPara->dwProcessHook;//得到函数入口地址
myInstallHookA();//call

return 0;
}

解决方案 »

  1.   

    不太明白你的意思,你是先将ProcessHook.dll注入到目标进程,然后再取得ProcessHook.dll中的函数地址,然后写到远程进程中,让远程线程去调用?
    问题在于目标进程加载你的ProcessHook.dll的地址可能不固定啊。所以你在远程线程中获取的ProcessHook.dll中的函数地址和你实际注入的DLL的地址可能已经不一样了。
      

  2.   

    谢谢 kugou123,那我该怎么做?如何得到的ProcessHook.dll中我的函数的地址?谢谢
      

  3.   

    你试试把DLL直接注入到目标进程中。
    调用你的DLL的函数的代码,你放在:if (dwReason == DLL_PROCESS_ATTACH)
    {
       ……  //放这里
    }