1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
BOOL Inject(string dll) {
DWORD ProcessID;
HWND wnd = FindWindow(0, "Minecraft");
GetWindowThreadProcessId(wnd, &ProcessID);
HANDLE Proc;
char buf[50]={0};
LPVOID RemoteString, LoadLibAddy;
if(!ProcessID)
return false;
Proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessID);
if(!Proc) {
sprintf(buf, "failed: %d", GetLastError());
MessageBox(NULL, buf, "Maple Injector", NULL);
return false;
}
LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
RemoteString = VirtualAllocEx(Proc, NULL, dll.size(), MEM_COMMIT, PAGE_READWRITE);
DWORD numBytesWritten;
WriteProcessMemory(Proc, RemoteString, dll.c_str(), dll.size(), &numBytesWritten);
CreateRemoteThread(Proc, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibAddy, RemoteString, 0, NULL);
ErrorExit("VirtualAllocEx");
ErrorExit("WriteProcessMemory");
ErrorExit("CreateRemoteThread");
CloseHandle(Proc);
return true;
}
|