All files / src/custom-nodes/unicode-array-nodes UnicodeArrayRotateFunctionNode.js

93.55% Statements 29/31
60% Branches 3/5
100% Functions 1/1
92.31% Lines 24/26
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  1x 1x 1x 1x 1x 1x 1x 1x   3x   1x 1x 1x 1x 1x     1x     1x     1x     1x 1x                   1x   1x                     1x 1x     1x  
"use strict";
const esprima = require('esprima');
const AppendState_1 = require("../../enums/AppendState");
const JSFuck_1 = require("../../enums/JSFuck");
const NoCustomNodesPreset_1 = require("../../preset-options/NoCustomNodesPreset");
const JavaScriptObfuscator_1 = require("../../JavaScriptObfuscator");
const Node_1 = require('../Node');
const NodeUtils_1 = require("../../NodeUtils");
const Utils_1 = require("../../Utils");
class UnicodeArrayRotateFunctionNode extends Node_1.Node {
    constructor(unicodeArrayName, unicodeArray, unicodeArrayRotateValue, options) {
        super(options);
        this.appendState = AppendState_1.AppendState.AfterObfuscation;
        this.unicodeArrayName = unicodeArrayName;
        this.unicodeArray = unicodeArray;
        this.unicodeArrayRotateValue = unicodeArrayRotateValue;
        this.node = this.getNodeStructure();
    }
    appendNode(blockScopeNode) {
        NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), 1);
    }
    getNode() {
        if (!this.unicodeArray.length) I{
            return;
        }
        return super.getNode();
    }
    getNodeStructure() {
        let arrayName = Utils_1.Utils.getRandomVariableName(), code = '', timesName = Utils_1.Utils.getRandomVariableName(), timesArgumentName = Utils_1.Utils.getRandomVariableName(), whileFunctionName = Utils_1.Utils.getRandomVariableName(), node;
        if (this.options.get('selfDefending')) I{
            code = JavaScriptObfuscator_1.JavaScriptObfuscator.obfuscate(`
                (function () {
                    var func = function(){return ${Utils_1.Utils.stringToUnicode('dev')};};
                                        
                    !Function(${Utils_1.Utils.stringToUnicode(`return/\\w+ *\\(\\) *{\\w+ *['|"].+['|"];? *}/`)})().test(func.toString()) ? []['filter']['constructor'](${Utils_1.Utils.stringToJSFuck('while')} + '(${JSFuck_1.JSFuck.True}){}')() : Function(${Utils_1.Utils.stringToUnicode('a')}, ${Utils_1.Utils.stringToUnicode('b')}, ${Utils_1.Utils.stringToUnicode('a(++b)')})(${whileFunctionName}, ${timesName}) ? []['filter']['constructor'](${Utils_1.Utils.stringToJSFuck('while')} + '(${JSFuck_1.JSFuck.False}){}')() : []['filter']['constructor'](${Utils_1.Utils.stringToJSFuck('while')} + '(${JSFuck_1.JSFuck.False}){}')();
                })();
            `, NoCustomNodesPreset_1.NO_CUSTOM_NODES_PRESET);
        }
        else {
            code = `${whileFunctionName}(++${timesName})`;
        }
        node = esprima.parse(`
            (function (${arrayName}, ${timesName}) {
                var ${whileFunctionName} = function (${timesArgumentName}) {
                    while (--${timesArgumentName}) {
                        ${arrayName}[${Utils_1.Utils.stringToUnicode('push')}](${arrayName}[${Utils_1.Utils.stringToUnicode('shift')}]());
                    }
                };
                
                ${code}
            })(${this.unicodeArrayName}, 0x${Utils_1.Utils.decToHex(this.unicodeArrayRotateValue)});
        `);
        NodeUtils_1.NodeUtils.addXVerbatimPropertyToLiterals(node);
        return NodeUtils_1.NodeUtils.getBlockStatementNodeByIndex(node);
    }
}
exports.UnicodeArrayRotateFunctionNode = UnicodeArrayRotateFunctionNode;
//# sourceMappingURL=UnicodeArrayRotateFunctionNode.js.map