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 36 37 38
| #include <stdio.h> #include <Windows.h>
BOOL Inject(DWORD dwProcessID, const WCHAR* szPath) { HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID); LPVOID lpAddress = VirtualAllocEx(hProcess, NULL, 0x100, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); SIZE_T sWriteLength = 0; BOOL bRet = WriteProcessMemory(hProcess, lpAddress, szPath, ((wcslen(szPath) + 1) * 2), &sWriteLength); if (bRet == FALSE) { MessageBoxW(NULL, L"WriteProcessMemory Failed!", L"Error", MB_OK); } HANDLE hThread = CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibraryW, lpAddress, NULL, NULL); WaitForSingleObject(hThread, INFINITE); VirtualFreeEx(hProcess, lpAddress, 0, MEM_RELEASE); CloseHandle(hProcess); CloseHandle(hThread); return TRUE; } int main() { Inject(53556, L"D:\\test\\CC++\\c生万物之windows程序开发\\C+windows\\x64\\Debug\\Dll1.dll"); system("pause"); return 0; }
|