0

I have to detour the assert function, but i don't know how to do it. I tried a few things but I don't share it here because it is garbage. i need to change them params.

#include <iostream>
#include <cassert>

int main()
{
    assert(2 + 2 == 4);
    std::cout << "Execution continues past the first assert\n";
}
HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
  • 6
    What does "detour" mean here? – Thomas Jager Apr 02 '20 at 17:57
  • `assert()` is supposed to crash the program if the assertion fails. Are you saying "how do I disable assertions?" – tadman Apr 02 '20 at 17:57
  • @tadman actually yes, i have to disable assertions from the process of injected dll. – Berkay Karatas Apr 02 '20 at 18:02
  • 1
    You mean [like this](https://stackoverflow.com/questions/5354314/how-to-completely-disable-assertion)? `assert()` should be disabled in non-debug builds. – tadman Apr 02 '20 at 18:05
  • Have you considered using a macro @Berkay Karatas? – Kaito Apr 02 '20 at 18:08
  • @tadman nah, probly main process is works on debug mode. so seems i need to detour it for pass params. – Berkay Karatas Apr 02 '20 at 18:08
  • @mix_42 i have no knowledge about macros, lemme research about it, thank you for your comment – Berkay Karatas Apr 02 '20 at 18:09
  • `assert` isn't a function, but a macro. It's up to the implementation that compiled said process whether it's possible to detour assertions in another process you don't own without detouring `abort` in general. (And if you do own it, you can do better.) – chris Apr 02 '20 at 18:09
  • 1
    Assertions shouldn't trip unless there's problems, so maybe fix those problems or change the assertions if you can. – tadman Apr 02 '20 at 18:09
  • Define `NDEBUG` when compiling. For `g++`/`clang++` add `-DNDEBUG` to the compilation command. – Ted Lyngmo Apr 02 '20 at 18:10
  • @chris probly you are right, your comment is the most logical. i m going to make some tests and than will share here the result. – Berkay Karatas Apr 02 '20 at 18:12
  • If you are making a release build in Visual Studio, `NDEBUG` should be defined automagically and `assert()` should do nothing. – Ted Lyngmo Apr 02 '20 at 18:15
  • @ThomasJager, Presumably, the OP is talking about the [Detours library](https://github.com/microsoft/Detours), which lets you redirect function calls without changing the source code. – chris Apr 02 '20 at 18:20
  • @BerkayKaratas "_i have to disable assertions from the process of injected dll_" - You can't disable assertions made within the DLL - unless you have the source code for the dll and can recompile it in release mode. Can you describe this in more detail, by [editing](https://stackoverflow.com/posts/60997981/edit) the question? Is the assertion done inside a DLL? Is it a DLL you have the source code for? Are you compiling it in debug or release mode? .Are you trying to use the detours library chris mentioned? – Ted Lyngmo Apr 02 '20 at 18:34

0 Answers0