Код: Выделить всё
#include
#include
int main(int argc, char *argv[])
{
if (argc < 2) {
printf("mssing argument \n");
return EXIT_FAILURE;
}
HANDLE hProcess, hThread = NULL;
BOOL bWrite;
LPVOID lValloc;
LPCVOID lpBuffer = "\x41\x41\x41\x41\x41";
DWORD PID = atoi(argv[1]), TID = atoi(argv[1]);
printf("pid is %ld\n", PID);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
if (hProcess == NULL) {
printf("Impossible to access process, error code :%ld\n", GetLastError());
return EXIT_FAILURE;
}
lValloc = VirtualAllocEx(hProcess, NULL, sizeof(lpBuffer), (MEM_COMMIT | MEM_RESERVE), PAGE_EXECUTE_READWRITE);
if (lValloc == NULL) {
printf("Impossible to allocate memory, error code : %ld", GetLastError());
return EXIT_FAILURE;
}
bWrite = WriteProcessMemory(hProcess, lValloc, lpBuffer, sizeof(lpBuffer), NULL);
if(bWrite == 0){
printf("Impossible to write in memory, error code : %ld\n", GetLastError());
return EXIT_FAILURE;
}
hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)lValloc, NULL, 0, &TID);
if(hThread == NULL) {
printf("CreateRemoteThread failed, error code: %ld\n", GetLastError());
CloseHandle(hProcess);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Код: Выделить всё
C:\Users\vbrain\source\repos\malware>a.exe 19236
pid is 19236
CreateRemoteThread failed, error code: 5
Однако я указал правильный доступ: PAGE_EXECUTE_READWRITE
Что мне не хватает?
Подробнее здесь: https://stackoverflow.com/questions/784 ... indows-api