We will be at OWASP APPSEC EUROPE 2017 - Belfast! Let’s talk!MORE INFO

Help Center

Get to know more about our API, Code Annotations and Code Transformations

Code Annotations

Applying the same set of transformations to a JavaScript application or source file may have an undesired impact on performance, or sometimes, an unsatisfactory obfuscation potency in a specific part of the source code. So, a feature that allows the user to change the behavior of Jscrambler in specific parts of the source code is extremely useful to mitigate those problems. Such a feature exists and it is called code annotations.

Code annotations are JavaScript comments (same syntax as JSDoc) that change Jscrambler’s behavior in specific parts of your source code. Preceding a line of code with a code annotation tells Jscrambler that new protection directives mays exists for that same line of code. For instance preceding a statement with a code annotation affects that statement only, where preceding a code block affects the whole block including all inner statements and blocks (i.e. inner blocks inherit their parent’s code annotations directives).

Jscrambler code annotation begin always with the tag @jscrambler followed by a directive or the global modifier. The only other JSDoc tags that JScrambler listens to are @preserve and @license. Here is a basic example of how code annotations look like:

1
2
3
4
5
/**
* @jscrambler define selfDefending {threshold: 512} as sd1
* @jscrambler enable functionOutlining, sd1
*/
function foo () {}

This configures JScrambler to preform function outlining in function foo body, and add self-defending capabilities to the function foo only if the size of the function is at least 512 chars long.

Currently there are 5 directives available in code annotations:

tag description
enable Enable transformations or transformations aliases
define Define a transformation alias with custom options
disable Disable transformations, targets, or transformations aliases
order Reorder and repeat transformations and aliases
target Enable all transformations available for a set of JavaScript targets (e.g. strings, numbers, functions)