16

Can somebody suggest me any disassembler for Atmel AVR 8-bit microcontrollers? There are opensource projects for this?

Thanx.

Eugene Burtsev
  • 1,465
  • 4
  • 24
  • 45
  • The answer was already made almost 6 years before this question `avr-objdump.exe -j .sec1 -d -m avr5 dumpfile.hex`, I tested it today because I'm working on atmega328p reverse engineering. [Information source here](https://www.avrfreaks.net/comment/158180#comment-158180) –  Mar 24 '20 at 02:02

8 Answers8

19

You can also use avr-objdump, a tool part of the avr-gcc toolset ( http://www.nongnu.org/avr-libc/ ). Ex:

avr-objdump -s -m <avr architecture> .d program.hex > program.dump

where <avr architecture> is found on http://www.nongnu.org/avr-libc/user-manual/using_tools.html

user1443332
  • 341
  • 2
  • 5
  • The command that worked for me was: `avr-objdump -s -m avr5 test.hex` – David Grayson Oct 31 '12 at 18:57
  • Hey @DavidGrayson Do you still use this program? What command is used today? I can't find a ``avr-objdump`` file to execute. – Rasmus Bækgaard Aug 10 '16 at 14:11
  • avr-objdump is part of binutils and should be available in any distribution of GCC for AVR. I would give you more specifics but you didn't say your OS. – David Grayson Aug 10 '16 at 14:50
  • 2
    These days it seems like `-s` does not give you disassembly; you have to use `-D` instead. Also, the AVR architecture argument depends on what chip you are disassembling for, and you might need to look at `config/avr/avr-mcus.def` in the GCC source code to figure out what the architecture of your AVR is. – David Grayson Sep 15 '17 at 21:48
  • For those on newer Ubuntu (22+), to install this toolset do `sudo apt install gcc-avr` – Raleigh L. Mar 20 '23 at 06:04
14

[plug]IDA Pro supports AVR disassembly[/plug]:

IDA Pro AVR disassembly

As for opensource, AVR GCC package includes a port of objdump, including disassembling functionality.

Igor Skochinsky
  • 24,629
  • 2
  • 72
  • 109
  • 1
    You can get IDA PRO for the affordable price of $1879 USD, I think it's better to stick with the [open source solution](https://stackoverflow.com/a/60824029/2188550) –  Mar 24 '20 at 02:15
6

http://www.onlinedisassembler.com/odaweb/

Lots of platforms (AVR also) but Microchip (which you didn't need either) is missing.

Big plus is that it is web based.

qratman
  • 75
  • 1
  • 8
  • Seems long on promise, short on delivery. AVR25 is garbage. Disassembly should match listing file operations. – mckenzm Feb 28 '18 at 07:19
5

Checkout vAVRdisasm.

waffleman
  • 4,159
  • 10
  • 39
  • 63
2

AVRDisassembler is an open source (MIT) AVR / Arduino disassembler written in .NET Core (which means it can run on Windows, Mac, Linux). Apart from writing the disassembly to stdout, it can also emit a JSON dump (for interopability, analysis purposes).

Disclaimer: I am the author of said library.

ChristopheD
  • 112,638
  • 29
  • 165
  • 179
0

I'm using avrdisas by Johannes Bauer. It works with dumped flash, rather than the .hex file or ELF.

Compiling the following :

  .include "tn13def.inc"
       ldi     r16,1
       out     ddrb,r16      ; PB0 as output
       sbiw    r24,1         ; slight wait
       brne    PC-1
       sbi     pinb,pinb0    ; toggle
       rjmp    PC-3          ; forever 

produces listing:

C:000000 e001             ldi     r16,1
C:000001 bb07             out     ddrb,r16      ; PB0 as output
C:000002 9701             sbiw    r24,1         ; slight wait
C:000003 f7f1             brne    PC-1
C:000004 9ab0             sbi     pinb,pinb0    ; toggle
C:000005 cffc             rjmp    PC-3          ; forever

extracting the flash contents with:

$ avrdude -p t13 -P usb -c usbtiny -U flash:r:flash.bin:r

gives: e001 bb07 9701 f7f1 9ab0 cffc

disassembly:

$ ./avrdisas -a1 -o1 -s1 flash.bin 
; Disassembly of flash.bin (avr-gcc style)

.text
main:
   0:   01 e0           ldi     r16, 0x01       ; 1
   2:   07 bb           out     0x17, r16       ; 23

; Referenced from offset 0x06 by brne
; Referenced from offset 0x0a by rjmp
Label1:
   4:   01 97           sbiw    r24, 0x01       ; 1
   6:   f1 f7           brne    Label1
   8:   b0 9a           sbi     0x16, 0         ; 0x01 = 1
   a:   fc cf           rjmp    Label1

and this works for me, even if the endian-ness does not match the listing and I would need to resolve 0x17 back to DDRB etc.

mckenzm
  • 1,545
  • 1
  • 12
  • 19
0

As opensource disassembler I've tried Radare2 which is command-line oriented but you can also use the GUI called Cutter. https://rada.re/n/

Or you can just use the classical avr-objdump:

avr-objdump.exe -j .sec1 -d -m avr5 dumpfile.hex

Information source here

-2

The question is rather about disassembling the HEX file and as a solution there are mentioned quite a lot tools above in other answers. Hard to add something more.

But if someone is looking for: it is also possible to disassemble the C/C++ while running in IDE. With Atmel studio with its integrated disassembling tool it can be done following way:

  1. Run project (it can be run in simulator without debugger hardware);
  2. Pause or stop at breakpoint;
  3. Press CTRL + ALT + D

This can be useful in order to verify that particular code fragments are compiled as needed because the optimization sometimes skips/mangles the sequence and leads to some unexpected behavior.

zviad
  • 586
  • 7
  • 18