diff --git a/package.json b/package.json index 1e1e5f10..84147aca 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "mkdirp": "0.5.1", "opencollective": "1.0.3", "reflect-metadata": "0.1.10", - "source-map-support": "0.4.17", + "source-map-support": "0.4.18", "string-template": "1.0.0", "tslib": "1.7.1" }, @@ -47,11 +47,11 @@ "@types/estree": "0.0.37", "@types/md5": "2.1.32", "@types/mkdirp": "0.5.1", - "@types/mocha": "2.2.42", - "@types/node": "8.0.26", + "@types/mocha": "2.2.43", + "@types/node": "8.0.28", "@types/sinon": "2.3.3", "@types/string-template": "1.0.2", - "@types/webpack-env": "1.13.0", + "@types/webpack-env": "1.13.1", "awesome-typescript-loader": "3.2.3", "babel-cli": "6.26.0", "babel-loader": "7.1.2", @@ -60,7 +60,7 @@ "chai": "4.1.2", "coveralls": "2.13.1", "istanbul": "1.1.0-alpha.1", - "mocha": "3.5.0", + "mocha": "3.5.1", "pre-commit": "1.2.2", "sinon": "3.2.1", "ts-node": "3.3.0", diff --git a/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/black-list-node-guard/BlackListObfuscatingGuard.spec.ts b/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec.ts similarity index 100% rename from test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/black-list-node-guard/BlackListObfuscatingGuard.spec.ts rename to test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec.ts diff --git a/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/black-list-node-guard/fixtures/use-strict-operator.js b/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/black-list-obfuscating-guard/fixtures/use-strict-operator.js similarity index 100% rename from test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/black-list-node-guard/fixtures/use-strict-operator.js rename to test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/black-list-obfuscating-guard/fixtures/use-strict-operator.js diff --git a/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts b/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts new file mode 100644 index 00000000..50f9994e --- /dev/null +++ b/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec.ts @@ -0,0 +1,77 @@ +import { assert } from 'chai'; + +import { IObfuscationResult } from '../../../../../../src/interfaces/IObfuscationResult'; + +import { JavaScriptObfuscator } from '../../../../../../src/JavaScriptObfuscatorFacade'; + +import { NO_CUSTOM_NODES_PRESET } from '../../../../../../src/options/presets/NoCustomNodes'; + +import { readFileAsString } from '../../../../../helpers/readFileAsString'; + +describe('ConditionalCommentObfuscatingGuard', () => { + describe('check (node: ESTree.Node): boolean', () => { + describe('variant #1: `disable` conditional comment', () => { + const obfuscatedVariableDeclarationRegExp: RegExp = /var *_0x([a-f0-9]){4,6} *= *0x1;/; + const ignoredVariableDeclarationRegExp: RegExp = /var *bar *= *2;/; + const consoleLogRegExp: RegExp = /console.log\(_0x([a-f0-9]){4,6}\);/; + + let obfuscatedCode: string; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/simple.js'); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_CUSTOM_NODES_PRESET + } + ); + + obfuscatedCode = obfuscationResult.getObfuscatedCode(); + }); + + it('match #1: should obfuscate variable declaration before `disable` conditional comment', () => { + assert.match(obfuscatedCode, obfuscatedVariableDeclarationRegExp); + }); + + it('match #2: should ignore variable declaration after `disable` conditional comment', () => { + assert.match(obfuscatedCode, ignoredVariableDeclarationRegExp); + }); + + it('match #3: should obfuscate variable name in `console.log`', () => { + assert.match(obfuscatedCode, consoleLogRegExp); + }); + }); + + describe('variant #2: `disable` and `enable` conditional comment', () => { + const obfuscatedVariableDeclaration1RegExp: RegExp = /var *_0x([a-f0-9]){4,6} *= *0x1;/; + const obfuscatedVariableDeclaration2RegExp: RegExp = /var *_0x([a-f0-9]){4,6} *= *0x3;/; + const ignoredVariableDeclarationRegExp: RegExp = /var *bar *= *2;/; + + let obfuscatedCode: string; + + beforeEach(() => { + const code: string = readFileAsString(__dirname + '/fixtures/disable-and-enable-comments.js'); + const obfuscationResult: IObfuscationResult = JavaScriptObfuscator.obfuscate( + code, + { + ...NO_CUSTOM_NODES_PRESET + } + ); + + obfuscatedCode = obfuscationResult.getObfuscatedCode(); + }); + + it('match #1: should obfuscate variable declaration before `disable` conditional comment', () => { + assert.match(obfuscatedCode, obfuscatedVariableDeclaration1RegExp); + }); + + it('match #2: should ignore variable declaration after `disable` conditional comment', () => { + assert.match(obfuscatedCode, ignoredVariableDeclarationRegExp); + }); + + it('match #3: should obfuscate variable declaration after `enable` conditional comment', () => { + assert.match(obfuscatedCode, obfuscatedVariableDeclaration2RegExp); + }); + }); + }); +}); diff --git a/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/fixtures/disable-and-enable-comments.js b/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/fixtures/disable-and-enable-comments.js new file mode 100644 index 00000000..22c59136 --- /dev/null +++ b/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/fixtures/disable-and-enable-comments.js @@ -0,0 +1,9 @@ +(function () { + var foo = 1; + + // javascript-obfuscator:disable + var bar = 2; + + // javascript-obfuscator:enable + var baz = 3; +})(); \ No newline at end of file diff --git a/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/fixtures/simple.js b/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/fixtures/simple.js new file mode 100644 index 00000000..ab6971d2 --- /dev/null +++ b/test/functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/fixtures/simple.js @@ -0,0 +1,8 @@ +(function () { + var foo = 1; + + // javascript-obfuscator:disable + var bar = 2; + + console.log(foo); +})(); \ No newline at end of file diff --git a/test/index.spec.ts b/test/index.spec.ts index de1f0e50..14665d20 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -58,7 +58,8 @@ import './functional-tests/node-transformers/obfuscating-transformers/labeled-st import './functional-tests/node-transformers/obfuscating-transformers/literal-transformer/LiteralTransformer.spec'; import './functional-tests/node-transformers/obfuscating-transformers/object-expression-transformer/ObjectExpressionTransformer.spec'; import './functional-tests/node-transformers/obfuscating-transformers/variable-declaration-transformer/VariableDeclarationTransformer.spec'; -import './functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/black-list-node-guard/BlackListObfuscatingGuard.spec'; +import './functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/black-list-obfuscating-guard/BlackListObfuscatingGuard.spec'; +import './functional-tests/node-transformers/parentizing-transformers/obfuscating-guards/conditional-comment-obfuscating-guard/ConditionalCommentObfuscatingGuard.spec'; import './functional-tests/templates/custom-nodes/domain-lock-nodes/DomainLockNodeTemplate.spec'; import './functional-tests/templates/custom-nodes/string-array-nodes/StringArrayCallsWrapperNodeTemplate.spec'; diff --git a/yarn.lock b/yarn.lock index 160de91e..407236e1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -52,17 +52,17 @@ dependencies: "@types/node" "*" -"@types/mocha@2.2.42": - version "2.2.42" - resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.42.tgz#ab769f51d37646b6fe8d4a086a98c285b1fab3f5" +"@types/mocha@2.2.43": + version "2.2.43" + resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-2.2.43.tgz#03c54589c43ad048cbcbfd63999b55d0424eec27" "@types/node@*": version "8.0.25" resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.25.tgz#66ecaf4df93f5281b48427ee96fbcdfc4f0cdce1" -"@types/node@8.0.26": - version "8.0.26" - resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.26.tgz#4d58be925306fd22b1141085535a0268b8beb189" +"@types/node@8.0.28": + version "8.0.28" + resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.28.tgz#86206716f8d9251cf41692e384264cbd7058ad60" "@types/sinon@2.3.3": version "2.3.3" @@ -72,9 +72,9 @@ version "1.0.2" resolved "https://registry.yarnpkg.com/@types/string-template/-/string-template-1.0.2.tgz#363b273c9b456705e3111e3571e9248f6474eba4" -"@types/webpack-env@1.13.0": - version "1.13.0" - resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.0.tgz#3044381647e11ee973c5af2e925323930f691d80" +"@types/webpack-env@1.13.1": + version "1.13.1" + resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.1.tgz#b45c222e24301bd006e3edfc762cc6b51bda236a" abbrev@1, abbrev@1.0.x: version "1.0.9" @@ -1934,6 +1934,10 @@ hawk@~3.1.3: hoek "2.x.x" sntp "1.x.x" +he@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd" + hmac-drbg@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" @@ -2674,9 +2678,9 @@ mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.1, mkdirp@~0.5.0: dependencies: minimist "0.0.8" -mocha@3.5.0: - version "3.5.0" - resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.5.0.tgz#1328567d2717f997030f8006234bce9b8cd72465" +mocha@3.5.1: + version "3.5.1" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-3.5.1.tgz#9b6d13ac1ccf957edd16f2e439055734b1b60391" dependencies: browser-stdout "1.3.0" commander "2.9.0" @@ -2685,6 +2689,7 @@ mocha@3.5.0: escape-string-regexp "1.0.5" glob "7.1.1" growl "1.9.2" + he "1.1.1" json3 "3.3.2" lodash.create "3.1.1" mkdirp "0.5.1" @@ -3520,7 +3525,13 @@ source-map-resolve@^0.5.0: source-map-url "^0.4.0" urix "^0.1.0" -source-map-support@0.4.17, source-map-support@^0.4.0, source-map-support@^0.4.15: +source-map-support@0.4.18: + version "0.4.18" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f" + dependencies: + source-map "^0.5.6" + +source-map-support@^0.4.0, source-map-support@^0.4.15: version "0.4.17" resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.17.tgz#6f2150553e6375375d0ccb3180502b78c18ba430" dependencies: