OK, so i have a project where i have to be able to interface with an Arduino which has a unknown program saved on it and I need to find out whats going e.g what pins are being used. It also hasn't been explicitly programmed to send this information, but isn't programmed to prevent this.
how would i go about doing this?
I'm a computer science student so I'm quite ignorant to the world of electronics. basically I've spent most of my time building applications using high level languages. simple programs are all I'm intending it for due to the tediousness of it.
so what your saying it will be easier to use the assembly code to generate pseudo-code e.g.
pin 1 is doing something intresting
the led is on!
As the code gets translated to assembly, yes you have to use a disassembler
(writing it yourself will enhance the understanding of the processor but is not neccessary).
After understanding what gets translated in which assembly sequence
(which can be made very hard by the optimizer),
you could create C code that has the same functionality as the original source.
All symbolic information is gone in the flash image.
What you want to do is a bit like trying to figure out the original questions for a cryptic crossword when all you have is the completed puzzle. In fact figuring out the dis-assembled code would probably be harder.
Unless the end product is extraordinarily valuable (many £000s) I suspect it would be more cost effective just to write new code from scratch having observed how the existing system operates.
An oscilloscope or logic analyzer will tell you quickly which pins are used.
If the pins are computed you will have to (mentally) simulate it,
if the pins and the corresponding bit-pattern come from constants
they could be directly visible in the assembly.
If pinMode, analog/digitalWrite/Read routines are used it could be easy.
Robin2:
An oscilloscope or logic analyzer will tell you quickly which pins are used.
You will not be able to see digitalReads or analogReads with this technique.
Whether it will be possible to tell a INPUT_PULLUP from a digitalWrite( ,HIGH)? I don't know.
Lastly through the register(memory) access and there are some possibilities for that.
If the normal sketch compile mechanism was used
and only standard calls (pinMode etc) were used,
you could identify the routines, their calls and the parameters.
It's an iterative process in my view, I
defined a file for the current knowlegde (data/code/.. from to, digitalWrite at, ....)
created a script that generates a source from the above
created an interactive dumper/disassembler with access to the above data
run the script to generate a sourcefile
dumped and disassembled adding comments/labels/names to the knowlegde file
I repeated the last two points quite often.
Whandall:
You will not be able to see digitalReads or analogReads with this technique.
Very true. But it also implies that the OP hasn't the slightest idea what the program is trying to achieve.
It can be difficult enough to figure out what a program is intended to do when I have the source code and I wrote it
I was assuming that some knowledge of the program's effect on the outside world (i.e. its outputs) would provide most of what is needed to make another program that did the same job, but not necessarily with identical code.