windows null page allocation

개발새발 2011. 5. 17. 22:30 posted by jz-


#include 

typedef DWORD (__stdcall *NTALLOCATEVIRTUALMEMORY)( DWORD handle,
											IN OUT PVOID baseaddr,
											DWORD zerobits,
											IN OUT PULONG size,
											DWORD type,
											DWORD protect ); 

void main()
{
	NTALLOCATEVIRTUALMEMORY NtAllocateVirtualMemory;
	
	NtAllocateVirtualMemory = (NTALLOCATEVIRTUALMEMORY)GetProcAddress( 
		GetModuleHandle( "ntdll.dll" ),
		"NtAllocateVirtualMemory" );
	
	DWORD addr = 1;
	DWORD size = 0x1000;
	DWORD stat = 0;
	
	stat = NtAllocateVirtualMemory( (DWORD)0xffffffff, 
		&addr, 
		0, 
		&size, 
		MEM_COMMIT | MEM_RESERVE, 
		PAGE_EXECUTE_READWRITE );
	
	DWORD *ptr = NULL;

	// ptr is null page memory

	*ptr = 10;
	*((BYTE*)NULL) = 'a';

}









여행가고 싶네요