Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I decompile a .hex file into C++ for Arduino?

I have a hex file that is to be flashed onto an Atmel chip running on an Arduino device.

There are certain aspects of this file that I would like to modify before putting it onto my Arduino, but I don't have the source C++; just the hex file.

Is there any efficient way to take a .hex file and reassemble the C code? If so, how?

like image 750
Matt Cashatt Avatar asked May 23 '13 05:05

Matt Cashatt


2 Answers

This may not have been available at the time the other answers was given. It coverts the .hex back to assembler. You might need to know the architecture of the original AVR it was intended for. Works well for me for code that I wrote and compiled. I tested with AVR-25 for Tiny 85. Hope it helps. Would be nice to have an offline version of same thing! http://www.onlinedisassembler.com/ An alternative commercial option is IDA from https://www.hex-rays.com/

like image 199
cdplayer Avatar answered Sep 18 '22 14:09

cdplayer


I would look at the output of avr-objdump (gulp):

avr-objdump -j .sec1 -d -m avr5 foo.hex 

You will have to change the words following the "-m" to your architecture. Even when/if this works it will give you the Assembly code, which might not look anything you have ever written. The variable names will different, and the handy Arduino functions will look like messy Assembly junk. I hope there is a better way, sorry.

See also AVR GCC forum - Using avr-objdump to disassemble hex code.

like image 42
John b Avatar answered Sep 19 '22 14:09

John b