I have a process that was being used externally and is now internal, this program uses ReadProcessMemory to copy data from memory into a Char *. Below is the code.
char* szMemDump = (char*)malloc(mbi.RegionSize+1);
ReadProcessMemory( NULL, (unsigned long*)dwMemAddr, szMemDump, mbi.RegionSize, NULL );
I am now doing this from within the program and my objective is to read that information into the same array without the use of RPM.
I have attempted memcpy although this seems to crash the program, since I am reading through large amounts of memory it is difficult to discover why is this happening.
memcpy(szMemDump, (void*)dwMemAddr, mbi.RegionSize);
The alternative to this program that uses RPM does not have any issues and allows data scanning accurately so I can only assume memcpy is incorrect.
Edit: The new code is being loaded as a DLL within the process, this should allow for values to be read internally.
Edit Update code.
if( VirtualQuery((unsigned long*)dwMemAddr, &mbi, sizeof(mbi) ) == sizeof(mbi) )
{
if( (mbi.Protect != PAGE_NOACCESS) && (mbi.State == MEM_COMMIT) )
{
char* szMemDump = (char*)malloc(mbi.RegionSize+1);
//ReadProcessMemory( NULL, (unsigned long*)dwMemAddr, szMemDump, mbi.RegionSize, NULL );
memcpy(szMemDump, (unsigned long*)dwMemAddr, mbi.RegionSize);
for( x=0; x<mbi.RegionSize; x++ )
{
//Loop actions
}
free( szMemDump );
}
}