mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed for-await-of construction add when deadCodeInjection option is enabled
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
Change Log
|
||||
|
||||
v2.4.3
|
||||
---
|
||||
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/769
|
||||
|
||||
v2.4.2
|
||||
---
|
||||
* Fixed `URI-malformed` when `splitStrings` and `stringArrayEncoding` options are enabled. https://github.com/javascript-obfuscator/javascript-obfuscator/issues/530
|
||||
|
||||
Vendored
+4
-4
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": "2.4.2",
|
||||
"version": "2.4.3",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
|
||||
+2
-1
@@ -106,7 +106,8 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
|
||||
|| NodeGuards.isContinueStatementNode(targetNode)
|
||||
|| NodeGuards.isAwaitExpressionNode(targetNode)
|
||||
|| NodeGuards.isYieldExpressionNode(targetNode)
|
||||
|| NodeGuards.isSuperNode(targetNode);
|
||||
|| NodeGuards.isSuperNode(targetNode)
|
||||
|| (NodeGuards.isForOfStatementNode(targetNode) && targetNode.await);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,6 +141,14 @@ export class NodeGuards {
|
||||
&& !('directive' in node);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
public static isForOfStatementNode (node: ESTree.Node): node is ESTree.ForOfStatement {
|
||||
return node.type === NodeType.ForOfStatement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
|
||||
+51
@@ -438,6 +438,57 @@ describe('DeadCodeInjectionTransformer', () => {
|
||||
assert.equal(superExpressionMatchesLength, expectedSuperExpressionMatchesLength);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #6 - for-await expression in block statement', () => {
|
||||
const functionRegExp: RegExp = new RegExp(
|
||||
`var ${variableMatch} *= *function *\\(\\) *\\{` +
|
||||
`console\\[${variableMatch}\\('${hexMatch}'\\)\\]\\(${variableMatch}\\('${hexMatch}'\\)\\);` +
|
||||
`\\};`,
|
||||
'g'
|
||||
);
|
||||
const awaitExpressionRegExp: RegExp = new RegExp(
|
||||
`for await *\\(const ${variableMatch} of *\\[]\\){}`,
|
||||
'g'
|
||||
);
|
||||
const expectedFunctionMatchesLength: number = 4;
|
||||
const expectedAwaitExpressionMatchesLength: number = 1;
|
||||
|
||||
let functionMatchesLength: number = 0,
|
||||
awaitExpressionMatchesLength: number = 0;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/for-await-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 awaitExpressionMatches: RegExpMatchArray = <RegExpMatchArray>obfuscatedCode.match(awaitExpressionRegExp);
|
||||
|
||||
if (functionMatches) {
|
||||
functionMatchesLength = functionMatches.length;
|
||||
}
|
||||
|
||||
if (awaitExpressionMatches) {
|
||||
awaitExpressionMatchesLength = awaitExpressionMatches.length;
|
||||
}
|
||||
});
|
||||
|
||||
it('match #1: shouldn\'t add dead code', () => {
|
||||
assert.equal(functionMatchesLength, expectedFunctionMatchesLength);
|
||||
});
|
||||
|
||||
it('match #2: shouldn\'t add dead code', () => {
|
||||
assert.equal(awaitExpressionMatchesLength, expectedAwaitExpressionMatchesLength);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Variant #5 - chance of `IfStatement` variant', () => {
|
||||
|
||||
+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) {
|
||||
for await (const item of []) {}
|
||||
}
|
||||
|
||||
foo();
|
||||
bar();
|
||||
baz();
|
||||
bark();
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user