Variable Masking

Potency Medium
Resilience High
Cost Medium
Tags: obfuscation, variables, parameters, arguments

Description

Variable Masking removes local variables and function parameters from the source code, replacing them with array subscripts which are harder to read.

Consider the following code snippet holding local variables and function parameters:

function getUrl(protocol, domain) {
  if(!protocol || !domain) throw new Error("Invalid Arguments");
  var url = protocol + '://' + domain;
  var endpoint = '/app';
  return url + endpoint;
}

Here is an example of what the code would look like after transformed:

function getUrl() {
  var a=[arguments];
  if(!a[0][0] || !a[0][1])
    throw new Error("Invalid Arguments");
  a[5] = a[0][0] + '://' + a[0][1];
  a[7] = '/app';
  return a[5] + a[7];
}

Optionally, you can target global variables too. Please be advised that global variables shared between HTML/JavaScript files won't work with this transformation.

The following code snippet holds both local and global variables, and also function parameters:

// ...
var globalDomain = "jscrambler.com";
// ...
function getUrl(protocol) {
  if(!protocol) throw new Error("Invalid Arguments");
  var url = protocol + '://' + globalDomain;
  var endpoint = '/app';
  return url + endpoint;
}

Here is an example of what the code would look like after transformed:

var a = [];
// ...
a[9] = "jscrambler.com";
// ...
function getUrl() {
  var b=[arguments];
  if(!b[0][0])
    throw new Error("Invalid Arguments");
  b[5] = b[0][0] + '://' + a[9];
  b[7] = '/app';
  return b[5] + b[7];
}

Note: Once Variable masking removes all function parameters, the property Function.length will not work as expected.

Code Annotation Example

// @jscrambler define variableMasking {options: {targetGlobalVars: true}} as varmask
// @jscrambler enable varmask

Note: Variable masking annotations should only be placed before function expressions or function declarations.

Option Types

Name Required Default Value Description
options No [] List of available options

Options

Name Description
targetGlobalVars Target global variables

API Parameters

Example:

{
  "keys": {
    "accessKey": "XXXXXX",
    "secretKey": "YYYYYY"
  },
  "applicationId": "ZZZZZZ",
  "params": [
    {
      "name": "variableMasking",
      "options": {
        "options": []
      }
    }
  ]
}