de-compiler.

Thread Starter

ron roberts

Joined May 7, 2008
49
Can anyone help with this question?
Can a HEX file be reverse worked to come out with the source code?
Is there any software available that will do this?

In other words a de-compiler.
 

spinnaker

Joined Oct 29, 2009
7,830
It's possible but difficult. For starters, you would need to know which compiler compiled the hex code in the first place and most likely the version of the compiler too. Then build a decomplier for that specific target.



It would be a lot "easier" to build a disassembler that disassembled back to assembly language. There are several already out there,
 

hgmjr

Joined Jan 28, 2005
9,027
Can anyone help with this question?
Can a HEX file be reverse worked to come out with the source code?
Is there any software available that will do this?

In other words a de-compiler.
As spinnaker has stated, converting the machine code back to the original source code is very complicated since it requires knowledge about the techniques used by the programmer that are not available.

For example, the programmer may have defined an array of constants at the beginning of the program for use during the programs execution. Without knowledge of the size of this array a disassembler would have no choice but to interpret the data as code and attempt to convert it to source code. The resulting code would be incorrect since the code was actually data. This data versus code differentiation is a major obstacle to successfully disassembling machine code.

hgmjr
 

AlexR

Joined Jan 16, 2008
732
Actually contrary to the above opinions the conversion of machine code to assembler is a fairly straight foreword process (there is a 1 to 1 relationship between assembler and machine code) and you can get dis-assembler software for most micro-controllers and micro-processors.

The real difficulty lays in interpreting the resultant assembly code. It obviously will not have any comments nor even meaningful names for variables and lables. Futher more if the original code was written in a high level language the resultant assembly code will jump around all over the place with no apparent rhyme or reason. So, if the code is reasonably short and you have a good idea of what it is trying to do then it could be worth while dis-assembling it, but if the code runs to many pages then it would probably be quicker and easier to start from scratch and write your own program.
 

hgmjr

Joined Jan 28, 2005
9,027
Ron,

One thing is for sure, if the disassembled code occupies many pages, you would be spending your time more effectively if you started from scratch.

hgmjr
 

spinnaker

Joined Oct 29, 2009
7,830
Actually contrary to the above opinions the conversion of machine code to assembler is a fairly straight foreword process (there is a 1 to 1 relationship between assembler and machine code) and you can get dis-assembler software for most micro-controllers and micro-processors.

The real difficulty lays in interpreting the resultant assembly code. It obviously will not have any comments nor even meaningful names for variables and lables. Futher more if the original code was written in a high level language the resultant assembly code will jump around all over the place with no apparent rhyme or reason. So, if the code is reasonably short and you have a good idea of what it is trying to do then it could be worth while dis-assembling it, but if the code runs to many pages then it would probably be quicker and easier to start from scratch and write your own program.

The opinions above regarding complexity were not directed at disassemblers. They were directed at decompilers.
 
Top