sanex3339
2020-01-29 22:26:33 +03:00
parent d60ec7afbb
commit fcbe2ee66e
10 changed files with 98 additions and 8 deletions
+4
View File
@@ -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
+3 -3
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -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');
@@ -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);
});
});
});
});
@@ -0,0 +1,9 @@
(function () {
var Foo = class {
getInstance () {
return new Foo();
}
};
new Foo();
})();
@@ -0,0 +1,7 @@
var Foo = class {
getInstance () {
return new Foo();
}
};
new Foo();
+1
View File
@@ -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';