Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions dist/index.browser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.cli.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "1.8.0",
"version": "1.8.1",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
[
Expand All @@ -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)
]
)
)
Expand Down
3 changes: 2 additions & 1 deletion src/enums/StringSeparator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum StringSeparator {
Dot = '.',
Comma = ',',
Dot = '.',
VerticalLine = '|'
}
3 changes: 2 additions & 1 deletion src/enums/node/NodeType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ export enum NodeType {
UpdateExpression = 'UpdateExpression',
VariableDeclaration = 'VariableDeclaration',
VariableDeclarator = 'VariableDeclarator',
WhileStatement = 'WhileStatement'
WhileStatement = 'WhileStatement',
YieldExpression = 'YieldExpression'
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|| NodeGuards.isBreakStatementNode(targetNode)
|| NodeGuards.isContinueStatementNode(targetNode)
|| NodeGuards.isAwaitExpressionNode(targetNode)
|| NodeGuards.isYieldExpressionNode(targetNode)
|| NodeGuards.isSuperNode(targetNode);
}

Expand Down
8 changes: 8 additions & 0 deletions src/node/NodeGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}'\\)\\);` +
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
})();
64 changes: 32 additions & 32 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -424,63 +424,63 @@
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.15.2.tgz#927997342bb9f4a5185a86e6579a0a18afc33b0a"
integrity sha512-67ZgZpAlhIICIdfQrB5fnDvaKFcDxpKibxznfYRVAT4mQE41Dido/3Ty+E3xGBmTogc5+0Qb8tWhna+5B8z1iQ==

"@typescript-eslint/[email protected].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/[email protected].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/[email protected].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/[email protected].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/[email protected].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/[email protected].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/[email protected].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/[email protected].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/[email protected].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/[email protected].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"
lodash "^4.17.15"
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/[email protected].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/[email protected].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"

Expand Down