Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > binary to C (gcc GNU/Linux compiled machine code)

Reply
Thread Tools

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

 
 
catcalls
Guest
Posts: n/a
 
      01-09-2011
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?
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      01-09-2011
On 01/ 9/11 05:08 PM, catcalls wrote:
> 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!

--
Ian Collins
 
Reply With Quote
 
 
 
 
catcalls
Guest
Posts: n/a
 
      01-09-2011
On Jan 9, 4:14*am, Ian Collins <(E-Mail Removed)> wrote:
> On 01/ 9/11 05:08 PM, catcalls wrote:
>
> > 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!
>
> --
> Ian Collins


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?
 
Reply With Quote
 
catcalls
Guest
Posts: n/a
 
      01-09-2011
On Jan 9, 4:23*am, catcalls <(E-Mail Removed)> wrote:
> On Jan 9, 4:14*am, Ian Collins <(E-Mail Removed)> wrote:
>
>
>
> > On 01/ 9/11 05:08 PM, catcalls wrote:

>
> > > 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!

>
> > --
> > Ian Collins

>
> 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?
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      01-09-2011
On 2011-01-09, catcalls <(E-Mail Removed)> wrote:
> 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
--
Copyright 2010, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
Uno
Guest
Posts: n/a
 
      01-09-2011
On 1/8/2011 9:27 PM, catcalls wrote:

> 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?


If there is one, I'd like to see how it works on the average K&R2
problem, as shown on the wiki.
--
Uno


 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      01-09-2011
On Sun, 2011-01-09, Ian Collins wrote:
> On 01/ 9/11 05:08 PM, catcalls wrote:
>> 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.


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

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-09-2011
catcalls <(E-Mail Removed)> writes:
> 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.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Chris H
Guest
Posts: n/a
 
      01-09-2011
In message <(E-Mail Removed)
..com>, catcalls <(E-Mail Removed)> writes
>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.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



 
Reply With Quote
 
catcalls
Guest
Posts: n/a
 
      01-09-2011
On Jan 9, 9:54*am, Chris H <(E-Mail Removed)> wrote:
> In message <(E-Mail Removed)
> .com>, catcalls <(E-Mail Removed)> writes
>
>
>
> >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.
>
> --
> \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
> \/\/\/\/\ Chris Hills *Staffs *England * * /\/\/\/\/
> \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/


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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reading binary data from a 32 bit machine on 64 bit machine harijay Python 2 02-19-2009 08:31 PM
If I create a page, then it's compiled upon first request, where cani find the compiled code?? lander ASP .Net 5 03-05-2008 04:34 PM
Segmentation fault when compiled binary is executed nae zot bba la C Programming 12 01-12-2006 06:43 PM
g++ compiled C++ code called from gcc compiled C code Klaus Schneider C++ 1 12-02-2004 01:44 PM



Advertisments