Results 1 to 1 of 1
  1. #1
    Dwar
    Dwar is offline
    Veteran Dwar's Avatar
    Join Date
    2010 Mar
    Posts
    2,222
    Thanks Thanks Given 
    211
    Thanks Thanks Received 
    2,230
    Thanked in
    292 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

Posting Permissions

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