Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: eduard2000 on October 11, 2008, 10:41:49 AM

Title: Reading micontrollers
Post by: eduard2000 on October 11, 2008, 10:41:49 AM
  I have seen non some programing programs have "read" function.  I would like to know if I  could really read PIC microcontroller  from the green board. There function of program.
Title: Re: Reading micontrollers
Post by: dsheller on October 11, 2008, 03:29:53 PM
I'm assuming you mean reading the current program on the microcontroller? I know mine can do this, but all you get out of it is the .hex file... good luck reversing that back to the original code if that is your intention.
Title: Re: Reading micontrollers
Post by: eduard2000 on October 12, 2008, 09:38:23 AM
Yes thankyou :D but can I read it?
Title: Re: Reading micontrollers
Post by: eduard2000 on October 12, 2008, 09:42:04 AM
and can i do the same thing with a green board from a garbegcan ???
Title: Re: Reading micontrollers
Post by: airman00 on October 12, 2008, 10:25:31 AM
some have blocks to read it
Title: Re: Reading micontrollers
Post by: izua on October 12, 2008, 11:47:09 AM
You are too vague and too incoherent for us to understand what you want.
To read data off a mass-produced board MCU (microcontroller unit), you'll first need to find out where are the programming pins of that MCU are. Check the datasheet and any relevant documents.
Next, trace where the respective pins lead, and make a connector suitable for the board connector. If there is no board connector (pretty likely, since mass-produced boards are contact-programmed), find a non-laquered spot on those traces, make a mirrored board of those spots, press it against the original board and make sure the mirrored traces overlap.

Next, connect the traces from your board to a suitable programmer for that MCU. Using your favourite programmer (or the suitable one) put it in read mode and pray that the code isn't protected. Which usually is, because no one likes outsiders peeking into their code. If it succeeds reading, you got yourself a nice little raw file. Using a decompiler (converts raw files to assembly instructions) if one exists for that architecture you can get a .asm.

From this point on, you need to be an assembly god in that MCU's hardware language if you want to understand what happens. Yep, no C, C++, basic or pascal will ever come out of a MCU.
Title: Re: Reading micontrollers
Post by: paulstreats on October 12, 2008, 07:21:32 PM
You can decompile assembly into c but its never a pleasant outcome.

 When the hex decompiles back into assembly you are likely to find that any handles or declared names no longer exist and they are just given refence numbers like a001 a002 a003. Its the same when decompiling this into c. If originally a variable like an unsigned int were called "time1" when it decompiles back into c from a decompiled assembly you might just get a variable called "a001" or whatever convention the decompiler uses. Its almost impossible to follow because the data names dont have any logical handles.

Also when you compile your code, a c compiler is likely to change the code including many of its original functions and structures if it feels that it can optimise your code better so what you get out of a decompiler is not likely to resemble what originally went into a compiler. So much so that if you want to copy somebody elses code thats running on an existing piece of hardware it will likely take more time than just writing your own. and thats not even taking into account any protection (mentioned above).

 Another note from the post above about accessing the hardware pins. If the programming pins are multi function and also connected to some other device on the pcb, you are likely to have to sever that devices connection to stop it interfering with read/program cycles.