js-confuser
js-confuser copied to clipboard
With statement obfuscation
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.