Click here to Skip to main content
15,886,026 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionMouse scroll wheel Pin
DanYELL20-Apr-10 9:55
DanYELL20-Apr-10 9:55 
AnswerRe: Mouse scroll wheel Pin
Michel Godfroid20-Apr-10 11:17
Michel Godfroid20-Apr-10 11:17 
AnswerRe: Mouse scroll wheel Pin
@Intersect☺™20-Apr-10 20:51
professional@Intersect☺™20-Apr-10 20:51 
QuestionHow to read a txt file in Windows CE (C++) Pin
Software200720-Apr-10 8:39
Software200720-Apr-10 8:39 
AnswerRe: How to read a txt file in Windows CE (C++) Pin
Eugen Podsypalnikov20-Apr-10 9:04
Eugen Podsypalnikov20-Apr-10 9:04 
GeneralRe: How to read a txt file in Windows CE (C++) Pin
Software200720-Apr-10 9:20
Software200720-Apr-10 9:20 
QuestionRe: How to read a txt file in Windows CE (C++) Pin
David Crow20-Apr-10 9:19
David Crow20-Apr-10 9:19 
QuestionWhy does this dode fail injection? Pin
rain-1320-Apr-10 6:51
rain-1320-Apr-10 6:51 
I got DLL injection example from youtube. http://www.youtube.com/watch?v=H3O3hmXkt1I
For some reason it says: "Injection failed" (under indows 7) and under win xp this exe doesn't even start (i see msgbox telling me to reinstall this app).

It compiles w/o errors

Injector.exe
#include <iostream><br />
#include <direct.h><br />
#include <windows.h><br />
#include <tlhelp32.h><br />
using namespace std;<br />
<br />
char* GetCurrentDir()<br />
{<br />
	char*	szRet = (char*)malloc(MAX_PATH);<br />
<br />
	_getcwd(szRet, MAX_PATH);<br />
<br />
	return szRet;<br />
}<br />
<br />
LPCTSTR SzToLPCTSTR(char* szString)<br />
{<br />
LPTSTR	lpszRet;<br />
size_t	 size = strlen(szString)+1;<br />
lpszRet = (LPTSTR)malloc(MAX_PATH);<br />
mbstowcs_s(NULL,lpszRet,size,szString,_TRUNCATE);<br />
return	lpszRet;<br />
}<br />
<br />
void WaitForProcessToAppear(LPCTSTR lpcszProc, DWORD dwDelay)<br />
{<br />
	HANDLE			hSnap;<br />
	PROCESSENTRY32	peProc;<br />
	BOOL			bAppeared = FALSE;<br />
<br />
	while (!bAppeared)<br />
	{<br />
		if((hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0)) != INVALID_HANDLE_VALUE)<br />
		{<br />
			peProc.dwSize = sizeof(PROCESSENTRY32);<br />
			if(Process32First(hSnap, &peProc))<br />
				while(Process32Next (hSnap, &peProc) && !bAppeared)<br />
					if(!lstrcmp(lpcszProc, peProc.szExeFile))<br />
						bAppeared = TRUE;<br />
		}<br />
		CloseHandle(hSnap);<br />
		Sleep(dwDelay);<br />
	}<br />
}<br />
<br />
DWORD GetProcessIdByName(LPCTSTR lpcszProc)<br />
{<br />
	HANDLE			hSnap;<br />
	PROCESSENTRY32	peProc;<br />
	DWORD			dwRet = -1;<br />
<br />
	if((hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0)) != INVALID_HANDLE_VALUE)<br />
		{<br />
			peProc.dwSize = sizeof(PROCESSENTRY32);<br />
			if(Process32First(hSnap, &peProc))<br />
				while(Process32Next (hSnap, &peProc))<br />
					if(!lstrcmp(lpcszProc, peProc.szExeFile))<br />
						dwRet = peProc.th32ProcessID;<br />
		}<br />
	CloseHandle(hSnap);<br />
	return dwRet;<br />
}<br />
<br />
BOOL InjectDLL(DWORD dwPid, char* szDllPath)<br />
{<br />
	DWORD	dwMemSize;<br />
	HANDLE	hProc;<br />
	LPVOID	lpRemoteMem, lpLoadLibrary;<br />
	BOOL	bRet = FALSE;<br />
<br />
	if((hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_CREATE_THREAD, FALSE, dwPid)) != NULL)<br />
	{<br />
		dwMemSize = strlen(szDllPath) +1;<br />
		if((lpRemoteMem = VirtualAllocEx(hProc,NULL,dwMemSize,MEM_COMMIT,PAGE_READWRITE)) != NULL)<br />
			if(WriteProcessMemory(hProc, lpRemoteMem, (LPCVOID)szDllPath,dwMemSize,NULL))<br />
			{<br />
				lpLoadLibrary = GetProcAddress(GetModuleHandleA("kernel32.dll"), "LoadLibraryA");<br />
				if(CreateRemoteThread(hProc, NULL, 0, (LPTHREAD_START_ROUTINE)lpLoadLibrary, lpRemoteMem, 0, NULL) != NULL)<br />
					bRet = TRUE;<br />
			}<br />
	}<br />
	CloseHandle(hProc);<br />
<br />
	return bRet;<br />
}<br />
<br />
int main()<br />
{<br />
	char	szProc[MAX_PATH],szDll[MAX_PATH];<br />
	char*	szDllPath = (char*)malloc(MAX_PATH);<br />
	LPTSTR	lpszProc = NULL;<br />
	for(;;)<br />
	{<br />
		cout << "Proccess: ";<br />
		cin >> szProc;<br />
		cout << "DLL: ";<br />
		cin >> szDll;<br />
		szDllPath = GetCurrentDir();<br />
		strcat_s(szDllPath,MAX_PATH,"\\");<br />
		strcat_s(szDllPath,MAX_PATH,szDll);<br />
		cout << "Waiting for process..." << endl;<br />
		WaitForProcessToAppear(SzToLPCTSTR(szProc), 100);<br />
		if(InjectDLL(GetProcessIdByName(SzToLPCTSTR(szProc)),szDllPath))<br />
			cout << "Injection succeeded!" << endl;<br />
		else<br />
			cout << "Injection failed!" << endl;<br />
		cout << "\n";<br />
	}<br />
<br />
	return 0;<br />
}


test.dll
#include <windows.h><br />
<br />
BOOL WINAPI DllMain(HANDLE hInstance, DWORD dwReason, LPVOID lpReserved)<br />
{<br />
	switch(dwReason)<br />
	{<br />
	case DLL_PROCESS_ATTACH:<br />
		MessageBox(0, L"I'm injected!",L"injxOrz", MB_OK);<br />
	}<br />
<br />
	return TRUE;<br />
}


any ideas?
AnswerRe: Why does this dode fail injection? Pin
«_Superman_»20-Apr-10 7:37
professional«_Superman_»20-Apr-10 7:37 
GeneralRe: Why does this dode fail injection? Pin
rain-1320-Apr-10 8:14
rain-1320-Apr-10 8:14 
GeneralRe: Why does this dode fail injection? Pin
«_Superman_»20-Apr-10 8:15
professional«_Superman_»20-Apr-10 8:15 
AnswerRe: Why does this dode fail injection? Pin
elchupathingy20-Apr-10 8:34
elchupathingy20-Apr-10 8:34 
GeneralRe: Why does this dode fail injection? [modified] Pin
rain-1320-Apr-10 8:55
rain-1320-Apr-10 8:55 
AnswerRe: Why does this dode fail injection? Pin
Stephen Hewitt20-Apr-10 15:01
Stephen Hewitt20-Apr-10 15:01 
AnswerRe: Why does this dode fail injection? Pin
Adam Roderick J20-Apr-10 20:26
Adam Roderick J20-Apr-10 20:26 
GeneralRe: Why does this dode fail injection? Pin
rain-1321-Apr-10 2:31
rain-1321-Apr-10 2:31 
QuestionOperator Usage Pin
ForNow20-Apr-10 6:32
ForNow20-Apr-10 6:32 
AnswerRe: Operator Usage Pin
Maximilien20-Apr-10 6:56
Maximilien20-Apr-10 6:56 
AnswerRe: Operator Usage Pin
«_Superman_»20-Apr-10 7:45
professional«_Superman_»20-Apr-10 7:45 
AnswerRe: Operator Usage [modified] Pin
Gwenio20-Apr-10 9:15
Gwenio20-Apr-10 9:15 
GeneralRe: Operator Usage Pin
CPallini20-Apr-10 11:40
mveCPallini20-Apr-10 11:40 
GeneralRe: Operator Usage Pin
ForNow21-Apr-10 2:52
ForNow21-Apr-10 2:52 
QuestionRe: Operator Usage Pin
CPallini21-Apr-10 10:31
mveCPallini21-Apr-10 10:31 
QuestionSwallow a keyup Pin
Rozis20-Apr-10 6:05
Rozis20-Apr-10 6:05 
QuestionRe: Swallow a keyup Pin
Iain Clarke, Warrior Programmer20-Apr-10 22:20
Iain Clarke, Warrior Programmer20-Apr-10 22:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.