Click here to Skip to main content
15,915,603 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: wave sound not playing properly..sounds different?? Pin
David Crow12-Aug-10 3:31
David Crow12-Aug-10 3:31 
AnswerRe: wave sound not playing properly..sounds different?? Pin
Niklas L12-Aug-10 5:37
Niklas L12-Aug-10 5:37 
GeneralRe: wave sound not playing properly..sounds different?? Pin
Richard MacCutchan12-Aug-10 6:15
mveRichard MacCutchan12-Aug-10 6:15 
QuestionRe: wave sound not playing properly..sounds different?? Pin
Niklas L12-Aug-10 6:48
Niklas L12-Aug-10 6:48 
AnswerRe: wave sound not playing properly..sounds different?? Pin
Richard MacCutchan12-Aug-10 9:57
mveRichard MacCutchan12-Aug-10 9:57 
GeneralRe: wave sound not playing properly..sounds different?? Pin
AmbiguousName12-Aug-10 6:32
AmbiguousName12-Aug-10 6:32 
AnswerRe: wave sound not playing properly..sounds different?? Pin
Richard MacCutchan12-Aug-10 10:00
mveRichard MacCutchan12-Aug-10 10:00 
QuestionCreateRemoteThread Error Pin
gothic_coder12-Aug-10 0:36
gothic_coder12-Aug-10 0:36 
Hello all,

I'm injecting my DLL (Hooking) to explorer.exe using CreatRemoteThread, Now this works fine in windows XP but when i tried in Windows Server 2003, CreateRemoteThread fails with error code 5 (Access Denied), What permission do i need to set?

#include "windows.h"
#include "stdio.h"
#include <tlhelp32.h>
#include <shlwapi.h>


BOOL Inject_DLL(DWORD dwID)

{
	HANDLE hToken = NULL;
	HANDLE hProc = NULL;
	HANDLE hThread = NULL;
	BOOL bReturn = FALSE;
	BOOL bLibLoaded = FALSE;
	BOOL bWriteCheck = FALSE;
	char szErrBuff[MAX_PATH] = "";	
	char szDllFolder[2 * MAX_PATH] = "";
	char szDllPath[2 * MAX_PATH] = "C:\\DelDll\\DetourExample.dll";
	//char szDllPath[2 * MAX_PATH] = "D:\\Working_Ashish\\DetourExample\\release\\DetourExample.dll";
	void*   pLibRemote = NULL;
	HMODULE hKernel32 = NULL;
	DWORD	err = 0;
	TCHAR	szTemp[MAX_PATH] = "";
	DWORD dwDesiredAccess;
	TCHAR	szError[MAX_PATH] = "";

	//Access Identifiers to open the target process
	dwDesiredAccess = PROCESS_CREATE_THREAD |
					  PROCESS_QUERY_INFORMATION |
					  PROCESS_VM_OPERATION|
					  PROCESS_VM_WRITE |
					  PROCESS_VM_READ;


	//Opening the target process.
	hProc = OpenProcess(dwDesiredAccess, FALSE, dwID);	
	if(hProc == NULL || hProc == INVALID_HANDLE_VALUE)
	{
		MessageBox(NULL, "Cannot Open Process", "Error", MB_OK);
		printf("Cannot Open Process\n");
		goto Cleanup;
	}

	

	hKernel32 = GetModuleHandle("Kernel32");
	if(hKernel32 == INVALID_HANDLE_VALUE || hKernel32 == NULL)
	{
		hKernel32 = LoadLibrary("Kernel32");
		if(hKernel32 == INVALID_HANDLE_VALUE || hKernel32 == NULL)
		{
			MessageBox(NULL, "Cannot Load Kernel", "Error", MB_OK);
			printf("Cannot Load Kernel32");			
			goto Cleanup;
		}
		else
		{
			bLibLoaded = TRUE;
		}
	}	

	//Allocate memory for the DLL name in the remote target process.
	pLibRemote = VirtualAllocEx(hProc, NULL, sizeof(szDllPath), MEM_COMMIT, PAGE_READWRITE );
	if(pLibRemote == NULL)
	{
		MessageBox(NULL, "Virtual Alloc Failed", "Error", MB_OK);
		printf("Virtual Alloc Failed\n");
		goto Cleanup;
	}


	//Write the DLL name, including full path, to the allocated memory.
	bWriteCheck = WriteProcessMemory(hProc, pLibRemote, (void*)szDllPath, sizeof(szDllPath), NULL );	
	if(bWriteCheck == 0)
	{
		MessageBox(NULL, "WriteProcess Memory Failed", "Error", MB_OK);
		printf("WriteProcessMemory Failes\n");
		goto Cleanup;
	}


	//Mapping our DLL to the remote process via CreateRemoteThread & LoadLibrary..
	hThread = CreateRemoteThread(	hProc,
									NULL,
									NULL,
									(LPTHREAD_START_ROUTINE)GetProcAddress(hKernel32,"LoadLibraryA"),
									pLibRemote,
									NULL, NULL);
	
	
	//Waiting until the remote thread terminates.
	if(hThread != INVALID_HANDLE_VALUE && hThread != NULL)
	{
		WaitForSingleObject( hThread, INFINITE );
		bReturn = TRUE;
	}
	else
	{
		DWORD err = GetLastError();
		TCHAR szTemp[MAX_PATH] = "";
		sprintf(szTemp, "CreateRemoteThread Failed, Error = %d", err);
		MessageBox(NULL, szTemp, "Error", MB_OK);
	}


//Cleaning up the modules, handles, memory.
Cleanup:

	if(hThread != INVALID_HANDLE_VALUE && hThread != NULL)
	{
		CloseHandle(hThread);
		hThread = NULL;
	}

	if(pLibRemote)
	{
		VirtualFreeEx(hProc, pLibRemote, sizeof(szDllPath), MEM_DECOMMIT);
		pLibRemote = NULL;
	}

	if(hProc != INVALID_HANDLE_VALUE && hProc != NULL)
	{
		CloseHandle(hProc);
		hProc = NULL;
		
	}

	if((hKernel32 != INVALID_HANDLE_VALUE && hKernel32 != NULL) && bLibLoaded)
	{
		FreeLibrary(hKernel32);
		hKernel32 = NULL;
	}

	//DeleteFile(szDllPath);

	return bReturn;
}

int main()
{
	BOOL bReturn = FALSE;

	bReturn  = Inject_DLL(3188);

	return bReturn;

}


Thanks.
AnswerRe: CreateRemoteThread Error Pin
_AnsHUMAN_ 12-Aug-10 2:30
_AnsHUMAN_ 12-Aug-10 2:30 
RantRe: CreateRemoteThread Error Pin
Cool_Dev12-Aug-10 3:30
Cool_Dev12-Aug-10 3:30 
AnswerRe: CreateRemoteThread Error Pin
Richard MacCutchan12-Aug-10 4:25
mveRichard MacCutchan12-Aug-10 4:25 
AnswerRe: CreateRemoteThread Error Pin
elchupathingy12-Aug-10 4:56
elchupathingy12-Aug-10 4:56 
GeneralRe: CreateRemoteThread Error Pin
gothic_coder12-Aug-10 21:15
gothic_coder12-Aug-10 21:15 
QuestionDuplicate String Pin
T.RATHA KRISHNAN11-Aug-10 23:08
T.RATHA KRISHNAN11-Aug-10 23:08 
QuestionRe: Duplicate String Pin
CPallini11-Aug-10 23:48
mveCPallini11-Aug-10 23:48 
AnswerRe: Duplicate String Pin
T.RATHA KRISHNAN11-Aug-10 23:59
T.RATHA KRISHNAN11-Aug-10 23:59 
AnswerRe: Duplicate String Pin
Nuri Ismail12-Aug-10 0:01
Nuri Ismail12-Aug-10 0:01 
GeneralRe: Duplicate String Pin
T.RATHA KRISHNAN12-Aug-10 0:12
T.RATHA KRISHNAN12-Aug-10 0:12 
GeneralRe: Duplicate String Pin
Nuri Ismail12-Aug-10 0:37
Nuri Ismail12-Aug-10 0:37 
GeneralRe: Duplicate String Pin
Aescleal12-Aug-10 0:14
Aescleal12-Aug-10 0:14 
GeneralRe: Duplicate String Pin
T.RATHA KRISHNAN12-Aug-10 0:32
T.RATHA KRISHNAN12-Aug-10 0:32 
GeneralRe: Duplicate String Pin
CPallini12-Aug-10 0:46
mveCPallini12-Aug-10 0:46 
GeneralRe: Duplicate String Pin
Aescleal12-Aug-10 1:18
Aescleal12-Aug-10 1:18 
GeneralRe: Duplicate String Pin
CPallini12-Aug-10 1:36
mveCPallini12-Aug-10 1:36 
GeneralRe: Duplicate String Pin
Aescleal12-Aug-10 2:17
Aescleal12-Aug-10 2:17 

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.