c++ - 如何在读取或写入该对象之前检查指针指向的地址是否指向对象而不是垃圾?
问题描述
如果我有一个指针(静态地址),它总是指向一个特定的变量地址(ex.health),那么如何在程序读取和写入这个不存在的对象之前检查 game.exe 是否销毁并释放这个对象?
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
解决方案
推荐阅读
- ios - 日志不能在一个项目中发生(NSLogs 不工作)
- javascript - array.splice = what does it means?
- android - 更改在 Google Play 商店中发布的应用的包名称
- c# - 从给定目录中获取文件信息并处理N个文件以同时和顺序上传到服务器
- machine-learning - ARKit 图像检测 - 许多图像
- python - 具有特定迭代顺序的坐标乘积
- javascript - 关闭标签和打开标签之间的光标位置
- python - 使用类列表作为 django_tables2 中表类的模型
- php - 如何在我的 Magento 应用程序中修复“已发送的标头”
- solr - solr 结果的差异(Web 界面结果与 http 请求结果)