mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed runtime error Uncaught SyntaxError: yield is a reserved identifier when deadCodeInjection is enabled
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
|
||||
v1.8.1
|
||||
---
|
||||
* Fixed runtime error `Uncaught SyntaxError: yield is a reserved identifier` when `deadCodeInjection` is enabled
|
||||
|
||||
v1.8.0
|
||||
---
|
||||
* `domainLock` option patterns with leading dot character (`.example.com`) now cover root domains (`example.com`) in addition to all sub-domains (`sub.example.com`). https://github.com/javascript-obfuscator/javascript-obfuscator/issues/640
|
||||
|
||||
Vendored
+5
-5
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
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "javascript-obfuscator",
|
||||
"version": "1.8.0",
|
||||
"version": "1.8.1",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
@@ -59,8 +59,8 @@
|
||||
"@types/sinon": "9.0.4",
|
||||
"@types/string-template": "1.0.2",
|
||||
"@types/webpack-env": "1.15.2",
|
||||
"@typescript-eslint/eslint-plugin": "3.7.0",
|
||||
"@typescript-eslint/parser": "3.7.0",
|
||||
"@typescript-eslint/eslint-plugin": "3.7.1",
|
||||
"@typescript-eslint/parser": "3.7.1",
|
||||
"chai": "4.2.0",
|
||||
"coveralls": "3.1.0",
|
||||
"eslint": "7.5.0",
|
||||
|
||||
+5
-2
@@ -6,6 +6,8 @@ import * as ESTree from 'estree';
|
||||
import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
|
||||
import { TStatement } from '../../types/node/TStatement';
|
||||
|
||||
import { StringSeparator } from '../../enums/StringSeparator';
|
||||
|
||||
import { ICustomCodeHelperFormatter } from '../../interfaces/custom-code-helpers/ICustomCodeHelperFormatter';
|
||||
import { IOptions } from '../../interfaces/options/IOptions';
|
||||
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
|
||||
@@ -79,6 +81,7 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode
|
||||
protected getNodeStructure (): TStatement[] {
|
||||
const controllerIdentifierName: string = this.randomGenerator.getRandomString(6);
|
||||
const indexIdentifierName: string = this.randomGenerator.getRandomString(6);
|
||||
|
||||
const structure: ESTree.BlockStatement = NodeFactory.blockStatementNode([
|
||||
NodeFactory.variableDeclarationNode(
|
||||
[
|
||||
@@ -87,12 +90,12 @@ export class BlockStatementControlFlowFlatteningNode extends AbstractCustomNode
|
||||
NodeFactory.callExpressionNode(
|
||||
NodeFactory.memberExpressionNode(
|
||||
NodeFactory.literalNode(
|
||||
this.originalKeysIndexesInShuffledArray.join('|')
|
||||
this.originalKeysIndexesInShuffledArray.join(StringSeparator.VerticalLine)
|
||||
),
|
||||
NodeFactory.identifierNode('split')
|
||||
),
|
||||
[
|
||||
NodeFactory.literalNode('|')
|
||||
NodeFactory.literalNode(StringSeparator.VerticalLine)
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
export enum StringSeparator {
|
||||
Dot = '.',
|
||||
Comma = ',',
|
||||
Dot = '.',
|
||||
VerticalLine = '|'
|
||||
}
|
||||
|
||||
@@ -49,5 +49,6 @@ export enum NodeType {
|
||||
UpdateExpression = 'UpdateExpression',
|
||||
VariableDeclaration = 'VariableDeclaration',
|
||||
VariableDeclarator = 'VariableDeclarator',
|
||||
WhileStatement = 'WhileStatement'
|
||||
WhileStatement = 'WhileStatement',
|
||||
YieldExpression = 'YieldExpression'
|
||||
}
|
||||
|
||||
@@ -104,6 +104,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|
||||
|| NodeGuards.isBreakStatementNode(targetNode)
|
||||
|| NodeGuards.isContinueStatementNode(targetNode)
|
||||
|| NodeGuards.isAwaitExpressionNode(targetNode)
|
||||
|| NodeGuards.isYieldExpressionNode(targetNode)
|
||||
|| NodeGuards.isSuperNode(targetNode);
|
||||
}
|
||||
|
||||
|
||||
@@ -421,4 +421,12 @@ export class NodeGuards {
|
||||
public static isWhileStatementNode (node: ESTree.Node): node is ESTree.WhileStatement {
|
||||
return node.type === NodeType.WhileStatement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isYieldExpressionNode (node: ESTree.Node): node is ESTree.YieldExpression {
|
||||
return node.type === NodeType.YieldExpression;
|
||||
}
|
||||
}
|
||||
|
||||
+52
-1
@@ -336,7 +336,58 @@ describe('DeadCodeInjectionTransformer', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #4 - super expression in block statement', () => {
|
||||
describe('Variant #4 - yield expression in block statement', () => {
|
||||
const functionRegExp: RegExp = new RegExp(
|
||||
`var ${variableMatch} *= *function *\\(\\) *\\{` +
|
||||
`console\\[${variableMatch}\\('${hexMatch}'\\)\\]\\(${variableMatch}\\('${hexMatch}'\\)\\);` +
|
||||
`\\};`,
|
||||
'g'
|
||||
);
|
||||
const yieldExpressionRegExp: RegExp = new RegExp(
|
||||
`yield *${variableMatch}\\(\\)`,
|
||||
'g'
|
||||
);
|
||||
const expectedFunctionMatchesLength: number = 4;
|
||||
const expectedAwaitExpressionMatchesLength: number = 1;
|
||||
|
||||
let functionMatchesLength: number = 0,
|
||||
yieldExpressionMatchesLength: number = 0;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/yield-expression.js');
|
||||
|
||||
const obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
deadCodeInjection: true,
|
||||
deadCodeInjectionThreshold: 1,
|
||||
stringArray: true,
|
||||
stringArrayThreshold: 1
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
const functionMatches: RegExpMatchArray = <RegExpMatchArray>obfuscatedCode.match(functionRegExp);
|
||||
const yieldExpressionMatches: RegExpMatchArray = <RegExpMatchArray>obfuscatedCode.match(yieldExpressionRegExp);
|
||||
|
||||
if (functionMatches) {
|
||||
functionMatchesLength = functionMatches.length;
|
||||
}
|
||||
|
||||
if (yieldExpressionMatches) {
|
||||
yieldExpressionMatchesLength = yieldExpressionMatches.length;
|
||||
}
|
||||
});
|
||||
|
||||
it('match #1: shouldn\'t add dead code', () => {
|
||||
assert.equal(functionMatchesLength, expectedFunctionMatchesLength);
|
||||
});
|
||||
|
||||
it('match #2: shouldn\'t add dead code', () => {
|
||||
assert.equal(yieldExpressionMatchesLength, expectedAwaitExpressionMatchesLength);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #5 - super expression in block statement', () => {
|
||||
const functionRegExp: RegExp = new RegExp(
|
||||
`var ${variableMatch} *= *function *\\(\\) *\\{` +
|
||||
`console\\[${variableMatch}\\('${hexMatch}'\\)\\]\\(${variableMatch}\\('${hexMatch}'\\)\\);` +
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
(async function * (){
|
||||
if (true) {
|
||||
var foo = function () {
|
||||
console.log('abc');
|
||||
};
|
||||
var bar = function () {
|
||||
console.log('def');
|
||||
};
|
||||
var baz = function () {
|
||||
console.log('ghi');
|
||||
};
|
||||
var bark = function () {
|
||||
console.log('jkl');
|
||||
};
|
||||
|
||||
if (true) {
|
||||
yield foo();
|
||||
}
|
||||
|
||||
foo();
|
||||
bar();
|
||||
baz();
|
||||
bark();
|
||||
}
|
||||
})();
|
||||
@@ -424,52 +424,52 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.15.2.tgz#927997342bb9f4a5185a86e6579a0a18afc33b0a"
|
||||
integrity sha512-67ZgZpAlhIICIdfQrB5fnDvaKFcDxpKibxznfYRVAT4mQE41Dido/3Ty+E3xGBmTogc5+0Qb8tWhna+5B8z1iQ==
|
||||
|
||||
"@typescript-eslint/eslint-plugin@3.7.0":
|
||||
version "3.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.7.0.tgz#0f91aa3c83d019591719e597fbdb73a59595a263"
|
||||
integrity sha512-4OEcPON3QIx0ntsuiuFP/TkldmBGXf0uKxPQlGtS/W2F3ndYm8Vgdpj/woPJkzUc65gd3iR+qi3K8SDQP/obFg==
|
||||
"@typescript-eslint/eslint-plugin@3.7.1":
|
||||
version "3.7.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-3.7.1.tgz#d144c49a9a0ffe8dd704bb179c243df76c111bc9"
|
||||
integrity sha512-3DB9JDYkMrc8Au00rGFiJLK2Ja9CoMP6Ut0sHsXp3ZtSugjNxvSSHTnKLfo4o+QmjYBJqEznDqsG1zj4F2xnsg==
|
||||
dependencies:
|
||||
"@typescript-eslint/experimental-utils" "3.7.0"
|
||||
"@typescript-eslint/experimental-utils" "3.7.1"
|
||||
debug "^4.1.1"
|
||||
functional-red-black-tree "^1.0.1"
|
||||
regexpp "^3.0.0"
|
||||
semver "^7.3.2"
|
||||
tsutils "^3.17.1"
|
||||
|
||||
"@typescript-eslint/experimental-utils@3.7.0":
|
||||
version "3.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.7.0.tgz#0ee21f6c48b2b30c63211da23827725078d5169a"
|
||||
integrity sha512-xpfXXAfZqhhqs5RPQBfAFrWDHoNxD5+sVB5A46TF58Bq1hRfVROrWHcQHHUM9aCBdy9+cwATcvCbRg8aIRbaHQ==
|
||||
"@typescript-eslint/experimental-utils@3.7.1":
|
||||
version "3.7.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-3.7.1.tgz#ab036caaed4c870d22531d41f9352f3147364d61"
|
||||
integrity sha512-TqE97pv7HrqWcGJbLbZt1v59tcqsSVpWTOf1AqrWK7n8nok2sGgVtYRuGXeNeLw3wXlLEbY1MKP3saB2HsO/Ng==
|
||||
dependencies:
|
||||
"@types/json-schema" "^7.0.3"
|
||||
"@typescript-eslint/types" "3.7.0"
|
||||
"@typescript-eslint/typescript-estree" "3.7.0"
|
||||
"@typescript-eslint/types" "3.7.1"
|
||||
"@typescript-eslint/typescript-estree" "3.7.1"
|
||||
eslint-scope "^5.0.0"
|
||||
eslint-utils "^2.0.0"
|
||||
|
||||
"@typescript-eslint/parser@3.7.0":
|
||||
version "3.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.7.0.tgz#3e9cd9df9ea644536feb6e5acdb8279ecff96ce9"
|
||||
integrity sha512-2LZauVUt7jAWkcIW7djUc3kyW+fSarNEuM3RF2JdLHR9BfX/nDEnyA4/uWz0wseoWVZbDXDF7iF9Jc342flNqQ==
|
||||
"@typescript-eslint/parser@3.7.1":
|
||||
version "3.7.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-3.7.1.tgz#5d9ccecb116d12d9c6073e9861c57c9b1aa88128"
|
||||
integrity sha512-W4QV/gXvfIsccN8225784LNOorcm7ch68Fi3V4Wg7gmkWSQRKevO4RrRqWo6N/Z/myK1QAiGgeaXN57m+R/8iQ==
|
||||
dependencies:
|
||||
"@types/eslint-visitor-keys" "^1.0.0"
|
||||
"@typescript-eslint/experimental-utils" "3.7.0"
|
||||
"@typescript-eslint/types" "3.7.0"
|
||||
"@typescript-eslint/typescript-estree" "3.7.0"
|
||||
"@typescript-eslint/experimental-utils" "3.7.1"
|
||||
"@typescript-eslint/types" "3.7.1"
|
||||
"@typescript-eslint/typescript-estree" "3.7.1"
|
||||
eslint-visitor-keys "^1.1.0"
|
||||
|
||||
"@typescript-eslint/types@3.7.0":
|
||||
version "3.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-3.7.0.tgz#09897fab0cb95479c01166b10b2c03c224821077"
|
||||
integrity sha512-reCaK+hyKkKF+itoylAnLzFeNYAEktB0XVfSQvf0gcVgpz1l49Lt6Vo9x4MVCCxiDydA0iLAjTF/ODH0pbfnpg==
|
||||
"@typescript-eslint/types@3.7.1":
|
||||
version "3.7.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-3.7.1.tgz#90375606b2fd73c1224fe9e397ee151e28fa1e0c"
|
||||
integrity sha512-PZe8twm5Z4b61jt7GAQDor6KiMhgPgf4XmUb9zdrwTbgtC/Sj29gXP1dws9yEn4+aJeyXrjsD9XN7AWFhmnUfg==
|
||||
|
||||
"@typescript-eslint/typescript-estree@3.7.0":
|
||||
version "3.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.7.0.tgz#66872e6da120caa4b64e6b4ca5c8702afc74738d"
|
||||
integrity sha512-xr5oobkYRebejlACGr1TJ0Z/r0a2/HUf0SXqPvlgUMwiMqOCu/J+/Dr9U3T0IxpE5oLFSkqMx1FE/dKaZ8KsOQ==
|
||||
"@typescript-eslint/typescript-estree@3.7.1":
|
||||
version "3.7.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.7.1.tgz#ce1ffbd0fa53f34d4ce851a7a364e392432f6eb3"
|
||||
integrity sha512-m97vNZkI08dunYOr2lVZOHoyfpqRs0KDpd6qkGaIcLGhQ2WPtgHOd/eVbsJZ0VYCQvupKrObAGTOvk3tfpybYA==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "3.7.0"
|
||||
"@typescript-eslint/visitor-keys" "3.7.0"
|
||||
"@typescript-eslint/types" "3.7.1"
|
||||
"@typescript-eslint/visitor-keys" "3.7.1"
|
||||
debug "^4.1.1"
|
||||
glob "^7.1.6"
|
||||
is-glob "^4.0.1"
|
||||
@@ -477,10 +477,10 @@
|
||||
semver "^7.3.2"
|
||||
tsutils "^3.17.1"
|
||||
|
||||
"@typescript-eslint/visitor-keys@3.7.0":
|
||||
version "3.7.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-3.7.0.tgz#ac0417d382a136e4571a0b0dcfe52088cb628177"
|
||||
integrity sha512-k5PiZdB4vklUpUX4NBncn5RBKty8G3ihTY+hqJsCdMuD0v4jofI5xuqwnVcWxfv6iTm2P/dfEa2wMUnsUY8ODw==
|
||||
"@typescript-eslint/visitor-keys@3.7.1":
|
||||
version "3.7.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-3.7.1.tgz#b90191e74efdee656be8c5a30f428ed16dda46d1"
|
||||
integrity sha512-xn22sQbEya+Utj2IqJHGLA3i1jDzR43RzWupxojbSWnj3nnPLavaQmWe5utw03CwYao3r00qzXfgJMGNkrzrAA==
|
||||
dependencies:
|
||||
eslint-visitor-keys "^1.1.0"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user