problem with VirtualAllocEx

Hi all,

I have a little problem with VirtualAllocEx() Win API Call.

I want to allocate some space in the process given the process
handle. I used the calls VirtualQueryEx() to find the next free block in the
Address Space. Once i get the free block i used the BaseAddress of
that block to allocate the Memory using VirtualAllocEx.

Here is a Flow of My Algorithm. Can any one clarify me as to why it
fails.

{

MEMORY_BASIC_INFORMATION memoryInformation;
LPVOID StartAddress = 0x401055; // some address in the
virtual address space of the process.

HANDLE pProcess = OpenProcess ( PROCESS_CREATE_THREAD
| // For CreateRemoteThread

PROCESS_QUERY_INFORMATION | // For VirtualQueryEx

PROCESS_VM_OPERATION | // For VirtualProtectEx
PROCESS_VM_READ
| // For ReadProcessMemory
PROCESS_VM_WRITE,
// For WriteProcessMemory
FALSE , nProcessID )
do {

VirtualQueryEx ( pProcess,
startAddress,&memoryInformation, sizeof( memoryInformation ) )
// Used to get the status of the virtual memory.

startAddress = (LPVOID ) ( (UINT32)startAddress +
memoryInformation.RegionSize );

} while ( memoryInformation.State != MEM_FREE );

VirtualAllocEx ( pProcess, memoryInformation.BaseAddress,
4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE )

}

VirtualAllocEx is failing with the error code 487(Attempt to access
invalid address.)

regards,
Murali.S


You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com