ATMEL AVR Hex file Converted to C

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a hex file that was made from an IAR C Compiler for the Atmel AVR ATmega8535 micro about 7 years ago. Due to the lack of engineering documentation disciplines the original C source code is missing. I need to modify the code, but can't since there is no source code. Does anyone know how I can convert the hex file to C. Please, no funny comments about doing it via the brute-force-method.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Does anyone know how I can convert the hex file to C

No chance. The best you can hope for is to run the binary through a disassembler and get back to some Asm source (though the asm generate by a C compiler can be hard to follow).

If it's just an 8K micro it'd probably be quicker to study the overall operation and then just reimplement the algorithm from scratch.

By the way you posted this to the wrong forum so I'm going to move it from Academy to AVR

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Please, no funny comments about doing it via the brute-force-method.

OK, then the only comment that can be made is:

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Since there are no pieces of land that are unexplored on Earth, the remaining final frontier for would-be explorers is a 200000-line uncommented Fortran program that was written in the 1960s and is absolutely necessary to maintain. Maybe a 'doomsday' weapon floating above the earth in a secret satellite installed by 20th-century lunatics like LBJ or Bhrezhnev.

Anyway...

I would isolate the section of the program that needs to be maintained from the rest of the program. Run the Hex file through a standard hex-to-bin program and then run the resulting bin file through a disassembler program for AVR.

Programs generally have an initialization section first, then a general user-input menu. The user's selection then jumps to separate blocks for each separate program operation.

The more complex the program, the less likely that it will be to reconstruct the source from the binary. If the binary is more than a few hundred instructions, then I agree that it would be nearly impossible to reconstruct. It is best to re-write the program again from the beginning.

For small programs, have your intern find the points in the code that accept user input and trace to the section that needs modification. Now move the disassembled binary to an AVR with larger Flash memory and patch the original using RJMP instructions.

Jump to an unused section of Flash and write the modifications in assembler. When completed, RJMP back to the original code; skipping over the original code that has been changed.

This is all time-intensive, so don't do it yourself on company-time. Get some underpaid or unpaid college intern to do it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

the best you can hope for is an approximation of the original C, based on what you see in the assembly. There are no automated tools for this, and you will need to be VERY familiar with the code generator of the compiler used (version specific)

Chances are that it'll be quicker to just re-develop the app from scratch in C, based on the known specifications for the app.

Sorry to say, compiling is pretty much a one-way process.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

Sorry to say, compiling is pretty much a one-way process.

No disassemble! (Johnny 5, Short Circuit)

http://www.imdb.com/title/tt0091...

Quote:

Stephanie Speck: [they're heading for the cliff] Oh, no - Jeez! Number Five, we're gonna be killed!
Number 5: Disassemble?
Stephanie Speck: Yes, disassemble ALL OVER THE PLACE!
...
Number 5: No disassemble Number Five!

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You could use reverse psychology and say the guy that wrote the original 8535 program in IAR was a superhuman and no-one could ever write an equivalent program in cv, gcc or icc to match the code density and functionality of his program. Then post the spec, go get a cup of coffee, and in a couple hours you will have a cv, gcc and icc version of the program to test.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This the new kind of problem.
Hex to C

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

badimuz wrote:
This the new kind of problem.
Hex to C

Actually not. We see these posts every few months.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So are they always think because the C file can be generated to become Hex file. They think it would be easy to reverse process.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My recommendation is: find the dork that lost the source and beat the crap out of him. Sorry, I guess that qualifies as brute force.

Besides a rewrite, disassemble and modify. The new code could be assembly and/or C. This can be painful but it has been done many times before.

C: i = "told you so";

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
They think it would be easy to reverse process
..including comments... :?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All the comments get transformed into a whitespace program

http://en.wikipedia.org/wiki/Whi...(programming_language)