mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
|
||||
v0.24.3
|
||||
---
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/535
|
||||
|
||||
v0.24.2
|
||||
---
|
||||
* Reverted validation errors under `node` target for `sourceMap*` options
|
||||
|
||||
Vendored
+3
-3
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "0.24.2",
|
||||
"version": "0.24.3",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
|
||||
@@ -126,10 +126,15 @@ export class ScopeAnalyzer implements IScopeAnalyzer {
|
||||
// fix of class scopes
|
||||
// trying to move class scope references to the parent scope
|
||||
if (childScope.type === 'class' && childScope.upper) {
|
||||
if (!childScope.variables.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
// class name variable is always first
|
||||
const classNameVariable: eslintScope.Variable = childScope.variables[0];
|
||||
|
||||
const upperVariable: eslintScope.Variable | undefined = childScope.upper.variables
|
||||
.find((variable: eslintScope.Variable) => {
|
||||
// class name variable is always first
|
||||
const classNameVariable: eslintScope.Variable = childScope.variables[0];
|
||||
const isValidClassNameVariable: boolean = classNameVariable.defs
|
||||
.some((definition: eslintScope.Definition) => definition.type === 'ClassName');
|
||||
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { NO_ADDITIONAL_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes';
|
||||
|
||||
import { getRegExpMatch } from '../../../../../helpers/getRegExpMatch';
|
||||
import { readFileAsString } from '../../../../../helpers/readFileAsString';
|
||||
|
||||
import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade';
|
||||
|
||||
describe('ScopeIdentifiersTransformer ClassExpression identifiers', () => {
|
||||
describe('transformation of ClassExpression identifiers', () => {
|
||||
describe('Variant #1: `ClassExpression` parent block scope is not a `ProgramNode`', () => {
|
||||
const classNameIdentifierRegExp: RegExp = /var (_0x[a-f0-9]{4,6}) *= *class *\{/;
|
||||
const classCallIdentifierRegExp: RegExp = /new *(_0x[a-f0-9]{4,6}) *\( *\);/;
|
||||
|
||||
let obfuscatedCode: string,
|
||||
classNameIdentifier: string,
|
||||
classCallIdentifier: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/base.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
classNameIdentifier = getRegExpMatch(obfuscatedCode, classNameIdentifierRegExp);
|
||||
classCallIdentifier = getRegExpMatch(obfuscatedCode, classCallIdentifierRegExp);
|
||||
});
|
||||
|
||||
it('should transform class variable name', () => {
|
||||
assert.equal(classNameIdentifier, classCallIdentifier);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #2: `ClassExpression` parent block scope is a `ProgramNode`', () => {
|
||||
const classNameIdentifierRegExp: RegExp = /var Foo *= *class *\{/;
|
||||
const classCallIdentifierRegExp: RegExp = /new *Foo *\( *\);/;
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/parent-block-scope-is-program-node.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('match #1: shouldn\'t transform class name', () => {
|
||||
assert.match(obfuscatedCode, classNameIdentifierRegExp);
|
||||
});
|
||||
|
||||
it('match #2: shouldn\'t transform class name', () => {
|
||||
assert.match(obfuscatedCode, classCallIdentifierRegExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
(function () {
|
||||
var Foo = class {
|
||||
getInstance () {
|
||||
return new Foo();
|
||||
}
|
||||
};
|
||||
|
||||
new Foo();
|
||||
})();
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
var Foo = class {
|
||||
getInstance () {
|
||||
return new Foo();
|
||||
}
|
||||
};
|
||||
|
||||
new Foo();
|
||||
@@ -79,6 +79,7 @@ import './functional-tests/node-transformers/obfuscating-transformers/labeled-st
|
||||
import './functional-tests/node-transformers/obfuscating-transformers/literal-transformer/LiteralTransformer.spec';
|
||||
import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/catch-clause/CatchClause.spec';
|
||||
import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-declaration/ClassDeclaration.spec';
|
||||
import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/class-expression/ClassExpression.spec';
|
||||
import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function-declaration/FunctionDeclaration.spec';
|
||||
import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/function/Function.spec';
|
||||
import './functional-tests/node-transformers/obfuscating-transformers/scope-identifiers-transformer/import-declaration/ImportDeclaration.spec';
|
||||
|
||||
Reference in New Issue
Block a user