2019-09-11 07:28:59 +08:00
|
|
|
#include "Process.h"
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
Process::Process(string path)
|
|
|
|
{
|
|
|
|
this->path = path;
|
|
|
|
ZeroMemory(&si, sizeof(si));
|
|
|
|
ZeroMemory(&pi, sizeof(pi));
|
|
|
|
}
|
|
|
|
|
|
|
|
Process::~Process()
|
|
|
|
{
|
|
|
|
//dtor
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Process::InjectDLL(string dllName) {
|
|
|
|
LPVOID load_library = (LPVOID) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "LoadLibraryA");
|
|
|
|
LPVOID remote_string = (LPVOID) VirtualAllocEx(pi.hProcess, NULL, strlen(dllName.c_str()) + 1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
|
|
|
WriteProcessMemory(pi.hProcess, remote_string, dllName.c_str(), strlen(dllName.c_str()) + 1, NULL);
|
|
|
|
HANDLE thread = CreateRemoteThread(pi.hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE) load_library, remote_string, CREATE_SUSPENDED, NULL);
|
|
|
|
ResumeThread(thread);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool Process::Create() {
|
|
|
|
return CreateProcess(NULL,
|
2019-09-12 07:55:52 +08:00
|
|
|
(char*)path.c_str(),
|
2019-09-11 07:28:59 +08:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
true,
|
|
|
|
CREATE_SUSPENDED,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&si,
|
|
|
|
&pi);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Process::Run() {
|
|
|
|
ResumeThread(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
}
|