Pages: [1] 2   Go Down
Author Topic: Copying a sketch from a microcontroller  (Read 1545 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Southern California
Offline Offline
God Member
*****
Karma: 5
Posts: 539
I like blinky lights
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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".
Logged

http://en.wiktionary.org/wiki/magagna <-- My last name.  Pretty apt.

Offline Offline
Full Member
***
Karma: 5
Posts: 207
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for the replays
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17305
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-wink

Lefty
Logged

TX
Offline Offline
Jr. Member
**
Karma: 2
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17305
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-wink
Logged

TX
Offline Offline
Jr. Member
**
Karma: 2
Posts: 99
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-wink

True, true ... smiley-razz
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 150
Posts: 5735
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.


Logged

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

Denmark
Offline Offline
Edison Member
*
Karma: 37
Posts: 1095
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27418
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@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
« Last Edit: July 16, 2013, 09:01:25 am by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Denmark
Offline Offline
Edison Member
*
Karma: 37
Posts: 1095
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 150
Posts: 5735
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

No.
Logged

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

Pages: [1] 2   Go Up
Jump to: