C++访问冲突崩溃
当我尝试访问此特定指针时,应用程序崩溃并显示 c0000005 访问冲突错误。
如何捕获此错误并防止其关闭进程,就像在 C# 中使用 try&catch 块一样。 或者在使用该内存区域之前如何检查该区域的访问是否被拒绝?
示例:
MyClass** a = (MyClass**)(0x12345678);
a[0]->b = 1;
我正在访问指针表并设置类成员之一的值。 这确实有效,但问题是“0x12345678”并不总是在该区域加载类。该地址有一个值,但它没有指向正确的内存区域,也没有保存值 0。
请记住,这是一个加载到应用程序中的 DLL,我不再拥有该应用程序的源代码。 所以我尝试动态设置应用程序的设置。
When I attempt to access this specific pointer, the application crashes and shows a c0000005 access violation error.
How can I catch this error and keep it from closing the process as I would in C# with a try&catch block.
Or how could I check if the access is denied to that area of memory before I use it?
Example:
MyClass** a = (MyClass**)(0x12345678);
a[0]->b = 1;
I am accessing a table of pointers and setting the value of one of the members of the class.
This does work, but the issue is that "0x12345678" doesn't always have the classes loaded in that area. The address has a value, but it doesn't point to the correct area of memory and it doesn't hold the value 0.
Keep in mind, this is a DLL that is loaded into a application that I no longer have the source for.
So I'm trying to set the settings of the application dynamically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用结构化异常处理 来捕获此类错误。特别是,过滤
EXCEPTION_ACCESS_VIOLATION
。只要确保您知道吞下异常时在做什么:如果您的垃圾地址指向防护页面,您可能会看到描述的行为 此处。
You can use Structured Exception Handling to trap these sorts of errors. In particular, filter for
EXCEPTION_ACCESS_VIOLATION
.Just make sure you know what you're doing when you swallow the exception: if your garbage address points to a guard page, you might see the behaviour described here.