# Is it possible to extract code from an arduino board?

Is there a way to export code for an arduino even as a hex file?

• Yes, using avrdude from the command line, unless the security fuse has been set. It might even be possible then, but intentionally much harder, and not clear if anyone has yet defeated that security mechanism. – Chris Stratton Mar 15 '13 at 21:56
• @ChrisStratton I was listening to a defcon talk where they talked about how it had been defeated. I can't remember which one it was, but google might remember. – Hair_of_the_Dog Mar 15 '13 at 21:58
• It has been defeated for some microcontrollers, and not (at least to public knowledge, short of physical dissection) yet for others. – Chris Stratton Mar 15 '13 at 22:00
• Yeah, I'm pretty sure it was dissected. – Hair_of_the_Dog Mar 16 '13 at 2:24

## 2 Answers

Perusing the source code of the Arduino bootloaders at https://github.com/arduino/Arduino/tree/master/hardware/arduino/bootloaders it appears that they do in fact support the stk500 readback functionality for flash memory, such that you can accomplish your goal with a client program such as avrdude.

So the answer to the question is that if you can access the bootloader, then yes you can read out the contents of the flash memory in a binary or hex format, without resorting to an external programmer.

If you cannot access the bootloader (reset troubles, or no intact bootloader present) then you may be able to do so with an external programmer, provided security fuse settings do not prevent this.

• It turns out that not only is readback supported, the default avrdude verify behavior relies on it as it works by reading back a buffer and performing comparison on the PC. So essentially, anyone who has ever uploaded code to an ATmega based Arduino by letting the IDE invoke avrdude with the default configuration, has also implicitly read one out. – Chris Stratton Feb 4 '18 at 21:53

Yes, I have successfully pulled the boot kernel from one Arduino Board via ISCP and pushed it into another. The security fuses were not set. where avrdude will work. Back then I used AVR Studio with a STK500 as it had a GUI and I did not need to learn all the avrdude switches. Either will work.

Setting the fuse defeats open source. That said the boot kernel is provided in the IDE. ..\Arduino\hardware\arduino\bootloaders\atmega8\ATmegaBOOT.hex along with others variant chips.