Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to make an app crash
Forum Updated to NodeBB v4.3 + New Features

how to make an app crash

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 6 Posters 625 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Blackzero
    wrote on last edited by
    #1

    You might be surprised by my question
    I have a system to detect whether the application has been cracked, here I use if and else conditions if the application has been cracked I want the application to crash or not responding when closing the application, is that possible to do in Qt5 c++?

    JonBJ C Pl45m4P 3 Replies Last reply
    0
    • B Blackzero

      You might be surprised by my question
      I have a system to detect whether the application has been cracked, here I use if and else conditions if the application has been cracked I want the application to crash or not responding when closing the application, is that possible to do in Qt5 c++?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Blackzero

      how to make an app crash

      There are many programmers you could employ where this would be the outcome :)

      Well there's nothing particular for this in Qt but plenty of possibilities in C++. Write code to divide by 0, dereference a nullptr, I think the library function _abort()/std::abort() will "crash" your app even in release compilation, etc. Or execute while (true) ::sleep(1);, that's not going anywhere.

      B A 2 Replies Last reply
      3
      • B Blackzero

        You might be surprised by my question
        I have a system to detect whether the application has been cracked, here I use if and else conditions if the application has been cracked I want the application to crash or not responding when closing the application, is that possible to do in Qt5 c++?

        C Offline
        C Offline
        ChrisW67
        wrote on last edited by
        #3

        @Blackzero If this is some sort of protection mechanism then you should not cause the program to crash at the same time/place as the integrity check that is failing. You could do something like:

        if (cracked_program_detected()) 
          QTimer::singleshot(QRandomGenerator::global()->bounded(100, 2000), this, &Foo::crashMeNow);
        

        So the program dies some random time later, while it is executing something other than the check code. You need to scatter checks like this throughout the executable. Each check should be coded differently, preferrably not in a single check function (inline code). Each should crash or exit the program in a different way. You need to make sure that these bits of code do not get merged or optimized out. Makes is harder to find the checks but is not going to stop a determined attempt.

        Signing the executable will flag attempts at altering the executable permanently.

        B 1 Reply Last reply
        3
        • JonBJ JonB

          @Blackzero

          how to make an app crash

          There are many programmers you could employ where this would be the outcome :)

          Well there's nothing particular for this in Qt but plenty of possibilities in C++. Write code to divide by 0, dereference a nullptr, I think the library function _abort()/std::abort() will "crash" your app even in release compilation, etc. Or execute while (true) ::sleep(1);, that's not going anywhere.

          B Offline
          B Offline
          Blackzero
          wrote on last edited by
          #4

          @JonB I have tried using the code while (true) sleep(1) but it stops and there is no affected loop still forced to stop by qt I think there is another way to make the application crash, I tried this code but it doesn't seem to happen anything

          char* crashPtr = nullptr;
          *crashPtr = 0xDE;
          std::memset(reinterpret_cast<void*>(0xDEADBEEF), 0, 1024);
          
          JonBJ C 2 Replies Last reply
          0
          • B Blackzero

            @JonB I have tried using the code while (true) sleep(1) but it stops and there is no affected loop still forced to stop by qt I think there is another way to make the application crash, I tried this code but it doesn't seem to happen anything

            char* crashPtr = nullptr;
            *crashPtr = 0xDE;
            std::memset(reinterpret_cast<void*>(0xDEADBEEF), 0, 1024);
            
            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #5

            @Blackzero said in how to make an app crash:

            but it stops and there is no affected loop still forced to stop by qt

            Dunno what you mean. You asked for e.g. " or not responding when closing the application,", such a loop should do that.

            Keep trying whatever if you want code to crash. Surprised that code attempts you show don't "crash", but there you are. Try what @ChrisW67 said.

            On a separate matter I cannot imagine why you are worried about anyone trying to "hack/crack" your code. Who can be bothered? If someone really wants to crack your code they are clever enough to deal with your "protection" mechanisms, seems a waste of time to me, but there you are.

            1 Reply Last reply
            0
            • B Blackzero

              @JonB I have tried using the code while (true) sleep(1) but it stops and there is no affected loop still forced to stop by qt I think there is another way to make the application crash, I tried this code but it doesn't seem to happen anything

              char* crashPtr = nullptr;
              *crashPtr = 0xDE;
              std::memset(reinterpret_cast<void*>(0xDEADBEEF), 0, 1024);
              
              C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6
              #include <QCoreApplication>
              #include <QTimer>
              #include <cstring>
              
              int main(int argc, char **argv) {
                      QCoreApplication app(argc, argv);
              
                      QTimer::singleShot(
                              3000,
                              // [](){ char* crashPtr = nullptr; *crashPtr = 0xDE; }
                              [](){ std::memset(reinterpret_cast<void*>(0xDEADBEEF), 0, 1024); }
                      );
              
                      return app.exec();
              }
              

              Both lambdas crash here as expected.

              My compiler just warns when given [](){ int xyzzy = 271828/0; } and optimizes out the unused variable. So, you need to be careful.

              JonBJ B 2 Replies Last reply
              0
              • C ChrisW67
                #include <QCoreApplication>
                #include <QTimer>
                #include <cstring>
                
                int main(int argc, char **argv) {
                        QCoreApplication app(argc, argv);
                
                        QTimer::singleShot(
                                3000,
                                // [](){ char* crashPtr = nullptr; *crashPtr = 0xDE; }
                                [](){ std::memset(reinterpret_cast<void*>(0xDEADBEEF), 0, 1024); }
                        );
                
                        return app.exec();
                }
                

                Both lambdas crash here as expected.

                My compiler just warns when given [](){ int xyzzy = 271828/0; } and optimizes out the unused variable. So, you need to be careful.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #7

                @ChrisW67 said in how to make an app crash:

                int xyzzy = 271828/0;

                But is clever enough for e.g.

                int abc = -1;
                for (int i = 0; i < 1; i++)
                    abc++;
                func(123456 / abc);
                

                or something similar? ;-)

                1 Reply Last reply
                0
                • J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on last edited by
                  #8

                  try

                  #include <signal.h>
                  ....
                  raise(SIGSEGV);
                  

                  it simulates a standard crash when access invalid memory. You can of course use other macros, instead of SIGSEV. See here for more information:
                  https://www.tutorialspoint.com/c_standard_library/signal_h.htm


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  1 Reply Last reply
                  2
                  • C ChrisW67

                    @Blackzero If this is some sort of protection mechanism then you should not cause the program to crash at the same time/place as the integrity check that is failing. You could do something like:

                    if (cracked_program_detected()) 
                      QTimer::singleshot(QRandomGenerator::global()->bounded(100, 2000), this, &Foo::crashMeNow);
                    

                    So the program dies some random time later, while it is executing something other than the check code. You need to scatter checks like this throughout the executable. Each check should be coded differently, preferrably not in a single check function (inline code). Each should crash or exit the program in a different way. You need to make sure that these bits of code do not get merged or optimized out. Makes is harder to find the checks but is not going to stop a determined attempt.

                    Signing the executable will flag attempts at altering the executable permanently.

                    B Offline
                    B Offline
                    Blackzero
                    wrote on last edited by
                    #9

                    @ChrisW67 said in how to make an app crash:

                    f this is some sort of protection mechanism then you should not cause the program to crash at the same time/place as the integrity check that is failing. You could do something like:

                    Yes, you understand what I mean.
                    I don't understand what the code is doing but I want to make the crash as if it is pure without having to create a class to make the crash.

                    1 Reply Last reply
                    0
                    • C ChrisW67
                      #include <QCoreApplication>
                      #include <QTimer>
                      #include <cstring>
                      
                      int main(int argc, char **argv) {
                              QCoreApplication app(argc, argv);
                      
                              QTimer::singleShot(
                                      3000,
                                      // [](){ char* crashPtr = nullptr; *crashPtr = 0xDE; }
                                      [](){ std::memset(reinterpret_cast<void*>(0xDEADBEEF), 0, 1024); }
                              );
                      
                              return app.exec();
                      }
                      

                      Both lambdas crash here as expected.

                      My compiler just warns when given [](){ int xyzzy = 271828/0; } and optimizes out the unused variable. So, you need to be careful.

                      B Offline
                      B Offline
                      Blackzero
                      wrote on last edited by
                      #10

                      @ChrisW67 said in how to make an app crash:

                      Both lambdas crash here as expected.

                      My compiler just warns when given { int xyzzy = 271828/0; } and optimizes out the unused variable. So, you need to be careful.

                      Your code works but it doesn't work until the application is closed,
                      see my code

                      MainWindow::~MainWindow()
                      {
                          if(cracked_program_detected())
                          {
                                  QTimer::singleShot(
                                             3000,
                                           // [](){ char* crashPtr = nullptr; *crashPtr = 0xDE; }
                                             [](){ std::memset(reinterpret_cast<void*>(0xDEADBEEF), 0, 1024); }
                              );
                          }
                          delete ui;
                      }
                      
                      JonBJ 1 Reply Last reply
                      0
                      • B Blackzero

                        @ChrisW67 said in how to make an app crash:

                        Both lambdas crash here as expected.

                        My compiler just warns when given { int xyzzy = 271828/0; } and optimizes out the unused variable. So, you need to be careful.

                        Your code works but it doesn't work until the application is closed,
                        see my code

                        MainWindow::~MainWindow()
                        {
                            if(cracked_program_detected())
                            {
                                    QTimer::singleShot(
                                               3000,
                                             // [](){ char* crashPtr = nullptr; *crashPtr = 0xDE; }
                                               [](){ std::memset(reinterpret_cast<void*>(0xDEADBEEF), 0, 1024); }
                                );
                            }
                            delete ui;
                        }
                        
                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #11

                        @Blackzero
                        You set off a "3-second delayed crash" in main window's destructor. If the main window is the last window visible and is being closed and/or you exit the main's app.exec() before the 3 seconds are up it won't get executed.

                        1 Reply Last reply
                        1
                        • B Blackzero

                          You might be surprised by my question
                          I have a system to detect whether the application has been cracked, here I use if and else conditions if the application has been cracked I want the application to crash or not responding when closing the application, is that possible to do in Qt5 c++?

                          Pl45m4P Offline
                          Pl45m4P Offline
                          Pl45m4
                          wrote on last edited by Pl45m4
                          #12

                          @Blackzero said in how to make an app crash:

                          I have a system to detect whether the application has been cracked

                          Would be interesting to hear how it works ;-)
                          If someone really wants to hack/crack your app, which I generally doubt, your "crack detection" mechanism would get bypassed as well somehow.

                          Edit:

                          Also, I think if you want to let your app crash in a "controlled" way, as soon as you have "detected something suspicious", you can throw exceptions instead of accessing an invalid pointer or perform some other "illegal" actions to make your program crash randomly (in an uncontrolled way).


                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          1 Reply Last reply
                          0
                          • JonBJ JonB

                            @Blackzero

                            how to make an app crash

                            There are many programmers you could employ where this would be the outcome :)

                            Well there's nothing particular for this in Qt but plenty of possibilities in C++. Write code to divide by 0, dereference a nullptr, I think the library function _abort()/std::abort() will "crash" your app even in release compilation, etc. Or execute while (true) ::sleep(1);, that's not going anywhere.

                            A Offline
                            A Offline
                            Asperamanca
                            wrote on last edited by
                            #13

                            @JonB said in how to make an app crash:

                            @Blackzero

                            how to make an app crash

                            Write code to divide by 0, dereference a nullptr,

                            Not a good idea. This us undefined behavior, and the compiler can do what it wants. It could e.g. optimize the whole checking function away. I liked your other suggestions better :-)

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved