Aug 13th, 2006, 04:39 PM
Classic VB - How can I get the source code of a compiled VB file (.exe/.dll/..)?
For early versions of VB (such as VB3) there are working de-compilers (if you can find them!), however most people who ask are looking for a VB5 or VB6 de-compiler, which is what we will discuss here.
The short version
Basically you can't get the source code of compiled VB programs. Even with the best tools available, you will spend more time 'fixing' and interpreting what they produce than you would re-writing the program.
A re-write is often much quicker than writing the original (as you already know how it was structured etc), and if you have time to spare you could try to write it all in a "better" way too. The most important thing tho, is to make regular backups of your code files in future - donít lose your work again!
The long version
When you write a program, you use a programming language (like VB) which you can read/write as it is almost in English.
A computer cannot read code written in VB, so a program known as a Compiler converts it into machine code, which is something that you could not readÖ well you probably could if you tried hard, but it would take a very long time and lots of headaches!
There are several major differences between the code you write, and the machine code equivalents. One of the major differences is variable names - they are only needed for the VB code, not for the machine code. Another big difference is that a couple of lines of seemingly simple VB code can become hundreds of lines of machine code; Also several different samples of VB code (which do the same thing, but using slightly different coding methods) could produce exactly the same section of machine code.
There are tools available (called de-compilers) which attempt to "undo" the compilation process, and convert the executable file back to VB code. Unlike de-compilers for some other languages, the ones for VB are patchy to say the least. The best results that we have heard about on the forums (after hundreds of threads) is getting the form design (eg: textboxes in the right positions), and some function names - very little if any VB code! (one of the better ones claims it can get "about 3%" of the code).
There are two noticeably different ways to compile VB programs, the one that most people use is Native code (your program is converted directly into machine code), and the other is P-Code, which is a "half-way" compilation. With P-code your program is converted into an intermediate language, and only converted into machine code when the program is running. This makes the program slower (as it needs to be compiled at run time), and theoretically makes de-compiling easier - but even with programs compiled using P-Code, de-compilers donít do very well.
As VB6 has been available since 1998 (and is being 'replaced' by VB.Net), this is very unlikely to change.
Click Here to Expand Forum to Full Width