R E L A T E D   C O N T E N T
ADVERTISEMENT

How to modify applications without the code

We find out how to work backwards, and migrate code you no longer have

Tim Anderson, Personal Computer World 05 May 2008
ADVERTISEMENT

What do you do when you need to modify your application but cannot find the code?

Peter Altman contacted me about a Visual Basic 3.0 puzzle which he wanted to run on his Windows Mobile PDA. All he had was the compiled code, written for him by a friend who had died. VB 3.0 is 16-bit software that is fifteen years old.

The best chance, short of a full rewrite, was to port the application to Visual Basic .Net, which runs on Windows Mobile under the Compact Framework runtime, but for that the source was required. This kind of scenario can be a critical problem when it happens with a business application. It should never happen, but small businesses can be disorganised, and developers can be protective of their code.

16-bit code is an interesting case. The move to 64-bit Windows is in its early stages, but will gather pace over the next few years, and 16-bit applications do not run on 64-bit Windows. Virtual PC or the like is one answer, since it lets you run a different operating system within Windows, but even that does not help you if you need to modify the code or port it to another platform.

Decompilation
If you have an executable for which the source is not available, then you can resort to a technique called decompilation. The aim is to start with the binary file and work backwards to the original code. Decompilation has many challenges. It may be illegal; many licence agreements forbid it. Some code is deliberately obfuscated to make decompilation more difficult.

Another factor is what type of compiled executable you are dealing with. Native code binaries such as those produced by C, C++ or Delphi are more difficult to decompile than the intermediate code in Java, .Net or early versions of Visual Basic. A lot of Java and .Net code is trivial to decompile with a suitable utility, unless the programmers have taken deliberate steps or used a tool to obscure it.

Here’s how we decompiled Peter Altman’s code.Visual Basic 3.0 uses an intermediate language. Many years ago a programmer c alled Hans-Peter Diettrich, also known as ‘Dodi’, created a decompiler, which is still probably the best tool for this. You need to have VB 3.0 installed. Microsoft can no longer supply it, but fortunately I still have a copy.

Windows XP or earlier is recommended, as Vista’s User Account Control introduces complications. Diettrich told me that he uses Windows 98 in a Virtual PC. I found it necessary to check the vb.ini file in the Windows directory, which should have a vbpath entry, in the Visual Basic section, pointing to where VB 3.0 is installed. Once everything is set up, run vbdis3.exe, which is the decompiler.

Choose File ­ Open and select the compiled VB 3.0 executable, which in this case is called counter.exe. Next, you are prompted for a location for the decompiled project. Click OK, and all being well the decompiler invokes VB 3.0 to complete the process. It’s not perfect and may trip up over some VBX controls. You will also find that variables and function names have auto-generated values.

It is a good idea to try renaming these to something meaningful, if you can figure it out. Nevertheless, it is a huge head start (see attached picture). Diettrich kindly provided a working demo version of his decompiler for PCW readers. A professional version is also available, with extra features for handling tricky problems like third-party VBX controls.

Porting to .Net
This is only the beginning of the porting process. How do you port a VB 3.0 application to VB .Net? One idea is to try Microsoft’s automatic project conversion. The first snag is that VB is fussy about what it will import. Visual Basic .Net will not look at a VB 3.0 project, but fortunately VB 6.0 is more tolerant.

Peter Altman’s simple application imported smoothly into VB 6.0, needing only the adjustment of a couple of API calls to 32-bit. It even ran correctly. The next step was to go from VB 6.0 to VB .Net. This is inherently difficult, because it is really a different platform, but Microsoft has put huge effort into it because it is a common scenario. I used Visual Studio 2008, and chose Convert from the Open menu.


All Software Applications
Tags: Software

Like this story? Spread the news by clicking below:

Post this to Delicious del.icio.us    Post this to Digg Digg this    Post this to reddit reddit!

Permalink for this story
R E A D E R   C O M M E N T S
M A R K E T P L A C E
Get your free demo of Numara Track-It! 8 - the leading help desk solution for IT related issues.
Make presentations, review documents & share your entire desktop. 30-day free trial! (cc required).
Discover how remote support can fuel your IT business in ways you've never thought of before.
Apply ITIL best practices at your service desk while eliminating integration cost. Learn more here.
WAN based, automated, daily vulnerability assessments. Click here to try and request our whitepapers.
Have your product or service listed here >   
Sponsored links
F E A T U R E D   J O B S
Hertfordshire, United Kingdom | SMART
 Business Development Executive, Hertfordshire, £20,000-£22,000 per annum OTE £34 -36k The role: An exciting opportunity has become available within a prestigious organisation with aggressive growth plans. We are looking to recruit an office based Business ... more >
Maidstone, United Kingdom | Kent Police
  Forensic Computer Analyst - Police Headquarters, Maidstone, £27,891 - £38,476 Permanent Contract Digital devices and information communication technology are present in almost every investigation the police service undertakes. Kent Police Digital Forensics Unit is ... more >
United Kingdom | Data Transparency
.NET Software Developer,  £20,000 - £35,000 depending on experience About us Data Transparency is a small, rapidly growing company established in 2006 by an Oxford graduate. We create bespoke web-based data systems that are used in ... more >
Slough, United Kingdom | Fiat Financial Services
  Business Analyst for growing finance company, excellent prospects and benefits, Slough Reporting to the IT Director, the role must provide an in-house business analysis capability to help drive business change.  You will support complex ... more >
More job opportunities