jeudi 30 septembre 2021

How to check that the address pointed by a pointer is pointing to an object not a garbage before reading or writing to this object? [duplicate]

If i have a pointer (static address) that will always point to a specific variable address (ex.health) then how to check if the game.exe destroyed and deallocates this object before program reads and writes to this non existing object at this time?

static DWORD baseAddress = 0x00000 ;
static DWORD healthPtr = (DWORD)(baseAddress + health_offset);

//when the game deallocates and destroys health object it's value become (??) garbage causing crash on reading or writing to it!

//So how to check here if the address pointing to health is realy pointing to a valid health object not a destroyed non sense garbage?

*(int*)(healthPtr) = 100;
// writing to a deallocated object will cause a crash

Aucun commentaire:

Enregistrer un commentaire