65,199
社区成员




#include "stdafx.h"
#include <tchar.h>
#include <malloc.h>
#include <TlHelp32.h>
//注意: dll路径一定要以绝对路径,否则会注入失败
BOOL WINAPI insertdll(DWORD dwprocessid,PCSTR filepath)
{
BOOL fok=FALSE;
HANDLE hprocess=NULL;
HANDLE hthread=NULL;
PCSTR re_filepath=NULL;
hprocess=::OpenProcess(PROCESS_CREATE_THREAD|PROCESS_VM_OPERATION|PROCESS_VM_WRITE,FALSE,dwprocessid);
if(hprocess==NULL)
{
return fok;
}
int count=1+(::lstrlen(filepath));
re_filepath=(PCSTR)::VirtualAllocEx(hprocess,NULL,count,MEM_COMMIT,PAGE_READWRITE);
if(re_filepath==NULL)
return fok;
if(!::WriteProcessMemory(hprocess,(PVOID)re_filepath,(PVOID)filepath,count,NULL))
return fok;
PTHREAD_START_ROUTINE fun_address=(PTHREAD_START_ROUTINE)::GetProcAddress(::GetModuleHandle("kernel32.dll"),"LoadLibraryA");
if(fun_address==NULL)
{
return fok;
}
hthread=::CreateRemoteThread (hprocess,NULL,0,fun_address,(PVOID)re_filepath,0,NULL);
if(hthread==NULL)
return fok;
::WaitForSingleObject(hthread,INFINITE);
fok=TRUE;
return fok;
}
DWORD SelectProcess(PCSTR ProcessName)
{
DWORD ProcessId=0;
HANDLE process=NULL;
process=CreateToolhelp32Snapshot(TH32CS_SNAPALL,::GetCurrentProcessId());
PROCESSENTRY32 pe={sizeof(pe)};
while(::Process32Next(process,&pe))
{
if(::lstrcmpi(pe.szExeFile,ProcessName)==0)
{
ProcessId=pe.th32ProcessID;
//MessageBox(NULL,pe.szExeFile,"hello",MB_OK);
break;
}
//MessageBox(NULL,pe.szExeFile,"hello",MB_OK);
}
return ProcessId;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
PCSTR processname="text1.exe";
DWORD processid=SelectProcess(processname);
PCSTR dllname="e:\\rc41.dll";
if(processid)
{
insertdll(processid,dllname);
}
return 0;
}