恍兮惚兮 98a5697bcc format
2024-04-02 18:02:06 +08:00

35 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include <Windows.h>
int dllinjectwmain(int argc, wchar_t *argv[])
{
for (int i = 1; i < argc - 1; i += 1)
{
auto PROCESS_INJECT_ACCESS = (PROCESS_CREATE_THREAD |
PROCESS_QUERY_INFORMATION |
PROCESS_VM_OPERATION |
PROCESS_VM_WRITE |
PROCESS_VM_READ);
auto pid = _wtoi(argv[i]);
auto hProcess = OpenProcess(PROCESS_INJECT_ACCESS, 0, pid);
if (hProcess == 0)
return 0;
auto size = (wcslen(argv[argc - 1]) + 1) * sizeof(wchar_t);
auto remoteData = VirtualAllocEx(hProcess,
nullptr,
size,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (remoteData == 0)
return 0;
WriteProcessMemory(hProcess, remoteData, argv[argc - 1], size, 0);
auto hThread = CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryW, remoteData, 0, 0);
// if (hThread == 0) return 0;很奇怪为0但是成功
WaitForSingleObject(hThread, 10000);
CloseHandle(hThread);
VirtualFreeEx(hProcess, remoteData, size, MEM_RELEASE);
CloseHandle(hProcess);
}
return 1;
}