Ver Fonte

Added StringArrayIntermediateCallsWrapperNode custom node

sanex há 4 anos atrás
pai
commit
b483ef17cf

Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/index.browser.js


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/index.cli.js


Diff do ficheiro suprimidas por serem muito extensas
+ 0 - 0
dist/index.js


+ 1 - 0
src/container/ServiceIdentifiers.ts

@@ -12,6 +12,7 @@ export enum ServiceIdentifiers {
     Factory__IObfuscatedCode = 'Factory<IObfuscatedCode>',
     Factory__IObjectExpressionKeysTransformerCustomNode = 'Factory<IObjectExpressionKeysTransformerCustomNode>',
     Factory__IObjectExpressionExtractor = 'Factory<IObjectExpressionExtractor>',
+    Factory__IStringArrayTransformerCustomNode = 'Factory<IStringArrayTransformerCustomNode>',
     Factory__TControlFlowStorage = 'Factory<TControlFlowStorage>',
     IArrayUtils = 'IArrayUtils',
     ICalleeDataExtractor = 'ICalleeDataExtractor',

+ 20 - 4
src/container/modules/custom-nodes/CustomNodesModule.ts

@@ -7,6 +7,7 @@ import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
 import { ControlFlowCustomNode } from '../../../enums/custom-nodes/ControlFlowCustomNode';
 import { DeadCodeInjectionCustomNode } from '../../../enums/custom-nodes/DeadCodeInjectionCustomNode';
 import { ObjectExpressionKeysTransformerCustomNode } from '../../../enums/custom-nodes/ObjectExpressionKeysTransformerCustomNode';
+import { StringArrayTransformerCustomNode } from '../../../enums/custom-nodes/StringArrayTransformerCustomNode';
 
 import { ObjectExpressionVariableDeclarationHostNode } from '../../../custom-nodes/object-expression-keys-transformer-nodes/ObjectExpressionVariableDeclarationHostNode';
 import { BinaryExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/BinaryExpressionFunctionNode';
@@ -17,6 +18,7 @@ import { CallExpressionFunctionNode } from '../../../custom-nodes/control-flow-f
 import { ControlFlowStorageNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ControlFlowStorageNode';
 import { ExpressionWithOperatorControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/ExpressionWithOperatorControlFlowStorageCallNode';
 import { LogicalExpressionFunctionNode } from '../../../custom-nodes/control-flow-flattening-nodes/LogicalExpressionFunctionNode';
+import { StringArrayIntermediateCallsWrapperNode } from '../../../custom-nodes/string-array-nodes/StringArrayIntermediateCallsWrapperNode';
 import { StringLiteralControlFlowStorageCallNode } from '../../../custom-nodes/control-flow-flattening-nodes/control-flow-storage-nodes/StringLiteralControlFlowStorageCallNode';
 import { StringLiteralNode } from '../../../custom-nodes/control-flow-flattening-nodes/StringLiteralNode';
 
@@ -68,6 +70,11 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
         .toConstructor(ObjectExpressionVariableDeclarationHostNode)
         .whenTargetNamed(ObjectExpressionKeysTransformerCustomNode.ObjectExpressionVariableDeclarationHostNode);
 
+    // string array transformer nodes
+    bind<interfaces.Newable<ICustomNode>>(ServiceIdentifiers.Newable__ICustomNode)
+        .toConstructor(StringArrayIntermediateCallsWrapperNode)
+        .whenTargetNamed(StringArrayTransformerCustomNode.StringArrayIntermediateCallsWrapperNode);
+
     // control flow customNode constructor factory
     bind<ICustomNode>(ServiceIdentifiers.Factory__IControlFlowCustomNode)
         .toFactory<ICustomNode>(InversifyContainerFacade
@@ -76,8 +83,7 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
                 ServiceIdentifiers.Factory__IIdentifierNamesGenerator,
                 ServiceIdentifiers.ICustomCodeHelperFormatter,
                 ServiceIdentifiers.IRandomGenerator,
-                ServiceIdentifiers.IOptions,
-                ServiceIdentifiers.IPrevailingKindOfVariablesAnalyzer
+                ServiceIdentifiers.IOptions
             ));
 
     // dead code injection customNode constructor factory
@@ -99,7 +105,17 @@ export const customNodesModule: interfaces.ContainerModule = new ContainerModule
                 ServiceIdentifiers.Factory__IIdentifierNamesGenerator,
                 ServiceIdentifiers.ICustomCodeHelperFormatter,
                 ServiceIdentifiers.IRandomGenerator,
-                ServiceIdentifiers.IOptions,
-                ServiceIdentifiers.IPrevailingKindOfVariablesAnalyzer
+                ServiceIdentifiers.IOptions
+            ));
+
+    // string array transformer customNode constructor factory
+    bind<ICustomNode>(ServiceIdentifiers.Factory__IStringArrayTransformerCustomNode)
+        .toFactory<ICustomNode>(InversifyContainerFacade
+            .getConstructorFactory<StringArrayTransformerCustomNode, ICustomNode>(
+                ServiceIdentifiers.Newable__ICustomNode,
+                ServiceIdentifiers.Factory__IIdentifierNamesGenerator,
+                ServiceIdentifiers.ICustomCodeHelperFormatter,
+                ServiceIdentifiers.IRandomGenerator,
+                ServiceIdentifiers.IOptions
             ));
 });

+ 0 - 8
src/custom-code-helpers/string-array/templates/string-array-calls-wrapper/StringArrayCallsWrapperIntermediateTemplate.ts

@@ -1,8 +0,0 @@
-/**
- * @returns {string}
- */
-export function StringArrayCallsWrapperIntermediateTemplate (): string {
-    return `
-        const {intermediateName} = {stringArrayCallsWrapperName};
-    `;
-}

+ 83 - 0
src/custom-nodes/string-array-nodes/StringArrayIntermediateCallsWrapperNode.ts

@@ -0,0 +1,83 @@
+import { inject, injectable, } from 'inversify';
+import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
+
+import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
+import { TStatement } from '../../types/node/TStatement';
+
+import { ICustomCodeHelperFormatter } from '../../interfaces/custom-code-helpers/ICustomCodeHelperFormatter';
+import { IOptions } from '../../interfaces/options/IOptions';
+import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
+
+import { initializable } from '../../decorators/Initializable';
+
+import { AbstractCustomNode } from '../AbstractCustomNode';
+import { NodeFactory } from '../../node/NodeFactory';
+import { NodeUtils } from '../../node/NodeUtils';
+
+@injectable()
+export class StringArrayIntermediateCallsWrapperNode extends AbstractCustomNode {
+    /**
+     * @type {string}
+     */
+    @initializable()
+    private stringArrayCallsWrapperName!: string;
+
+    /**
+     * @type {string}
+     */
+    @initializable()
+    private stringArrayIntermediateCallsWrapperName!: string;
+
+
+    /**
+     * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
+     * @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
+     * @param {IRandomGenerator} randomGenerator
+     * @param {IOptions} options
+     */
+    public constructor (
+        @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
+            identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
+        @inject(ServiceIdentifiers.ICustomCodeHelperFormatter) customCodeHelperFormatter: ICustomCodeHelperFormatter,
+        @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
+        @inject(ServiceIdentifiers.IOptions) options: IOptions
+    ) {
+        super(
+            identifierNamesGeneratorFactory,
+            customCodeHelperFormatter,
+            randomGenerator,
+            options
+        );
+    }
+
+    /**
+     * @param {string} stringArrayIntermediateCallsWrapperName
+     * @param {string} stringArrayCallsWrapperName
+     */
+    public initialize (
+        stringArrayIntermediateCallsWrapperName: string,
+        stringArrayCallsWrapperName: string
+    ): void {
+        this.stringArrayIntermediateCallsWrapperName = stringArrayIntermediateCallsWrapperName;
+        this.stringArrayCallsWrapperName = stringArrayCallsWrapperName;
+    }
+
+    /**
+     * @returns {TStatement[]}
+     */
+    protected getNodeStructure (): TStatement[] {
+        const structure: TStatement = NodeFactory.variableDeclarationNode(
+            [
+                NodeFactory.variableDeclaratorNode(
+                    NodeFactory.identifierNode(this.stringArrayIntermediateCallsWrapperName),
+                    NodeFactory.identifierNode(this.stringArrayCallsWrapperName)
+                )
+            ],
+            'const',
+        );
+
+        NodeUtils.parentizeAst(structure);
+
+        return [structure];
+    }
+}

+ 3 - 0
src/enums/custom-nodes/StringArrayTransformerCustomNode.ts

@@ -0,0 +1,3 @@
+export enum StringArrayTransformerCustomNode {
+    StringArrayIntermediateCallsWrapperNode = 'StringArrayIntermediateCallsWrapperNode'
+}

+ 30 - 17
src/node-transformers/string-array-transformers/StringArrayTransformer.ts

@@ -3,11 +3,14 @@ import { ServiceIdentifiers } from '../../container/ServiceIdentifiers';
 
 import * as ESTree from 'estree';
 
+import { TInitialData } from '../../types/TInitialData';
 import { TNodeWithLexicalScope } from '../../types/node/TNodeWithLexicalScope';
 import { TStringArrayEncoding } from '../../types/options/TStringArrayEncoding';
 import { TStringArrayIntermediateCallsWrapperDataByEncoding } from '../../types/node-transformers/string-array-transformers/TStringArrayIntermediateCallsWrapperDataByEncoding';
+import { TStringArrayTransformerCustomNodeFactory } from '../../types/container/custom-nodes/TStringArrayTransformerCustomNodeFactory';
 
 import { IArrayUtils } from '../../interfaces/utils/IArrayUtils';
+import { ICustomNode } from '../../interfaces/custom-nodes/ICustomNode';
 import { IEscapeSequenceEncoder } from '../../interfaces/utils/IEscapeSequenceEncoder';
 import { IIdentifierNamesGenerator } from '../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator';
 import { TIdentifierNamesGeneratorFactory } from '../../types/container/generators/TIdentifierNamesGeneratorFactory';
@@ -20,6 +23,7 @@ import { IStringArrayStorageItemData } from '../../interfaces/storages/string-ar
 import { IVisitor } from '../../interfaces/node-transformers/IVisitor';
 
 import { NodeTransformationStage } from '../../enums/node-transformers/NodeTransformationStage';
+import { StringArrayTransformerCustomNode } from '../../enums/custom-nodes/StringArrayTransformerCustomNode';
 
 import { AbstractNodeTransformer } from '../AbstractNodeTransformer';
 import { NodeAppender } from '../../node/NodeAppender';
@@ -29,6 +33,7 @@ import { NodeLiteralUtils } from '../../node/NodeLiteralUtils';
 import { NodeMetadata } from '../../node/NodeMetadata';
 import { NodeUtils } from '../../node/NodeUtils';
 import { NumberUtils } from '../../utils/NumberUtils';
+import { StringArrayIntermediateCallsWrapperNode } from '../../custom-nodes/string-array-nodes/StringArrayIntermediateCallsWrapperNode';
 
 @injectable()
 export class StringArrayTransformer extends AbstractNodeTransformer {
@@ -70,6 +75,11 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
      */
     private readonly stringArrayStorageAnalyzer: IStringArrayStorageAnalyzer;
 
+    /**
+     * @type {TStringArrayTransformerCustomNodeFactory}
+     */
+    private readonly stringArrayTransformerCustomNodeFactory: TStringArrayTransformerCustomNodeFactory;
+
     /**
      * @type {TNodeWithLexicalScope[]}
      */
@@ -78,32 +88,36 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
     /**
      * @param {IRandomGenerator} randomGenerator
      * @param {IOptions} options
+     * @param {IArrayUtils} arrayUtils
+     * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
      * @param {ILiteralNodesCacheStorage} literalNodesCacheStorage
      * @param {IStringArrayStorage} stringArrayStorage
      * @param {IStringArrayStorageAnalyzer} stringArrayStorageAnalyzer
-     * @param {IArrayUtils} arrayUtils
-     * @param {IEscapeSequenceEncoder} escapeSequenceEncoder
      * @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
+     * @param {TStringArrayTransformerCustomNodeFactory} stringArrayTransformerCustomNodeFactory
      */
     public constructor (
         @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
         @inject(ServiceIdentifiers.IOptions) options: IOptions,
+        @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils,
+        @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder,
         @inject(ServiceIdentifiers.ILiteralNodesCacheStorage) literalNodesCacheStorage: ILiteralNodesCacheStorage,
         @inject(ServiceIdentifiers.IStringArrayStorage) stringArrayStorage: IStringArrayStorage,
         @inject(ServiceIdentifiers.IStringArrayStorageAnalyzer) stringArrayStorageAnalyzer: IStringArrayStorageAnalyzer,
-        @inject(ServiceIdentifiers.IArrayUtils) arrayUtils: IArrayUtils,
-        @inject(ServiceIdentifiers.IEscapeSequenceEncoder) escapeSequenceEncoder: IEscapeSequenceEncoder,
         @inject(ServiceIdentifiers.Factory__IIdentifierNamesGenerator)
             identifierNamesGeneratorFactory: TIdentifierNamesGeneratorFactory,
+        @inject(ServiceIdentifiers.Factory__IStringArrayTransformerCustomNode)
+            stringArrayTransformerCustomNodeFactory: TStringArrayTransformerCustomNodeFactory
     ) {
         super(randomGenerator, options);
 
+        this.arrayUtils = arrayUtils;
+        this.escapeSequenceEncoder = escapeSequenceEncoder;
         this.literalNodesCacheStorage = literalNodesCacheStorage;
         this.stringArrayStorage = stringArrayStorage;
         this.stringArrayStorageAnalyzer = stringArrayStorageAnalyzer;
-        this.arrayUtils = arrayUtils;
-        this.escapeSequenceEncoder = escapeSequenceEncoder;
         this.identifierNamesGenerator = identifierNamesGeneratorFactory(options);
+        this.stringArrayTransformerCustomNodeFactory = stringArrayTransformerCustomNodeFactory;
     }
 
     /**
@@ -360,20 +374,19 @@ export class StringArrayTransformer extends AbstractNodeTransformer {
 
             for (const stringArrayIntermediateCallsWrapperName of names) {
                 const stringArrayRootCallsWrapperName: string = this.getStringArrayRootCallsWrapperName(encoding);
+                const stringArrayIntermediateCallsWrapperNode: ICustomNode<TInitialData<StringArrayIntermediateCallsWrapperNode>> =
+                    this.stringArrayTransformerCustomNodeFactory(
+                        StringArrayTransformerCustomNode.StringArrayIntermediateCallsWrapperNode
+                    );
+
+                stringArrayIntermediateCallsWrapperNode.initialize(
+                    stringArrayIntermediateCallsWrapperName,
+                    stringArrayRootCallsWrapperName
+                );
 
                 NodeAppender.prepend(
                     lexicalScopeBodyNode,
-                    [
-                        NodeFactory.variableDeclarationNode(
-                            [
-                                NodeFactory.variableDeclaratorNode(
-                                    NodeFactory.identifierNode(stringArrayIntermediateCallsWrapperName),
-                                    NodeFactory.identifierNode(stringArrayRootCallsWrapperName)
-                                )
-                            ],
-                            'var',
-                        )
-                    ]
+                    stringArrayIntermediateCallsWrapperNode.getNode()
                 );
             }
         }

+ 7 - 0
src/types/container/custom-nodes/TStringArrayTransformerCustomNodeFactory.ts

@@ -0,0 +1,7 @@
+import { ICustomNode } from '../../../interfaces/custom-nodes/ICustomNode';
+
+import { StringArrayTransformerCustomNode } from '../../../enums/custom-nodes/StringArrayTransformerCustomNode';
+
+export type TStringArrayTransformerCustomNodeFactory = <
+    TInitialData extends unknown[] = unknown[]
+> (stringArrayTransformerCustomNodeName: StringArrayTransformerCustomNode) => ICustomNode <TInitialData>;

+ 85 - 53
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/StringArrayTransformer.spec.ts

@@ -69,17 +69,17 @@ describe('StringArrayTransformer', function () {
                 const stringArrayCallRegExp: RegExp = new RegExp(
                         'return _0x([a-f0-9]){4,6};' +
                     '};' +
-                    'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                    'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                    'var foo *= *_0x([a-f0-9]){4,6}\\(\'0x0\'\\);' +
-                    'var bar *= *_0x([a-f0-9]){4,6}\\(\'0x1\'\\);' +
-                    'var baz *= *_0x([a-f0-9]){4,6}\\(\'0x2\'\\);'
+                    'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                    'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                    'const foo *= *_0x([a-f0-9]){4,6}\\(\'0x0\'\\);' +
+                    'const bar *= *_0x([a-f0-9]){4,6}\\(\'0x1\'\\);' +
+                    'const baz *= *_0x([a-f0-9]){4,6}\\(\'0x2\'\\);'
                 );
 
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count-const.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -101,18 +101,18 @@ describe('StringArrayTransformer', function () {
                 const stringArrayCallRegExp: RegExp = new RegExp(
                         'return _0x([a-f0-9]){4,6};' +
                     '};' +
-                    'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                    'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                    'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                    'var foo *= *_0x([a-f0-9]){4,6}\\(\'0x0\'\\);' +
-                    'var bar *= *_0x([a-f0-9]){4,6}\\(\'0x1\'\\);' +
-                    'var baz *= *_0x([a-f0-9]){4,6}\\(\'0x2\'\\);'
+                    'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                    'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                    'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                    'const foo *= *_0x([a-f0-9]){4,6}\\(\'0x0\'\\);' +
+                    'const bar *= *_0x([a-f0-9]){4,6}\\(\'0x1\'\\);' +
+                    'const baz *= *_0x([a-f0-9]){4,6}\\(\'0x2\'\\);'
                 );
 
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count-const.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -135,18 +135,18 @@ describe('StringArrayTransformer', function () {
             describe('Variant #1: option value is lower then count `literal` nodes in the scope', () => {
                 const stringArrayCallRegExp: RegExp = new RegExp(
                     'function test *\\( *\\) *{' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x3\'\\);' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x4\'\\);' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x5\'\\);' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x3\'\\);' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x4\'\\);' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x5\'\\);' +
                     '}'
                 );
 
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count-const.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -167,19 +167,19 @@ describe('StringArrayTransformer', function () {
             describe('Variant #2: option value is bigger then count `literal` nodes in the scope', () => {
                 const stringArrayCallRegExp: RegExp = new RegExp(
                     'function test *\\(\\) *{' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x3\'\\);' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x4\'\\);' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x5\'\\);' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x3\'\\);' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x4\'\\);' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x5\'\\);' +
                     '}'
                 );
 
                 let obfuscatedCode: string;
 
                 before(() => {
-                    const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count.js');
+                    const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count-const.js');
 
                     obfuscatedCode = JavaScriptObfuscator.obfuscate(
                         code,
@@ -198,7 +198,39 @@ describe('StringArrayTransformer', function () {
             });
         });
 
-        describe('Variant #3: correct evaluation of the intermediate calls', () => {
+        describe('Variant #3: prevailing kind of variables', () => {
+            const stringArrayCallRegExp: RegExp = new RegExp(
+                    'return _0x([a-f0-9]){4,6};' +
+                '};' +
+                'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                'var foo *= *_0x([a-f0-9]){4,6}\\(\'0x0\'\\);' +
+                'var bar *= *_0x([a-f0-9]){4,6}\\(\'0x1\'\\);' +
+                'var baz *= *_0x([a-f0-9]){4,6}\\(\'0x2\'\\);'
+            );
+
+            let obfuscatedCode: string;
+
+            before(() => {
+                const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count-var.js');
+
+                obfuscatedCode = JavaScriptObfuscator.obfuscate(
+                    code,
+                    {
+                        ...NO_ADDITIONAL_NODES_PRESET,
+                        stringArray: true,
+                        stringArrayThreshold: 1,
+                        stringArrayIntermediateVariablesCount: 2
+                    }
+                ).getObfuscatedCode();
+            });
+
+            it('should add intermediate calls to the string array calls wrapper with a correct variables kind', () => {
+                assert.match(obfuscatedCode, stringArrayCallRegExp);
+            });
+        });
+
+        describe('Variant #4: correct evaluation of the intermediate calls', () => {
             const expectedEvaluationResult: string = '12345';
             let evaluationResult: string;
 
@@ -504,19 +536,19 @@ describe('StringArrayTransformer', function () {
                     const stringArrayIntermediateCallRegExp: RegExp = new RegExp(
                             'return _0x([a-f0-9]){4,6};' +
                         '};' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
                         // this one may be added or not depends on:
                         // if all literal values encoded with a single encoding or not
-                        '(?:var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};)?' +
-                        'var foo *= *_0x([a-f0-9]){4,6}\\(\'0x0\'\\);' +
-                        'var bar *= *_0x([a-f0-9]){4,6}\\(\'0x1\'\\);' +
-                        'var baz *= *_0x([a-f0-9]){4,6}\\(\'0x2\'\\);'
+                        '(?:const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};)?' +
+                        'const foo *= *_0x([a-f0-9]){4,6}\\(\'0x0\'\\);' +
+                        'const bar *= *_0x([a-f0-9]){4,6}\\(\'0x1\'\\);' +
+                        'const baz *= *_0x([a-f0-9]){4,6}\\(\'0x2\'\\);'
                     );
 
                     let obfuscatedCode: string;
 
                     before(() => {
-                        const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count.js');
+                        const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count-const.js');
 
                         obfuscatedCode = JavaScriptObfuscator.obfuscate(
                             code,
@@ -542,20 +574,20 @@ describe('StringArrayTransformer', function () {
                     const stringArrayIntermediateCallRegExp: RegExp = new RegExp(
                             'return _0x([a-f0-9]){4,6};' +
                         '};' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                        'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                        'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
                         // this one may be added or not depends on:
                         // if all literal values encoded with a single encoding or not
-                        '(?:var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};)?' +
-                        'var foo *= *_0x([a-f0-9]){4,6}\\(\'0x0\'\\);' +
-                        'var bar *= *_0x([a-f0-9]){4,6}\\(\'0x1\'\\);' +
-                        'var baz *= *_0x([a-f0-9]){4,6}\\(\'0x2\'\\);'
+                        '(?:const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};)?' +
+                        'const foo *= *_0x([a-f0-9]){4,6}\\(\'0x0\'\\);' +
+                        'const bar *= *_0x([a-f0-9]){4,6}\\(\'0x1\'\\);' +
+                        'const baz *= *_0x([a-f0-9]){4,6}\\(\'0x2\'\\);'
                     );
 
                     let obfuscatedCode: string;
 
                     before(() => {
-                        const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count.js');
+                        const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count-const.js');
 
                         obfuscatedCode = JavaScriptObfuscator.obfuscate(
                             code,
@@ -582,20 +614,20 @@ describe('StringArrayTransformer', function () {
                 describe('Variant #1: `1` intermediate variable for each encoding type', () => {
                     const stringArrayIntermediateCallRegExp: RegExp = new RegExp(
                         'function test *\\( *\\) *{' +
-                            'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                            'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
                             // this one may be added or not depends on:
                             // if all literal values encoded with a single encoding or not
-                            '(?:var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};)?' +
-                            'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x3\'\\);' +
-                            'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x4\'\\);' +
-                            'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x5\'\\);' +
+                            '(?:const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};)?' +
+                            'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x3\'\\);' +
+                            'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x4\'\\);' +
+                            'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x5\'\\);' +
                         '}'
                     );
 
                     let obfuscatedCode: string;
 
                     before(() => {
-                        const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count.js');
+                        const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count-const.js');
 
                         obfuscatedCode = JavaScriptObfuscator.obfuscate(
                             code,
@@ -620,21 +652,21 @@ describe('StringArrayTransformer', function () {
                 describe('Variant #2: `2` intermediate variables for each encoding type', () => {
                     const stringArrayIntermediateCallRegExp: RegExp = new RegExp(
                         'function test *\\( *\\) *{' +
-                            'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
-                            'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                            'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
+                            'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};' +
                             // this one may be added or not depends on:
                             // if all literal values encoded with a single encoding or not
-                            '(?:var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};)?' +
-                            'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x3\'\\);' +
-                            'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x4\'\\);' +
-                            'var _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x5\'\\);' +
+                            '(?:const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4};)?' +
+                            'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x3\'\\);' +
+                            'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x4\'\\);' +
+                            'const _0x([a-f0-9]){4,6} *= *_0x([a-f0-9]){4,6}\\(\'0x5\'\\);' +
                         '}'
                     );
 
                     let obfuscatedCode: string;
 
                     before(() => {
-                        const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count.js');
+                        const code: string = readFileAsString(__dirname + '/fixtures/intermediate-variables-count-const.js');
 
                         obfuscatedCode = JavaScriptObfuscator.obfuscate(
                             code,

+ 9 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/intermediate-variables-count-const.js

@@ -0,0 +1,9 @@
+const foo = 'foo'
+const bar = 'bar';
+const baz = 'baz';
+
+function test () {
+    const bark = 'bark'
+    const hawk = 'hawk';
+    const eagle = 'eagle';
+}

+ 0 - 0
test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/intermediate-variables-count.js → test/functional-tests/node-transformers/string-array-transformers/string-array-transformer/fixtures/intermediate-variables-count-var.js


Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff