Merge pull request #167 from javascript-obfuscator/wrong-string-array-calls-wrapper-name

Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/…
This commit is contained in:
Timofey Kachalov
2018-01-07 01:08:29 +03:00
committed by GitHub
7 changed files with 46 additions and 5 deletions
+2
View File
@@ -3,6 +3,8 @@ Change Log
v0.14.0
---
* **Breaking change:** Now CLI obfuscating directory recursively. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/157
* Fixed runtime errors when `deadCodeInjection` is enabled and `identifierNamesGenerator` is set to `mangled`
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/166
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/156
* Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/159
+1 -1
View File
File diff suppressed because one or more lines are too long
@@ -223,8 +223,8 @@ export class DeadCodeInjectionTransformer extends AbstractNodeTransformer {
const random2: boolean = this.randomGenerator.getMathRandom() > 0.5;
const operator: ESTree.BinaryOperator = random1 ? '===' : '!==';
const leftString: string = this.randomGenerator.getRandomString(3);
const rightString: string = random2 ? leftString : this.randomGenerator.getRandomString(3);
const leftString: string = this.randomGenerator.getRandomString(5);
const rightString: string = random2 ? leftString : this.randomGenerator.getRandomString(5);
const [consequent, alternate]: [ESTree.BlockStatement, ESTree.BlockStatement] = random1 === random2
? [blockStatementNode, randomBlockStatementNode]
@@ -250,8 +250,13 @@ export class StringLiteralObfuscatingReplacer extends AbstractObfuscatingReplace
));
}
const stringArrayIdentifierNode: ESTree.Identifier = Nodes.getIdentifierNode(stringArrayStorageCallsWrapperName);
// prevent obfuscation of this identifier
stringArrayIdentifierNode.obfuscatedNode = true;
return Nodes.getCallExpressionNode(
Nodes.getIdentifierNode(stringArrayStorageCallsWrapperName),
stringArrayIdentifierNode,
callExpressionArgs
);
}
+2 -1
View File
@@ -238,11 +238,12 @@ export class NodeGuards {
);
const parentNodeIsMethodDefinitionNode: boolean = NodeGuards.isMethodDefinitionNode(parentNode) &&
!parentNode.computed;
const isLabelIdentifierNode: boolean = NodeGuards.isLabelIdentifierNode(node, parentNode);
return !parentNodeIsPropertyNode &&
!parentNodeIsMemberExpressionNode &&
!parentNodeIsMethodDefinitionNode &&
!NodeGuards.isLabelIdentifierNode(node, parentNode);
!isLabelIdentifierNode;
}
/**
@@ -2,6 +2,7 @@ import { assert } from 'chai';
import { IObfuscationResult } from '../../../../../src/interfaces/IObfuscationResult';
import { IdentifierNamesGenerator } from '../../../../../src/enums/generators/identifier-names-generators/IdentifierNamesGenerator';
import { StringArrayEncoding } from '../../../../../src/enums/StringArrayEncoding';
import { NO_CUSTOM_NODES_PRESET } from '../../../../../src/options/presets/NoCustomNodes';
@@ -289,6 +290,31 @@ describe('LiteralTransformer', () => {
assert.closeTo(noStringArrayProbability, stringArrayThreshold, delta);
});
});
describe('variant #11: string array calls wrapper name', () => {
const regExp: RegExp = /console\[b\('0x0'\)]\('a'\);/;
let obfuscatedCode: string;
before(() => {
const code: string = readFileAsString(__dirname + '/fixtures/string-array-calls-wrapper-name.js');
const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate(
code,
{
...NO_CUSTOM_NODES_PRESET,
stringArray: true,
stringArrayThreshold: 1,
identifierNamesGenerator: IdentifierNamesGenerator.MangledIdentifierNamesGenerator
}
);
obfuscatedCode = obfuscationResult.getObfuscatedCode();
});
it('match #1: should keep identifier with string array calls wrapper name untouched after obfuscation', () => {
assert.match(obfuscatedCode, regExp);
});
});
});
describe('transformation of literal node with boolean value', () => {
@@ -0,0 +1,7 @@
(function(){
function foo () {
console.log('a');
var b;
function b () {}
}
})();