Go Down

Topic: Copying a sketch from a microcontroller (Read 1 time) previous topic - next topic

Is it possible to copy a sketch from another microcontroller  to your pc to edit

magagna

Sort of, but not really. Given enough effort you can get the binary machine code off the chip and into a PC editor, but (A) it won't be easy, and (B) it won't be pretty.

What you're asking for is the equivalent of saying "here's a cake; how can I get the eggs back out".
http://en.wiktionary.org/wiki/magagna <-- My last name.  Pretty apt.

bobthebanana

Getting the machine code back out is easy with atmel studio or avrdude if you have an isp programmer. There's no way to get the c code back though


retrolefty

Quote
What you're asking for is the equivalent of saying "here's a cake; how can I get the eggs back out".


I like that one a lot.  ;)

Lefty

modeller


What you're asking for is the equivalent of saying "here's a cake; how can I get the eggs back out".


Not really - he doesn't want the eggs, he wants the cake recipe.

retrolefty



What you're asking for is the equivalent of saying "here's a cake; how can I get the eggs back out".


Not really - he doesn't want the eggs, he wants the cake recipe.


But his is the funnier sound bite.  ;)

modeller




What you're asking for is the equivalent of saying "here's a cake; how can I get the eggs back out".


Not really - he doesn't want the eggs, he wants the cake recipe.


But his is the funnier sound bite.  ;)


True, true ... :P

GDH5

So is there a tutorial somewhere on how I can use atmel studio or avrdude to read the data from a chip? I'm really interested in seeing if I can reverse engineer things like that...

fungus


So is there a tutorial somewhere on how I can use atmel studio or avrdude to read the data from a chip? I'm really interested in seeing if I can reverse engineer things like that...


Just grab a .hex file from any old sketch and start from there...after that you can move onto unknown sketches.


No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Erni

Take a look at6 the AVRDude tutorial here
http://www.ladyada.net/learn/avr/avrdude.html

Example:
This will copy the hexfile from arduino to the file test.hex

avrdude -pm328p -Pcom20 -carduino -D -U flash:r:test.hex:i

CrossRoads

#11
Jul 16, 2013, 03:58 pm Last Edit: Jul 16, 2013, 04:01 pm by CrossRoads Reason: 1
@GDH5,
You might be better off compiling a known sketch, then look at the .hex file that was created and see if you can work backwards from there.

There are decompiler programs such as this
https://www.hex-rays.com/products/decompiler/index.shtml

You can search for an 8-bit AVR version, some links here maybe:
http://stackoverflow.com/questions/5141177/atmel-avr-disassembler
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

GDH5

Thanks for all the advice guys... So if I understand this correctly, I will be able to read the code from the chip, and create a hex file with its contents.

Then I should be able to use that hex file to program a new board, right? And assuming all the hardware is wired up the same, it will be an exact copy?

Also, once I have the hex file, can I convert it to C, so I can read its contents?

Erni

Quote
Then I should be able to use that hex file to program a new board, right?


Yes, in the example above you could do something like this:

avrdude -pm328p -Pcom20 -carduino -D -U flash:w:test.hex:i

r - read from flash
w - write to flash

Ofcource you will have to ensure that the fuses are the same

fungus


Also, once I have the hex file, can I convert it to C, so I can read its contents?


No.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Go Up