
Ask HN: How to Decode .exe Binary to Recover Source Code - linuxdeveloper
Hello Hackers,<p>I recently came upon some school work of mine, code I wrote, from high school in 2001 as a sophomore.<p>For my high school CS101 class, I wrote a C++ game called Snake. The game was written using a graphics library called Allegro (https:&#x2F;&#x2F;www.allegro.cc&#x2F;). Allegro was a lovely library.<p>It is still possible to download the original zipped binaries which I uploaded 19 years ago. They can be downloaded here: https:&#x2F;&#x2F;www.allegro.cc&#x2F;depot&#x2F;snake2<p>I also put them online here: https:&#x2F;&#x2F;github.com&#x2F;natehouk&#x2F;snake<p>(There is also a second game Mastermind available here https:&#x2F;&#x2F;github.com&#x2F;natehouk&#x2F;mastermind and here https:&#x2F;&#x2F;www.allegro.cc&#x2F;depot&#x2F;mastermind)<p>Unfortunately, I can not find the source code anywhere. I am very saddened by this. I thought it would be very fun to see code I wrote when I was 15, nearly 20 years ago. It would be especially fun to see how I&#x27;ve improved, or what neat tricks I came up with at that young age.<p>I have the .exe and the .dat data files and the original readme.txt. I have tried running my program on Windows 10 and with Wine. In both cases, the program crashes. I have tried all of the compatibility modes in Windows 10 and none of them work.<p>The year was 2001, so I believe we must have been using Windows 98 in the classroom, maybe Windows NT 2000? I can&#x27;t remember.<p>I know that my program ran great back in the day. It even got 100,000 downloads off Download.com back then before cnet ruined them.<p>I want to play my game. What can I do to get my program running again? It seems like Allegro is barely supported these days. I think I need to try a native Windows 2000 install. Was it naive of me to think I would easily be able to run a program from nearly 20 years back?<p>What tools are available and what is state of the art for decoding a compiled binary back into readable source code?<p>Thanks for any info.
======
alltakendamned
A first step can be disassembling and then decompiling the binary. A good,
free tool for this is Ghidra: [https://ghidra-sre.org/](https://ghidra-
sre.org/)

It will not give you code that you can recompile, but it should be possible to
understand and recreate the code based on the result of decompiling the
software

An alternative approach can be to emulate the binary under e.g. qemu

------
non-entity
The easiest way to run it would probably be running an older windows version
on a VM. Maybe not 2000, but something like XP might work?

I suppose you could always reverse engineer it worst case, but that's probably
a much more work than you're looking to do, especially without any debug
symbol info.

~~~
Keverw
Yeah. I think around Vista something changed with compatibility. If I remember
the more expensive version of Vista had a way to get a included XP virtual
machine... so I think a VM might be the best idea.

Edit: oh Windows 7 includes a XP mode that uses a VM in seemless mode and
already licensed bundled with your 7 license.
[https://en.m.wikipedia.org/wiki/Windows_Virtual_PC](https://en.m.wikipedia.org/wiki/Windows_Virtual_PC)

Also surprised they did programming in high school, especially back then... I
guess my school just sucked compared to others... there’s some guy I used to
talk to said their school used all iMacs while someone else has a robotics
club! While we had old machines not even meeting the minimum windows specs...

~~~
non-entity
> Also surprised they did programming in high school, especially back then...
> I guess my school just sucked compared to others...

My HS didn't have programming classes either (although they were added the
year after I graduated) and that that was I the 2010s. I took a networking
course that would have yielded certs, but they decided to scrap that path when
I was a senior.

------
jg23497
Unfortunately, obtaining the source code used to produce a C++ executable from
only the executable itself is an unsolved problem and reverse engineering is a
generally difficult and labour-intensive process. However, there are tools
that will help to reduce the level of pain involved.

The Hex-Rays Decompiler for IDA Pro will produce a remarkably good result in
functional terms, but its output won't closely resemble the code you remember
writing.

Ghidra looks like a good open-source alternative, though I haven't tried it
myself.

------
kleer001
What you're asking for is skill held by a well paid discipline within the
practical arm of the computer science industry. In other words, some people
spend their entire careers on reverse engineering compiled binaries. And
there's a whole fascinating back and forth arms race between them and people
who don't want their code decompiled.

------
im3w1l
I don't have answers to your questions, but I can offer one piece of advice.
The program is compressed with UPX, and you must decompress it before you
decompile it.

