Symbian developer community

 
wiki

Protecting Web Runtime widget source code

From Symbian Developer Community

Jump to: navigation, search

Web Runtime widgets are delivered as WGZ archives which are essentially ZIP files. This means that the end users have access to the full widget source code. In many cases this is either desirable or not a problem. For commercial applications, however, this is very undesirable.

Contents


JavaScript obfuscation

The problem is easily solved using obfuscation. Similar to obfuscation in other languages (e.g. java) the idea is to transform the code until it is extremely difficult to reuse or read. Obfuscation removes white space, encodes strings, renames functions and variables and may even implement code optimisations.

A free, online javascript obfuscator is available here. This is a great tool for understanding how obfuscation works. As an example consider the following simple javascript program:

 
var a="Hello World!";
function MsgBox(msg)
{
alert(msg+"\n"+a);
}
MsgBox("OK");
 

Using the javascriptobfuscator.com online obfuscation the resulting script is:

 
var _0x7114=["\x48\x65\x6C\x6C\x6F\x20\x57\x6F\x72\x6C\x64\x21","\x0A","\x4F\x4B"];var a=_0x7114[0];function MsgBox(_0xa061x3){alert(_0xa061x3+_0x7114[1]+a);} ;MsgBox(_0x7114[2]);
 

The result of obfuscation is garbled code that is very difficult to read and understand.

However, in order to use obfuscators in a project and have much more control over obfuscation process, it is usually more convenient to have off-line command line based tool. A free, open source obfuscator is available from Shane Ng here. Another free minifier/obfuscator is Dojo compressor.

There are many commercial obfuscators and readers can easily find them using search engines.


JavaScript minification

One frequent side effect of obfuscation is that the source files can become smaller (typically when strings are not encrypted). As a result, widget start-up time - time to load a parse html/css/script - is shorter and applications start faster. Further still, because variable and function names are made shorter, general widget performance also improves. Finally, obfuscation may implement some optimisations which often significantly improve performance. So even if we don't want to protect the code with obfuscation, it makes sense to 'minify' scripts to gain these benefits.

Minification is a process similar to obfuscation, but is focused on making scripts smaller and run faster. For experimentation, an online minifier can be found here.

Readers can explore minification by reading about the following tools:

Comments

Sign in to comment…