X Tutup
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Change Log
===
v0.18.2
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/320
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/319

v0.18.1
---
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/317
Expand Down
6 changes: 3 additions & 3 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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "javascript-obfuscator",
"version": "0.18.1",
"version": "0.18.2",
"description": "JavaScript obfuscator",
"keywords": [
"obfuscator",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ export abstract class AbstractPropertiesExtractor implements IPropertiesExtracto
return null;
}

/**
* @param {Node} node
* @returns {propertyValueNode is Pattern}
*/
protected static isProhibitedHostParent (node: ESTree.Node): node is ESTree.Pattern {
return NodeGuards.isMemberExpressionNode(node);
}

/**
* @param {Node} node
* @returns {propertyValueNode is Pattern}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ export class AssignmentExpressionPropertiesExtractor extends AbstractPropertiesE
objectExpressionNode: ESTree.ObjectExpression,
hostNode: ESTree.AssignmentExpression
): ESTree.Node {
const hostParentNode: ESTree.Node | undefined = hostNode.parentNode;
const leftNode: ESTree.MemberExpression | ESTree.Pattern = hostNode.left;

// left node shouldn't be as Pattern node
if (AbstractPropertiesExtractor.isProhibitedPattern(leftNode)) {
return objectExpressionNode;
}

// left node shouldn't be as Pattern node
if (hostParentNode && AbstractPropertiesExtractor.isProhibitedHostParent(hostParentNode)) {
return objectExpressionNode;
}

return this.transformObjectExpressionNode(
objectExpressionNode,
leftNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class FunctionTransformer extends AbstractNodeTransformer {
*/
private isGlobalFunctionDeclarationIdentifier (node: ESTree.Identifier, parentNode: ESTree.Node): boolean {
if (!NodeGuards.isFunctionDeclarationNode(parentNode) || parentNode.id !== node) {
return false
return false;
}

const lexicalScopeNode: TNodeWithLexicalScope | undefined = NodeLexicalScopeUtils.getLexicalScopes(parentNode)[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
*/
public replace (nodeValue: string): ESTree.Node {
if (this.isReservedString(nodeValue)) {
return NodeFactory.literalNode(nodeValue);
return this.replaceWithReservedLiteralNode(nodeValue);
}

const useStringArray: boolean = this.canUseStringArray(nodeValue);
Expand Down Expand Up @@ -227,6 +227,16 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
);
}

/**
* @param {string} value
* @returns {Node}
*/
private replaceWithReservedLiteralNode (value: string): ESTree.Node {
return NodeFactory.literalNode(
this.escapeSequenceEncoder.encode(value, false)
);
}

/**
* @param {string} value
* @returns {Node}
Expand Down
6 changes: 2 additions & 4 deletions test/dev/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import { NO_ADDITIONAL_NODES_PRESET } from '../../src/options/presets/NoCustomNo

let obfuscatedCode: string = JavaScriptObfuscator.obfuscate(
`
function foo (foo) {}

new foo();

var n;
(n = {foo: 'bar'}).baz = n.foo;
`,
{
...NO_ADDITIONAL_NODES_PRESET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,5 +519,31 @@ describe('ObjectExpressionKeysTransformer', () => {
});
});
});

describe('Variant #4: assignment expression and member expression', () => {
const match: string = `` +
`var ${variableMatch}; *` +
`\\(${variableMatch} *= *{'foo': *'bar'}\\)\\['baz'] *= *${variableMatch}\\['foo'];` +
``;
const regExp: RegExp = new RegExp(match);

let obfuscatedCode: string;

before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/assignment-expression-and-member-expression.js');

obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
transformObjectKeys: true
}
).getObfuscatedCode();
});

it('shouldn\'t transform object keys', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(function(){
var n;
(n = {foo: 'bar'}).baz = n.foo;
})();
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ describe('LiteralTransformer', () => {
let obfuscatedCode: string;

before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');

obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
Expand Down Expand Up @@ -342,7 +342,7 @@ describe('LiteralTransformer', () => {
let obfuscatedCode: string;

before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');

obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
Expand Down Expand Up @@ -373,7 +373,7 @@ describe('LiteralTransformer', () => {
let obfuscatedCode: string;

before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');

obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
Expand Down Expand Up @@ -402,7 +402,7 @@ describe('LiteralTransformer', () => {
let obfuscatedCode: string;

before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');

obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
Expand Down Expand Up @@ -432,7 +432,7 @@ describe('LiteralTransformer', () => {
let obfuscatedCode: string;

before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option.js');
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-1.js');

obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
Expand All @@ -452,6 +452,28 @@ describe('LiteralTransformer', () => {
assert.match(obfuscatedCode, stringLiteralRegExp2);
});
});

describe('Variant #4: correct escape of special characters', () => {
const stringLiteralRegExp: RegExp = /var baz *= *'Cannot\\x20find\\x20module\\x20\\x27' *\+ *foo *\+ *'\\x27';/;

let obfuscatedCode: string;

before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/reserved-strings-option-2.js');

obfuscatedCode = JavaScriptObfuscator.obfuscate(
code,
{
...NO_ADDITIONAL_NODES_PRESET,
reservedStrings: ['a']
}
).getObfuscatedCode();
});

it('match #1: should ignore reserved strings', () => {
assert.match(obfuscatedCode, stringLiteralRegExp);
});
});
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var foo = 'bar';
var baz = 'Cannot find module \'' + foo + '\'';
X Tutup