Results 1 to 1 of 1
  1. #1
    Dwar
    Dwar is offline
    Veteran Dwar's Avatar
    Join Date
    2010 Mar
    Posts
    2,221
    Thanks
    211
    Thanked 2,224 Times in 289 Posts
    Rep Power
    10

    [C++] Inject Into a Running Process

    With following code you can make an injector for running processes, it means the injector can work in a background thread and inject whenever the user starts the game from anywhere (ie ASE).
    BOOL InjectIntoProcess(TCHAR* szExeName, TCHAR* szDllName) 
    {
    TCHAR szProcessName[MAX_PATH];
    TCHAR szDllNameAndPath[MAX_PATH];
    DWORD aProcesses[1024], cb, cProcesses;
    HANDLE hProcess = NULL;
    HMODULE hMod = NULL;
    UINT i = 0;

    // Get the full path to the DLL for later use
    GetCurrentDirectory(MAX_PATH, szDllNameAndPath);
    wcscat(szDllNameAndPath, _T("\\"));
    wcscat(szDllNameAndPath, szDllName);

    // Get the list of process identifiers
    if(!EnumProcesses(aProcesses, sizeof(aProcesses), &cb))
    return FALSE;

    // Calculate how many process identifiers were returned
    cProcesses = cb / sizeof(DWORD);

    // Get the name and process identifier for each process
    for(i = 0; i < cProcesses; i++)
    {
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, aProcesses[i]);

    if(hProcess)
    {
    if(EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cb))
    {
    GetModuleBaseNameW(hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR));
    }

    if(wcscmp(wcslwr(szProcessName), szExeName) == 0)
    {
    // We found the process, inject our DLL
    if(DetourContinueProcessWithDllW(hProcess, szDllNameAndPath))
    {
    return TRUE;
    }
    }
    }

    CloseHandle(hProcess);
    }

    return FALSE;
    }

    Now we can inject a DLL as easily as this:
      if(InjectIntoProcess(_T("et.exe"), _T("hax.dll"))) 
    {
    _tprintf(_T("Injection successful!\n"));
    }
    else {
    _tprintf(_T("Injection failed.\n"));
    }

    And you can use a loop to check when to inject.
    by Sinner
    Please, post your questions on forum, not by PM or mail

    I spend my time, so please pay a little bit of your time to keep world in equilibrium

Visitors found this page by searching for:

c inject into process

Inject Process C

inject code to process c

c inject dll to process

inject into running process C

inject into process c

C inject dll into process

InjectIntoProcess(TCHAR* szExeName TCHAR*

c inject into a process

inject dll into running process

thread c inject

if process exist c

inject dll into process c

c inject dll

c process inject

c inject into running process

c inject code into process

c inject to processc inject in running processc inject dll into gameinject dll into running process cc injecting a executable in running processC injectc injecet processc inject code to process

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •