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

C / C++ / MFC

 
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"

GeneralRe: about Hook WriteProcessMemory Pin
Garth J Lancaster28-May-10 15:07
professionalGarth J Lancaster28-May-10 15:07 
GeneralRe: about Hook WriteProcessMemory Pin
rockago28-May-10 21:48
rockago28-May-10 21:48 
GeneralRe: about Hook WriteProcessMemory Pin
Garth J Lancaster28-May-10 22:27
professionalGarth J Lancaster28-May-10 22:27 
AnswerRe: about Hook WriteProcessMemory Pin
Richard MacCutchan28-May-10 22:22
mveRichard MacCutchan28-May-10 22:22 
GeneralRe: about Hook WriteProcessMemory Pin
Garth J Lancaster28-May-10 22:33
professionalGarth J Lancaster28-May-10 22:33 
GeneralRe: about Hook WriteProcessMemory Pin
Richard MacCutchan28-May-10 23:09
mveRichard MacCutchan28-May-10 23:09 
QuestionWrite a function to cause a thread to wait Pin
Danzy8328-May-10 9:08
Danzy8328-May-10 9:08 
AnswerRe: Write a function to cause a thread to wait Pin
CPallini28-May-10 9:19
mveCPallini28-May-10 9:19 
AnswerRe: Write a function to cause a thread to wait Pin
Luc Pattyn28-May-10 9:33
sitebuilderLuc Pattyn28-May-10 9:33 
AnswerRe: Write a function to cause a thread to wait Pin
Cedric Moonen28-May-10 10:02
Cedric Moonen28-May-10 10:02 
GeneralRe: Write a function to cause a thread to wait Pin
CPallini28-May-10 11:08
mveCPallini28-May-10 11:08 
AnswerRe: Write a function to cause a thread to wait Pin
malaugh28-May-10 11:18
malaugh28-May-10 11:18 
AnswerRe: Write a function to cause a thread to wait Pin
Richard MacCutchan28-May-10 22:17
mveRichard MacCutchan28-May-10 22:17 
QuestionOnPrint from IE Pin
mesajflaviu28-May-10 4:34
mesajflaviu28-May-10 4:34 
AnswerRe: OnPrint from IE Pin
mesajflaviu28-May-10 7:43
mesajflaviu28-May-10 7:43 
QuestionAllocating memory for function pointers [modified] Pin
SelvaKr28-May-10 4:08
SelvaKr28-May-10 4:08 
AnswerRe: Allocating memory for function pointers Pin
Aescleal28-May-10 4:16
Aescleal28-May-10 4:16 

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.