binary to C (gcc GNU/Linux compiled machine code)

C

catcalls

Hi groupies,

Any program for GNU out there that basically converts the machine code
generated by GCC back to C?

Tried searching the group, could not find anything.

Basically, in a nutshell, I wrote a C program under GNU/Linux a few
years ago using standard C libraries to boot. And compiled it, but
lost the source code to the program. Now, all I have left is a Fedora
5 binary!

I want my source code back because it was during deep hacking on the
code that I found the solution to the problem, and I do not think I
could write the source again. Its impossible.

I just need my original C code back.

Any help?
 
I

Ian Collins

Hi groupies,

Any program for GNU out there that basically converts the machine code
generated by GCC back to C?

No. There isn't a two way translation between executables and C.
I just need my original C code back.

Any help?

Backups!
 
C

catcalls

No. There isn't a two way translation between executables and C.



Backups!

Oh, I was taking regular backups to my website. But, shortly after
finishing the code and releasing the binaries on-line, my computer
crashed hard. It was a nightmare. Just thankful that I have working
binaries after all these years.

Btw...I also have a Windows binary if there is a program for Windows
that converts machine code to C? It's standard C so I thought that it
wouldn't be a problem converting back?
 
C

catcalls

Oh, I was taking regular backups to my website. But, shortly after
finishing the code and releasing the binaries on-line, my computer
crashed hard. It was a nightmare. Just thankful that I have working
binaries after all these years.

Btw...I also have a Windows binary if there is a program for Windows
that converts machine code to C? It's standard C so I thought that it
wouldn't be a problem converting back?

http://www.hex-rays.com/decompiler.shtml

See, I found this program. But, I was wondering if there is a GNU
version? For GCC compiled code?
 
S

Seebs

Any program for GNU out there that basically converts the machine code
generated by GCC back to C?

Short answer: Yes.
Equally good short answer: No.
Tried searching the group, could not find anything.

That's because gcc-specifically, it's not topical here. Generically,
it's mostly not possible.
I want my source code back because it was during deep hacking on the
code that I found the solution to the problem, and I do not think I
could write the source again. Its impossible.

I'd guess you could.
I just need my original C code back.

If you didn't compile with full debugging symbols, you are probably
screwed.

-s
 
J

Jorgen Grahn

No. There isn't a two way translation between executables and C.

Well, there *is*, but the C code wouldn't look anything like what he
originally wrote. It would look more like the source for an x86 (or
whatever architecture he used) emulator.

There might exist such a program ... but the audience would be very
small and so would the benefits.

/Jorgen
 
K

Keith Thompson

catcalls said:
Any program for GNU out there that basically converts the machine code
generated by GCC back to C?

Tried searching the group, could not find anything.

Basically, in a nutshell, I wrote a C program under GNU/Linux a few
years ago using standard C libraries to boot. And compiled it, but
lost the source code to the program. Now, all I have left is a Fedora
5 binary!

I want my source code back because it was during deep hacking on the
code that I found the solution to the problem, and I do not think I
could write the source again. Its impossible.

I just need my original C code back.

Too much information is lost during compilation for it to be
possible, even theoretically, to get your original C code back from
an executable. (Well, a compiler could maintain enough information
in the generated executable to allow this, but in practice they
don't.)

For example, compilation (and linking) will almost certainly lose
the names of any identifiers that aren't externally visible, and may
lose the externally visible ones as well. A for loop and a while
loop might result in identical machine code; there's no way to tell
which one was originally written. And if the code was compiled
with optimization, it's likely to be mangled beyond recognition.
It's like reconstructing a raw egg from an omelette.

It's certainly possible, given an executable, to generate a C
program that has the same behavior, but it's not at all likely to
be legible or maintainable.
 
C

Chris H

In message <[email protected]
..com> said:
Hi groupies,

Any program for GNU out there that basically converts the machine code
generated by GCC back to C?

Tried searching the group, could not find anything.

Basically, in a nutshell, I wrote a C program under GNU/Linux a few
years ago using standard C libraries to boot. And compiled it, but
lost the source code to the program. Now, all I have left is a Fedora
5 binary!

I want my source code back because it was during deep hacking on the
code that I found the solution to the problem, and I do not think I
could write the source again. Its impossible.

I just need my original C code back.

Any help?

You don't say what the target MCU/CPU is or if it runs on an OS/RTOS

There are tools that help automate the process but nothing that is fully
automatic.

Unless you had all the debug information compiled in you will have to
manually name all the variables.

Due to optimisation etc within the compiler and linker you will never
get back to the original source code. Especially as GCC is not ISO-C

I have tools that can do some of the work but it is only a semi
automatic process. It is probably far better to start again.
 
C

catcalls

In message <[email protected]










You don't say what the target MCU/CPU is or if it runs on an OS/RTOS

There are tools that help automate the process but nothing that is fully
automatic.

Unless you had all the debug information compiled in you will have to
manually name all the variables.

Due to optimisation etc within the compiler and linker you will never
get back to  the original source code. Especially as GCC is not ISO-C

I have tools that can do some of the work but it is only a semi
automatic process.  It is probably far better to start again.

Thanks for all the replies. I guess I should just be thankful that I
have working binaries for Windows and GNU.

At least I can use the programs as I intended them to be used ~ but ~
for how long?
 
N

Nick Keighley

Any program for GNU out there that basically converts the machine code
generated by GCC back to C?

sort of.
Tried searching the group, could not find anything.

such programs are called decompilers. They don't work very well as too
much information is discarded in the compilation process.
Basically, in a nutshell, I wrote a C program under GNU/Linux a few
years ago using standard C libraries to boot. And compiled it, but
lost the source code to the program. Now, all I have left is a Fedora
5 binary!

I want my source code back because it was during deep hacking on the
code that I found the solution to the problem, and I do not think I
could write the source again. Its impossible.

its morepossible to reconstruct your program than it is to decompile
it. Use the executable as a specification and write a program that
does the same thing. What sort of "deep hacking" were you doing that
is so hard to duplicate?
 
G

Geoff

Hi groupies,

Any program for GNU out there that basically converts the machine code
generated by GCC back to C?

Tried searching the group, could not find anything.

Basically, in a nutshell, I wrote a C program under GNU/Linux a few
years ago using standard C libraries to boot. And compiled it, but
lost the source code to the program. Now, all I have left is a Fedora
5 binary!

I want my source code back because it was during deep hacking on the
code that I found the solution to the problem, and I do not think I
could write the source again. Its impossible.

I just need my original C code back.

Any help?

Start writing the application again.

Decompiling, as others have stated, isn't possible. What you get is a
very poor decompilation at best. Reverse engineering the binary is
actually more difficult than the task you face of re-writing the
application from memory. Who knows, you might even code it better.

Faced with a binary, you first have to disassemble it, then in a
step-wise series of iterations, identify variables and bits of code
and eventually get to an assembly listing with enough human readable
information that you can identify library calls and argument values
such that you can write C functions based on the disassembled code.
You not only have to know C, but you have to know assembler, the
target environment and the insides of the compiler that generated the
code.

The effort of all this is expensive, time consuming and unwarranted
except where the value of the code is extremely high or the size of
the program is very small. Reversing is usually only possible for very
small programs like worms and viruses where the analysis is needed to
fix the vulnerabilities they exploit.
 
S

Stephen Sprunk

At least I can use the programs as I intended them to be used ~ but ~
for how long?

The Linux one will probably work for decades; the Windows one may well
stop working (correctly or at all) with your next OS upgrade.

In either case, though, the problem is rarely that the program's
behavior changes; it's that your definition of "working" changes and,
without the ability to change the program to keep up, you'll gradually
find it less and less useful.

S
 
E

Eric Sosman

The Linux one will probably work for decades; the Windows one may well
stop working (correctly or at all) with your next OS upgrade.

*No* Linux program, not even one, has worked "for decades."

(Hint: Torvalds *started* developing Linux in 1991, slightly
less than "decadeS" ago.)
In either case, though, the problem is rarely that the program's
behavior changes;[...]

True. Linux' threading model and libc implementation have been
rock-stolid. (Right?)
 
S

Seebs

An executable doesn't know what compiler it came from. A decompiler should work
as well regardless of the source language or compiler.

Not true. You can recognize idioms used by a particular compiler.

-s
 
I

ImpalerCore

Hi groupies,

Any program for GNU out there that basically converts the machine code
generated by GCC back to C?

Tried searching the group, could not find anything.

Basically, in a nutshell, I wrote a C program under GNU/Linux a few
years ago using standard C libraries to boot. And compiled it, but
lost the source code to the program. Now, all I have left is a Fedora
5 binary!

I want my source code back because it was during deep hacking on the
code that I found the solution to the problem, and I do not think I
could write the source again. Its impossible.

I just need my original C code back.

Any help?

If it was a mechanical hard drive crash, you may be able to recover
something from the drive if you can find a company that can reseat the
magnetic disk in a new enclosure and try to probe the directory and
file structures for your source code files. It's somewhat costly and
not guaranteed to work, but it's an option for the desperate.

Consider it an expensive and important lesson in backup management. I
backup my work daily on my own personal USB stick, an external hard
drive, a network backup, which is then sent to tape each night (though
IT has been periodically undependable) to backup my work. I have had
two of those options go down at the same time, but not all four.

If you're willing to invest in some public or private online source
repository, it can be another option to backup your code online.

Good luck.
John D.
 
R

robin

| Hi groupies,
|
| Any program for GNU out there that basically converts the machine code
| generated by GCC back to C?
|
| Tried searching the group, could not find anything.
|
| Basically, in a nutshell, I wrote a C program under GNU/Linux a few
| years ago using standard C libraries to boot. And compiled it, but
| lost the source code to the program. Now, all I have left is a Fedora
| 5 binary!
|
| I want my source code back because it was during deep hacking on the
| code that I found the solution to the problem, and I do not think I
| could write the source again. Its impossible.
|
| I just need my original C code back.

The best way is via necktop computer.
 
A

Angel

I want my source code back because it was during deep hacking on the
code that I found the solution to the problem, and I do not think I
could write the source again. Its impossible.

I just need my original C code back.

To do this you need a tool called a decompiler. However, since a lot of
metadata gets lost during compilation (even more so if the binary is
stripped aftterwards), results may leave a lot to be desired.

I may be mistaken, but I don't think there are any GNU tools that do
this. The closest thing would be gdb, the GNU debugger, which can at
least tell you what your program is doing.

You may be better of just rewriting your program. I'm sure people here
can help you if you encounter a problem you can't solve by yourself.
Maybe you should describe the actual problem here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,006
Latest member
LauraSkx64

Latest Threads

Top