Click here to Skip to main content
16,008,750 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: can you tell me what is that mean?? Pin
Nelek5-May-08 1:18
protectorNelek5-May-08 1:18 
AnswerRe: can you tell me what is that mean?? Pin
David Crow5-May-08 2:53
David Crow5-May-08 2:53 
GeneralRe: can you tell me what is that mean?? Pin
Nelek5-May-08 3:17
protectorNelek5-May-08 3:17 
QuestionReplacements for IsBadReadPtr and IsBadWritePtr Pin
Blake Miller2-May-08 5:59
Blake Miller2-May-08 5:59 
AnswerRe: Replacements for IsBadReadPtr and IsBadWritePtr Pin
Mike Dimmick2-May-08 7:05
Mike Dimmick2-May-08 7:05 
GeneralRe: Replacements for IsBadReadPtr and IsBadWritePtr Pin
Blake Miller2-May-08 7:18
Blake Miller2-May-08 7:18 
GeneralRe: Replacements for IsBadReadPtr and IsBadWritePtr Pin
Mike Dimmick2-May-08 13:14
Mike Dimmick2-May-08 13:14 
AnswerRe: Replacements for IsBadReadPtr and IsBadWritePtr [modified] Pin
Randor 2-May-08 8:51
professional Randor 2-May-08 8:51 
For a read pointer all we need to know is if VirtualQuery can read it. So you could do something like this:

BOOL IsBadReadPointerCheck(char *p, size_t size)
{
	MEMORY_BASIC_INFORMATION mbi;
	for (void *pStop = p + size; p < pStop;p =p+mbi.RegionSize)
	{
		if(!VirtualQuery(p,&mbi,sizeof(mbi)))
		{
			return FALSE;
		}
	}
	return TRUE;
}


For a write pointer we would need to iterate through the entire range and check the bits stored in the Protect member of the MEMORY_BASIC_INFORMATION structure. Something like this:

BOOL IsBadWritePointer(char *p, size_t size)
{
	BOOL bRet = FALSE;
	void *pStop = p+size;
	MEMORY_BASIC_INFORMATION mbi;
	for(p;p < pStop;++p))
	{
		if(VirtualQueryEx(GetCurrentProcess(),(LPVOID)p,&mbi,sizeof(MEMORY_BASIC_INFORMATION)))
		{
			if(!(((mbi.Protect & PAGE_READWRITE) == PAGE_READWRITE) || ((mbi.Protect & PAGE_EXECUTE_READWRITE) == PAGE_EXECUTE_READWRITE)))
			{
				return TRUE;
			}
		}
	}
	return bRet;
}


Lets say that you have a pointer to a member function and you want to validate the member function pointer. You might do something like this:

MEMORY_BASIC_INFORMATION mbi;
if(VirtualQueryEx(GetCurrentProcess(),(LPVOID)pInstructions,&mbi,sizeof(MEMORY_BASIC_INFORMATION)))
{
	if(mbi.Protect & PAGE_EXECUTE_READ && mbi.State & MEM_COMMIT && mbi.AllocationProtect & PAGE_EXECUTE_WRITECOPY && mbi.Type & MEM_IMAGE)
	{
		(*this.*MemberFunction)(val);
		return TRUE;
	}
}


*Disclaimer Edit*
I have not had time to test these functions as I am currently too busy. These functions were removed from some experimental code I was working on some time back. Use/Modify them at your own risk. Just by looking over them I can see they need to have additional error handling.

Best Wishes,
-David Delaune

modified on Friday, May 2, 2008 3:05 PM

QuestionUNICODE problem Pin
gabbana2-May-08 2:54
gabbana2-May-08 2:54 
AnswerRe: UNICODE problem Pin
Matthew Faithfull2-May-08 3:40
Matthew Faithfull2-May-08 3:40 
AnswerRe: UNICODE problem Pin
David Crow2-May-08 3:45
David Crow2-May-08 3:45 
GeneralRe: UNICODE problem [modified] Pin
gabbana2-May-08 3:56
gabbana2-May-08 3:56 
GeneralRe: UNICODE problem Pin
David Crow2-May-08 4:24
David Crow2-May-08 4:24 
GeneralRe: UNICODE problem Pin
gabbana2-May-08 4:32
gabbana2-May-08 4:32 
GeneralRe: UNICODE problem Pin
gabbana2-May-08 4:49
gabbana2-May-08 4:49 
QuestionRe: UNICODE problem Pin
David Crow2-May-08 4:56
David Crow2-May-08 4:56 
GeneralRe: UNICODE problem Pin
marcinj2-May-08 9:12
marcinj2-May-08 9:12 
GeneralRe: UNICODE problem Pin
gabbana2-May-08 20:01
gabbana2-May-08 20:01 
GeneralRe: UNICODE problem Pin
marcinj3-May-08 11:44
marcinj3-May-08 11:44 
QuestionNeed to load a directory without the User seeing it- How? Pin
Larry Mills Sr2-May-08 2:30
Larry Mills Sr2-May-08 2:30 
AnswerRe: Need to load a directory without the User seeing it- How? Pin
Hamid_RT2-May-08 2:40
Hamid_RT2-May-08 2:40 
AnswerRe: Need to load a directory without the User seeing it- How? [modified] Pin
_AnsHUMAN_ 2-May-08 2:41
_AnsHUMAN_ 2-May-08 2:41 
GeneralRe: Need to load a directory without the User seeing it- How? Pin
ThatsAlok5-May-08 0:09
ThatsAlok5-May-08 0:09 
AnswerRe: Need to load a directory without the User seeing it- How? Pin
Rajesh R Subramanian2-May-08 2:55
professionalRajesh R Subramanian2-May-08 2:55 
GeneralRe: Need to load a directory without the User seeing it- How? Pin
Larry Mills Sr2-May-08 6:46
Larry Mills Sr2-May-08 6:46 

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.