Anyone know how to decompile source code?

FleshLight

Diamond Member
Mar 18, 2004
6,883
0
71
I'm somewhat new to C++ and I'm trying to figure out how someone did their encryption in a console application.

Since it's a dos app, I don't think it would be that hard to decompile? Or am I a clueless n00b?
 

Lithium381

Lifer
May 12, 2001
12,452
2
0
Originally posted by: FleshLight
I am a clueless n00b

there we go!

I'm not quite sure what you mean by Decompile.....if you have the source code, you can reverse engineer it, and figure out what he did, but if you're working with the executable, no hope for you!

 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
Originally posted by: Lithium381
Originally posted by: FleshLight
I am a clueless n00b

there we go!

I'm not quite sure what you mean by Decompile.....if you have the source code, you can reverse engineer it, and figure out what he did, but if you're working with the executable, no hope for you!

Yeah, I think he is talking about decompiling Binaries....
 

Pex

Banned
Aug 21, 2003
1,161
0
0
if we could decompile...wouldn't someone just decompile dos and make a gui for it? kinda like finding out the source code to 3.1
 

yllus

Elite Member & Lifer
Aug 20, 2000
20,577
432
126
Okay this isn't really an area I know much about, so I may be wrong - hopefully Descartes or Ameesh can come along and clear things up. But here goes.

We can decompile any executable code, simply because if the computer can read it so can we. However, we can only decompile from machine byte code to the assembly language level. This means you'll see the code as one huge block of ASM with no defined start or end to procedures, no variable names, no comments...you're next to blind. So with enough effort you could possibly decompile even Windows XP, but the process of doing so would be defined as cruel and unusual punishment.

To make a long story short, you could do it - and the fact that it's probably a fairly small DOS program helps immensely in your rooting around in the code trying to put the pieces together. It's still going to be hell though.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Of course you can decompile it to assembly and even some form of C/C++ if that was the language used, but you don't get back the original variable names, function names, or comments.

So
shields -= (laser_power / distance) ;
update_hud( HUD_SHIELDS );

becomes
v1021 -= v2345 / v2021 ;
f204( 6 ) ;

...and the tools to do it aren't free.
 

atom

Diamond Member
Oct 18, 1999
4,722
0
0
What program would that be?

If there is a program that can actually take into account so many variables (compiler, compiler version, specific optimizations enabled during compilation, platform, etc.) and get a translation even near your example, I'd be thoroughly surprised.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: atom
What program would that be?

If there is a program that can actually take into account so many variables (compiler, compiler version, specific optimizations enabled during compilation, platform, etc.) and get a translation even near your example, I'd be thoroughly surprised.
Agreed that it would look less like the original for large blocks of code, but optimization won't change function calls too much. Calls to library functions like sprintf or Win32 API functions like DrawText() would look very similar to the original source.

Dr. Dobbs and CUJ have ads for these tools, I've never had a use for them so I haven't bothered to see what platforms they currently support.

My points were:
- it's not "impossible," it's already been done for some platforms.
- the results aren't what you might then expect, i.e. you get back source, but not the original source.
 

atom

Diamond Member
Oct 18, 1999
4,722
0
0
Well, I say it's more or less impossible in the sense that he wants to decompile a C++ program to find how the original coder implemented something (although he's not really clear how specific a translation he wants). If he wants to find a functional equivalent, it's definitely possible.
 

GtPrOjEcTX

Lifer
Jul 3, 2001
10,784
6
81
it can be done, however, when the code was originally compiled, the compiler optimized it in a way where if you wanted it decompiled, the recursion/iteration originally used is gone and replaced by (in most cases) a much less optimal way.

In other words, yes it can be decompiled, but No, you will not find out how he coded it because decompiling it gives a different version of the source code than originally used.
 

FleshLight

Diamond Member
Mar 18, 2004
6,883
0
71
Oh thanks guys for the replies!

To elaborate a little bit, i was wondering if i could decrypt file.exe into file.cpp where I could just try reading the code from there. I downloaded a $120 program with a 30 day trial (legally) and disassembled it or whatever. What i was left with left me even more confused.

Of course, this is my 2nd week into this c++ class (definitely not college level) so maybe i'll understand more later.