1
0
Fork 0

DBG: better callstack (soon fixing #301) + added some functions in memory.cpp

This commit is contained in:
Mr. eXoDia 2015-07-31 20:11:55 +02:00
parent 6a269202c3
commit eac21d6a3b
3 changed files with 33 additions and 2 deletions

View File

@ -333,4 +333,33 @@ uint MemAllocRemote(uint Address, uint Size, DWORD Type, DWORD Protect)
bool MemFreeRemote(uint Address)
{
return !!VirtualFreeEx(fdProcessInfo->hProcess, (LPVOID)Address, 0, MEM_RELEASE);
}
bool MemGetPageInfo(uint Address, MEMPAGE* PageInfo, bool Refresh)
{
// Update the memory map if needed
if (Refresh)
MemUpdateMap();
SHARED_ACQUIRE(LockMemoryPages);
// Search for the memory page address
auto found = memoryPages.find(std::make_pair(Address, Address));
if (found == memoryPages.end())
return false;
// Return the data when possible
if (PageInfo)
*PageInfo = found->second;
return true;
}
bool MemIsCodePage(uint Address, bool Refresh)
{
MEMPAGE PageInfo;
if (!MemGetPageInfo(Address, &PageInfo, Refresh))
return false;
return (PageInfo.mbi.Protect & PAGE_EXECUTE) == PAGE_EXECUTE;
}

View File

@ -14,4 +14,6 @@ bool MemPatch(uint BaseAddress, const void* Buffer, uint Size, uint* NumberOfByt
bool MemIsValidReadPtr(uint Address);
bool MemIsCanonicalAddress(uint Address);
uint MemAllocRemote(uint Address, uint Size, DWORD Type = MEM_RESERVE | MEM_COMMIT, DWORD Protect = PAGE_EXECUTE_READWRITE);
bool MemFreeRemote(uint Address);
bool MemFreeRemote(uint Address);
bool MemGetPageInfo(uint Address, MEMPAGE* PageInfo, bool Refresh = false);
bool MemIsCodePage(uint Address, bool Refresh = false);

View File

@ -196,7 +196,7 @@ void stackgetcallstack(uint csp, CALLSTACK* callstack)
{
uint data = 0;
MemRead(i, &data, sizeof(uint));
if(MemIsValidReadPtr(data)) //the stack value is a pointer
if(MemIsValidReadPtr(data) && MemIsCodePage(data, false)) //the stack value is a pointer to an executable page
{
uint size = 0;
uint base = MemFindBaseAddr(data, &size);