Browse Source

moving from `format-unicorn` on `string-template` package

sanex3339 8 years ago
parent
commit
ee018dd75b
24 changed files with 535 additions and 262 deletions
  1. 477 210
      dist/index.js
  2. 3 3
      package.json
  3. 1 0
      src/cli/JavaScriptObfuscatorCLI.ts
  4. 2 2
      src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts
  5. 2 2
      src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionDivideFunctionNode.ts
  6. 2 2
      src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionExponentiationFunctionNode.ts
  7. 2 2
      src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionMultiplyFunctionNode.ts
  8. 2 2
      src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionSubtractFunctionNode.ts
  9. 2 2
      src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionSumFunctionNode.ts
  10. 2 2
      src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/ControlFlowStorageCallNode.ts
  11. 2 2
      src/custom-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts
  12. 2 2
      src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts
  13. 2 2
      src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts
  14. 2 2
      src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts
  15. 2 2
      src/custom-nodes/domain-lock-nodes/DomainLockNode.ts
  16. 3 3
      src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts
  17. 3 1
      src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts
  18. 5 5
      src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts
  19. 2 2
      src/custom-nodes/string-array-nodes/StringArrayNode.ts
  20. 3 3
      src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts
  21. 1 1
      src/node-control-flow-changers/control-flow-replacers/AbstractControlFlowReplacer.ts
  22. 6 3
      test/dev/dev.ts
  23. 2 2
      test/functional-tests/templates/custom-nodes/domain-lock-nodes/DomainLockNodeTemplate.spec.ts
  24. 5 5
      test/functional-tests/templates/custom-nodes/string-array-nodes/StringArrayCallsWrapperNodeTemplate.spec.ts

File diff suppressed because it is too large
+ 477 - 210
dist/index.js


+ 3 - 3
package.json

@@ -27,9 +27,9 @@
     "escodegen": "1.8.1",
     "esprima": "3.1.1",
     "estraverse": "4.2.0",
-    "format-unicorn": "1.1.0",
     "mkdirp": "0.5.1",
-    "source-map-support": "0.4.6"
+    "source-map-support": "0.4.6",
+    "string-template": "^1.0.0"
   },
   "devDependencies": {
     "@types/chai": "3.4.34",
@@ -39,12 +39,12 @@
     "@types/esprima": "2.1.33",
     "@types/estraverse": "0.0.6",
     "@types/estree": "0.0.34",
-    "@types/format-unicorn": "0.0.29",
     "@types/joi": "9.0.33",
     "@types/mkdirp": "0.3.29",
     "@types/mocha": "2.2.33",
     "@types/node": "6.0.47",
     "@types/sinon": "1.16.31",
+    "@types/string-template": "^1.0.2",
     "awesome-typescript-loader": "2.2.4",
     "babel-cli": "6.18.0",
     "babel-loader": "6.2.7",

+ 1 - 0
src/cli/JavaScriptObfuscatorCLI.ts

@@ -145,6 +145,7 @@ export class JavaScriptObfuscatorCLI {
             .usage('<inputPath> [options]')
             .option('-o, --output <path>', 'Output path for obfuscated code')
             .option('--compact <boolean>', 'Disable one line output code compacting', JavaScriptObfuscatorCLI.parseBoolean)
+            .option('--controlFlow <boolean>', 'Enables control flow change', JavaScriptObfuscatorCLI.parseBoolean)
             .option('--debugProtection <boolean>', 'Disable browser Debug panel (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean)
             .option('--debugProtectionInterval <boolean>', 'Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)', JavaScriptObfuscatorCLI.parseBoolean)
             .option('--disableConsoleOutput <boolean>', 'Allow console.log, console.info, console.error and console.warn messages output into browser console', JavaScriptObfuscatorCLI.parseBoolean)

+ 2 - 2
src/custom-nodes/console-output-nodes/ConsoleOutputDisableExpressionNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 
@@ -69,7 +69,7 @@ export class ConsoleOutputDisableExpressionNode extends AbstractCustomNode {
      * @returns {string}
      */
     public getCode (): string {
-        return ConsoleOutputDisableExpressionTemplate().formatUnicorn({
+        return format(ConsoleOutputDisableExpressionTemplate(), {
             consoleLogDisableFunctionName: Utils.getRandomVariableName(),
             singleNodeCallControllerFunctionName: this.callsControllerFunctionName
         });

+ 2 - 2
src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionDivideFunctionNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
 
@@ -30,7 +30,7 @@ export class BinaryExpressionDivideFunctionNode extends AbstractCustomNode {
      */
     public getCode (): string {
         return JavaScriptObfuscator.obfuscate(
-            BinaryExpressionDivideFunctionTemplate().formatUnicorn({
+            format(BinaryExpressionDivideFunctionTemplate(), {
                 functionName: Utils.getRandomVariableName()
             }),
             NO_CUSTOM_NODES_PRESET

+ 2 - 2
src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionExponentiationFunctionNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
 
@@ -30,7 +30,7 @@ export class BinaryExpressionExponentiationFunctionNode extends AbstractCustomNo
      */
     public getCode (): string {
         return JavaScriptObfuscator.obfuscate(
-            BinaryExpressionExponentiationFunctionTemplate().formatUnicorn({
+            format(BinaryExpressionExponentiationFunctionTemplate(), {
                 functionName: Utils.getRandomVariableName()
             }),
             NO_CUSTOM_NODES_PRESET

+ 2 - 2
src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionMultiplyFunctionNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
 
@@ -30,7 +30,7 @@ export class BinaryExpressionMultiplyFunctionNode extends AbstractCustomNode {
      */
     public getCode (): string {
         return JavaScriptObfuscator.obfuscate(
-            BinaryExpressionMultiplyFunctionTemplate().formatUnicorn({
+            format(BinaryExpressionMultiplyFunctionTemplate(), {
                 functionName: Utils.getRandomVariableName()
             }),
             NO_CUSTOM_NODES_PRESET

+ 2 - 2
src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionSubtractFunctionNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
 
@@ -30,7 +30,7 @@ export class BinaryExpressionSubtractFunctionNode extends AbstractCustomNode {
      */
     public getCode (): string {
         return JavaScriptObfuscator.obfuscate(
-            BinaryExpressionSubtractFunctionTemplate().formatUnicorn({
+            format(BinaryExpressionSubtractFunctionTemplate(), {
                 functionName: Utils.getRandomVariableName()
             }),
             NO_CUSTOM_NODES_PRESET

+ 2 - 2
src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/BinaryExpressionSumFunctionNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
 
@@ -30,7 +30,7 @@ export class BinaryExpressionSumFunctionNode extends AbstractCustomNode {
      */
     public getCode (): string {
         return JavaScriptObfuscator.obfuscate(
-            BinaryExpressionSumFunctionTemplate().formatUnicorn({
+            format(BinaryExpressionSumFunctionTemplate(), {
                 functionName: Utils.getRandomVariableName()
             }),
             NO_CUSTOM_NODES_PRESET

+ 2 - 2
src/custom-nodes/control-flow-replacers-nodes/binary-expression-control-flow-replacer-nodes/ControlFlowStorageCallNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../../types/TNodeWithBlockStatement';
 
@@ -70,7 +70,7 @@ export class ControlFlowStorageCallNode extends AbstractCustomNode {
      * @returns {string}
      */
     public getCode (): string {
-        return ControlFlowStorageCallTemplate().formatUnicorn({
+        return format(ControlFlowStorageCallTemplate(), {
             controlFlowStorageKey: this.controlFlowStorageKey,
             controlFlowStorageName: this.controlFlowStorageName,
             leftValue: this.leftValue,

+ 2 - 2
src/custom-nodes/control-flow-storage-nodes/ControlFlowStorageNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 
@@ -57,7 +57,7 @@ export class ControlFlowStorageNode extends AbstractCustomNode {
      * @returns {string}
      */
     public getCode (): string {
-        return ControlFlowStorageTemplate().formatUnicorn({
+        return format(ControlFlowStorageTemplate(), {
             controlFlowStorage: this.controlFlowStorage.toString(),
             controlFlowStorageName: this.controlFlowStorageName
         });

+ 2 - 2
src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionCallNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 
@@ -43,7 +43,7 @@ export class DebugProtectionFunctionCallNode extends AbstractCustomNode {
      * @returns {string}
      */
     public getCode (): string {
-        return DebugProtectionFunctionCallTemplate().formatUnicorn({
+        return format(DebugProtectionFunctionCallTemplate(), {
             debugProtectionFunctionName: this.debugProtectionFunctionName
         });
     }

+ 2 - 2
src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionIntervalNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 
@@ -43,7 +43,7 @@ export class DebugProtectionFunctionIntervalNode extends AbstractCustomNode {
      * @returns {string}
      */
     public getCode (): string {
-        return DebugProtectionFunctionIntervalTemplate().formatUnicorn({
+        return format(DebugProtectionFunctionIntervalTemplate(), {
             debugProtectionFunctionName: this.debugProtectionFunctionName
         });
     }

+ 2 - 2
src/custom-nodes/debug-protection-nodes/DebugProtectionFunctionNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 
@@ -50,7 +50,7 @@ export class DebugProtectionFunctionNode extends AbstractCustomNode {
      * @returns {string}
      */
     public getCode (): string {
-        return DebugProtectionFunctionTemplate().formatUnicorn({
+        return format(DebugProtectionFunctionTemplate(), {
             debugProtectionFunctionName: this.debugProtectionFunctionName
         });
     }

+ 2 - 2
src/custom-nodes/domain-lock-nodes/DomainLockNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 
@@ -72,7 +72,7 @@ export class DomainLockNode extends AbstractCustomNode {
         let domainsString: string = this.options.domainLock.join(';'),
             [hiddenDomainsString, diff]: string[] = Utils.hideString(domainsString, domainsString.length * 3);
 
-        return DomainLockNodeTemplate().formatUnicorn({
+        return format(DomainLockNodeTemplate(), {
             domainLockFunctionName: Utils.getRandomVariableName(),
             diff: diff,
             domains: hiddenDomainsString,

+ 3 - 3
src/custom-nodes/node-calls-controller-nodes/NodeCallsControllerFunctionNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 
@@ -77,14 +77,14 @@ export class NodeCallsControllerFunctionNode extends AbstractCustomNode {
     public getCode (): string {
         if (this.appendState === AppendState.AfterObfuscation) {
             return JavaScriptObfuscator.obfuscate(
-                SingleNodeCallControllerTemplate().formatUnicorn({
+                format(SingleNodeCallControllerTemplate(), {
                     singleNodeCallControllerFunctionName: this.callsControllerFunctionName
                 }),
                 NO_CUSTOM_NODES_PRESET
             ).getObfuscatedCode();
         }
 
-        return SingleNodeCallControllerTemplate().formatUnicorn({
+        return format(SingleNodeCallControllerTemplate(), {
             singleNodeCallControllerFunctionName: this.callsControllerFunctionName
         });
     }

+ 3 - 1
src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts

@@ -1,3 +1,5 @@
+import * as format from 'string-template';
+
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 
 import { IOptions } from '../../interfaces/IOptions';
@@ -71,7 +73,7 @@ export class SelfDefendingUnicodeNode extends AbstractCustomNode {
      */
     public getCode (): string {
         return JavaScriptObfuscator.obfuscate(
-            SelfDefendingTemplate().formatUnicorn({
+            format(SelfDefendingTemplate(), {
                 selfDefendingFunctionName: Utils.getRandomVariableName(),
                 singleNodeCallControllerFunctionName: this.callsControllerFunctionName
             }),

+ 5 - 5
src/custom-nodes/string-array-nodes/StringArrayCallsWrapper.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 import { TStatement } from '../../types/TStatement';
@@ -80,7 +80,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
         const decodeNodeTemplate: string = this.getDecodeStringArrayTemplate();
 
         return JavaScriptObfuscator.obfuscate(
-            StringArrayCallsWrapperTemplate().formatUnicorn({
+            format(StringArrayCallsWrapperTemplate(), {
                 decodeNodeTemplate,
                 stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
                 stringArrayName: this.stringArrayName
@@ -111,7 +111,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
             selfDefendingCode: string = '';
 
         if (this.options.selfDefending) {
-            selfDefendingCode = SelfDefendingTemplate().formatUnicorn({
+            selfDefendingCode = format(SelfDefendingTemplate(), {
                 stringArrayCallsWrapperName: this.stringArrayCallsWrapperName,
                 stringArrayName: this.stringArrayName
             });
@@ -119,7 +119,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
 
         switch (this.options.stringArrayEncoding) {
             case StringArrayEncoding.base64:
-                decodeStringArrayTemplate = StringArrayBase64DecodeNodeTemplate().formatUnicorn({
+                decodeStringArrayTemplate = format(StringArrayBase64DecodeNodeTemplate(), {
                     atobPolyfill: AtobTemplate(),
                     selfDefendingCode,
                     stringArrayCallsWrapperName: this.stringArrayCallsWrapperName
@@ -128,7 +128,7 @@ export class StringArrayCallsWrapper extends AbstractCustomNode {
                 break;
 
             case StringArrayEncoding.rc4:
-                decodeStringArrayTemplate = StringArrayRc4DecodeNodeTemplate().formatUnicorn({
+                decodeStringArrayTemplate = format(StringArrayRc4DecodeNodeTemplate(), {
                     atobPolyfill: AtobTemplate(),
                     rc4Polyfill: Rc4Template(),
                     selfDefendingCode,

+ 2 - 2
src/custom-nodes/string-array-nodes/StringArrayNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 import { TStatement } from '../../types/TStatement';
@@ -74,7 +74,7 @@ export class StringArrayNode extends AbstractCustomNode {
      * @returns {string}
      */
     public getCode (): string {
-        return StringArrayTemplate().formatUnicorn({
+        return format(StringArrayTemplate(), {
             stringArrayName: this.stringArrayName,
             stringArray: this.stringArray.toString()
         });

+ 3 - 3
src/custom-nodes/string-array-nodes/StringArrayRotateFunctionNode.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { TNodeWithBlockStatement } from '../../types/TNodeWithBlockStatement';
 
@@ -77,7 +77,7 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
             whileFunctionName: string = Utils.getRandomVariableName();
 
         if (this.options.selfDefending) {
-            code = SelfDefendingTemplate().formatUnicorn({
+            code = format(SelfDefendingTemplate(), {
                 timesName,
                 whileFunctionName
             });
@@ -86,7 +86,7 @@ export class StringArrayRotateFunctionNode extends AbstractCustomNode {
         }
 
         return JavaScriptObfuscator.obfuscate(
-            StringArrayRotateFunctionTemplate().formatUnicorn({
+            format(StringArrayRotateFunctionTemplate(), {
                 code,
                 timesName,
                 stringArrayName: this.stringArrayName,

+ 1 - 1
src/node-control-flow-changers/control-flow-replacers/AbstractControlFlowReplacer.ts

@@ -32,7 +32,7 @@ export abstract class AbstractControlFlowReplacer implements IControlFlowReplace
      */
     protected static getStorageKey (): string {
         return Utils.getRandomGenerator().string({
-            length: 3,
+            length: 4,
             pool: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
         });
     }

+ 6 - 3
test/dev/dev.ts

@@ -37,14 +37,17 @@ if (!(<any>global)._babelPolyfill) {
         
         function t () {
             return function () {
-                return 100 * 2;
+                return 100 * 2 - 70;
             }
         }
         
-        var s = 100 + 50;
+        var n = 100 + 50;
+        var b = true + true;
+        var s = 'str' + 'ing';
+        var r = /re/ + /g/;
         
         console.log(t()());
-        console.log(s);
+        console.log(n);
     })();
     `,
         Object.assign({}, NO_CUSTOM_NODES_PRESET, {

+ 2 - 2
test/functional-tests/templates/custom-nodes/domain-lock-nodes/DomainLockNodeTemplate.spec.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { DomainLockNodeTemplate } from '../../../../../src/templates/custom-nodes/domain-lock-nodes/domain-lock-node/DomainLockNodeTemplate';
 
@@ -14,7 +14,7 @@ const assert: Chai.AssertStatic = require('chai').assert;
  * @returns {Function}
  */
 function getFunctionFromTemplate (templateData: any, callsControllerFunctionName: string,  currentDomain: string) {
-    let domainLockTemplate: string = DomainLockNodeTemplate().formatUnicorn(templateData);
+    let domainLockTemplate: string = format(DomainLockNodeTemplate(), templateData);
 
     return Function(`
         document = {

+ 5 - 5
test/functional-tests/templates/custom-nodes/string-array-nodes/StringArrayCallsWrapperNodeTemplate.spec.ts

@@ -1,4 +1,4 @@
-import 'format-unicorn';
+import * as format from 'string-template';
 
 import { AtobTemplate } from '../../../../../src/templates/custom-nodes/AtobTemplate';
 import { Rc4Template } from '../../../../../src/templates/custom-nodes/Rc4Template';
@@ -23,7 +23,7 @@ function getFunctionFromTemplateBase64Encoding (
     stringArrayCallsWrapperName: string,
     index: string
 ) {
-    let stringArrayCallsWrapperTemplate: string = StringArrayCallsWrapperTemplate().formatUnicorn(templateData);
+    let stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), templateData);
 
     return Function(`
         var ${stringArrayName} = ['${Utils.btoa('test1')}'];
@@ -49,7 +49,7 @@ function getFunctionFromTemplateRc4Encoding (
     index: string,
     key: string
 ) {
-    let stringArrayCallsWrapperTemplate: string = StringArrayCallsWrapperTemplate().formatUnicorn(templateData);
+    let stringArrayCallsWrapperTemplate: string = format(StringArrayCallsWrapperTemplate(), templateData);
 
     return Function(`
         var ${stringArrayName} = ['${Utils.btoa(Utils.rc4('test1', key))}'];
@@ -63,12 +63,12 @@ function getFunctionFromTemplateRc4Encoding (
 describe('StringArrayCallsWrapperNodeTemplate (): string', () => {
     let stringArrayName: string = 'stringArrayName',
         stringArrayCallsWrapperName: string = 'stringArrayCallsWrapperName',
-        atobDecodeNodeTemplate: string = StringArrayBase64DecodeNodeTemplate().formatUnicorn({
+        atobDecodeNodeTemplate: string = format(StringArrayBase64DecodeNodeTemplate(), {
             atobPolyfill: AtobTemplate(),
             selfDefendingCode: '',
             stringArrayCallsWrapperName
         }),
-        rc4DecodeNodeTemplate: string = StringArrayRc4DecodeNodeTemplate().formatUnicorn({
+        rc4DecodeNodeTemplate: string = format(StringArrayRc4DecodeNodeTemplate(), {
             atobPolyfill: AtobTemplate(),
             rc4Polyfill: Rc4Template(),
             selfDefendingCode: '',

Some files were not shown because too many files changed in this diff