-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Description
Expected Behavior
The obfuscated output should preserve the original binding semantics.
A semantically correct result would be equivalent to:
import { i as _imp } from './runtime.js';
function factory() {
return 'factory-result';
}
var P = class _cls {
static instance;
static getInstance() {
return _cls.instance ||= new _cls(), _cls.instance;
}
};
var x = _imp(factory(), 1);
export { P, x };or:
import { i as _imp } from './runtime.js';
function factory() {
return 'factory-result';
}
var _P = class {
static instance;
static getInstance() {
return _P.instance ||= new _P(), _P.instance;
}
};
var x = _imp(factory(), 1);
export { _P as P, x };Current Behavior
The obfuscated output rewrites the class self-reference to the imported binding.
It becomes effectively:
import { i as _0x48e620 } from './runtime.js';
function factory() {
return 'factory-result';
}
var P = class e {
static ['instance'];
static ['getInstance']() {
return _0x48e620['instance'] ||= new _0x48e620(), _0x48e620['instance'];
}
};
var x = _0x48e620(factory(), 0x1);
export { P, x };This is incorrect because _0x48e620 is the imported binding, not the class.
If the imported binding is a function or arrow function, runtime execution fails with:
TypeError: function is not a constructor
Steps to Reproduce
- Open https://obfuscator.io/legacy-playground
- Paste
runtime.jsand the main module code below into the editor - Use the obfuscator options listed below
- Run obfuscation
- Inspect the generated
getInstance()method - Notice that the class self-reference is rewritten to the imported binding
JavaScript Obfuscator Edition
- JavaScript Obfuscator Open Source
- JavaScript Obfuscator Pro via API or http://obfuscator.io
Your Environment
javascript-obfuscator:4.2.2- Also reproduced after testing newer versions, including
5.3.0
- Also reproduced after testing newer versions, including
- Node.js:
20.x - OS: macOS
Stack trace
Minimal working example that will help to reproduce issue
// runtime.js
export const i = (value, flag) => ({ value, flag });import { i as e } from './runtime.js';
function factory() {
return 'factory-result';
}
var P = class e {
static instance;
static getInstance() {
return e.instance ||= new e(), e.instance;
}
};
var x = e(factory(), 1);
export { P, x };Reactions are currently unavailable