On my windows PC an Arduino Uno is detected on USB serial port COM4.
So, I can open a cmd window and type
> avrdude -p atmega328p -c arduino -P com4 -U flash:r:board.hex:i
The PC will read the program in the flash memory of the Arduino Uno board and write a file to the computer called "board.hex"
Change :r: to :w: and you can write the hex file back into the flash of the Arduino. Or upload it to another board.
> avrdude -p atmega328p -c arduino -P com4 -U flash:w:board.hex:i
A program called avr-objdump will allow you to disassemble the executable code into an assembler code that you can read and reverse engineer. You are not re-creating the original source. The avr-objdump program has many options.
Avr-objdump converts executable files. Here it generates a disassembly.
Intel hex format files can be opened and read with notepad or a specialized hex reader program. Emulators can load and run the hex program just like a hardware device.
The Arduino IDE can give you a hex file through the menus Sketch->Export compiled Binary. You can generate executable hex files that will run on your Uno from IDEs like WinAVR, CodeBlocks, MPLab, AtmelStudio and from the command line.
Linux?
On linux it is almost identical. First we find the port for the Arduino by listing all teletype devices.
$ ls dev/tty*
Two Unos are in this listing. /dev/ttyACM0 is an Arduino board and /dev/ttyUSB0 is a clone board with the CH340 interface chip. Put the correct port into the command.
$ avrdude -p m328p -c arduino -P /dev/ttyACM0 -U flash:r:board.hex:i
The programmer setting is -c arduino for either type of board. The same progress is displayed.
Comments