[Frage]C++ Injector

07/21/2011 10:03 XxharCs#1
Ok, ich habe zum ersten mal einen Injector in C++ gemacht. Nur leider funktioniert er nicht.
Ich will meine .dll in das Spiel injizieren. Die .dll hat aber auch noch ne Konfigurationsdatei, liegt es villeicht daran ?
Oder liegt das ich beim Namen des Spiels den Process Namen angeben soll oder doch einfach den Window name ?

Naja hier ist der Code, ich hoffe auf eure hilfe =)

Code:
#include "stdafx.h"
#include "windows.h"
#include <iostream>

using namespace std;

char const Path[]="Aimbot.dll";

void SetDebugPrivilege() 
{
	HANDLE hProcess=GetCurrentProcess(), hToken;
	TOKEN_PRIVILEGES priv;
	LUID luid;

	OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken);

    priv.PrivilegeCount = 1;
	priv.Privileges[0].Luid = luid;
	priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    AdjustTokenPrivileges(hToken, false, &priv, 0, 0, 0);

	CloseHandle(hToken); 
}

int main(int argc, char* argv)
{
    HANDLE hWnd, hProcess, AllocAdresse, hRemoteThread;
    DWORD PID;


    hWnd = FindWindow(0, L"Counter-Strike"); //oder soll da hl stehen ? Da es der Process Name hl.exe ist
    GetWindowThreadProcessId((HWND)hWnd, &PID);
    
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, PID);

    AllocAdresse = VirtualAllocEx(hProcess, 0, sizeof(Path), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    WriteProcessMemory(hProcess, (void*)AllocAdresse, (void*)Path, sizeof(Path), 0);
    hRemoteThread=CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE) GetProcAddress(GetModuleHandle(L"kernel32.dll"),"LoadLibraryA"), AllocAdresse, 0, 0);
    
    WaitForSingleObject(hRemoteThread, INFINITE);

    VirtualFreeEx(hProcess, AllocAdresse, sizeof(Path), MEM_DECOMMIT);
    CloseHandle(hProcess);
}
07/21/2011 19:19 MrSm!th#2
Srsly, du kannst die Sprache nicht und willst nen Injector schreiben?

Woher ich das weiß?

Quote:
//oder soll da hl stehen ? Da es der Process Name hl.exe ist
FindWindow.....wieso sollte man da den Prozessnamen angeben?
Natürlich den Fenstertitel...
Btw. bei einer Art Funktion FindProcess wäre es dann natürlich auch "hl.exe" und nicht nur "hl".

Füg mal ein paar Debug-Ausgaben in deinen Code!
Sprich, überprüf die Rückgabewerte und gib eventuelle Fehler aus.
Dann teile uns diese auch mit.
Hellsehen kann hier keiner.
07/21/2011 20:36 XxharCs#3
Ich kann die Sprache, aber nicht so gut wie du. Ich lerne Java in der Schule, und diese Sprache ist sehr C++ ähnlich. Aber naja das ist egal.

Ich probier es mal mit Debug Ausgaben. Aber ich denke das es an der Konfigurations datei meiner .dll liegt~
07/21/2011 20:47 MrSm!th#4
Was für eine Konfigurationsdatei?
07/21/2011 20:54 XxharCs#5
Ist so eine art kleine Options-speicherung für die .dll
Bild:
07/21/2011 21:41 Lazeboy#6
Code:
#include "stdafx.h"
[COLOR="Red"]#include <windows.h>[/COLOR]
#include <iostream>

using namespace std;

char const Path[]="Aimbot.dll";

void SetDebugPrivilege() 
{
	HANDLE hProcess=GetCurrentProcess(), hToken;
	TOKEN_PRIVILEGES priv;
	LUID luid;

	OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken);

    priv.PrivilegeCount = 1;
	priv.Privileges[0].Luid = luid;
	priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    AdjustTokenPrivileges(hToken, false, &priv, 0, 0, 0);

	CloseHandle(hToken); 
}

int main(int argc, char* argv)
{
    HANDLE hWnd, hProcess, AllocAdresse, hRemoteThread;
    DWORD PID;


    hWnd = FindWindow(0, L"Counter-Strike"); //oder soll da hl stehen ? Da es der Process Name hl.exe ist
    GetWindowThreadProcessId((HWND)hWnd, &PID);

    [COLOR="Red"]SetDebugPrivilege();[/COLOR] 

    hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, PID);

    AllocAdresse = VirtualAllocEx(hProcess, 0, sizeof(Path), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    WriteProcessMemory(hProcess, (void*)AllocAdresse, (void*)Path, sizeof(Path), 0);
    hRemoteThread=CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE) GetProcAddress(GetModuleHandle(L"kernel32.dll"),"LoadLibraryA"), AllocAdresse, 0, 0);
    
    WaitForSingleObject(hRemoteThread, INFINITE);

    VirtualFreeEx(hProcess, AllocAdresse, sizeof(Path), MEM_DECOMMIT);
    CloseHandle(hProcess);
}

dann gibste den kompletten Path an oder holst ihn dir

Code:
char lpModulePath[MAX_PATH] = {0};
GetModuleFileNameA(NULL,lpModulePath,MAX_PATH);
    lpModulePath[strlen(lpModulePath) - 4] = 0;
    strcat(lpModulePath,".dll");
wenn dein Injector jetzt "Injector.exe" heisst läd er eine Libary "Injector.dll" die in dem selben ordner ist
07/21/2011 21:48 XxharCs#7
Danke, funkt prima, kann geclosed werden.