Click here to Skip to main content
15,913,610 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionForground Window in WinXP and Win7 both Pin
rahul.kulshreshtha28-May-10 21:59
rahul.kulshreshtha28-May-10 21:59 
AnswerRe: Forground Window in WinXP and Win7 both Pin
rahul.kulshreshtha28-May-10 22:15
rahul.kulshreshtha28-May-10 22:15 
AnswerRe: Forground Window in WinXP and Win7 both Pin
gothic_coder28-May-10 23:15
gothic_coder28-May-10 23:15 
GeneralRe: Forground Window in WinXP and Win7 both Pin
rahul.kulshreshtha28-May-10 23:17
rahul.kulshreshtha28-May-10 23:17 
GeneralRe: Forground Window in WinXP and Win7 both Pin
gothic_coder28-May-10 23:22
gothic_coder28-May-10 23:22 
GeneralRe: Forground Window in WinXP and Win7 both Pin
rahul.kulshreshtha28-May-10 23:46
rahul.kulshreshtha28-May-10 23:46 
GeneralRe: Forground Window in WinXP and Win7 both Pin
gothic_coder29-May-10 0:04
gothic_coder29-May-10 0:04 
GeneralRe: Forground Window in WinXP and Win7 both Pin
rahul.kulshreshtha29-May-10 0:21
rahul.kulshreshtha29-May-10 0:21 
QuestionInstall IIS Pin
gothic_coder28-May-10 21:39
gothic_coder28-May-10 21:39 
AnswerRe: Install IIS Pin
Hristo-Bojilov29-May-10 0:16
Hristo-Bojilov29-May-10 0:16 
GeneralRe: Install IIS Pin
gothic_coder29-May-10 0:39
gothic_coder29-May-10 0:39 
GeneralRe: Install IIS Pin
Hristo-Bojilov29-May-10 0:47
Hristo-Bojilov29-May-10 0:47 
GeneralRe: Install IIS Pin
gothic_coder29-May-10 0:53
gothic_coder29-May-10 0:53 
GeneralRe: Install IIS Pin
gothic_coder3-Jun-10 0:17
gothic_coder3-Jun-10 0:17 
QuestionWhy C++ doesn't use the parent's class function? (C++ question) Pin
Green Fuze28-May-10 21:10
Green Fuze28-May-10 21:10 
AnswerRe: Why C++ doesn't use the parent's class function? (C++ question) Pin
Green Fuze28-May-10 21:11
Green Fuze28-May-10 21:11 
GeneralRe: Why C++ doesn't use the parent's class function? (C++ question) Pin
eusto28-May-10 23:20
eusto28-May-10 23:20 
GeneralRe: Why C++ doesn't use the parent's class function? (C++ question) Pin
Green Fuze29-May-10 1:33
Green Fuze29-May-10 1:33 
GeneralRe: Why C++ doesn't use the parent's class function? (C++ question) Pin
eusto29-May-10 8:44
eusto29-May-10 8:44 
Questionproblem with creating model-less dialog as a child of CFormView Pin
m_code28-May-10 18:54
m_code28-May-10 18:54 
AnswerRe: problem with creating model-less dialog as a child of CFormView Pin
Richard MacCutchan28-May-10 22:26
mveRichard MacCutchan28-May-10 22:26 
GeneralRe: problem with creating model-less dialog as a child of CFormView Pin
m_code29-May-10 8:39
m_code29-May-10 8:39 
Questionabout Hook WriteProcessMemory Pin
rockago28-May-10 12:30
rockago28-May-10 12:30 
AnswerRe: about Hook WriteProcessMemory Pin
Garth J Lancaster28-May-10 14:02
professionalGarth J Lancaster28-May-10 14:02 
GeneralRe: about Hook WriteProcessMemory Pin
rockago28-May-10 14:23
rockago28-May-10 14:23 
<br />
//.cpp<br />
#include "stdafx.h"<br />
#include "DetourDll.h"<br />
<br />
#include "detours.h"	//the main API header of detours<br />
<br />
#pragma comment(lib,"detours.lib")<br />
<br />
BOOL WINAPI MyWriteProcessMemory(<br />
HANDLE hProcess, // handle to process<br />
LPVOID lpBaseAddress, // base of memory area<br />
LPVOID lpBuffer, // data buffer<br />
DWORD nSize, // number of bytes to write<br />
LPDWORD lpNumberOfBytesWritten // number of bytes written<br />
);<br />
DETOUR_TRAMPOLINE(BOOL WINAPI CopyWriteProcessMemory(HANDLE, LPVOID, LPVOID, DWORD, LPDWORD), WriteProcessMemory);<br />
BOOL WINAPI MyWriteProcessMemory(<br />
HANDLE hProcess, // handle to process<br />
LPVOID lpBaseAddress, // base of memory area<br />
LPVOID lpBuffer, // data buffer<br />
DWORD nSize, // number of bytes to write<br />
LPDWORD lpNumberOfBytesWritten) // number of bytes written<br />
{<br />
BOOL nResult=WriteProcessMemory(hProcess,lpBaseAddress,lpBaseAddress,nSize,lpNumberOfBytesWritten); //call origin function<br />
MessageBoxA(NULL,(LPCTSTR)lpBaseAddress,"Hook!",MB_OK); <br />
return nResult;<br />
}<br />
<br />
BOOL APIENTRY DllMain( HANDLE hModule, <br />
                       DWORD  ul_reason_for_call, <br />
                       LPVOID lpReserved<br />
					 )<br />
{<br />
    switch (ul_reason_for_call)<br />
	{<br />
		case DLL_PROCESS_ATTACH:<br />
			OutputDebugString("Detour dll Load!");<br />
			DetourFunctionWithTrampoline((PBYTE)CopyWriteProcessMemory, (PBYTE)MyWriteProcessMemory);<br />
		//	DetourFunctionWithTrampoline((PBYTE)CopyMessageBoxW, (PBYTE)MyMessageBoxW);<br />
			break;<br />
		case DLL_THREAD_ATTACH:<br />
			break;<br />
		case DLL_THREAD_DETACH:<br />
			break;<br />
		case DLL_PROCESS_DETACH:<br />
			OutputDebugString("Detour dll Exit!");<br />
			DetourRemove((PBYTE)CopyWriteProcessMemory, (PBYTE)MyWriteProcessMemory);<br />
		//	DetourRemove((PBYTE)CopyMessageBoxW, (PBYTE)MyMessageBoxW);<br />
			break;<br />
    }<br />
    return TRUE;<br />
}<br />
<br />
<br />
LRESULT WINAPI MsgProc(int code, WPARAM wParam, LPARAM lParam)<br />
{<br />
	//note :on windows 2k ,the 1st paramter to CallNextHookEx can be NULL<br />
	//On win 98 ,it must be the hook handle<br />
	return(CallNextHookEx(NULL,code,wParam,lParam));<br />
}<br />
<br />
//.def<br />
EXPORTS<br />
;dll export functions<br />
	MsgProc<br />
<br />
//.h<br />
<br />
// The following ifdef block is the standard way of creating macros which make exporting <br />
// from a DLL simpler. All files within this DLL are compiled with the DETOURDLL_EXPORTS<br />
// symbol defined on the command line. this symbol should not be defined on any project<br />
// that uses this DLL. This way any other project whose source files include this file see <br />
// DETOURDLL_API functions as being imported from a DLL, wheras this DLL sees symbols<br />
// defined with this macro as being exported.<br />
#ifdef DETOURDLL_EXPORTS<br />
#define DETOURDLL_API __declspec(dllexport)<br />
#else<br />
#define DETOURDLL_API __declspec(dllimport)<br />
#endif<br />
<br />
LRESULT WINAPI MsgProc(int code, WPARAM wParam, LPARAM lParam);<br />


this's my all code.
When I use the "WriteProcessMemory" after the injection, but it won't execute "MessageBoxA"

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.