i need to loop through a memory region which contains my own defined types:
struct ModuleList
{
char ModuleName[64];
int32_t NumberOfFunctions;
};
struct FunctionList
{
char FunctionName[64];
DWORD FunctionAddress;
};
These lays out in memory like this:
0: ModuleList[0]
0 + sizeof(ModuleList): FunctionsList[NumberOfFunctions]
0 + sizeof(ModuleList)+ NumberOfFunctions * sizeof(FunctionList): ModuleList[1]
.
.
.
What i want to do is, overloading operator ++ for ModuleList* so i can easily increment my pointer correctly, because default ++ operator for pointer only increments for sizeof(ModuleList) and i want to increment for sizeof(ModuleList) and size of functions (which is NumberOfFunctions * sizeof(FunctionList)). These structs in memory are completely dynamic, which my program gets over the network. Currently, i am doing this:
unsigned short ModuleCount = 0;
BYTE* pTemp = (BYTE*)MemoryAdr;
for (; std::string(((ModuleList*)(pTemp))->ModuleName).find(".dll") != std::string::npos; pTemp += ModuleListSize + ((ModuleList*)(pTemp))->NumberOfFunctions * FunctionListSize)
ModuleCount++;
But i think it looks ugly. Any suggestions?
void next()or similar toModuleList, and call that in your foor loop