Is it possible to decompile a C++ executable file [duplicate] - c++

This question already has answers here:
Is it possible to "decompile" a Windows .exe? Or at least view the Assembly?
(16 answers)
Is there a C++ decompiler? [closed]
(5 answers)
Closed 4 years ago.
I lost the source code to an executable file but still have the actual file. Is there any way to retrieve the original C++ code?

Duplicate of this question here.
Yes, it is possible, however when it comes to peeking function bodies and the like, you might have a little less luck. Operating systems like Kali Linux specialize in de-compilation and reverse engineering, so maybe look into a VM of that. And of course, windows has a lot of applications you can use as well to check the application code.
Look over the other question for specific app suggestions. :)
Edit : You will most likely have lost all your logic and function bodies, but you might be able to recover the overall structure. It's your EXE so you might be more familiar with how it was all connected up.

You cannot get the original source code but you can decompile the binary into source code using tools given in this similar question: Is there a C++ decompiler?
The output source code will not look like the original as the compiler will have optimised the original source when generating the executable.

Short answer NO.
Long answer, because C++ doesn't use some intermediate code like C# or Java you cannot decompile the app in some readable format. But if you can read assembly maybe you can save some time.

Related

Programming and platform dependance for c++ questions [duplicate]

This question already has answers here:
How to write portable code in c++?
(12 answers)
What is "Portable C++"? [duplicate]
(2 answers)
What is meant when a piece of code is said to be portable? [closed]
(3 answers)
Closed 4 months ago.
The community reviewed whether to reopen this question 4 months ago and left it closed:
Original close reason(s) were not resolved
Not sure if this is the right place to ask this:
How do programs written in c++ run on other computers if you don't write them specifically to do that? I saw something about not just sending the .exe, but also sending other things with it?
Is there a high level programming language that is as fast or nearly as fast (in run speed) as c++ while also being platform independent?
See above.
You compile your code for all the platforms you target and deploy a number of executables. Hence, Write once, compile anywhere.
C++ allows you to write portable source code. So assuming you write portable code to start with, you can compile it for some target platform, and run the resulting binary on that target.
Now, depending on what your program uses, you may have to package other "stuff" with the executable. What you mention ("I saw something about not just sending the .exe, but also sending other things with it?") would arise if your program used some dynamic link libraries that were not part of the OS (presumably Windows, based on the mention of .exe). But, it's kind of up to you to decide whether to use a library that's packaged as a DLL or not. If you don't want to package DLLs with your executable, don't use them (but sometimes, you may decide it's less trouble to use and package the DLL than do without).
As far as another language goes...doesn't really make a lot of difference as a rule. If you write code that depends on something else, you have to satisfy that dependency on the target computer. Some languages require you to add some DLLs to support the language itself, but most C++ compilers don't. On other OSes, those dependencies won't be called "DLLs", but most reasonably modern OSes provide something similar.

C++ - Create function at runtime [duplicate]

This question already has answers here:
Is it possible to create a function dynamically, during runtime in C++?
(14 answers)
Closed 8 years ago.
In C++, I have to make some user-defined actions on each cells of a big table.
Because of the size of the table, I'd like not to use interpreted instructions but to compile during runtime a function that I will call on each cell.
The user-defined actions are pretty simple :
if ((state1 && state2) || state3) then change_a_value_in_memory
That's why I don't need to use the LLVM or other JIT libraries.
I hesitate to just use mmap and add the code in hex directly.
I'd like to know if it exists better solutions, or, if not, where I can find the basic format of a C++ function code to directly write it in memory.
Thanks, and sorry for my english :/
This is not the most elegant, but it works always: generate a file with the C++ code of your function, call the compiler using system(), load the generated .so file using dlopen, and use the function!
This will take some time (due to the compiler call), but if you keep the function and maintain a database of the functions you already have, then you can save the amount of compilations.

Protect C++ program against decompiling [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Is it possible to decompile C++ Builder exe? Is C++ Builder exe safe?
I use Microsoft Visual C++ 2010 Express to write my programs. When i want to distribute my program I compile it with 'Release' configuration and also I set the linker to not add debug information. So my question is, Is my executable safe or anyone can decompile it and see the source code? If it is unsafe, how can I prevent it from being decompiled?
All programs can be decompiled to a degree. However, the vast bulk of the useful information in your source code is removed during compilation. The source code that a decompiler produces is a pale imitation of the original.
The variable names, function names, class names etc. will not be available after decompilation. So the best that a decompiler can do is to turn your functions that look like this:
double CalculateWidgetStrength(int WidgetType, int WidgetFrobishness);
into rather meaningless code like this:
double Function85(int p1, int p2);
And even succeeding in doing that much accurately can be very hard for a decompiler.
Can anyone decompile it to see the original source code? Not likely, but the original source code isn't that important. For example:
int x = 1 - 1;
and
int x = 0;
will be equivalent in the binaries, but it doesn't really matter, does it?
For a large enough project, decompiling isn't really a concern, because you can't really make use of the generated code. It takes years to get to know even a small part of a large-scale project, taking into account you benefit from knowledge transfer, documentation and proper naming. I imagine it's impossible just with a decompiler.
For particular functionalities, yes, I imagine there's a risk, but one that can't be fully, 100% taken out.
You cannot fully protect the code.
IMHO the time you spend protecting your code is better spent on making your product function rich and error free then do frequent releases. Making the code obfuscated in one way or the other has the potential to introduce hard to find bugs that become very difficult to fix.
The only way to keep it "safe" in the way you imply is not to deploy it, i.e. you do a web service or some such.
You can't make it safe from the people executing it without making it impossible for them to execute it.
Given what you've already done decompiling would require a amount significant effort, my question would be. Why would anyone bother, as it's likely that it would require more effort than simply "rolling your own"

What is the tool to check include file that are useless?(c++) [duplicate]

This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
Tools to find included headers which are unused?
I would like to check useless header file in c++ files(.h and .cpp)
During developing, There are so many relations between files.
So it cause compile time more longer.
Can you tell me what's the tool that help me.
Thank you.
Have a look at the Dehydra.
From the website:
Dehydra is a lightweight, scriptable, general purpose static analysis tool capable of application-specific analyses of C++ code. In the simplest sense, Dehydra can be thought of as a semantic grep tool.
It should be possible to come up with a script that checks for unused #include files.
I use lint, Verify the link, it does mention unused variables, unreachable statements and many more.

automatically skipping/ignoring external code in gdb [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to avoid entering library's source files while debugging in Qt Creator with gdb?
anybody know how to tell gdb to only enter code that is in your project? I know it's hard for a debugger to know what is "in the project" and what is a library....but I thought some naive checks could help, eg don't look in any files that aren't in the users home directory. I frequently have code like this:
MyFunction(complexVarable, complexvar); //passed by value
and gdb insists on going through the copy constructors of the two passed values, but all I care about is MyFunction. Any tips? There are two parts to the question,
ignore code that isn't mine (not in home dir)
skip copies for function calls.
thanks.
EDIT: btw I use emacs, maybe there are some tools there I missed, but I'm open to using external gdb frontends.
As per my opinion this cannot be done.
every project has a flow of data from one function to other.
gdb is designed to work on the flow of data.
so if your project is somewhere in the middle of the flow,gdb cant help you,since evry function has some purpose to do with the input it gets and output it gives.
all you can do is create the same function separately and replicate the scenario as if its running in teh flow by giving the inputs it needs and output it gives.