捕获“运行时检查失败 #0 - ESP 的值不正确”
因此,我从我的 C# 代码中调用非托管 .dll 文件中的函数。根据传递给该函数的参数,它可能会导致“运行时检查失败#0 - ESP 的值不正确”错误。这是该函数完全正常的行为(是的,我知道这听起来很奇怪,但是请耐心听我说)。 但是,如果发生这种情况,我希望能够处理它,就像处理异常一样:只是优雅地失败,向用户输出一条消息并避免整个程序崩溃。 这可能吗?
So, I am calling a function from an unmanaged .dll file from my C# code. Depending on the arguments passed to that function, it can cause "Run-Time Check Failure #0 - The value of ESP was not properly " error.This is completely normal behavior for the function ( yes , I know this sounds VERY strange, but bear with me ).
However, if this happens I want to be able to handle it , like I would handle an exception: just fail gracefully , output a message to the user and avoid crashing my entire program.
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 GS 标志,则可以通过调用函数
__set_security_error_handler
来覆盖该行为。这允许您指定当 GS 标志和其他安全错误被触发时调用的函数。不过我强烈建议不要这样做。任何经常破坏 ESP 的函数听起来都是一个真正的问题。您还可能通过覆盖此函数来隐藏其他真正的安全问题。
更好的解决方案是将单个方法标记为裸方法并防止发生 GS 检查。
If you are using the GS flag you can override the behavior by calling the function
__set_security_error_handler
. This allows you to specify the function that is called when the GS flag, and other security errors, is tripped.I highly advise against this though. Any function that regularly corrupts ESP sounds like a real problem. You also risk hiding other real security issues by overriding this function.
A much better solution would be to mark the individual method as naked and prevent the GS check from occuring.