de-compiler.

Discussion in 'Programmer's Corner' started by ron roberts, Jan 16, 2010.

  1. ron roberts

    Thread Starter Active Member

    May 7, 2008
    49
    0
    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.
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    991
    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,
     
  3. odinhg

    Active Member

    Jul 22, 2009
    65
    15
    If it's from an Atmel AVR, you can use AVR Studio to disassemble the hex into assembly.
     
  4. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  5. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    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.
     
  6. hgmjr

    Moderator

    Jan 28, 2005
    9,030
    214
    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
     
  7. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    991

    The opinions above regarding complexity were not directed at disassemblers. They were directed at decompilers.
     
  8. ron roberts

    Thread Starter Active Member

    May 7, 2008
    49
    0
    Thanks to all for replying. Seems like I need to learn a lot more.
     
Loading...