   Assembly Question C++ Source
  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~   
  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.   ;  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 eithermov eax, amul eax, 2mov a, eaxormov eax, alea eax, dword ptr [eax * 2]mov a, eaxThis 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.   ;  So is thier any roms that have been done this way that you know of and how is C++ mapping to machine code more complex, an example?   ;Quote:Original post by ZedFxIt 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 ofI 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.;  It is possible take a look at boomerang http://boomerang.sourceforge.net/   ;  Even if it were possible, shall we have a competition to try to list the legal applications? Bet you can't name 10 :)   ;  you could try the open source boomerang decompiler at http://boomerang.sourceforge.net/ but even the people who make it admit that it's not too accurate.   ;  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.;Quote:Original post by EasilyConfusedEven 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]