When i go to inject my dll into any process it crashes at the part where i push back the address of a unsigned char* to a vector<unsigned char*> object i got from a block of memory i scanned. i also made sure to protect it to PAGE_EXECUTE_READWRITE and revert it back to its original protection but it still crashes. The code ran fine when i didn't include my scanner function.
i've done some debugging to it in the past and made sure there was no access violations.
code:
int scanprocess(vector<unsigned char*> &storage,int find)
{
MEMORY_BASIC_INFORMATION mbi = { 0 };
unsigned char *pAddress = NULL,
*pEndRegion = NULL;
It looks like it should crash at this point: *pAddress == dwFindData
You can't dereference pointers across processes, because they exist in separate memory spaces. You need to use ReadProcessMemory().
It doesn't make sense to scan memory from within the same address space that you want to scan. For example, how do handle the case where pAddress points to dwFindData, or to find, or to other copies of the same value? Which is bound to happen, since you're searching the entire address space.
You really should do this from a separate process.
Anyway, this is probably a problem:
lpflOldProtect [out]
A pointer to a variable that receives the previous access protection value of the first page in the specified region of pages. If this parameter is NULL or does not point to a valid variable, the function fails.