Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C++/C Programming › [HELP]C++ Injector error??

[HELP]C++ Injector error??

Posts 1–15 of 49 · Page 1 of 4
Pixie
Pixie
[HELP]C++ Injector error??
I had 14 errors, then I fixed it up a bit to 12...
Can some one please fix up my code and post it here or PM me please??

Here is my code:
Code:
#include <iostream>
#include <direct.h>
#include <windows.h>
#include <tlhelp32.h>
using namespace std;


char* GetCurrentDir()
{
	char* szRet = (char*)malloc(MAX_PATH);

	_getcwd(szRet, MAX_PATH);

	return szRet;

	)
		LPCTSTR SzToLPCTSTR(char* szString)
	{
		LPTSTR lpszRet;
		size_t side = strlen(szString)+1;

		lpszRet = (LPTSTR)malloc(MAX_PATH);
		mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE);

		return lpszRet;

		)
			void WaitForProcessToAppear (LPCTSTR, lpsztProc, DWORD dwDelay)
		{
			HANDLE          hSnap;
			PROCESSENTRY32  peProc;
			BOOL            bAppeared = FALSE;
			
			while(!bAppeared)
			{
	if ((hSnap = CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE
		(
		peProc.dwSize = sizeof(PROCESSENTRY32);
	if(Process32First(hSnap, &peProc))
		while(Process32Next(hSnap, &peProc) && !bAppeared)
			if(!lstrcmp(lpcszProc, peProc.szExeFile))
				bAppeared = TRUE;
			}
			CloseHandle(hSnap);
			Sleep(dwDelay);
		}
		)
			DWORD GetProcessIdByName(LPCTSTR lpcszProc)
		{
			HANDLE          hSnap;
			PROCESSENTRY32  peProc;
			DWORD           dwRet = -1;
			
			if((hSnap = CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE)
{
	peProc.dwSize = sizeof(PROCESSENTRY32);
	if(Process32First(hSnap, &peProc))
		while(Process32Next(hSnap, &peProc))
			if(!lstrcmp(lpcszProc, peProc.szExeFile))
				dwRet = peProc.th32ProcessID;
			}
			CloseHandle(hSnap);
			
			return dwRet;
			)
				
				BOOL InjectDll(DWORD dwPid, char* szDllPath)
			{
				DWORD       dwMemSize;
				HANDLE      hProc;
				LPVOID      IpRemoteMem, IpLoadLibrary;
				BOOL        bRet = FALSE;
				
				if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, dwPid)) != NULL)
				{
					dwMemSize = strlen(szDllPath)+1;
					if((IpRemoteMem = VirtualAllocEx(hProc, NULL, dwMemSize, MEM_COMMIT, PAGE_READWRITE) != NULL)
						if(WriteProcessMemory(hProc, IpRemoteMem, (LPCVOID)szDllPath, dwMemSize, NULL))
						{
							IpLoadLibrary = GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA");
							if(CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)IpLoadLibrary, IpRemoteMem, 0, NULL)!= NULL)
								bRet = True
								)
						}
						CloseHandle(hProc);
						
						return bRet;
						)

							int main()
						{
							char szProc[MAX_PATH], szDll[MAX_PATH];
							char* szDllPath = (char*)malloc(MAX_PATH);
							LPTSTR lpszProc = NULL;

							for(;;)
							
							{
								cout << "Process: ";
								cin >> szProc;
								cout << "DLL: ";
								cin >> szDll;
								szDllPath = GetCurrentDir();
								strcat_s(szDllPath, MAX_PATH, "\\");
								strcat_s(szDllPath, MAX_PATH, szDll);
								cout << "Waiting for process..." << endl;
								WaitForProcessToAppear(SzToLPCTSTR(szProc), 100);
								if(InjectDll(GetProcessIdByName(SzToLPCTSTR(szProc)), szDllPath))
									cout << "Injection Success!" << endl;
								else
									cout << "Failed to inject!" << endl;
								cout << "\n";
							}
							
							return 0;
						}
The Error Log:

Code:
------ Build started: Project: Luigi, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(23) : error C2065: 'size' : undeclared identifier
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(27) : error C2061: syntax error : identifier 'lpsztProc'
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(35) : error C3861: 'CreateToolHelp32Snapshot': identifier not found
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(42) : error C2065: 'lpcszProc' : undeclared identifier
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(48) : error C2065: 'dwDelay' : undeclared identifier
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(59) : error C3861: 'CreateToolHelp32Snapshot': identifier not found
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(88) : error C2440: '=' : cannot convert from 'bool' to 'LPVOID'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(89) : error C2143: syntax error : missing ')' before '{'
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(96) : error C2065: 'True' : undeclared identifier
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(96) : error C2143: syntax error : missing ';' before '}'
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(119) : error C2660: 'WaitForProcessToAppear' : function does not take 2 arguments
Build log was saved at "file://c:\Documents and Settings\-----\My Documents\Visual Studio 2008\Projects\Luigi\Luigi\Debug\BuildLog.htm"
Luigi - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#1 · edited 17y ago · 17y ago
Hell_Demon
Hell_Demon
You're using ) instead of } as closing brackets o__O
#2 · 17y ago
Pixie
Pixie
Quote Originally Posted by Hell_Demon View Post
You're using ) instead of } as closing brackets o__O
So where should I put them, it's a Command Prompt Injector
#3 · 17y ago
Hell_Demon
Hell_Demon
Code:
#include <iostream>
#include <direct.h>
#include <windows.h>
#include <tlhelp32.h>
using namespace std;


char* GetCurrentDir()
{
	char* szRet = (char*)malloc(MAX_PATH);

	_getcwd(szRet, MAX_PATH);

	return szRet;

}

LPCTSTR SzToLPCTSTR(char* szString)
{
	LPTSTR lpszRet;
	size_t side = strlen(szString)+1;
	lpszRet = (LPTSTR)malloc(MAX_PATH);
	mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE);
	return lpszRet;
}

void WaitForProcessToAppear (LPCTSTR, lpsztProc, DWORD dwDelay)
{
	HANDLE          hSnap;
	PROCESSENTRY32  peProc;
	BOOL            bAppeared = FALSE;

	while(!bAppeared)
	{
		if ((hSnap = CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE)
		{
			peProc.dwSize = sizeof(PROCESSENTRY32);
			if(Process32First(hSnap, &peProc))
			{
				while(Process32Next(hSnap, &peProc) && !bAppeared)
				{
					if(!lstrcmp(lpcszProc, peProc.szExeFile))
					{
						bAppeared = TRUE;
					}
					CloseHandle(hSnap);
				}
				Sleep(dwDelay);
			}
		}
	}
}
DWORD GetProcessIdByName(LPCTSTR lpcszProc)
{
	HANDLE          hSnap;
	PROCESSENTRY32  peProc;
	DWORD           dwRet = -1;
			
	if((hSnap = CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE)
	{
		peProc.dwSize = sizeof(PROCESSENTRY32);
		if(Process32First(hSnap, &peProc))
		{
			while(Process32Next(hSnap, &peProc))
			{
				if(!lstrcmp(lpcszProc, peProc.szExeFile))
				{
					dwRet = peProc.th32ProcessID;
				}
				CloseHandle(hSnap);
			}
			
		}
		return dwRet;
	}
}
				
BOOL InjectDll(DWORD dwPid, char* szDllPath)
{
	DWORD       dwMemSize;
	HANDLE      hProc;
	LPVOID      IpRemoteMem, IpLoadLibrary;
	BOOL        bRet = FALSE;
	
	if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, dwPid)) != NULL)
	{
		dwMemSize = strlen(szDllPath)+1;
		if((IpRemoteMem = VirtualAllocEx(hProc, NULL, dwMemSize, MEM_COMMIT, PAGE_READWRITE) != NULL)
		{
			if(WriteProcessMemory(hProc, IpRemoteMem, (LPCVOID)szDllPath, dwMemSize, NULL))
			{
				IpLoadLibrary = GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA");
				if(CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)IpLoadLibrary, IpRemoteMem, 0, NULL)!= NULL)
				{
					bRet = True
				}
				CloseHandle(hProc);
			}					
			return bRet;
		}
	}
}

int main()
{
	char szProc[MAX_PATH], szDll[MAX_PATH];
	char* szDllPath = (char*)malloc(MAX_PATH);
	LPTSTR lpszProc = NULL;
	for(;;)
	{
		cout << "Process: ";
		cin >> szProc;
		cout << "DLL: ";
		cin >> szDll;
		szDllPath = GetCurrentDir();
		strcat_s(szDllPath, MAX_PATH, "\\");
		strcat_s(szDllPath, MAX_PATH, szDll);
		cout << "Waiting for process..." << endl;
		WaitForProcessToAppear(SzToLPCTSTR(szProc), 100);
		if(InjectDll(GetProcessIdByName(SzToLPCTSTR(szProc)), szDllPath))
		{
			cout << "Injection Success!" << endl;
		}
		else
		{
			cout << "Failed to inject!" << endl;
			cout << "\n";
		}
	}
	return 0;
}
Fixed brackets and indention, no idea if it will work.
just use s1nject(closed source) or tatnium injector(open source)
#4 · 17y ago
Pixie
Pixie
Quote Originally Posted by Hell_Demon View Post
Code:
#include <iostream>
#include <direct.h>
#include <windows.h>
#include <tlhelp32.h>
using namespace std;


char* GetCurrentDir()
{
	char* szRet = (char*)malloc(MAX_PATH);

	_getcwd(szRet, MAX_PATH);

	return szRet;

}

LPCTSTR SzToLPCTSTR(char* szString)
{
	LPTSTR lpszRet;
	size_t side = strlen(szString)+1;
	lpszRet = (LPTSTR)malloc(MAX_PATH);
	mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE);
	return lpszRet;
}

void WaitForProcessToAppear (LPCTSTR, lpsztProc, DWORD dwDelay)
{
	HANDLE          hSnap;
	PROCESSENTRY32  peProc;
	BOOL            bAppeared = FALSE;

	while(!bAppeared)
	{
		if ((hSnap = CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE)
		{
			peProc.dwSize = sizeof(PROCESSENTRY32);
			if(Process32First(hSnap, &peProc))
			{
				while(Process32Next(hSnap, &peProc) && !bAppeared)
				{
					if(!lstrcmp(lpcszProc, peProc.szExeFile))
					{
						bAppeared = TRUE;
					}
					CloseHandle(hSnap);
				}
				Sleep(dwDelay);
			}
		}
	}
}
DWORD GetProcessIdByName(LPCTSTR lpcszProc)
{
	HANDLE          hSnap;
	PROCESSENTRY32  peProc;
	DWORD           dwRet = -1;
			
	if((hSnap = CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE)
	{
		peProc.dwSize = sizeof(PROCESSENTRY32);
		if(Process32First(hSnap, &peProc))
		{
			while(Process32Next(hSnap, &peProc))
			{
				if(!lstrcmp(lpcszProc, peProc.szExeFile))
				{
					dwRet = peProc.th32ProcessID;
				}
				CloseHandle(hSnap);
			}
			
		}
		return dwRet;
	}
}
				
BOOL InjectDll(DWORD dwPid, char* szDllPath)
{
	DWORD       dwMemSize;
	HANDLE      hProc;
	LPVOID      IpRemoteMem, IpLoadLibrary;
	BOOL        bRet = FALSE;
	
	if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, dwPid)) != NULL)
	{
		dwMemSize = strlen(szDllPath)+1;
		if((IpRemoteMem = VirtualAllocEx(hProc, NULL, dwMemSize, MEM_COMMIT, PAGE_READWRITE) != NULL)
		{
			if(WriteProcessMemory(hProc, IpRemoteMem, (LPCVOID)szDllPath, dwMemSize, NULL))
			{
				IpLoadLibrary = GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA");
				if(CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)IpLoadLibrary, IpRemoteMem, 0, NULL)!= NULL)
				{
					bRet = True
				}
				CloseHandle(hProc);
			}					
			return bRet;
		}
	}
}

int main()
{
	char szProc[MAX_PATH], szDll[MAX_PATH];
	char* szDllPath = (char*)malloc(MAX_PATH);
	LPTSTR lpszProc = NULL;
	for(;;)
	{
		cout << "Process: ";
		cin >> szProc;
		cout << "DLL: ";
		cin >> szDll;
		szDllPath = GetCurrentDir();
		strcat_s(szDllPath, MAX_PATH, "\\");
		strcat_s(szDllPath, MAX_PATH, szDll);
		cout << "Waiting for process..." << endl;
		WaitForProcessToAppear(SzToLPCTSTR(szProc), 100);
		if(InjectDll(GetProcessIdByName(SzToLPCTSTR(szProc)), szDllPath))
		{
			cout << "Injection Success!" << endl;
		}
		else
		{
			cout << "Failed to inject!" << endl;
			cout << "\n";
		}
	}
	return 0;
}
Fixed brackets and indention, no idea if it will work.
just use s1nject(closed source) or tatnium injector(open source)
Titanium injector??

Edit: It didn't work, it only fixed one error...
#5 · edited 17y ago · 17y ago
Micheltjuh
Micheltjuh
An error log would make it a lot easier.
#6 · 17y ago
Pixie
Pixie
Quote Originally Posted by Micheltjuh View Post
An error log would make it a lot easier.
Error Log:
Code:
------ Build started: Project: Luigi, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(23) : error C2065: 'size' : undeclared identifier
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(27) : error C2061: syntax error : identifier 'lpsztProc'
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(35) : error C3861: 'CreateToolHelp32Snapshot': identifier not found
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(42) : error C2065: 'lpcszProc' : undeclared identifier
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(48) : error C2065: 'dwDelay' : undeclared identifier
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(59) : error C3861: 'CreateToolHelp32Snapshot': identifier not found
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(88) : error C2440: '=' : cannot convert from 'bool' to 'LPVOID'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(89) : error C2143: syntax error : missing ')' before '{'
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(96) : error C2065: 'True' : undeclared identifier
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(96) : error C2143: syntax error : missing ';' before '}'
c:\documents and settings\-----\my documents\visual studio 2008\projects\luigi\luigi\main.cpp(119) : error C2660: 'WaitForProcessToAppear' : function does not take 2 arguments
Build log was saved at "file://c:\Documents and Settings\-----\My Documents\Visual Studio 2008\Projects\Luigi\Luigi\Debug\BuildLog.htm"
Luigi - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
#7 · 17y ago
why06
why06
Hmmmm... well you've got a bunch of uncdeclared identifiers from what I can see. You either need to imports some files that declare those identifiers or use unmanaged ones. Let me look into it.

EDIT: (3 minutes after looking at code)
Wow. There are way to many managed to unmanaged C++ conversions in there. Maybe HD or BA would have a better time understanding it. I suck with managed.



PS: Does anyone know somewhere I could get acquainted with managed C++? A book or a web page or something. Not exactly sure what I should look for.
#8 · edited 17y ago · 17y ago
Pixie
Pixie
Quote Originally Posted by why06 View Post
Hmmmm... well you've got a bunch of uncdeclared identifiers from what I can see. You either need to imports some files that declare those identifiers or use unmanaged ones. Let me look into it.

EDIT: (3 minutes after looking at code)
Wow. There are way to many managed to unmanaged C++ conversions in there. Maybe HD or BA would have a better time understanding it. I suck with managed.



PS: Does anyone know somewhere I could get acquainted with managed C++? A book or a web page or something. Not exactly sure what I should look for.
I fixed it up a little, and changed the BOOL, and the FALSE and TRUE to undercase letters.

Now, I only have 10 errors...
#9 · 17y ago
B1ackAnge1
B1ackAnge1
MSDN

one way to approach is it to think that Managed C++ = C# using C++ syntax..


Dont' realyl have time to go over all of this, but for instance this:

...\luigi\main.cpp(23) : error C2065: 'size' : undeclared identifier



Look in that block of code
Code:
LPCTSTR SzToLPCTSTR(char* szString)
{
	LPTSTR lpszRet;
	size_t side = strlen(szString)+1;
	lpszRet = (LPTSTR)malloc(MAX_PATH);
	mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE);
	return lpszRet;
}
notice anything what it probably should've been?
Why would anyone call the length of a string 'side' instead of size ?
I'm sure there's more like those..
#10 · 17y ago
why06
why06
Quote Originally Posted by B1ackAnge1 View Post
MSDN

one way to approach is it to think that Managed C++ = C# using C++ syntax..
Hmmm I had a feeling someone would say that. Basically MSDN = the manual xD.

Oh well and looking at the small code snipet I see what you mean. whoever wrote this didn't pay much attention to what they were doing or at least didnt debug it. Anyway it also looks like they added 1 to the string length.. o_O wth?

Meh. I'll try to figure it out. it will take a while because I have less experience, I just have to break each function down part by part. Could take about a week, but this should give me some good practice with managed.
#11 · edited 17y ago · 17y ago
B1ackAnge1
B1ackAnge1
Couple of missing brackets, semi colon, few too many comma's in places they shouldn't be, variable name mis-spellings, Upper vs Lower Case ..

And btw - no managed code in here.. just good old-fashioned Win32 C++

Not trying to sound like an arrogant prick ('cause i'm really not) lol but but this should be beginner level to figure this stuff out, especially when running it through a compiler and it basically telling you what the problem is Perhaps now that you see what the changes are, compare and see if it make sense with what the error message was for each of the errors. Learning opportunity here


Code:
#include <iostream>
#include <direct.h>
#include <windows.h>
#include <tlhelp32.h>
using namespace std;


char* GetCurrentDir()
{
	char* szRet = (char*)malloc(MAX_PATH);

	_getcwd(szRet, MAX_PATH);

	return szRet;

}

LPCTSTR SzToLPCTSTR(char* szString)
{
	LPTSTR lpszRet;
	size_t size = strlen(szString)+1;
	lpszRet = (LPTSTR)malloc(MAX_PATH);
	mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE);
	return lpszRet;
}

void WaitForProcessToAppear(LPCTSTR lpszProc, DWORD dwDelay)
{
	HANDLE          hSnap;
	PROCESSENTRY32  peProc;
	BOOL            bAppeared = FALSE;

	while(!bAppeared)
	{
		if ((hSnap = CreateToolhelp32Snapshot((DWORD)TH32CS_SNAPPROCESS, (DWORD)0)) != INVALID_HANDLE_VALUE)
		{
			peProc.dwSize = sizeof(PROCESSENTRY32);
			if(Process32First(hSnap, &peProc))
			{
				while(Process32Next(hSnap, &peProc) && !bAppeared)
				{
					if(!lstrcmp(lpszProc, peProc.szExeFile))
					{
						bAppeared = TRUE;
					}
					CloseHandle(hSnap);
				}
				Sleep(dwDelay);
			}
		}
	}
}
DWORD GetProcessIdByName(LPCTSTR lpcszProc)
{
	HANDLE          hSnap;
	PROCESSENTRY32  peProc;
	DWORD           dwRet = -1;
			
	if((hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE)
	{
		peProc.dwSize = sizeof(PROCESSENTRY32);
		if(Process32First(hSnap, &peProc))
		{
			while(Process32Next(hSnap, &peProc))
			{
				if(!lstrcmp(lpcszProc, peProc.szExeFile))
				{
					dwRet = peProc.th32ProcessID;
				}
				CloseHandle(hSnap);
			}
			
		}
		return dwRet;
	}
}
				
BOOL InjectDll(DWORD dwPid, char* szDllPath)
{
	DWORD       dwMemSize;
	HANDLE      hProc;
	LPVOID      IpRemoteMem, IpLoadLibrary;
	BOOL        bRet = FALSE;
	
	if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, dwPid)) != NULL)
	{
		dwMemSize = strlen(szDllPath)+1;
		if( (IpRemoteMem = VirtualAllocEx(hProc, NULL, dwMemSize, MEM_COMMIT, PAGE_READWRITE)) != NULL)
		{
			if(WriteProcessMemory(hProc, IpRemoteMem, (LPCVOID)szDllPath, dwMemSize, NULL))
			{
				IpLoadLibrary = GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA");
				if(CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)IpLoadLibrary, IpRemoteMem, 0, NULL)!= NULL)
				{
					bRet = TRUE;
				}
				CloseHandle(hProc);
			}					
			return bRet;
		}
	}
}

int main()
{
	char szProc[MAX_PATH], szDll[MAX_PATH];
	char* szDllPath = (char*)malloc(MAX_PATH);
	LPTSTR lpszProc = NULL;
	for(;;)
	{
		cout << "Process: ";
		cin >> szProc;
		cout << "DLL: ";
		cin >> szDll;
		szDllPath = GetCurrentDir();
		strcat_s(szDllPath, MAX_PATH, "\\");
		strcat_s(szDllPath, MAX_PATH, szDll);
		cout << "Waiting for process..." << endl;
		WaitForProcessToAppear(SzToLPCTSTR(szProc), 100);
		if(InjectDll(GetProcessIdByName(SzToLPCTSTR(szProc)), szDllPath))
		{
			cout << "Injection Success!" << endl;
		}
		else
		{
			cout << "Failed to inject!" << endl;
			cout << "\n";
		}
	}
	return 0;
}
disclaimer: it BUILDS, that's it - didn't test if it runs or does what it's supposed to
#12 · edited 17y ago · 17y ago
Pixie
Pixie
Quote Originally Posted by B1ackAnge1 View Post
Couple of missing brackets, semi colon, few too many comma's in places they shouldn't be, variable name mis-spellings, Upper vs Lower Case ..

And btw - no managed code in here.. just good old-fashioned Win32 C++

Not trying to sound like an arrogant prick ('cause i'm really not) lol but but this should be beginner level to figure this stuff out, especially when running it through a compiler and it basically telling you what the problem is Perhaps now that you see what the changes are, compare and see if it make sense with what the error message was for each of the errors. Learning opportunity here


Code:
#include <iostream>
#include <direct.h>
#include <windows.h>
#include <tlhelp32.h>
using namespace std;


char* GetCurrentDir()
{
	char* szRet = (char*)malloc(MAX_PATH);

	_getcwd(szRet, MAX_PATH);

	return szRet;

}

LPCTSTR SzToLPCTSTR(char* szString)
{
	LPTSTR lpszRet;
	size_t size = strlen(szString)+1;
	lpszRet = (LPTSTR)malloc(MAX_PATH);
	mbstowcs_s(NULL, lpszRet, size, szString, _TRUNCATE);
	return lpszRet;
}

void WaitForProcessToAppear(LPCTSTR lpszProc, DWORD dwDelay)
{
	HANDLE          hSnap;
	PROCESSENTRY32  peProc;
	BOOL            bAppeared = FALSE;

	while(!bAppeared)
	{
		if ((hSnap = CreateToolhelp32Snapshot((DWORD)TH32CS_SNAPPROCESS, (DWORD)0)) != INVALID_HANDLE_VALUE)
		{
			peProc.dwSize = sizeof(PROCESSENTRY32);
			if(Process32First(hSnap, &peProc))
			{
				while(Process32Next(hSnap, &peProc) && !bAppeared)
				{
					if(!lstrcmp(lpszProc, peProc.szExeFile))
					{
						bAppeared = TRUE;
					}
					CloseHandle(hSnap);
				}
				Sleep(dwDelay);
			}
		}
	}
}
DWORD GetProcessIdByName(LPCTSTR lpcszProc)
{
	HANDLE          hSnap;
	PROCESSENTRY32  peProc;
	DWORD           dwRet = -1;
			
	if((hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)) != INVALID_HANDLE_VALUE)
	{
		peProc.dwSize = sizeof(PROCESSENTRY32);
		if(Process32First(hSnap, &peProc))
		{
			while(Process32Next(hSnap, &peProc))
			{
				if(!lstrcmp(lpcszProc, peProc.szExeFile))
				{
					dwRet = peProc.th32ProcessID;
				}
				CloseHandle(hSnap);
			}
			
		}
		return dwRet;
	}
}
				
BOOL InjectDll(DWORD dwPid, char* szDllPath)
{
	DWORD       dwMemSize;
	HANDLE      hProc;
	LPVOID      IpRemoteMem, IpLoadLibrary;
	BOOL        bRet = FALSE;
	
	if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, dwPid)) != NULL)
	{
		dwMemSize = strlen(szDllPath)+1;
		if( (IpRemoteMem = VirtualAllocEx(hProc, NULL, dwMemSize, MEM_COMMIT, PAGE_READWRITE)) != NULL)
		{
			if(WriteProcessMemory(hProc, IpRemoteMem, (LPCVOID)szDllPath, dwMemSize, NULL))
			{
				IpLoadLibrary = GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA");
				if(CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)IpLoadLibrary, IpRemoteMem, 0, NULL)!= NULL)
				{
					bRet = TRUE;
				}
				CloseHandle(hProc);
			}					
			return bRet;
		}
	}
}

int main()
{
	char szProc[MAX_PATH], szDll[MAX_PATH];
	char* szDllPath = (char*)malloc(MAX_PATH);
	LPTSTR lpszProc = NULL;
	for(;;)
	{
		cout << "Process: ";
		cin >> szProc;
		cout << "DLL: ";
		cin >> szDll;
		szDllPath = GetCurrentDir();
		strcat_s(szDllPath, MAX_PATH, "\\");
		strcat_s(szDllPath, MAX_PATH, szDll);
		cout << "Waiting for process..." << endl;
		WaitForProcessToAppear(SzToLPCTSTR(szProc), 100);
		if(InjectDll(GetProcessIdByName(SzToLPCTSTR(szProc)), szDllPath))
		{
			cout << "Injection Success!" << endl;
		}
		else
		{
			cout << "Failed to inject!" << endl;
			cout << "\n";
		}
	}
	return 0;
}
Is that like a major changed code?? And the Changing the side to Size brought me down by 1 error, now I'm at 9...
#13 · 17y ago
B1ackAnge1
B1ackAnge1
The code I pasted has 0 build errors, so copy & paste that
#14 · 17y ago
why06
why06
Quote Originally Posted by B1ackAnge1 View Post
Couple of missing brackets, semi colon, few too many comma's in places they shouldn't be, variable name mis-spellings, Upper vs Lower Case ..

And btw - no managed code in here.. just good old-fashioned Win32 C++

Not trying to sound like an arrogant prick ('cause i'm really not) lol but but this should be beginner level to figure this stuff out, especially when running it through a compiler and it basically telling you what the problem is Perhaps now that you see what the changes are, compare and see if it make sense with what the error message was for each of the errors. Learning opportunity here

disclaimer: it BUILDS, that's it - didn't test if it runs or does what it's supposed to
ok one last question. What is MAX_PATH. It comes up all throughout the code and I have no idea what it is. not even the slightest.
#15 · 17y ago
Posts 1–15 of 49 · Page 1 of 4

Post a Reply

Similar Threads

  • Help please injector errorBy dfjyo in CrossFire Spammers, Injectors and Multi Tools
    7Last post 15y ago
  • help me for error visual c++By cheateroO in CrossFire Help
    2Last post 15y ago
  • Help quick big errorBy mitchellk9 in CrossFire Help
    3Last post 15y ago
  • Help with injectorBy rubice24 in CrossFire Help
    1Last post 15y ago
  • Help with injectorsBy dfjyo in CrossFire Help
    2Last post 15y ago

Tags for this Thread

#error#helpc#injector