element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Self-Destructing arduino code
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 29 replies
  • Answers 1 answer
  • Subscribers 406 subscribers
  • Views 3439 views
  • Users 0 members are here
  • self.destructing.arduino.code
Related

Self-Destructing arduino code

dirtdiver
dirtdiver over 12 years ago

Hi everyone,

   so I've been wondering if there is a way to make a hidden button on a device (device wokring with ardunino) that will (once pressed) render the code useless - for example to delete values (val1, val2 ...) or in any way destroy the program that runs that device.

Any ideas?

Thanks,

Lubo (Bo)

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 12 years ago in reply to dirtdiver +2
    Don't patent it! I tell you, it's a waste of time, money and effort. You need to pay thousands of dollars, and here's the worst part: you have to publish a detailed description of your product and how…
  • sonuame
    sonuame over 12 years ago in reply to Former Member +2
    @Rahul,, yeah i am agreed to you , I just told that Reset pin is too much a easy way to stop execution of the microcontroller for that complex machine. sure continously reading the EEPROM values sometimes…
  • ntewinkel
    ntewinkel over 12 years ago in reply to sonuame +2
    I really like Sunil's idea of it only checking after a few days! Much less obvious that way. You might also make it use a jumper on pins instead of a button, to prevent accidental presses. You could probably…
Parents
  • Former Member
    0 Former Member over 12 years ago

    Yeah, you have 1K of internal EEPROM to mess around with, and it's dead easy to control with Arduino. You can do what Nico suggested and make the thing check for the important variable first before executing the never ending loop. Something like this (pseudocode, ceebs to write the real thing):

     

    //burn this program to the Arduino first

     

    void setup()

    {

         //write, say, the number 123 to eeprom adress 7 (completely arbitrary numbers I chose)

    }

     

    void loop()

    {

         //nothing to do here

    }

     

    //then erase that old program and write this new one

     

    void setup()

    {

         //whatever your normal code would require in the setup goes here

    }

     

    void loop()

    {

         while(eeprom adress 7 == 123)

         {

              //work properly

     

              if(secret button pressed)

              {

                   //clear EEPROM address 7

              }

     

         }

            lcd.print ("don't mess with a programmer");

    }

     

    I just thought of this code off the top of my head, I'm sure you can make it more efficient, maybe by using interrupts or something. No need for a keypad system or anything, unless you really want some password feature built into it. To reprogram the chip just pull it out of the DIP socket and stick it in your Arduino board, or include an ISP header in your design.

     

    Really cool project btw, hope it all goes well image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 12 years ago

    Yeah, you have 1K of internal EEPROM to mess around with, and it's dead easy to control with Arduino. You can do what Nico suggested and make the thing check for the important variable first before executing the never ending loop. Something like this (pseudocode, ceebs to write the real thing):

     

    //burn this program to the Arduino first

     

    void setup()

    {

         //write, say, the number 123 to eeprom adress 7 (completely arbitrary numbers I chose)

    }

     

    void loop()

    {

         //nothing to do here

    }

     

    //then erase that old program and write this new one

     

    void setup()

    {

         //whatever your normal code would require in the setup goes here

    }

     

    void loop()

    {

         while(eeprom adress 7 == 123)

         {

              //work properly

     

              if(secret button pressed)

              {

                   //clear EEPROM address 7

              }

     

         }

            lcd.print ("don't mess with a programmer");

    }

     

    I just thought of this code off the top of my head, I'm sure you can make it more efficient, maybe by using interrupts or something. No need for a keypad system or anything, unless you really want some password feature built into it. To reprogram the chip just pull it out of the DIP socket and stick it in your Arduino board, or include an ISP header in your design.

     

    Really cool project btw, hope it all goes well image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • ntewinkel
    0 ntewinkel over 12 years ago in reply to Former Member

    From what I understand, eeprom gets cleared when you upload a new sketch (you might want to test that just to make sure, of course).

     

    Also, from the docs for Read, it mentions that the value will be 255 if that location hasn't been written.

     

    So you'd simply have to do something like this:

     

    void setup() {

    }

     

    void loop() {

     

         while (EEPROM.read(0) == 42) {  // you can use your own favourite number as the flag, of course.

              // self destruct button has been pressed

              // maybe blink a light indicating "malfuntion" ?

         }

     

         // do regular work

     

         if (selfDestructButtonWasPressed()) {

              EEPROM.write(0, 42);

         }

     

    }

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mcb1
    0 mcb1 over 12 years ago in reply to ntewinkel

    Nico

    The EEPROM doesn't get overwritten with a new sketch.

    You need to clear it. there is an example under the EEPROM library.

     

    There are are limited number of writes, but unlimited reads.

     

    I've been using it to store the date when the Go button is pressed. Each reboot checks to see if the new date is greater then the EEPROM, and acts accordingly.

     

    dirtdiver

    A word of caution.

    I would check to see if 'time bombs' and the like are legal.

    It might pay to ensure the client is aware of these and accepts them. (in writing)

     

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • ntewinkel
    0 ntewinkel over 12 years ago in reply to mcb1

    Thanks Mark, that's good to know. I had done a quick search and I must've gotten something outdated or just wrong image

    So that would mean dirtdiver would just need a separate sketch to clear the one memory address he is using as the flag.

     

    Interesting point about the legal side of it. I once put a time limit on a custom app, requiring a typed-in key to unlock it, and I'm pretty sure I would not have gotten paid without it!

     

    dirtdiver, In terms of the number of writes available, you would only write the one memory location once per self-destruct button press. Or if the trigger is time related I suppose you could check it before writing so you don't re-write it unnecessarily.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • dirtdiver
    0 dirtdiver over 12 years ago in reply to ntewinkel

    yes in terms of number of writes available i will be OK, and as far as the legal side goes im not selling this im getting involved in a partnership, and the club is not mine so whats stopping the guy from saing thats his, i have no way of proving that i made the simulator and like i said i can gain leverage when i simply render the teensy useles. (I am also thinking about patenting the simulator but im not sure how to do that or what will the cost or time be like)(The other possibility is a contract which i will look into)

     

    Anyway thanks for the help,i will keep you posted on my progress!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago in reply to dirtdiver

    Don't patent it!

     

    I tell you, it's a waste of time, money and effort. You need to pay thousands of dollars, and here's the worst part: you have to publish a detailed description of your product and how it works! You're just making it a hundred times easier for some el-cheapo manufacturer to copy it! They won't care if you have a patent. If you do decide to sue someone over copying it, then that's going to set you back quite a bit for a lawyer! There's no way, even if you win, that you'll get that much money back from the patent.

     

    If you decide to sell it (perhaps on a large scale) then there are precautions you can take to stop people from copying it. For example, you could get a custom PCB built for it, and sandpaper off all the markings on the ICs. If and when you decide to go big, then maybe a patent might be feasable. Also, if you don't really care about the money, and just want to get recognised, a patent might be a good idea, even now. Just know that you'll be paying a LOT of money for it. Think of how many goodies you can get on this website for $5000!

     

    ---

     

    Also, @Sunil, the EEPROM method may not necessarily be the best way. In fact, there may not be a 'best' way at all. It's one way of doing things, and it seems feasable. It all depends on what the kill switch is for, how much effort you are willing to go to write the code, how good you are at coding, your time constraints, etc, etc, etc. This kill switch idea is good, but I can see it causing some disputes. A dedicated self destruct button will tick off the club owner much more than a simple discreet reset switch (which by the way, is not analogue as you mentioned before - analogue refers to a range of voltages in this case, the reset switch still uses digital logic), and you can still use the switch for leverage. Just tell the guy you need to take it for 'servicing' and secretly flip the switch while pretending to calibrate stuff, and give him a long technincal explanation as to why it went bust, like "the internal temperature of the dual H-bridge stepper driver rose too far beyond the nominal". He won't know you designed it for leverage (which I'm sure will make him mad and ruin the partnership), but he will know that only you can fix it, which gives you the leverage. Also it requires no extra coding. In addition to this, constantly checking the EEPROM might be quite taxing to the microcontroller, especially since it's doing a LOT of other work - this simulator is pretty complex! You might find that it decreases performance. This might be in the form of jittery servos for example - even with simple programs, if the MCU is checking constantly for, say, a timer value, then the servo just freaks out and goes all over the place! You could optimise this out using interrupts and all that but that just adds to the complexity of your program!

     

    Again, this is also just one way of doing things. It may or may not be better than the EEPROM method, but it's up to dirtdriver to decide image

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • sonuame
    0 sonuame over 12 years ago in reply to Former Member

    @Rahul,,

    yeah i am agreed to you , I just told that Reset pin is too much a easy way to stop execution of the microcontroller for that complex machine.

     

    sure continously reading the EEPROM values sometimes may delay in response and surely it will impact the servo one day theoretically...but so far now I have not seen such a case yet..May be i have to do some more EEPROM stress analysis.

     

    What if we mount a small RTC IC (DS1307) and read the EEPROM values after a specefic period of time say once in 2 days or 4 days etc...coz that will surely give the chip some time to relax. And if the value is not there after 2 days...Simulater will shutoff...!! until unless the value is not saved in it again.

     

    DS1307 can last upto 5yrs approx with a single coin cell and we can detect from the Arduino or any other Microcontroller wether RTC is running or not, just incase if somebody plugs out the cell from it and make our program much stable and secured with it...

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • dirtdiver
    0 dirtdiver over 12 years ago in reply to sonuame

    Yeah, thats what i heard about the patenting too, so its out of the game,

    also im not worried about reverse engineering couse all they are going to see is the teensy the code in it cant be extracted as far as I know (it can but it will be all messed up and not full- it will be pretty useles)

    I have a friend lawyer, i will talkmto him about a shor contract declaring that i have rights over the simulator or something similar i dont know yet .

    Im not a good programer,as you can see from the simulator i dont have that kind of money to fool around with image, i dont have much time,I will try the EEPROM (at least for the educational purpose of it , but if it slows down the program, then i wont use it)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • ntewinkel
    0 ntewinkel over 12 years ago in reply to sonuame

    I really like Sunil's idea of it only checking after a few days! Much less obvious that way. You might also make it use a jumper on pins instead of a button, to prevent accidental presses.

     

    You could probably just use millis() to check, as it rolls over after 50 days, which gives plenty of time: http://arduino.cc/en/Reference/millis

    So you could check at startup, and every time millis() is divisible by, say, 200,000 (2.3 days).

     

    Kind of like this:

     

    void setup() {

           if (EEPROM.read(0) == 42) {

                selfDestructLoop();

           }

    }

     

    void loop() {

     

         if (millis() % 200000ul == 0) {  // test with a smaller number. I think you need the "ul" to indicate "unsigned long" to allow for the big number.

              if (EEPROM.read(0) == 42) {

                   selfDestructLoop();

              }

         }

     

         // do regular work

     

         if (selfDestructButtonWasPressed()) {

              EEPROM.write(0, 42);

         }

     

    }

     

    void selfDestructLoop() {

         // blink the warning light.

    }

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • sonuame
    0 sonuame over 12 years ago in reply to ntewinkel

    @Nico,,

    I guess, millis() gets reset once the sim is shutdown, hw exactly we can track the number of days passed

     

    For me RTC was the good choice for the timing purpose..its small, cheap and very much reliable

    I hve made a number of RTCs at home.

     

    @dirtdriver

    So you started the work dude....!!!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • ntewinkel
    0 ntewinkel over 12 years ago in reply to sonuame

    Hi Sunil,

     

    I agree, millis() gets reset on startup. My thought was that if the sim is running and the button was pressed, it would run for a few days and then shut down. If it is restarted anytime sooner after the button was pressed, it would fail immediately and it would look like there was a startup failure of some sort.

     

    I do like your RTC idea too - they're not too pricey either.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube