bool Injector::Inject(DWORD processID)
{
    HANDLE process = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID);
    if(!process) {
        return false;
    }

    std::vector<HANDLE> threads;
    EnumerateThreads(process, [&](DWORD tid){
        if(HANDLE thread=::OpenThread(THREAD_ALL_ACCESS, FALSE, tid)) {
            ::SuspendThread(thread);
            threads.push_back(thread);
        }
    });
    {
        HMODULE kernel32 = ::GetModuleHandleA(KernelDLLFileName);
        HMODULE tkernel32 = FindModule(process, KernelDLLFileName);
        void *base = ::GetProcAddress(kernel32, "SetUnhandledExceptionFilter");
        void *tbase = (void*) ((size_t)tkernel32+((size_t)base-(size_t)kernel32));
        SetThreadTrap(process, tbase);
    }
    std::for_each(threads.begin(), threads.end(), [](HANDLE thread){
        ::ResumeThread(thread);
    });

    std::string dll_path = std::getenv("USERPROFILE");
    dll_path += AddInDir;
    dll_path += MLBDllFileName;

    bool result = InjectDLL(process, dll_path.c_str());
    ::CloseHandle(process);
    return result;
}
Exemple #2
0
//-------------------------------------------------------------------------
static void Freeze(int pos, int action)
{
    EnumerateThreads();

    if (g_threads.items != NULL)
    {
        int i;
        for (i = 0; i < g_threads.size; ++i)
        {
            HANDLE hThread = OpenThread(MH_THREAD_ACCESS, FALSE, g_threads.items[i]);
            if (hThread != NULL)
            {
                SuspendThread(hThread);
                ProcessThreadIPs(hThread, pos, action);
                CloseHandle(hThread);
            }
        }
    }
}
Exemple #3
0
//-------------------------------------------------------------------------
static VOID Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action)
{
    pThreads->pItems   = NULL;
    pThreads->capacity = 0;
    pThreads->size     = 0;
    EnumerateThreads(pThreads);

    if (pThreads->pItems != NULL)
    {
        UINT i;
        for (i = 0; i < pThreads->size; ++i)
        {
            HANDLE hThread = OpenThread(MH_THREAD_ACCESS, FALSE, pThreads->pItems[i]);
            if (hThread != NULL)
            {
                SuspendThread(hThread);
                ProcessThreadIPs(hThread, pos, action);
                CloseHandle(hThread);
            }
        }
    }
}