mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Merge pull request #514 from javascript-obfuscator/issue-512
Fixed object keys extraction when using with template literals
This commit is contained in:
@@ -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`
|
||||
|
||||
|
||||
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
Vendored
+1
-1
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
@@ -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();
|
||||
|
||||
|
||||
+28
@@ -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', () => {
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
var foo = `${{
|
||||
foo: 'bar',
|
||||
baz: 'bark'
|
||||
}}`;
|
||||
+27
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
var foo = `${{
|
||||
foo: 'bar'
|
||||
}}`;
|
||||
Reference in New Issue
Block a user