B
Bob Karaban
We ran into a problem using VirtualAllocEx and were wondering if anybody has
a way around this. We have an executable that stores a hash table in a
remote process. The VirtualAllocEx function fails on the 32665 item. Below
is a sample project to show it.
Program 1 (where the memory will be stored)
---------------------------------------------
#include "stdafx.h"
#include <windows.h>
#include <iostream.h>
int main(int argc, char* argv[])
{
cout << "Process ID: " << GetCurrentProcessId() << endl;
HANDLE object = CreateSemaphore(NULL,0,1,NULL);
WaitForSingleObject(object,INFINITE);
return 0;
}
Program 2 (who will do the allocating - Note: update PID to the pid of the
above code)
---------------------------------------------
#include "stdafx.h"
#include <windows.h>
// Main program
int main(int argc, char* argv[])
{
int i=0;
long err = 0;
HANDLE hProcess = 0;
long remoteMemory[100000];
char* srcMemory = new char[1024];
memset(&srcMemory[0],75,1024);
////////////
// Connect // Make sure you change the pid
hProcess =
OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE,
FALSE, <CHANGE TO YOUR PID>);
////////////
// Allocate
for (i=0; i<100000; i++)
{
remoteMemory =
(long)VirtualAllocEx(hProcess,NULL,1024,MEM_COMMIT,PAGE_READWRITE);
if (remoteMemory == 0)
err = GetLastError(); // Create
break point here
// you should get err = 8 -->
ERROR_NOT_ENOUGH_MEMORY
}
////////////
// Free
for (i=0;i<100000;i++)
VirtualFreeEx(hProcess,(void*)remoteMemory,0,MEM_RELEASE);
CloseHandle(hProcess);
return 0;
}
Does anyone know where this limit of 32664 is coming from (almost an int)?
Is there some way around this limitation? Any help would be greatly
appreciated. Feel free to contact me back at any of these newsgroups or
directly via email - thanks in advance!
Bob
a way around this. We have an executable that stores a hash table in a
remote process. The VirtualAllocEx function fails on the 32665 item. Below
is a sample project to show it.
Program 1 (where the memory will be stored)
---------------------------------------------
#include "stdafx.h"
#include <windows.h>
#include <iostream.h>
int main(int argc, char* argv[])
{
cout << "Process ID: " << GetCurrentProcessId() << endl;
HANDLE object = CreateSemaphore(NULL,0,1,NULL);
WaitForSingleObject(object,INFINITE);
return 0;
}
Program 2 (who will do the allocating - Note: update PID to the pid of the
above code)
---------------------------------------------
#include "stdafx.h"
#include <windows.h>
// Main program
int main(int argc, char* argv[])
{
int i=0;
long err = 0;
HANDLE hProcess = 0;
long remoteMemory[100000];
char* srcMemory = new char[1024];
memset(&srcMemory[0],75,1024);
////////////
// Connect // Make sure you change the pid
hProcess =
OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE,
FALSE, <CHANGE TO YOUR PID>);
////////////
// Allocate
for (i=0; i<100000; i++)
{
remoteMemory =
(long)VirtualAllocEx(hProcess,NULL,1024,MEM_COMMIT,PAGE_READWRITE);
if (remoteMemory == 0)
err = GetLastError(); // Create
break point here
// you should get err = 8 -->
ERROR_NOT_ENOUGH_MEMORY
}
////////////
// Free
for (i=0;i<100000;i++)
VirtualFreeEx(hProcess,(void*)remoteMemory,0,MEM_RELEASE);
CloseHandle(hProcess);
return 0;
}
Does anyone know where this limit of 32664 is coming from (almost an int)?
Is there some way around this limitation? Any help would be greatly
appreciated. Feel free to contact me back at any of these newsgroups or
directly via email - thanks in advance!
Bob