I can use GetModuleHandle to get its base offset, but I also need to know the size of the code segment of the DLL or EXE. For example, I need to estimate nSize in this code:
char aCrashSignatureBytesAtEIP[] = { 0x87, 0x12, 0x00, ... };
char* pBaseOffset = (char*) GetModuleHandle(NULL);
int nSize = ???;
for (int i = 0; i<nSize; i++)
if (!memcmp(&pBaseOffset[i], aCrashSignatureBytesAtEIP, sizeof(aCrashSignatureBytesAtEIP)))
{
printf("Crash signature found at offset %p", &pBaseOffset[i]);
}
PSAPIgets you this:GetModuleInformationfunction returns youMODULEINFOstructure with both base address and size of the image.