What is reverse engineering?
Reverse engineering is the process of taking a compiled binary and attempting to recreate (or simply understand) the original way the program works. A programmer initially writes a program, usually in a high-level language such as C++ or Visual Basic (or God forbid, Delphi). Because the computer does not inherently speak these languages, the code that the programmer wrote is assembled into a more machine specific format, one to which a computer does speak. This code is called, originally enough, machine language. This code is not very human friendly, and often times requires a great deal of brain power to figure out exactly what the programmer had in mind.
What is reverse engineering used for?
Reverse engineering can be applied to many areas of computer science, but here are a couple of generic categories;
- Making it possible to interface to legacy code (where you do not have the original code source).
- Breaking copy protection (ie. Impress your friends and save some $$).
- Studying virii and malware.
- Evaluating software quality and robustness.
- Adding functionality to existing software.
The first category is reverse engineering code to interface with existing binaries when the source code is not available. I will not be discussing this much, as it is boring.
The second category (and the biggest) is breaking copy protection. This means disabling time trials, defeating registration, and basically everything else to get commercial software for free. This we will be discussing at great length.
The third category is studying virus and malware code. Reverse engineering is required because not a lot of virus coders out there don’t send instructions on how they wrote the code, what it is supposed to accomplish, and how it will accomplish this (unless they are really dumb). This is a pretty exciting field, but requires a great deal of knowledge. We will not discuss this much until later on.
The fourth category is evaluating software security and vulnerabilities. When creating large (think Windows Operating Systems), reverse engineering is used to make sure that the system does not contain any major vulnerabilities, security flaws, and frankly, to make it as hard as possible to allow crackers to crack the software.
The final category is adding functionality to existing software. Personally, I think this is one of the most fun. Don’t like the graphics used in your web design software? Change them. Want to add a menu item to encrypt your documents in your favorite word processor? Add it. Want to annoy your co-workers to no end by adding derogatory message boxes to Windows calculator? Let’s do it. This we will be getting into later in the series.
What knowledge is required?
As you can probably guess, a great deal of knowledge is necessary to be an effective reverse engineer. Fortunately, a great deal of knowledge is not necessary to ‘begin’ reverse engineering, and that’s where I hope to come in. That being said, to have fun with reversing and to get something out of these tutorials you should at least have a basic understanding of how program flow works (for example, you should know what a basic if…then statement does, what an array is, and have at least seen a hello world program). Secondly, becoming familiar with Assembly Language is highly suggested; You can get thru the tutorials without it, but at some point you will want to become a guru at ASM to really know what you are doing. In addition, a lot of your time will be devoted to learning how to use tools. These tools are invaluable to a reverse engineer, but also require learning each tool’s shortcuts, flaws and idiosyncrasies. Finally, reverse engineering requires a significant amount of experimentation; playing with different packers/protectors/encryption schemes, learning about programs originally written in different programming languages (even Delphi), deciphering anti-reverse engineering tricks…the list goes on and on. At the end of this tutorial I have added a ‘further reading’ section with some suggested sources. If you really want to get good at reversing, I highly suggest you do some further reading.
What kinds of tools are used?
There are many different kinds of tools used in reversing. Many are specific to the types of protection that must be overcome to reverse a binary. There are also several that just make the reverser’s life easier. And then some are what I consider the ‘staple’ items- the ones you use regularly. For the most part, the tools fit into a couple categories:
1. Disassemblers
Disassemblers attempt to take the machine language codes in the binary and display them in a friendlier format. They also extrapolate data such as function calls, passed variables and text strings. This makes the executable look more like human-readable code as opposed to a bunch of numbers strung together. There are many disassemblers out there, some of them specializing in certain things (such as binaries written in Delphi). Mostly it comes down to the one your most comfortable with. I invariably find myself working with IDA (there is a free version available http://www.hex-rays.com/), as well as a couple of lesser known ones that help in specific cases.
2. Debuggers
Debuggers are the bread and butter for reverse engineers. They first analyze the binary, much like a disassembler Debuggers then allow the reverser to step through the code, running one line at a time and investigating the results. This is invaluable to discover how a program works. Finally, some debuggers allow certain instructions in the code to be changed and then run again with these changes in place. Examples of debuggers are Windbg and Ollydbg. I almost solely use Ollydbg (http://www.ollydbg.de/), unless debugging kernel mode binaries, but we’ll get to that later.
3. Hex editors
Hex editors allow you to view the actual bytes in a binary, and change them. They also provide searching for specific bytes, saving sections of a binary to disk, and much more. There are many free hex editors out there, and most of them are fine. We won’t be using them a great deal in these tutorials, but sometimes they are invaluable.
4. PE and resource viewers/editors
Every binary designed to run on a windows machine (and Linux for that matter) has a very specific section of data at the beginning of it that tells the operating system how to set up and initialize the program. It tells the OS how much memory it will require, what support DLLs the program needs to borrow code from, information about dialog boxes and such. This is called the Portable Executable, and all programs designed to run on windows needs to have one.
In the world of reverse engineering, this structure of bytes becomes very important, as it gives the reverser needed information about the binary. Eventually, you will want to (or need to) change this information, either to make the program do something different than what it was initially for, or to change the program BACK into something it originally was (like before a protector made the code really hard to understand). There are a plethora of PE viewers and editors out there. I use CFF Explorer (http://www.ntcore.com/exsuite.php) and LordPE (http://www.woodmann.com/collaborative/tools/index.php/LordPE), but you can feel free to use whichever you’re comfortable with.
Most files also have resource sections. These include graphics, dialog items, menu items, icons and text strings. Sometimes you can have fun just by looking at (and altering ) the resource sections. I will show you an example at the end of this tutorial.
5. System Monitoring tools
When reversing programs, it is sometimes important (and when studying virii and malware, of the utmost importance) to see what changes an application makes to the system; are there registry keys created or queried? are there .ini files created? are separate processes created, perhaps to thwart reverse engineering of the application? Examples of system monitoring tools are procmon , regshot , and process hacker. We will discuss these later in the tutorial.
6. Miscellaneous tools and information
There are tools we will pick up along the way, such as scripts, unpackers, packer identifiers etc. Also in this category is some sort of reference to the Windows API. This API is huge, and at times, complicated. It is extremely helpful in reverse engineering to know exactly what called functions are doing.
7. Beer.
So Let’s Get On With It, Already!
Even though we are starting with very little knowledge, I did want to give you at least a little taste of reversing in this first tutorial. I have included a resource viewer/edit in this tutorial (see the Files folder) called XN Resource Editor . It is freeware. Basically, this program allows you to see the resource section in an exe file, as well as modify these resources. I have found that you can have an awful lot of fun with these- they allow you to change the menus, icons, graphics, dialogs, you name it, in programs. Let’s try one ourselves…
First, run XN. Click on the load icon on top, and click over to Windows\System32\ and load calc.exe (you’re default windows location may vary.) You should see a bunch of folders available:
You can see that there are folders for Bitmaps (any graphics the program displays), Menu (the top menu items), Dialog (dialog boxes, along with text and buttons), String Table, IconGroup etc. You should feel free to mess around with these things. Just make sure to save it as a different file (you would hate to have to re-install windows just for the dumb calculator). In particular, try this:
Click on the plus next to Menu. You will then see a folder with a number as a name. This is the ID that windows will use to access this resource in the program. Open this folder as well. You should now see an icon for “English (United States)” or something like this. If you click on this you will see a diagram of what the menu will look like (you can even click around- it works just like a real menu).
Now, click on the menu option “Scientific”. The Caption field should change to “&Scientific”. The ampersand is there to tell you what the ‘Hot-Key’ is, in this case ‘S’. If instead we wanted the ‘e’ to be the hot-key, it would look like this “Sci&entific”. So already, don’t like the built in hot-key’s for calc? Just change them!! But let’s do something different.In the Caption field, replace the &Scientific with “&Nerd”. This will now change the menu option to “Nerd” and use the hot-key ‘N’ (I looked through the other options in the menu to make user no other menu option used ‘N’ as a hot-key). You should do this for all of the menu entries. Now, go up to File (in XN Resource) and choose “Save As…” Save your new version of calc to a different name (and preferably a different location) and then run it.
Of course, you don’t have to stop there. In order to drive my coworkers nuts, I changed all of the numbers in their calcs.
As you can see, the sky’s the limit.
Till next time…
-R4ndom
ps. Thanks go out to Lena151, for showing me the way, A.S.L., snaker, Qwerton and Jibz for showing me the secrets, and Olly , Yoda-mmi, uCF and Colin Wilson for giving me the tools.
Further Reading
1. Assembly Language. Assembly Language For Intel Based Computers is the de-facto book on it . You can also check out some web sites that offer a tremendous amount of downloads , instruction , sample code , and help . Another good resource is “The Art of Assembly”. I will be including this in one of the next tutorials, but you can also download it here .
2. The PE file structure. One of the best resources is from Microsoft themselves: “An in-depth look into the Win32 Portable Executable File Format “. Another good document (with lots of pretty pictures) is “PE File Structure “. It is a downloadable PDF.
3. Windows Operating System Internals. The de-facto book is “Microsoft Windows Internals ” by Mark Russinovich. It’s about as exciting as women’s baseball, but it is THE resource.
4. Cracking tutorials. www.Tuts4You.com is the place to be.
May 23rd, 2012 on 4:16 pm
Wow, this is very helpful! I’ve been struggling with this for YEARS, but this blog is the only one that has helped me solve my problem! YOU ARE A GOD! Thanks!
May 24th, 2012 on 4:02 am
blammo , i totally agree ~~
May 31st, 2012 on 8:59 am
How do you make a blog look this cool. Email me if you want and share your wisdom. Id be appreciative.
May 31st, 2012 on 2:25 pm
I would need you email address first. You can give it to me thru the contact button at the top of this site.
May 31st, 2012 on 7:33 pm
articles doesn’t necessarily need too much words to be good, and yours amazing.
May 31st, 2012 on 11:35 pm
true that.
June 1st, 2012 on 2:41 am
please keep the good and creative ideas coming guys.
June 1st, 2012 on 4:19 am
this is the first time i am hearing of this. thanks for the information.
June 1st, 2012 on 5:51 am
i’m sorry but i think you should improve the organization of the website.
June 1st, 2012 on 2:50 pm
I would love to. Do you have any suggestions?
June 1st, 2012 on 8:50 am
i don’t know how you can write so well, your articles are excellent.
June 1st, 2012 on 10:56 am
your posts are always so explicative, and i like it because i have a problem in understanding such things.
June 1st, 2012 on 11:20 am
i always like your posts because you have such a good way of expressing yourself, and this is a virtue in these days.
June 1st, 2012 on 12:30 pm
i would like to read your newer posts, so i will bookmark you. hope to see your updates.
June 4th, 2012 on 11:20 am
Je think cet is un de the most vital info pour moi. Et i sont satisfied studying votre article. But should remark sur some common things, le site taste est perfect, les articles sont truly excellent : D. Excellent job, acclame We’re a la liasse(le bande) de volontaires et opening a tout nouveau complote dans notre communaut�. Votre site provided nous avec valuable info work sur. Vous have performed a formidable process et notre whole neighborhood shall be thankful � vous.
June 4th, 2012 on 3:53 pm
At least if you’re going to spam my site, do it in ENGLISH!!!!
July 24th, 2012 on 2:21 pm
Does the XN Resource Editor work on Vista? Or is there a similar program I can download that does run with vista? Thanks.
July 24th, 2012 on 6:40 pm
XN does work with vista. You can also try Resource Hacker. It’s on my tools page.
July 24th, 2012 on 8:31 pm
Thanks, downloading it now. It just didn’t mention Vista.
August 6th, 2012 on 9:47 am
Hey XN Resource Editor gives a system error code 50 when I try to save the Calc.exe after changing to nerd. After researching it, this seems to be a common problem with XN Editor and was advised to use Resource Hacker or Resedit. I used both but they do not have the menu tab like XN does. Do you know where to find it on Res Hacker or Resedit? Thanks.
August 6th, 2012 on 6:29 pm
Try “Resource Tuner”
http://www.restuner.com/
August 7th, 2012 on 1:24 pm
Thanks. Resource Tuner does not open calc.exe on my 64 bit os because it says 64 bit is not supported yet. I am pretty sure that this is why XN Resource editor gave me that error code 50. Because of the 64 bit os. Thanks anyway.
December 21st, 2012 on 1:57 am
Has anyone found a resource editor that doesn’t produce the error code 50? I’m on windows 7. I’ve downloaded CFF Explorer VIII and when I open up calc.exe, there isn’t a menu items. Is this an issue with permissions or could this be a windows 7 os issue?
I would like to move to tutorial #2 but I’m concerned downloading ollydbg will produce a similar error.
Any guidance would be appreciated.
November 5th, 2012 on 10:44 pm
those series on reversing are huge, man. that stuff just RIPPED my college literature. your work is appreciated!
December 9th, 2012 on 4:33 am
I would highly recommend reading this article on reverse engineering before getting into these tutorials (don’t worry, it is written assuming you know nothing about Assembly):
http://www.ethicalhacker.net/content/view/152/2/
Even though Random’s tutorials are very easy to follow, reading this article will greatly help you understand many things he tries to teach you such as the stack/plate analogy.
January 2nd, 2013 on 8:47 pm
For PE files, I’d recommend corkami’s guide to the PE file format, since that’s what I’m familiar with, and it helped me learn the basics of the PE file format pretty quick. It’s a really big picture, a tiny bit of explanation and some sample code. That and the actual PE file specification are my go to reference on the file format. Link to the guide here:
https://code.google.com/p/corkami/wiki/PE101
February 2nd, 2013 on 2:42 am
When someone writes an post he/she keeps the thought of a user
in his/her mind that how a user can understand it. So that’s why this piece of writing is amazing. Thanks!
March 4th, 2013 on 7:26 am
I absolutely love your blog and find almost all of your post’s to be exactly what I’m looking for.
Would you offer guest writers to write content
for yourself? I wouldn’t mind composing a post or elaborating on most of the subjects you write about here. Again, awesome web site!
March 20th, 2013 on 6:29 pm
I have been surfing on-line more than three hours lately, but I by
no means discovered any fascinating article like yours.
It is lovely price sufficient for me. Personally, if all web owners and bloggers made good content material as you did,
the internet might be a lot more useful than ever before.
April 12th, 2013 on 9:56 pm
I’ll immediately seize your rss as I can’t find your email subscription link or newsletter service. Do you have any? Kindly permit me realize so that I may just subscribe. Thanks.
April 13th, 2013 on 2:30 am
Why is there the phrase “fast payday loans” hidden everywhere in the text?
April 18th, 2013 on 9:16 pm
I absolutely love your blog and find nearly all of
your post’s to be just what I’m looking for.
Does one offer guest writers to write content for you?
I wouldn’t mind writing a post or elaborating on a few of the subjects you write related to here. Again, awesome web log!
April 27th, 2013 on 7:13 pm
I know of the fact that nowadays, more and more people are being attracted to cameras and the issue of photography. However, being a photographer, you must first shell out so much period deciding the exact model of camera to buy and moving store to store just so you could possibly buy the most economical camera of the trademark you have decided to decide on. But it does not end right now there. You also have take into consideration whether you can purchase a digital digicam extended warranty. Thanks for the good suggestions I gathered from your website.
May 18th, 2013 on 5:28 am
Kaludi was arrested by SOG with Mobile Sim card obtained using fake identity.
May 21st, 2013 on 5:15 am
ynjzegdlkthl
May 21st, 2013 on 5:16 am
nkntkwwdigra
May 21st, 2013 on 5:16 am
nhzzeddvtyrd
May 21st, 2013 on 5:17 am
krgemuixomtx
May 21st, 2013 on 5:17 am
ylbqfdrcjtic
May 21st, 2013 on 5:18 am
xuocoiuaubrw
May 21st, 2013 on 5:18 am
osijrrvuciin
May 21st, 2013 on 6:41 pm
yacpltwgpalf
May 22nd, 2013 on 3:50 pm
khttcjkahbnw
May 23rd, 2013 on 1:43 am
mzvafhztdxmc
May 25th, 2013 on 6:27 am
hrddbsslfqgc
May 25th, 2013 on 8:19 pm
rhzybbxmhlml
May 26th, 2013 on 4:40 am
hmdoftzejcqp
May 26th, 2013 on 4:51 am
kreouvexqhur
May 26th, 2013 on 8:32 am
tbdjhxhsdfwj
May 26th, 2013 on 4:26 pm
ryfiarvtbrur
May 27th, 2013 on 3:18 am
cpmqpiqgoiod
May 27th, 2013 on 4:21 am
tmxabadxshno
May 27th, 2013 on 4:53 am
hkkqfwubuhod
May 27th, 2013 on 10:33 am
uixmjsitouzp
May 27th, 2013 on 5:50 pm
vsinintobwnn
May 27th, 2013 on 7:28 pm
vhshfvvlgdei
May 28th, 2013 on 7:47 am
I am truly pleased to glance at this blog posts which carries lots of
useful information, thanks for providing these data.
May 28th, 2013 on 1:05 pm
qdecymrdtqyl
May 28th, 2013 on 9:39 pm
axtmhmsdmpfk
May 28th, 2013 on 10:02 pm
dpnkearehnqs
May 28th, 2013 on 10:25 pm
vuaovxflkxgb
May 30th, 2013 on 11:26 am
dgndxneeoxrj
May 30th, 2013 on 2:41 pm
yomdtenfgidn
May 31st, 2013 on 12:50 am
anvkfjyfjeio
June 3rd, 2013 on 8:53 am
opqxavnkptxv
June 7th, 2013 on 7:30 am
My wife and i were very relieved Albert could deal with his survey with the precious recommendations he came across when using the web pages. It’s not at all simplistic to just be giving out tricks which others could have been selling. And we also do understand we now have the writer to appreciate for that. The type of illustrations you’ve made, the straightforward blog navigation, the friendships you can make it possible to engender – it’s got many fabulous, and it is leading our son and our family believe that this content is excellent, and that is seriously serious. Thanks for all the pieces!
June 18th, 2013 on 11:07 pm
Howdy, I think your blog could be having web browser compatibility problems.
Whenever I look at your site in Safari, it looks
fine however, if opening in I.E., it has some overlapping
issues. I merely wanted to give you a quick heads up!
Apart from that, excellent site!
June 23rd, 2013 on 9:30 pm
Looking forward to going through your tutorials!
July 3rd, 2013 on 5:50 am
jtwzpximrxln
September 5th, 2013 on 9:30 am
Very good tutorial. I’m a beginner in reverse engin. It helps me lot.
Thanks
September 10th, 2013 on 7:27 pm
I love this blog. Amazing..