Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to disable c++ assert from .net app

Tags:

c++

c#

I have the following problem: I use c++ library from my WPF app, the library throws an assertion in some very rare cases. It shows a nice dialog with c++ filename, the line number and assert expression. So the question is: can I disable asserts in the c++ library assuming that I don't have source code. What I really need is to "catch" this assertion and log it.

Thanks.

like image 715
Alex Semenov Avatar asked Nov 10 '10 13:11

Alex Semenov


2 Answers

One way is to create a thread that performs EnumWindows every so often and detects if an assert window pops up, it can then capture the message and click the ignore button. This will still cause the window to show up for a short while (depending on your interval between EnumWindows but I assume you customers aren't going to be getting the debug DLL so it shouldn't matter.


Another option is calling _CrtSetReportMode(_CRT_ASSERT, 0) to disable asserts from being shown altogether. If you want to PInvoke this from .NET note that _CRT_ASSERT is equal to 2.

like image 81
Motti Avatar answered Sep 28 '22 14:09

Motti


Depending on your assembler skills and whether steps have been taken deliberately to block this type of stuff, it's usually possible to modify binary code to prevent this sort of message being displayed.

However, an assertion firing is often a precursor to some more spectacular crash or other misbehaviour, so just stopping the message box might not get you much further. Of course, some assertions are buggy, so this might be all you need.

If I had to modify this DLL, I would disassemble it with IDA and work out a patch. Hiding the assertion would probably be fairly easy, logging it quite a lot harder.

like image 31
Will Dean Avatar answered Sep 28 '22 13:09

Will Dean