Click here to Skip to main content
15,883,847 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Limiting selected checkbox items in a CListCtrl Pin
softwaremonkey2-Dec-12 22:45
softwaremonkey2-Dec-12 22:45 
QuestionUsing VISUAL C++ 6.0 with OLE Pin
ForNow30-Nov-12 9:06
ForNow30-Nov-12 9:06 
AnswerRe: Using VISUAL C++ 6.0 with OLE Pin
jschell30-Nov-12 10:46
jschell30-Nov-12 10:46 
SuggestionRe: Using VISUAL C++ 6.0 with OLE Pin
David Crow30-Nov-12 14:24
David Crow30-Nov-12 14:24 
GeneralRe: Using VISUAL C++ 6.0 with OLE Pin
ForNow4-Dec-12 13:48
ForNow4-Dec-12 13:48 
AnswerRe: Using VISUAL C++ 6.0 with OLE Pin
Stephen Hewitt2-Dec-12 4:54
Stephen Hewitt2-Dec-12 4:54 
AnswerRe: Using VISUAL C++ 6.0 with OLE Pin
Cristian Amarie3-Dec-12 8:52
Cristian Amarie3-Dec-12 8:52 
QuestionDll injection and hooking Pin
miniman0630-Nov-12 7:47
miniman0630-Nov-12 7:47 
Hello once again,I have been working on some project for a while now and I needed to hook a creation of processes,I have that code(hook/detour)
C++
BOOL WINAPI CreateProcH::CreateProcessInternalW	(	HANDLE 	hToken,
												 LPCWSTR 	lpApplicationName,
												 LPWSTR 	lpCommandLine,
												 LPSECURITY_ATTRIBUTES 	lpProcessAttributes,
												 LPSECURITY_ATTRIBUTES 	lpThreadAttributes,
												 BOOL 	bInheritHandles,
												 DWORD 	dwCreationFlags,
												 LPVOID 	lpEnvironment,
												 LPCWSTR 	lpCurrentDirectory,
												 LPSTARTUPINFOW 	lpStartupInfo,
												 LPPROCESS_INFORMATION 	lpProcessInformation,
												 PHANDLE 	hNewToken 
												 )
	clogf("start %x ref: %x",realCreateProcessInternalW,&realCreateProcessInternalW);
	BOOL res = FALSE;
	res = realCreateProcessInternalW(hToken,lpApplicationName,lpCommandLine,lpProcessAttributes,lpThreadAttributes,bInheritHandles,dwCreationFlags,lpEnvironment,lpCurrentDirectory,lpStartupInfo,lpProcessInformation,hNewToken);
	if(res == FALSE)
		return res;

	Sleep(100);//let it load

	vector<wchar_t*> ::iterator it;
	for(it = pubvPaths.begin(); it < pubvPaths.end(); it++)
	{	
		if(!CDetour::InjectDll(lpProcessInformation->hProcess,*it))
			clogf("InjectDll(lpProcessInformation->hProcess,*it) FAILED!");
		clogf("Strlen %d Injecting dll: %ls",lstrlenW(*it),*it);
	}
	clogf("hThread: %d hProcess: %d dwThreadId: %d dwProcessId: %d",lpProcessInformation->hThread,lpProcessInformation->hProcess,lpProcessInformation->dwThreadId,lpProcessInformation->dwProcessId);
	return res;
};

LOG:
[Fri Nov 30 20:22:20 2012] CreateProcH::CreateProcessInternalW reported: start 7d843e8 ref: 741285ac
[Fri Nov 30 20:22:20 2012] CreateProcH::CreateProcessInternalW reported: Strlen 103 Injecting dll: C:/Users/JEAN/SplitPLayGUI-build-desktop-Qt_4_8_1_for_Desktop_-_MSVC2010__Qt_SDK__Debug/CreateProcH.dll
[Fri Nov 30 20:22:20 2012] CreateProcH::CreateProcessInternalW reported: hThread: 5360 hProcess: 5376 dwThreadId: 8376 dwProcessId: 1388


but the process fails to create or crashes not sure what is wrong,
So I just commented out
C++
if(!CDetour::InjectDll(lpProcessInformation->hProcess,*it))
    clogf("InjectDll(lpProcessInformation->hProcess,*it) FAILED!");


and everything logged the same way but the process actually created and ran, here is CDetour::InjectDll
C++
bool CDetour::InjectDll(HANDLE hProcess ,wchar_t * pwstrDll)
{
	LPVOID RemoteString, LoadLibAddy;

	if(!hProcess)
		return false;

	LoadLibAddy = (LPVOID)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryW");
	if(!LoadLibAddy)
	{
		clogf("GetProcAddress(GetModuleHandle(L\"kernel32.dll\"), \"LoadLibraryW\") FAILED WITH %d!",GetLastError());
		return false;
	}
	RemoteString = (LPVOID)VirtualAllocEx(hProcess, NULL, (lstrlenW(pwstrDll)*2)+2, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
	if(!RemoteString)
	{
		clogf("VirtualAllocEx(hProcess, NULL, lstrlenW(pwstrDll)+2, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); FAILED WITH %d!",GetLastError());
		return false;
	}
	if(WriteProcessMemory(hProcess, (LPVOID)RemoteString, pwstrDll,(lstrlenW(pwstrDll)*2)+2, NULL) == 0)
	{
		clogf("WriteProcessMemory(hProcess, (LPVOID)RemoteString, pwstrDll,lstrlenW(pwstrDll)+2, NULL) FAILED WITH %d!",GetLastError());
		return false;
	}
	if(CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, (LPVOID)RemoteString, NULL, NULL) == NULL)
	{
		clogf("CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddy, (LPVOID)RemoteString, NULL, NULL) FAILED WITH %d!",GetLastError());
		return false;
	}

	return true;
}

I hope someone else could figure it out ,thanks in advance Smile | :)
AnswerRe: Dll injection and hooking Pin
miniman061-Dec-12 19:01
miniman061-Dec-12 19:01 
Questionsimple program in linux doesnt work Pin
a1_shay29-Nov-12 22:59
a1_shay29-Nov-12 22:59 
AnswerRe: simple program in linux doesnt work Pin
Graham Breach30-Nov-12 0:24
Graham Breach30-Nov-12 0:24 
GeneralRe: simple program in linux doesnt work Pin
a1_shay30-Nov-12 1:43
a1_shay30-Nov-12 1:43 
AnswerRe: simple program in linux doesnt work Pin
jschell30-Nov-12 10:49
jschell30-Nov-12 10:49 
QuestionRead binary File Pin
002comp28-Nov-12 23:05
002comp28-Nov-12 23:05 
AnswerRe: Read binary File Pin
Richard MacCutchan28-Nov-12 23:14
mveRichard MacCutchan28-Nov-12 23:14 
AnswerRe: Read binary File Pin
Freak3028-Nov-12 23:18
Freak3028-Nov-12 23:18 
GeneralRe: Read binary File Pin
002comp28-Nov-12 23:41
002comp28-Nov-12 23:41 
QuestionRe: Read binary File Pin
David Crow29-Nov-12 2:37
David Crow29-Nov-12 2:37 
Questionextracting resources from an exe for translation Pin
chronodekar28-Nov-12 21:28
chronodekar28-Nov-12 21:28 
AnswerRe: extracting resources from an exe for translation Pin
Mattias G3-Dec-12 22:24
Mattias G3-Dec-12 22:24 
Questioncompile code twice,why the two result is differrent Pin
yingkou28-Nov-12 21:10
yingkou28-Nov-12 21:10 
AnswerRe: compile code twice,why the two result is differrent Pin
Stefan_Lang28-Nov-12 22:31
Stefan_Lang28-Nov-12 22:31 
AnswerRe: compile code twice,why the two result is differrent Pin
Stephen Hewitt29-Nov-12 0:42
Stephen Hewitt29-Nov-12 0:42 
AnswerRe: compile code twice,why the two result is differrent Pin
Sajeesh Payolam30-Nov-12 18:28
Sajeesh Payolam30-Nov-12 18:28 
AnswerRe: compile code twice,why the two result is differrent Pin
Cristian Amarie3-Dec-12 8:55
Cristian Amarie3-Dec-12 8:55 

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.