mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Fixed object expression keys transformation when of sequence expressions, when identifier is referenced on the same expression
This commit is contained in:
Vendored
+3
-3
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": "0.24.0-rc.2",
|
||||
"version": "0.24.0-rc.3",
|
||||
"description": "JavaScript obfuscator",
|
||||
"keywords": [
|
||||
"obfuscator",
|
||||
|
||||
@@ -188,8 +188,6 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer {
|
||||
|
||||
// should mark node as prohibited if identifier of node is referenced somewhere inside other nodes
|
||||
for (const nodeToSearch of nodesToSearch) {
|
||||
const identifierNamesSetForCurrentNode: string[] = [];
|
||||
|
||||
estraverse.traverse(nodeToSearch, {
|
||||
enter: (node: ESTree.Node): void | estraverse.VisitorOption => {
|
||||
if (node === objectExpressionNode) {
|
||||
@@ -201,7 +199,7 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer {
|
||||
}
|
||||
|
||||
if (!isCurrentNode) {
|
||||
identifierNamesSetForCurrentNode.push(node.name);
|
||||
identifierNamesSet.push(node.name);
|
||||
} else if (identifierNamesSet.includes(node.name)) {
|
||||
isReferencedIdentifierName = true;
|
||||
|
||||
@@ -212,8 +210,6 @@ export class ObjectExpressionKeysTransformer extends AbstractNodeTransformer {
|
||||
|
||||
if (isCurrentNode || isReferencedIdentifierName) {
|
||||
break;
|
||||
} else {
|
||||
identifierNamesSet.push(...identifierNamesSetForCurrentNode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-5
@@ -7,14 +7,15 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo
|
||||
|
||||
let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
|
||||
`
|
||||
function foo () {
|
||||
function test() {
|
||||
var foo;
|
||||
var bar;
|
||||
(foo = {foo: 1}), (bar = {bar: foo.foo});
|
||||
return bar.bar;
|
||||
return (foo = {props: 1})['state'] = {
|
||||
expanded: foo.props
|
||||
},
|
||||
foo.state.expanded;
|
||||
}
|
||||
|
||||
console.log(foo());
|
||||
console.log(test());
|
||||
`,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
|
||||
+51
-22
@@ -1523,33 +1523,62 @@ describe('ObjectExpressionKeysTransformer', () => {
|
||||
});
|
||||
|
||||
describe('Variant #6: return statement sequence expression identifier reference', () => {
|
||||
const match: string = `` +
|
||||
`var ${variableMatch};` +
|
||||
`var ${variableMatch};` +
|
||||
`var ${variableMatch} *= *{};` +
|
||||
`${variableMatch}\\['foo'] *= *0x1;` +
|
||||
`return ${variableMatch} *= *${variableMatch}, *` +
|
||||
`${variableMatch} *= *{'bar' *: *${variableMatch}\\['foo']}, *` +
|
||||
`${variableMatch}\\['bar'];` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(match);
|
||||
describe('Variant #1: reference on other sequence expression identifier', () => {
|
||||
const match: string = `` +
|
||||
`var ${variableMatch};` +
|
||||
`var ${variableMatch};` +
|
||||
`var ${variableMatch} *= *{};` +
|
||||
`${variableMatch}\\['foo'] *= *0x1;` +
|
||||
`return ${variableMatch} *= *${variableMatch}, *` +
|
||||
`${variableMatch} *= *{'bar' *: *${variableMatch}\\['foo']}, *` +
|
||||
`${variableMatch}\\['bar'];` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(match);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/return-statement-sequence-expression-identifier-reference.js');
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/return-statement-sequence-expression-identifier-reference-1.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
transformObjectKeys: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
transformObjectKeys: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('shouldn ignore sequence expression object expression if it references other sequence expression identifier', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
|
||||
it('shouldn ignore sequence expression object expression if it references other sequence expression identifier', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
describe('Variant #2: reference on same sequence expression identifier', () => {
|
||||
const match: string = `` +
|
||||
`var ${variableMatch};` +
|
||||
`return *\\(${variableMatch} *= *{'props' *: *0x1}\\)\\['state'] *= *{'expanded' *: *${variableMatch}\\['props']}, *` +
|
||||
`${variableMatch}\\['state']\\['expanded'];` +
|
||||
``;
|
||||
const regExp: RegExp = new RegExp(match);
|
||||
|
||||
let obfuscatedCode: string;
|
||||
|
||||
before(() => {
|
||||
const code: string = readFileAsString(__dirname + '/fixtures/return-statement-sequence-expression-identifier-reference-2.js');
|
||||
|
||||
obfuscatedCode = JavaScriptObfuscator.obfuscate(
|
||||
code,
|
||||
{
|
||||
...NO_ADDITIONAL_NODES_PRESET,
|
||||
transformObjectKeys: true
|
||||
}
|
||||
).getObfuscatedCode();
|
||||
});
|
||||
|
||||
it('shouldn ignore sequence expression object expression if it references other sequence expression identifier', () => {
|
||||
assert.match(obfuscatedCode, regExp);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
function test() {
|
||||
var foo;
|
||||
return (foo = {props: 1})['state'] = {
|
||||
expanded: foo.props
|
||||
},
|
||||
foo.state.expanded;
|
||||
}
|
||||
Reference in New Issue
Block a user