Sign in to follow this  

Assembly Question C++ Source

This topic is 4226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have seen dissasemblers that can turn .exe and rom riles into assembly, I was wondering why it is not possible then to turn the assembly into C++ code with an application. Thanks a ton!!!!! ~Mad_Koder~

Share this post


Link to post
Share on other sites
The transformation from C++ loses information. The mapping from machine code to assembly is quite simple. The mapping from assembly to C++ is very complex, and in general cannot be determined with any kind of accuracy (you could guess, I suppose).

If somebody bothered to write such a program (by using the "guess the mapping" method), it would produce output that would (when compiled) yeild the original input only for the most trivial cases.

Such a program would be completely useless, because the resulting C++ would look nothing like the original C++ that compiled the original .exe, which is why nobody has really bothered to put for the effort.

Share this post


Link to post
Share on other sites
It is possible to turn the assembly into C++ code, however, it depends if you know the compiler and the compilation rules which built the executable file.

for example, the following line could be compiled in many different ways (two are shown here)

a *= 2;

where a is an unsigned int, could be either

mov eax, a
mul eax, 2
mov a, eax

or

mov eax, a
lea eax, dword ptr [eax * 2]
mov a, eax

This is of course using x86 assembler. So if you know how the compiler has done it you can get it in C++, otherwise learn assembler.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by ZedFx
It is possible to turn the assembly into C++ code, however, it depends if you know the compiler and the compilation rules which built the executable file.

Nevertheless, it is generally absolutely unfeasible, even for an average program.
Even if you take assembly created by a C compiler and try to translate it back to C, it will rarely be particularly useful or even retain much of the high level stuff, that we as humans find helpful-rather you'll basically look at some sort "macro assembler", in fact that's exactly what any asm2source converter will be doing: fill in dozens of hex arrays for stuff that cannot be directly mapped back to source code.

That is, while you may in fact end up with some sort of "valid C++" source code, this can usually hardly be considered useful or even comprehensible, it's much more like mangled/obfuscated source code.

So, if you intend to work with such source code, you'll usually have to do lots of manual work afterwards.


Quote:

So is thier any roms that have been done this way that you know of

I don't think I am getting what you are asking?

Quote:
and how is C++ mapping to machine code more complex, an example?

actually, it's vice versa: mapping a low level language to a higher level language, will inevitably result in many ambiguities.


Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It is possible take a look at boomerang http://boomerang.sourceforge.net/

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
if this is any kind of theoretical effort, your best bet would certainly be the gcc suite, simply because it is open source and pretty well documented, so that you should be able to come up with rules to derive source code from assembly with a relatively high probability of matching the original HLL constructs.
Something like this could be implemented by looking at how exactly gcc deals with HLL features such as classes and templates and how they are generally translated to assembly.
So you would end up with some sort of backtracking mechanism that uses pattern matching in order to try to "guess" what certain assembly constructs looked liked originally in the corresponding HLL. Of course this wouldn't be an absolute solution, but certainly much more promising than anything currently available.
Theoretically, you should even be able to refactor the gcc sources in a matter than gcc itself would provide an assembly to source converter, much of the code is already in place in gcc-it would mainly come down to reversing the current translation process.

Share this post


Link to post
Share on other sites
Quote:
Original post by EasilyConfused
Even if it were possible, shall we have a competition to try to list the legal applications? Bet you can't name 10 :)


key word being 'legal' huh?

Heh heh.
[cool]

Share this post


Link to post
Share on other sites

This topic is 4226 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this