|
Comments
|
Today's Top SOA Links
Features The New Generation of Decompilers
How to protect your code
By: Arthur Hefti
Sep. 9, 2009 01:00 PM
The latest development technologies rely on intermediate languages and can be decompiled. PowerBuilder is no exception. In this article, we will address the risks posed by decompilers. We will also discuss what can be done to protect against the possible negative results of decompilation - whether you create in-house applications, commercial applications, or are using these applications for your business. A PowerBuilder Decompiler? Other technologies also have their own decompilers. Microsoft provides, as part of the .NET SDK, a tool called ILDASM that reverse-engineers a (non-protected) .NET assembly. The popular "Reflector" tool (by Lutz Roeder, now acquired by Red Gate Software Ltd) shows your original source code in full detail. To take a look at the source code of Java classes, you can make use of several tools, including the DJ Java Decompiler. Decompiled machine code is very hard to understand. However, this is not true for intermediate language, which leads to a key question: Do PowerBuilder decompilers exist? Unfortunately the answer is yes, as it is for any other successful development environment. PowerBuilder is widely used for creating mission-critical applications, something that clearly stimulates the creation of decompilers. The next question is: Do decompilers work with PB? Yes, they do. They can retrieve your full source code as nicely formatted PowerScript with all variable, object, and function names, and ready to work on; all that's missing are the comments. If you don't deploy source code along with your application, it's because you have good reason not to. Protecting your property, prohibiting unauthorized changes, or protecting your license-checking routines are all valid reasons to keep your code to yourself. But, be informed that upon deploying executables, you are basically exposing your full source code. Now is the time to start protecting! How Will This Affect Me?
Quality Assurance and IT Audits How Can I Fight Back? When deploying an application to customers, there is an option to encrypt the executable. This is done by adding a small loader to your application. When the application starts, it unpacks the file and executes it. This option cannot be used with a PowerBuilder application including PBDs. Using it for a single EXE works, but by using a debugger, this protection could be broken as well. Another way to protect your code is to write "spaghetti code" (code that is very hard to read and understand). It's said that certain programmers do that on a daily basis, unintentionally. There's a contest for programs written in C called the "International Obfuscated C Code Contest." The major disadvantage of spaghetti code programs is that maintenance is almost impossible. More sophisticated solutions use programs to generate something similar to spaghetti code from source code. The advantage with this is that the code can be easily maintained, but the distributed code is very hard to reverse-engineer. This process is called obfuscation. Besides making it very hard to read the code, it also protects the code from being reused. If someone were to steal your code and it went to trial, it would be hard for the person with obfuscated code to claim that he wrote it this way. What Is Obfuscation? In order to make code difficult to understand, obfuscation techniques address:
If you have never seen the effects of obfuscation, you'll be surprised at how difficult it is to understand obfuscated code. Obfuscation is an alternate way to deploy source code for libraries or frameworks. For example, deploying a PowerBuilder application to Appeon, WinForms, and WebForms requires full source code; however, you probably don't want to publish the original source code. This means that users can take advantage of the generation to .NET by using an obfuscated version of the library source code. As a word of warning, if you have your database password in the application or you have simple license check algorithms, rest assured that someone will use decompilers to take advantage of your good intentions. How Does Obfuscation Work? Even without comments, variable and class names ("symbols") help programmers understand the meaning of your code. Thanks to PowerBuilder naming conventions, our source code is often very easy to read. But, imagine that your variable ls_license_code (computed by very complex algorithms) was named x4tg6_jh instead; it would not be easy to understand what the program does. Unfortunately renaming is not so easy, especially if you consider incremental compilation (that every script must be compiled before being saved) and all the possible references that you have in your programs. Finding elements to rename is not easy either, because if you obfuscate "Messagebox" or "Describe", your application will no longer work. A symbol table is a technical term used by compilers to express the list of symbols used in the source code. Machine code compilers discard the symbol table, because it's not considered a central part of the source code. But intermediate language code compilers don't. The technique for destroying a symbol table is to find variable, class, and method names defined by programmers and to replace them with alternate symbols. By systematically renaming them all (in every part of the program, including strings, DataWindows, etc.), you can build a new obfuscated program that's ready to be compiled. It will have the same functionalities as the original application, but will be much more difficult to understand (see Figure 1). The obfuscation process starts from plain code and:
The result of this process is new obfuscated source code and a symbol table that shows the original symbols along with their new names. This new symbol table is like the Rosetta Stone; keep it in a safe place with the original source code. A PowerBuilder Obfuscator? I applied to be a beta tester for PBProtect 2.0. During the following weeks I tested various alpha and beta releases with different PowerBuilder projects and was more and more pleased with each new version. I passed my findings by email to Gian Luca and we often chatted on IM about details. PBProtect was easy to use. To obfuscate a whole application you have to select a target, choose the right PowerBuilder version, name the output library for the obfuscated code, put your copyright text, and click obfuscate. The whole obfuscation process could be included into a batch build by passing a project file on the command line to PBProtect. After clicking obfuscate, PBProtect parses the source of all the objects and presents you with a list of symbols (objects, functions, properties, etc.). There's a default setting of what gets obfuscated. All the PowerBuilder keywords are excluded. By default, all symbols that contain an underscore (_) are included. This can be changed by using filter expressions with syntax similar to the PB Match function or by including or excluding each symbol individually (see Figure 2). After hitting confirm, the sources will be obfuscated, imported, and rebuilt - ready to be deployed. Listing 1 shows the obfuscated code whereas Listing 2 shows the same code before obfuscation. The listings are a few simple code lines used in a resize event; imagine how it looks when you obfuscate more complex code. (Download Listings 1 and 2 here.) You might wonder what's happening behind the scenes. In the first step, all the source codes are exported into a temporary directory from where they are parsed. During parsing, all the symbols are collected, PowerBuilder keywords are removed from the symbols found, and the list of symbols is displayed in a window. There you can use various criteria to look at the symbols and create filters to include and exclude symbols (see Figure 3). For each symbol, you can define an exception to choose whether or not it gets obfuscated. In the next step, PBProtect obfuscates all the sources according to your settings. After this step, the PB sources are imported into the target library and migrated. In addition to the basic settings, there's also an advanced tab page that you will rarely use. After the obfuscation, you can deploy your project normally. PBProtect is not limited to whole projects. It can be used to obfuscate single libraries as well. At the beginning of the year we decided to write a commercial PDF creation engine (CATsoftPDF) for creating PDFs without the need for a PDF printer driver. The availability of a PowerBuilder decompiler made us quite uneasy about deploying a PBL with all the information - also known as PBD. Anybody could get the trial version of the PB decompiler and get a look at our source code, maybe even steal the code and create his own commercial library. With PBProtect, we can obfuscate the source and distribute the obfuscated PBL instead of the compiled PBD. The advantage of distributing a PBL including the obfuscated source code is that it can be used for .NET projects as well. In the obfuscation process we have to exclude the few functions and objects that need to be accessed from projects using our library.
Summary
In both cases, this has many more potential repercussions than simply using software without proper authorization. Fortunately, obfuscation makes it very difficult to reverse-engineer your code. Using an obfuscator like PBProtect made me feel confident that I could deploy my application without worrying that somebody might disclose my work or reuse my code and create a competitive product. Resource Reader Feedback: Page 1 of 1
Your Feedback
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
|
SYS-CON Featured Whitepapers
Most Read This Week |
||||||||||||||||||||||||||||||