C++ Decompiling

Started by EightyVice, Mar 30, 2017, 07:09 AM

Previous topic - Next topic

EightyVice

Hello guys :D
I tried decompiling C++ by some programs and methods and some times the pc crash
i used boomerang and snowman but no thing
any help?

Shadow

What do you want to do with it? There's no use for 'decompiling' as you name it, all you can do is to view the assembly code and perhaps use some sort of analyzer to try and replicate the original code but it is in no way easy to understand, mainly because without any sort of debugging symbols you are not going to be able to view anything other than values and offsets. Even types are mismatched at times, even by the best analyzers. Plus it takes a lot of C/C++ and reverse engineering to make anything significant out of it.
QuotePS:is trash is ur home language??

.

The amount of optimizations a compiler does nowadays and the amount of abstraction that C++ has over machine language is insane. There's no such thing as de-compiling C++. Even C with it's simplistic design can't be de-compiled after the compiler finishes optimizing the crap out of it. The code you feed to the compiler is a mere suggestion with C/C++. The compiler is free to arrange it however it wants or thinks it provides the best efficiency.

De-compiling C++? Especially in this day and age. Absolute joke. There's no such thing. If it were then no one would probably use C or C++. All you can do is reverse-engineer and try to figure out what the code wanted to do and not how it looked.
.

EK.IceFlake

Quote from: happymint on Mar 30, 2017, 05:11 PMfigure out what the code wanted to do
Which is exactly what I wanted to do in my case but couldn't figure out how to.

.

#4
Quote from: EK.IceFlake on Mar 30, 2017, 07:57 PM
Quote from: happymint on Mar 30, 2017, 05:11 PMfigure out what the code wanted to do
Which is exactly what I wanted to do in my case but couldn't figure out how to.

I didn't say that was easy either.



To elaborate on what what I meant when I said that your code is a mere suggestion to the compiler and that the compiler is a monster at optimizing code.

Let's take this relatively simple code for example:
int v[4];
for (int i = 0; i < 4; ++i) {
    v[i] = i;
}

The compiler, being a smart son of a b!tch reaches the conclusion that the loop is not necessary so it can unroll the loop to:
int v[4];
v[1] = 1;
v[2] = 2;
v[3] = 3;
v[4] = 4;

Take this code for example:
unsigned int foo(unsigned int n) {
    n = (n * 2);
    unsigned int a = 32;
    unsigned int b = a + 235;
    n = (n + b);
    return n;
}

The compiler, again, being a smart a$$ m*f*er can transform it into this:
unsigned int foo(unsigned int n) {
    return (n << 1) + 267;
}

How so? Well, it knows that a multiplication operation can be "costly" and since this multiplication is a power of 2 (in this case) it uses a shift left because that takes <= to a CPU cycle. And then because the he's even smarter he realized that `a` and `b` are constant values and as such it can fold them  at compile time. And if the function `foo` would be in a header there's a 99% chance a function like this would be inlined and it'll be as if the function `foo` didn't even existed as long as it's not exported.

This was just some trivial code to make it possible for anyone who wrote a line of code to understand and follow allong. The optimizations that the compiler throws at your code are much, MUCH more complex than this. Which is why you can't get the exact same code back. Because there's a very wide contract between you and the compiler. Especially when you demand it to optimize your code.
.

EightyVice

Quote from: EK.IceFlake on Mar 30, 2017, 07:57 PM
Quote from: happymint on Mar 30, 2017, 05:11 PMfigure out what the code wanted to do
Which is exactly what I wanted to do in my case but couldn't figure out how to.
K , There is a game and it has .dll file i dont want to whole source , just some functions to hook it with the game
for more explanations (Modding the game)
 i de-compiled alot c++ dll that in the game but it was some useless dlls like sound and object declarations but i need to decompile the main dll but my pc is crashing during the decompiling :v , just some help pls V:

EK.IceFlake

Quote from: Zeyad Ahmed on Apr 05, 2017, 09:14 AM
Quote from: EK.IceFlake on Mar 30, 2017, 07:57 PM
Quote from: happymint on Mar 30, 2017, 05:11 PMfigure out what the code wanted to do
Which is exactly what I wanted to do in my case but couldn't figure out how to.
K , There is a game and it has .dll file i dont want to whole source , just some functions to hook it with the game
for more explanations (Modding the game)
 i de-compiled alot c++ dll that in the game but it was some useless dlls like sound and object declarations but i need to decompile the main dll but my pc is crashing during the decompiling :v , just some help pls V:
You'll have to reverse engineer it without decompiling. Use something like Cheat Engine to get the addresses you need and then hook to them.