Variable Masking

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

Description

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];
}

Code Annotation Example

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

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": []
      }
    }
  ]
}