js-confuser icon indicating copy to clipboard operation
js-confuser copied to clipboard

With statement obfuscation

Open MichaelXF opened this issue 1 year ago • 2 comments

The with statement is able to obfuscate variable names, that could be very difficult for AST analyzers to understand. You can also do weird things with proxies.

const namespace = new Proxy(
  {},
  {
    has(target, key) {
      // Avoid trapping global properties like `console`
      if (key in globalThis) {
        return false;
      }
      // Trap all property lookups
      return true;
    },
    get(target, key) {
      return key;
    },
  }
);

with (namespace) {
  console.log(a, b, c); // "a" "b" "c"
}

Unfortunately, the with statement is deprecated, however it will most likely be supported for a very long time and every browser still supports it. You also lose various optimizations as variables cannot be assumed anymore.

MichaelXF avatar Aug 11 '24 17:08 MichaelXF