Does anyone know how one can take a program already burned onto an ATMega168 and upload it to the Arduino IDE? Does the program itself contain this functionality, or is there a standalone program that would allow one to do so? Would such a program only give one access to the C code that the IDE creates from the Arduino IDE's libraries? Thank you in advance for your thoughts.
You want to decompile a program already on the chip?
Thanks for the quick response! Yes thats correct, I believe. I may be using my language imprecisely as a newbie, so let me try to clarify: I wrote a program, uploaded it to ATMega168 and neglected to save it. Therefore, although I have already re-written the program, I would like to know if there is a way to decompile the program on the chip, and again access the code as I had originally written it within the Arduino IDE.
Its probably theoretically possible but I havent heard of any tools to do it.
I would be interested in any thoughts you have about what challenges exist in doing so. My understanding of the flow of operations is that when one programs in the Arduino IDE, they do so in a sort of meta-language which is sequentially translated to C++ -> C -> Assembly -> Binary (?). Would the challenge be two folded: (1) taking this final form of the code (binary?) and decompiling it back up the chain to C++ then ultimately the Arduino's version of it; (2) find a serial interface to transfer the code language stored on the Atmega168 (again, binary?) so that this hypothetical program could do its work of bringing it back up the chain?
Decompiling is easier than you'd think for the Arduino since its pretty simple.
I dont know if there are any programs which do it though.
'Binary' to Assembly is simple. They are basically identical.
I'd imagine that using a ISP cable you could download the data from the chip.
Compiling a source program like C, C++ to assembler and then binary is a one way, unreversible process. You can disassemble AVR binary using AVR Studio, but you will get assembler. Converting back to C and C++ is possible, but you will get an equivalent code, never the exact original code... The best and only tool I know is finding the author of the original program and asking for the source code! If the code is yours, and the source is lost, then it is the best time to learn AVR assembler
It's impossible to de-compile code back to C. as above comment said..
The best result just only disassembler to assembly language, and learn how code flow only.
Compiling a source program like C, C++ to assembler and then binary is a one way, unreversible process.
Well technically you can make a program read the assembly and reconstruct the control structures.
Works rather well with Java.
Its by no means impossible. Just bloody difficult.
Well technically you can make a program read the assembly and reconstruct the control structures.
Works rather well with Java.Its by no means impossible. Just bloody difficult.
:-? most absolutely impossible, C programming not like Java
when I compile
void test2(void)
{
... something;
}
void loop(void)
{
test2();
}
internal process flow is : compile -> assembler -> linker -> .hex (machine code)
if you have only .hex, there's no any algorithm to get the name "test2" back from physical address.
because no any map or hint on .hex, just equivalent code and xxx variable named in best case.
but Java can, because .jar package had store all name and also algorithm/method inside
@nkcelectronics said is right
Of course you can write a tool that converts assembler to a high level language like C, and you can obtain an EQUIVALENT code, but never exactly the SAME code (well, maybe if you try all the possible combinations, one of them IS the exact original code).
Java is a different language, as it does not compile and generate machine language. It generates a metalanguage that is interpreted by the Java Virtual Machine... I guess if you ask the Java Virtual Machine or the compiler to OPTIMIZE the code or to do dynamic native compilation, then it is probable that you will not get back the ORIGINAL code anymore... I am not sure, just guessing...
Its possible. Just rather difficult.
I dont think its been done for AVRs though.
Java's bytecode is relatively similar to assembly.
The theory is the same.