Solved Injector not working

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

maxibaby

Newbie
Full Member
Oct 23, 2015
48
383
1
Hello guys, I'm currently working on
How to hack any game series.

I'm currently trying to make the injector work, even with a simple DLL, but can't.
I even downloaded the Injector and DLL Fleep posted and neither worked.
Downloaded a random injector and it did the job.

Whats wrong? What can I do?

I'm on Windows 7 x64, this is my injector code

C++:
/* Language: C++
 * Injector.
 */
 #include <windows.h>
 #include <unistd.h>
 #include <iostream>
 #include <TlHelp32.h>
 #include <fstream> // File Exists?

 using namespace std;


 char processName[] = "pinball.exe";
 char dllName[] = "nte.dll";
 bool injectDLL(DWORD processId);

int main(){
	DWORD processId = 0;
	HANDLE snapshot;
	PROCESSENTRY32 process;
	process.dwSize = sizeof(PROCESSENTRY32);

	while(!processId){
		system("cls");
		cout << "Searching: " << processName << endl;
		snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
		if (Process32First(snapshot, &process)){
			while (Process32Next(snapshot, &process)){
				if (!strcmp(process.szExeFile, processName)){
					cout << "Process found at PID: " << process.th32ProcessID << endl;
					processId = process.th32ProcessID;
					break;
				}
			}
		}
		Sleep(1000);
	}
	ifstream ifile(dllName);
	if (ifile) {
		while(!injectDLL(processId)){
		Sleep(1000);
		};
	} else {
		cout << "That DLL Doesn't exist";
	}

	CloseHandle(snapshot);
	return 0;
}

bool injectDLL(DWORD processId){
	HANDLE hProcess;
	bool memoryW;
	void * functionAdress;
	LPVOID libraryAdress;

	if( (hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, processId) ) != NULL) {
		if ((functionAdress = VirtualAllocEx(hProcess, 0, strlen(dllName)+1, MEM_COMMIT, PAGE_READWRITE)) != NULL){
		cout << "New memory at:" << functionAdress << endl;
			if (WriteProcessMemory(hProcess, functionAdress, dllName, strlen(dllName)+1, NULL)){
				cout << "Memory Written" << endl;
				libraryAdress = (LPVOID) GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
				cout <<"["<< libraryAdress << "] Library adress" << endl;
				if (memoryW = CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE) libraryAdress, functionAdress, 0, 0) != NULL){
					cout << "Thread created" << endl;
				} else {
					cout << "Error: " << GetLastError() << endl;
				}
			}
		}
	}

	CloseHandle(hProcess);
	return memoryW;
}
 

mambda

headass
Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
2,294
37,938
269
There's no reason for code like that to stop working, so you'd want to step through it and ensure that all the values are correct ( no nullptrs, no invalid handle values, all that stuff )
 

Broihon

edgy 12 y/o
Escobar Tier VIP
Fleep Tier Donator
Dec 22, 2013
1,745
40,528
316
Hello guys, I'm currently working on
How to hack any game series.

I'm currently trying to make the injector work, even with a simple DLL, but can't.
I even downloaded the Injector and DLL Fleep posted and neither worked.
Downloaded a random injector and it did the job.

Whats wrong? What can I do?

I'm on Windows 7 x64, this is my injector code

C++:
/* Language: C++
 * Injector.
 */
 #include <windows.h>
 #include <unistd.h>
 #include <iostream>
 #include <TlHelp32.h>
 #include <fstream> // File Exists?

 using namespace std;


 char processName[] = "pinball.exe";
 char dllName[] = "nte.dll";
 bool injectDLL(DWORD processId);

int main(){
	DWORD processId = 0;
	HANDLE snapshot;
	PROCESSENTRY32 process;
	process.dwSize = sizeof(PROCESSENTRY32);

	while(!processId){
		system("cls");
		cout << "Searching: " << processName << endl;
		snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
		if (Process32First(snapshot, &process)){
			while (Process32Next(snapshot, &process)){
				if (!strcmp(process.szExeFile, processName)){
					cout << "Process found at PID: " << process.th32ProcessID << endl;
					processId = process.th32ProcessID;
					break;
				}
			}
		}
		Sleep(1000);
	}
	ifstream ifile(dllName);
	if (ifile) {
		while(!injectDLL(processId)){
		Sleep(1000);
		};
	} else {
		cout << "That DLL Doesn't exist";
	}

	CloseHandle(snapshot);
	return 0;
}

bool injectDLL(DWORD processId){
	HANDLE hProcess;
	bool memoryW;
	void * functionAdress;
	LPVOID libraryAdress;

	if( (hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, processId) ) != NULL) {
		if ((functionAdress = VirtualAllocEx(hProcess, 0, strlen(dllName)+1, MEM_COMMIT, PAGE_READWRITE)) != NULL){
		cout << "New memory at:" << functionAdress << endl;
			if (WriteProcessMemory(hProcess, functionAdress, dllName, strlen(dllName)+1, NULL)){
				cout << "Memory Written" << endl;
				libraryAdress = (LPVOID) GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");
				cout <<"["<< libraryAdress << "] Library adress" << endl;
				if (memoryW = CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE) libraryAdress, functionAdress, 0, 0) != NULL){
					cout << "Thread created" << endl;
				} else {
					cout << "Error: " << GetLastError() << endl;
				}
			}
		}
	}

	CloseHandle(hProcess);
	return memoryW;
}
What error occurs?
 

maxibaby

Newbie
Full Member
Oct 23, 2015
48
383
1
No errors, it would inject, even say "Thread created" but nothing appears to be injected.
 

mambda

headass
Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
2,294
37,938
269
Are you certain nothings injected? Check it out with something like Process Hacker 2 and check the modules loaded in your program. Does your DLL have a proper DllMain?
 

maxibaby

Newbie
Full Member
Oct 23, 2015
48
383
1
Checked with Process Hacker 2, and nothing injects.
Def, something wrong with the injector.
 

maxibaby

Newbie
Full Member
Oct 23, 2015
48
383
1
Looks like I finally made it work, using Full path instead of Relative path to Dll.
Maybe my thread was terminating due to File Not Found as stated.

"Note that CreateRemoteThread may succeed even if lpStartAddress points to data, code, or is not accessible. If the start address is invalid when the thread runs, an exception occurs, and the thread terminates. Thread termination due to a invalid start address is handled as an error exit for the thread's process. This behavior is similar to the asynchronous nature of CreateProcess, where the process is created even if it refers to invalid or missing dynamic-link libraries (DLL)."

How can I actually check if the thread died, and the reason behind it? Tried with GetLastError() but won't get anything.


Doing

C++:
HANDLE memoryW;
memoryW = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE) libraryAdress, functionAdress, 0, NULL);
GetExitCodeThread(memoryW,threadErrorCode);
Would cause me crash.

Also i Would need this to debug my DLL, otherwise I can't know what errors im getting.
 
Last edited:

mambda

headass
Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
2,294
37,938
269
Yeah you can, if the dll actually gets loaded then you can attach visual studio and breakpoint as normal.

Other than that, threadErrorCode should be something like a DWORD iirc

GetExitCodeThread(memoryW, &threadErrorCode);
printf("Error code: %X\n", threadErrorCode);
 

maxibaby

Newbie
Full Member
Oct 23, 2015
48
383
1
C++:
BOOL WINAPI GetExitCodeThread(
  _In_  HANDLE  hThread,
  _Out_ LPDWORD lpExitCode
);
C++:
HANDLE memoryW;
LPDWORD threadHandle, threadErrorCode;
GetExitCodeThread(memoryW,threadErrorCode);
Still crashes.
 

mambda

headass
Escobar Tier VIP
Trump Tier Donator
Jun 25, 2014
2,294
37,938
269
Well what error does it give you? Like i said i recommend using a dword and passing that address ( DWORD threadCode, GetExitWHatever(handle, & threadCode)
 

maxibaby

Newbie
Full Member
Oct 23, 2015
48
383
1
Will need to check on that, need to learn how to use a debugger to go step by step, I'm coming from a Python / java background and no Ide's.

:yawn:

Wil llet you know, thanks
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods