Merge branch 'master' into file-path-in-error-messages-directory-fix

# Conflicts:
#	dist/index.cli.js
#	dist/index.js
This commit is contained in:
sanex3339
2020-02-05 09:40:44 +03:00
13 changed files with 136 additions and 26924 deletions
+4
View File
@@ -1,5 +1,9 @@
Change Log
v0.24.5
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/542
v0.24.4
---
* Fixed rc4 encoded value collision: https://github.com/javascript-obfuscator/javascript-obfuscator/issues/538
+3 -3
View File
File diff suppressed because one or more lines are too long
+1 -13763
View File
File diff suppressed because one or more lines are too long
+1 -13118
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.4",
"version": "0.24.5",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
@@ -321,9 +321,17 @@ export class ScopeIdentifiersTransformer extends AbstractNodeTransformer {
* @returns {boolean}
*/
private isProhibitedPropertyNode (node: ESTree.Node, parentNode: ESTree.Node): node is ESTree.Identifier {
return NodeGuards.isPropertyNode(parentNode)
const isProhibitedPropertyIdentifier = NodeGuards.isPropertyNode(parentNode)
&& !parentNode.computed
&& parentNode.key === node;
const isProhibitedPropertyAssignmentPatternIdentifier = NodeGuards.isAssignmentPatternNode(parentNode)
&& parentNode.left === node
&& !!parentNode.parentNode
&& NodeGuards.isPropertyNode(parentNode.parentNode)
&& parentNode.left === parentNode.parentNode.key;
return isProhibitedPropertyIdentifier
|| isProhibitedPropertyAssignmentPatternIdentifier;
}
/**
+4 -22
View File
@@ -7,33 +7,15 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`
class A {
foo() {
return A;
}
bar() {
var A = 1;
return A;
}
function foo({bar = ''}) {
return bar;
}
console.log(A);
function foo () {
class B {
foo() {
return B;
}
}
console.log(B);
}
console.log(foo({bar: 1}));
`,
{
...NO_ADDITIONAL_NODES_PRESET,
compact: false,
target: 'node'
compact: false
}
).getObfuscatedCode();
@@ -426,6 +426,58 @@ describe('ScopeIdentifiersTransformer Function identifiers', () => {
assert.match(obfuscatedCode, objectPatternRegExp);
});
});
describe('Variant #6: skip rename of object pattern property identifier with default value', () => {
const functionParameterRegExp: RegExp = /function *\(\{ *bar *= *'' *\}\) *\{/;
const functionBodyRegExp: RegExp = /return *bar;/;
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter-6.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET
}
).getObfuscatedCode();
});
it('match #1: shouldn\'t transform function parameter object pattern property identifier', () => {
assert.match(obfuscatedCode, functionParameterRegExp);
});
it('match #2: shouldn\'t transform function body identifier', () => {
assert.match(obfuscatedCode, functionBodyRegExp);
});
});
describe('Variant #7: skip rename of object pattern property identifier with default value and property alias', () => {
const functionParameterRegExp: RegExp = /function *\(\{ *bar *: *_0x[a-f0-9]{4,6} *= *'' *\}\) *\{/;
const functionBodyRegExp: RegExp = /return *bar *\+ *_0x[a-f0-9]{4,6};/;
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-as-parameter-7.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET
}
).getObfuscatedCode();
});
it('match #1: should correctly transform function parameter identifiers', () => {
assert.match(obfuscatedCode, functionParameterRegExp);
});
it('match #2:should correctly transform function body identifiers', () => {
assert.match(obfuscatedCode, functionBodyRegExp);
});
});
});
describe('assignment pattern as parameter', () => {
@@ -0,0 +1,5 @@
(function () {
var test = function ({ bar = '' }) {
return bar;
}
})();
@@ -0,0 +1,5 @@
(function () {
var test = function ({ bar: baz = '' }) {
return bar + baz;
}
})();
@@ -314,28 +314,58 @@ describe('ScopeIdentifiersTransformer VariableDeclaration identifiers', () => {
});
describe('Variant #9: object pattern as variable declarator', () => {
const objectPatternVariableDeclaratorRegExp: RegExp = /var \{ *bar *\} *= *\{ *'bar' *: *'foo' *\};/;
const variableUsageRegExp: RegExp = /console\['log'\]\(bar\);/;
describe('Variant #1: single level object pattern', () => {
const objectPatternVariableDeclaratorRegExp: RegExp = /var \{ *bar *\} *= *\{ *'bar' *: *'foo' *\};/;
const variableUsageRegExp: RegExp = /console\['log'\]\(bar\);/;
let obfuscatedCode: string;
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/object-pattern.js');
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-1.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET
}
).getObfuscatedCode();
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
renameGlobals: true
}
).getObfuscatedCode();
});
it('match #1: shouldn\'t transform object pattern variable declarator', () => {
assert.match(obfuscatedCode, objectPatternVariableDeclaratorRegExp);
});
it('match #2: shouldn\'t transform object pattern variable declarator', () => {
assert.match(obfuscatedCode, variableUsageRegExp);
});
});
it('match #1: shouldn\'t transform object pattern variable declarator', () => {
assert.match(obfuscatedCode, objectPatternVariableDeclaratorRegExp);
});
describe('Variant #2: nested object pattern with property alias', () => {
const objectPatternVariableDeclaratorRegExp: RegExp = /var \{ *bar *: *{ *baz *: *_0x([a-f0-9]){4,6} *= *0x1 *\} *\} *= *\{ *'bar' *: *\{ *'baz' *: *0x2 *\} *\};/;
const variableUsageRegExp: RegExp = /console\['log'\]\(bar, *baz, *_0x([a-f0-9]){4,6}\);/;
it('match #2: shouldn\'t transform object pattern variable declarator', () => {
assert.match(obfuscatedCode, variableUsageRegExp);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/object-pattern-2.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
renameGlobals: true
}
).getObfuscatedCode();
});
it('match #1: shouldn\'t transform object pattern variable declarator', () => {
assert.match(obfuscatedCode, objectPatternVariableDeclaratorRegExp);
});
it('match #2: shouldn\'t transform object pattern variable declarator', () => {
assert.match(obfuscatedCode, variableUsageRegExp);
});
});
});
@@ -0,0 +1,5 @@
(function () {
var { bar: {baz: bark = 1} } = { bar: {baz: 2} };
console.log(bar, baz, bark);
})();