Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reverse engineering c programs

every c program is converted to machine code, if this binary is distributed. Since the instruction set of a computer is well known, is it possible to get back the C original program?

like image 836
shreyasva Avatar asked Feb 16 '10 11:02

shreyasva


People also ask

Can C be reverse engineered?

C Code Reverser (Reverser) is designed to reverse engineer legacy C code into a model. The Reverser allows you to reverse engineer compilable C code to a model, which you may want to do for the following reasons: To view the structure of the C code in Modeler.

Which language is best for reverse engineering?

C++ If you want to crack corporate software or reverse engineer applications, you should invest your time in learning C++. The language gives you low-level access to system resources and analyzes machine code.

Can you reverse compiled code?

You can never get back to the exact same source since there is no meta-data about that saved with the compiled code. But you can re-create code out from the assembly-code. Check out this book if you are interested in these things: Reversing: Secrets of Reverse Engineering.

Should I learn C or C++ for reverse engineering?

C and C++ can be useful for reverse-engineering and finding vulnerabilities. A lot of malware is written in the C++ programming language. Thus, learning C++ is important for reading and understanding open-source code. Many cybersecurity programs, such as Nmap, the network mapper tool are created using C++.


2 Answers

You can never get back to the exact same source since there is no meta-data about that saved with the compiled code.

But you can re-create code out from the assembly-code.

Check out this book if you are interested in these things: Reversing: Secrets of Reverse Engineering.

Edit

Some compilers-101 here, if you were to define a compiler with another word and not as technical as "compiler", what would it be?

Answer: Translator

A compiler translates the syntax / phrases you have written into another language a C compiler translates to Assembly or even Machine-code. C# Code is translated to IL and so forth.

The executable you have is just a translation of your original text / syntax and if you want to "reverse it" hence "translate it back" you will most likely not get the same structure as you had at the start.

A more real life example would be if you Translate from English to German and the from German back to English, the sentance structure will most likely be different, other words might be used but the meaning, the context, will most likely not have changed.

The same goes for a compiler / translator if you go from C to ASM, the logic is the same, it's just a different way of reading it ( and of course its optimized ).

like image 169
Filip Ekberg Avatar answered Sep 28 '22 17:09

Filip Ekberg


It depends on what you mean by original C program. Things like local variable names, comments, etc... are not included in the binary, so there's no way to get the exact same source code as the one used to produce the binary. Tools such as IDA Pro might help you disassemble a binary.

like image 21
Darin Dimitrov Avatar answered Sep 28 '22 18:09

Darin Dimitrov