YOUR FEEDBACK
Chris Keene's Prescription for Curing the Java Flu
Pedro wrote: "Adobe and Microsoft are doing a far better job making their ...

SYS-CON.TV
TOP MICROSOFT .NET LINKS


Decompiler Round-Up, Regenerating Your Code
Regenerating your code

Digg This!

Recently, there has been much debate over open source software. But what most developers overlook is that even though they don't release their source, it may still be available. In the general scheme of things, there is always someone out there who will, by some means, be able to regenerate your code if they so desire. Whether it is by analyzing how your application works and replicating its behavior, or by reverse engineering with a tool, it will always be possible for someone to produce the same output with an appropriate amount of time in which to do it.

With .NET, assemblies compile to an Intermediate Language (IL), which allows them to be executed on any system supporting Microsoft's Common Language Runtime (CLR). There are many benefits to this solution that are outside the scope of this article, but a major drawback is the extent to which your code is compiled. It is first compiled into the assembly, then, upon runtime, it is compiled again. The IL to which your assembly is compiled is not dependent on any machine or software aspects excluding the Just In Time (JIT) compiler. It compiles your code the second time into native machine code, then executes it. Your assemblies also include metadata, which describes the types in your code as well as a few other things. For these reasons, .NET assemblies are relatively insecure to decompilers.

The .NET framework also ships with a tool to convert your compiled assembly into plain text MSIL, which looks like a high-level assembly language. This alone could be enough for most skilled programmers to see what is going on in your program.

Converting this IL back into its original language is another story. Currently, there are few tools suited for this task. I will be focusing on the three major professional solutions I have found, but in addition to these, there is a free tool as well as an open source tool, which has been discontinued (references at the end of the article). I chose to leave these two tools out of this article. Why? Well, for the same reason I don't do my own electrical work: if I hire someone, I can hold him/her liable for faulty work, whereas if I burn my house down I've got no one to blame but myself. The same goes for software: when it doesn't work, the publishers should fix it; if not, demand your money back. With free or open source software, you don't have that kind of leverage. Second, in most cases, the authors create their free software in their spare time, which isn't much time at all. The now?discontinued open source software was closed due to lack of time. The other tool (Reflector for .NET), however, is doing an extremely good job, but is unable to reproduce some complex pointer statements. Don't get me wrong, these are fantastic tools that are worth checking out, but personally, I would not rely on them in a professional environment, as they do not offer the needed level of support. I included a code sample of Reflector.NET to demonstrate this. The tools I did evaluate include Remotesoft's Salamander, 9Rays' Spices.NET, and Jungle Creature's Decompiler.NET.

To evaluate each piece of software, I first decided to look at the basics, such as keywords, modifiers, and so on. Then, I created some complex loops, structures, and inheritance examples. Next, I wanted to see how each could handle pointers, because they are my favorite aspect of programming. And finally, I picked a random control that I did not create or have access to the source. I evaluated solely on runtime behavior. That control was HyperCoder's FileSystemControls, which allows you to mimic Windows Explorer.

Salamander features the familiar class browser interface and can examine managed C++ code as well. I was impressed by its robustness; because it uses an explorer with plug-in support you can perform many tasks in a single program. It also has the ability to generate Visual Studio Project files, which is a nice plus that none of the other decompilers feature. I was disappointed when I tried to decompile my complex pointer examples. In my pointer arithmetic example, the offset was not divided by the type that would lead to a nice runtime bug to squash. Complex nested statements gave the decompiler some trouble as well. Switches decompile to if-then-elses with correct runtime behavior. Overall, there were only a few goto statements, but they popped up here and there.

9Rays' Spices.NET offers a slick class browser interface and many options. Spices.NET also uses its own reflector for decompiling, giving it the most freedom to get the job done. Sadly, some very crucial elements are missing. For instance, pointers resolve but the methods are not marked as unsafe. In order to compile, you must manually fix these methods. Also, there is no support for stackallocate or the volatile keyword. Switches left lots of goto statements in code, which reminds me of good old spaghetti coding.

Jungle Creature's Decompiler.NET features a simple and easy-to-use interface. It was by far the easiest out of which to get source files. The most impressive feature was its ability to handle pointers. It handled all complex pointer examples, as well as pointer member access (->), which no other decompilers could handle. Switch statements decompiled flawlessly. Overall, there were virtually no goto statements.

Both Salamander and Decompiler.NET featured the ability to look at the programmer database (*.pdb file when compiled in debug mode) and resolve exact variable names. This is extremely useful if you happen to lose your source yet still have a debug lying around. This has actually happened to me once. I had a hard drive failure but had already sent the debug build to the host. If I had known of these products, I would have saved a lot of time.

Listing 1 is a sample of the code I tested. The goal of this code is to run through an array with a pointer. The output should be all zeros because there are no values.

Salamander had trouble with the pointer arithmetic and declared the pointer as a reference variable. Spices.NET was along the same lines. Neither compiled. Reflector.NET has some interesting output. It did compile, but produced way off output. This is where using a free tool can get frustrating. The code compiles, but can leave a nasty bug that is hard to trace down, especially because it may not be your code. Salamander has stated that they are working on a new version to support better pointer operations. Spices.NET also has plans, but they are currently working on a few projects. Decompiler.NET was the only application to consistently produce compilable correct code, even in this case. Table 1 compares these features.

How to Prevent
These decompilers demonstrate amazing ability, which might leave you afraid to develop in .NET. But with .NET, there is always another solution. The best way, in this case, is to obfuscate your code. When you do this, you make it unreadable from a person's perspective. For example, getXML(string path) could obfuscate to aaa(string aaa), which gives no meaning to a person. Because the computer sees no symbolic difference between getXML and aaa, both compile and run correctly. Salamander has the most powerful obfuscator, as it will take your compiled assembly and output an exe, which in some cases, would not need the .NET framework to run. It had trouble decompiling some examples and it was a bit buggy, but it features enough options to toggle to always get an obfuscated release. I then tried to decompile this release with Jungle Creature's Decompiler.NET. It was successful when the fail-safe options were set, but the code was very difficult to follow. Jungle Creatures built-in obfuscator was a bit disappointing at first, mainly because it takes an assembly and decompiles it into obfuscated source code. Upon first glance, I saw this as a major vulnerability, especially after the power of Salamander's obfuscator. But the code was extremely difficult to follow. I later liked the ability to modify the source and verify what my code would look like, then modify if necessary and recompile. It would have been nice if the obfuscator also outputted an assembly similar to Salamander.

Conclusion
All products offer a free trial of some sort, and they are all worth the time to evaluate on your own to see which best fits your needs. For me, Jungle Creature's Decompiler.NET offers tremendous abilities, especially with pointers. Its GUI is simple and easy to use, but it lets you do what needs to be done. More importantly, it can handle whatever you throw at it. Salamander is close, but still needs some optimizations. Overall, I was a bit disappointed by Spices.NET's performance, but its future looks promising. It has a strong foundation on which to build. Jungle Creature's Decompiler.NET with obfuscator is available for $500 per CPU, giving it leverage over its toughest competitor, Salamander, which sells for $1099, plus an additional $799 if you want the obfuscator. Spices.NET is the cheapest of the bunch, at $292.95, which reflects the code it generates. If you only need the simplest of decompilations, Reflector.NET or Spices.NET can do the job. But the results from a commercial product that you can send your requests to for an immediate fix make the investment worthwhile. Trying to track down a bug in decompiled source code that you didn't write will end up costing you even more than Salamander with the obfuscator.

Resources

  • Decompiler.NET: www.junglecreatures.com
  • Salamander: www.remotesoft.com
  • Spices.NET: www.9rays.net
  • Reflector.NET: www.aisto.com/roeder/dotnet
  • Open Source Decompiler: www.saurik.com/net/exemplar

  • About Robert Stanton
    Robert Stanton is a developer for Realized Solutions (www.realizedsolutions.com) in Bristol, CT. He has been developing for 8 years.

    9Rays.Net wrote: Bob did not address to us for receiving fully functional copy of Spices.Decompiler.Net for tests. I don't know how Bob wrote this article, but Spices.Decompiler .Net produces code with a lot of goto as doesn't optimize generated code, this is functionality limitation of EVALUATION VERSION. With full version Spices.Decompiler produces formatted, optimized and very smooth code for 6 languages, user can choose to generate optimized or unoptimized code in the Decompiler settings. Also 9Rays.net constantly works on improving our decompiler smart optimization engine and periodically publishes new versions. Very incompetent article. Victor Victorov, CTO, 9Rays.Net
    read & respond »
    erin wrote: Thanks for the FileDisassembler link.
    read & respond »
    Jonathan Pierce wrote: The author mentions Anakrino as an early decompiler that is no longer being supported by it''s author. His does include some code generation results from Reflector. The author did perform an unbiased evaluation of all of the products and obtained permission in advance to include each vendor''s product in his review as well as giving each vendor a chance to respond to his concerns with new versions prior to his final draft. His conclusions indicate his positive experience using our product over the others, but this is not based on any bias other than his own preferences after evaluating each of the respective products and level of support provided to him by each of the vendors involved. Jonathan Pierce President Jungle Creatures, Inc. http://www.junglecreature s.com/
    read & respond »
    / wrote: The author is not unbiased. The scoring card and the careful phrasing to ditch Spices and Salamander shows this. Also, he is leaving half the tools (Anakrino, Reflector, LSW) out only giving a "doing his own electrical work" argument as a rationale so it isn''t a good overview in the first place.
    read & respond »
    Jonathan Pierce wrote: I assure you that the conclusions drawn in the article were independant and unbiased based on the author''s own experience evaluation each of the products on his own. All of the vendors were given feedback regarding the author''s experience using their product to provide them an opportunity to resolve any issues with newer versions of their product. Their level of response also served as a measure to the author of the level of support that they provide and their timeliness in responding to user reported bugs. The level of support that the author personally received from each vendor was also a primary concern and contributed to his decision to recommend commercial products over free alternatives. In our case, Decompiler.NET worked correctly already so the author did not require additional produc...
    read & respond »
    / wrote: Okay, lets leave it that way. The article has too many coincidences and you are too well informed on what the author did and didn''t do to make it believable. All the tools mentioned are very nice and no harm done if everybody is doing his own evaluation...
    read & respond »
    Jonathan Pierce wrote: The author of this article contacted each of the vendors on his own and requested permission to include their product in his evaluation. The article was written entirely by the author including his code examples chosen by him based on his own experiences with each of the products he tested for his own needs. From reading the article, it looks to me like the author was trying to identify unusual test cases to measure the robustness of all of the products included in his evaluation. From the author''s conclusions, it appears that he was unable to identify any cases where Decompiler.NET did not generate correct code to meet his needs. There are many other cases where the other products fail, so I am not surprised that the author was able to identify some common cases that affected him personally. ...
    read & respond »
    / wrote: Jonathan, did the author of this article report those bugs to the tool authors or did you tell him what to write about?
    read & respond »
    Jonathan Pierce wrote: Reflector is an excellent tool that I use often myself for casual browsing and code generation comparison. However, There are still many instances where Decompiler.NET generates higher level and more accurate code which is important to most professional developers. The current version of Reflector was released this week after this article was published and addresses these specific bugs over 4 months after they were reported to the author. There are many other code generation bugs in the current versions of the tools mentioned here that were not covered by the article. The author also made the point that Decompiler.NET was the only tool that generated code that had correct compile and runtime behavior for all of the test cases that he attempted including his Hypersonic example. This is not the c...
    read & respond »
    / wrote: The author is not unbiased. Just read this: "I chose to leave these two tools out of this article. Why? Well, for the same reason I don''t do my own electrical work." "They do not offer the needed level of support." [Three times in a row. Apparently they do, his example runs fine in the current version.] "Decompiler.NET with obfuscator is available for $500 per CPU, giving it leverage over its toughest competitor" [Please click here to purchase without thinking]
    read & respond »
    Jonathan Pierce wrote: I was pleased to see the author''s unbiased review confirming his positive experiences using our product. I''ve done my best to send bug reports regarding code generation issues to each of my competitors regarding their products including the bugs exposed by the examples the author has chosen in this article. I reported most of these bugs to the authors of the products mentioned here including Reflector 4.0 back as early as 04/2004. The newsgroup discussions that I had partipated in regarding code generation accuracy occurred prior to this article being written and I personally made all of the vendors mentioned in the article aware of code generation problems in their products. Each vendor had ample time to address these code generation issues prior to this article being written, and their respon...
    read & respond »
    / wrote: The decompiler.net sales guy is using the very same code examples and arguments to advertise his product in newsgroups. What a coincidence this tool comes out with perfect scores ;-)
    read & respond »
    ComPILers4 wrote: did I miss something or did the author look at five different compilers?
  • Decompiler.NET: www.junglecreatures.com
  • Salamander: www.remotesoft.com
  • Spices.NET: www.9rays.net
  • Reflector.NET: www.ai sto.com/roeder/dotnet
  • Open Source Decompiler: www.saurik.co m/net/exemplar
    Obviously 4 lots of the 5 folks were bound to be upset, no matter what. ;-)
  • read & respond »
    x wrote: This is an amateurish attempt to trick the reader into wasting money on some unknown decompiler tool. Scott Mitchell wrote a good summary on what professionals are really using: http://aspnet.4guy sfromrolla.com/articles/0 80404-1.aspx Reflector is the best tool available (and it is available for free). This add-in does the rest of the work: http://www.denisbauer.com /NETTools/FileDisassemble r.aspx
    read & respond »
    Anonymous wrote: Agree, Reflector is what all professional .NET developers are using. The whole eletrical engineering analogy is plain stupid and shows that the author has no idea what he''s talking about.
    read & respond »
    Mario wrote: This article is bizarre. The author makes a lot of effort to downplay .NET Reflector which is the tool everybody on the street is using (it was rated one of the top 10 developer tools). Next the author is comparing more expensive tools but only along the criteria that make Decompiler.net look good. The code output example is not correct or maybe just outdated (again it makes Decompiler.net look good). The comment "how each could handle pointers, because they are my favorite aspect of programming" makes this way too obvious. What do you think?
    read & respond »
    MICROSOFT .NET LATEST STORIES
    Peer Networking Series - A Closer Look at PNRP vs. Bonjour/ZeroConf
    It seems as though whenever I bring up PNRP and its benefits, I am immediately inundated with a list of questions or comments indicating that Microsoft is re-inventing the wheel and that PNRP has already been implemented before in the form of ZeroConf and, more specifically, Apple's im
    db4o Open Source Object-Oriented Database Supports LINQ
    db4objects has announced that its db4o object database is now optimized for Microsoft's LINQ. With the new support, developers can choose an object-oriented optimized engine without changing the API or compromising performance. db4object's db4o database offers a persistence solution to
    Microsoft, Unisys, Yahoo and Vista
    Microsoft, which spent $6 billion on aQuantive and was chasing Yahoo for its ads before it came to a dead stop, has been supporting - as in helping write - legislation in New York and Connecticut that would regulate the data that companies like Yahoo and Google collect for targeted adv
    AJAX World - Xceed Launches Microsoft Silverlight 2 Control
    Xceed launched Xceed Upload for Silverlight, the commercial offering in support of Microsoft's promising new Silverlight technology. The product is available now for purchase or as a fully functional 45-day trial on Xceed's website. Xceed Upload for Silverlight lets developers add uplo
    Microsoft To Keynote 4th International Virtualization Conference & Expo
    Mike Neil is general manager for virtualization strategy in the Windows Server Division at Microsoft. Mike is focused on the delivery of the Windows virtualization technology, including Windows Server 2008 Hyper-V, Microsoft Hyper-V Server and Virtual PC 2007. Mike also directs the tec
    SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
    SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
    Click to Add our RSS Feeds to the Service of Your Choice:
    Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
    myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
    Publish Your Article! Please send it to editorial(at)sys-con.com!

    Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

    SYS-CON FEATURED WHITEPAPERS

    ADS BY GOOGLE
    BREAKING NEWS FROM THE WIRES
    High Growth Forecasted for the Mobile search 2008-2013: Profiting From Information and Advertising on the Move
    Reportlinker.com announces that a new market research report related to the Wireless industr