Merge pull request #514 from javascript-obfuscator/issue-512

Fixed object keys extraction when using with template literals
This commit is contained in:
Timofey Kachalov
2020-01-21 00:14:56 +03:00
committed by GitHub
10 changed files with 73 additions and 9 deletions
+1
View File
@@ -5,6 +5,7 @@ v0.24.0
* **Internal refactoring:** completely new mechanism to rename variable names
* Dynamic import and `import.meta` support. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/505
* Now usage of some browser-related options with `target: 'node'` will cause a validation error
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/512
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/496
* **Internal:** switched from `awesome-typescript-loader` on `ts-loader`
+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
File diff suppressed because one or more lines are too long
@@ -122,6 +122,7 @@ export class TemplateLiteralTransformer extends AbstractNodeTransformer {
}
NodeUtils.parentizeAst(transformedNode);
NodeUtils.parentizeNode(transformedNode, parentNode);
return transformedNode;
}
+6 -6
View File
@@ -1,21 +1,21 @@
'use strict';
import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNodes';
import { ObfuscationTarget } from '../../src/enums/ObfuscationTarget';
(function () {
const JavaScriptObfuscator: any = require('../../index');
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`
function f(obj) {
const {c} = obj;
}
const foo = \`\${{
foo: 'bar',
baz: 'bark'
}.baz}\`;
console.log(foo);
`,
{
...NO_ADDITIONAL_NODES_PRESET,
sourceMap: true,
target: ObfuscationTarget.Browser
transformObjectKeys: true
}
).getObfuscatedCode();
@@ -424,6 +424,34 @@ describe('ObjectExpressionKeysTransformer', () => {
assert.match(obfuscatedCode, regExp);
});
});
describe('Variant #14: template literal', () => {
const match: string = `` +
`var *${variableMatch} *= *{};` +
`${variableMatch}\\['foo'] *= *'bar';` +
`${variableMatch}\\['baz'] *= *'bark';` +
`var *foo *= *'' *\\+ *_0x[a-f0-9]{4,6};` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/template-literal.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
).getObfuscatedCode();
});
it('shouldn transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
describe('member expression as host of object expression', () => {
@@ -0,0 +1,4 @@
var foo = `${{
foo: 'bar',
baz: 'bark'
}}`;
@@ -182,4 +182,31 @@ describe('TemplateLiteralTransformer', () => {
assert.match(obfuscatedCode, /^\[]\['map']\(\(\) *=> *'foo'\);$/);
});
});
describe('Variant #8: parentize node', () => {
const match: string = `` +
`var *_0x[a-f0-9]{4,6} *= *{};` +
`_0x[a-f0-9]{4,6}\\['foo'] *= *'bar';` +
`var *foo *= *'' *\\+ *_0x[a-f0-9]{4,6};` +
``;
const regExp: RegExp = new RegExp(match);
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/parentize-node.js');
obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
).getObfuscatedCode();
});
it('should correctly obfuscate code without maximum call stack error', () => {
assert.match(obfuscatedCode, regExp);
});
});
});