All files / src/node-groups StringArrayNodesGroup.ts

100% Statements 23/23
100% Branches 6/6
100% Functions 1/1
100% Lines 22/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88    1x   1x 1x 1x   1x 1x 1x   2583x       2583x         2583x         2583x                     2583x 2061x     522x 508x         14x     522x 522x           522x                             522x 508x                     522x      
import { ICustomNode } from '../interfaces/custom-nodes/ICustomNode';
 
import { AppendState } from '../enums/AppendState';
 
import { UnicodeArrayCallsWrapper } from '../custom-nodes/unicode-array-nodes/UnicodeArrayCallsWrapper';
import { UnicodeArrayNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayNode';
import { UnicodeArrayRotateFunctionNode } from '../custom-nodes/unicode-array-nodes/UnicodeArrayRotateFunctionNode';
 
import { AbstractNodesGroup } from './AbstractNodesGroup';
import { UnicodeArray } from '../UnicodeArray';
import { Utils } from '../Utils';
 
export class UnicodeArrayNodesGroup extends AbstractNodesGroup {
    /**
     * @type {AppendState}
     */
    protected appendState: AppendState = AppendState.AfterObfuscation;
 
    /**
     * @type {string}
     */
    private unicodeArrayName: string = Utils.getRandomVariableName(UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH);
 
    /**
     * @type {string}
     */
    private unicodeArrayCallsWrapper: string = Utils.getRandomVariableName(UnicodeArrayNode.UNICODE_ARRAY_RANDOM_LENGTH);
 
    /**
     * @type {number}
     */
    private unicodeArrayRotateValue: number;
 
    /**
     * @returns {Map<string, ICustomNode> | undefined}
     */
    public getNodes (): Map <string, ICustomNode> | undefined {
        if (!this.options.unicodeArray) {
            return;
        }
 
        if (this.options.rotateUnicodeArray) {
            this.unicodeArrayRotateValue = Utils.getRandomGenerator().integer({
                min: 100,
                max: 500
            });
        } else {
            this.unicodeArrayRotateValue = 0;
        }
 
        const unicodeArray: UnicodeArray = new UnicodeArray();
        const unicodeArrayNode: ICustomNode = new UnicodeArrayNode(
            unicodeArray,
            this.unicodeArrayName,
            this.unicodeArrayRotateValue,
            this.options
        );
        const customNodes: Map <string, ICustomNode> = new Map <string, ICustomNode> ([
            [
                'unicodeArrayNode', unicodeArrayNode,
            ],
            [
                'unicodeArrayCallsWrapper',
                new UnicodeArrayCallsWrapper(
                    this.unicodeArrayCallsWrapper,
                    this.unicodeArrayName,
                    unicodeArray,
                    this.options
                )
            ]
        ]);
 
        if (this.options.rotateUnicodeArray) {
            customNodes.set(
                'unicodeArrayRotateFunctionNode',
                new UnicodeArrayRotateFunctionNode(
                    this.unicodeArrayName,
                    unicodeArray,
                    this.unicodeArrayRotateValue,
                    this.options
                )
            );
        }
 
        return this.syncCustomNodesWithNodesGroup(customNodes);
    }
}