All files / src/custom-nodes/self-defending-nodes SelfDefendingUnicodeNode.js

95% Statements 19/20
66.67% Branches 2/3
100% Functions 1/1
94.74% Lines 18/19
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  1x 1x 1x 1x 1x 1x 1x 1x   3x   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 SelfDefendingUnicodeNode extends Node_1.Node {
    constructor(options) {
        super(options);
        this.appendState = AppendState_1.AppendState.AfterObfuscation;
        this.node = this.getNodeStructure();
    }
    appendNode(blockScopeNode) {
        let programBodyLength = blockScopeNode.body.length, randomIndex = 0;
        if (programBodyLength > 2) I{
            randomIndex = Utils_1.Utils.getRandomGenerator().integer({
                min: programBodyLength / 2,
                max: programBodyLength - 1
            });
        }
        NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), randomIndex);
    }
    getNodeStructure() {
        let node = esprima.parse(JavaScriptObfuscator_1.JavaScriptObfuscator.obfuscate(`
                (function () {                                
                    var func = function(){return ${Utils_1.Utils.stringToUnicode('dev')};},
                        func2 = function () {
                            return 'window';
                        };
                
                    !Function(${Utils_1.Utils.stringToUnicode(`return/\\w+ *\\(\\) *{\\w+ *['|"].+['|"];? *}/`)})().test(func.toString()) ? Function(${Utils_1.Utils.stringToUnicode(`return/(\\\\[x|u](\\w){2,4})+/`)})().test(func2.toString()) ? []['filter']['constructor'](${Utils_1.Utils.stringToJSFuck('while')} + '(${JSFuck_1.JSFuck.False}){}')() : []['filter']['constructor'](${Utils_1.Utils.stringToJSFuck('while')} + '(${JSFuck_1.JSFuck.True}){}')() : []['filter']['constructor'](${Utils_1.Utils.stringToJSFuck('while')} + '(${JSFuck_1.JSFuck.False}){}')();
                })();
            `, NoCustomNodesPreset_1.NO_CUSTOM_NODES_PRESET));
        NodeUtils_1.NodeUtils.addXVerbatimPropertyToLiterals(node);
        return NodeUtils_1.NodeUtils.getBlockStatementNodeByIndex(node);
    }
}
exports.SelfDefendingUnicodeNode = SelfDefendingUnicodeNode;
//# sourceMappingURL=SelfDefendingUnicodeNode.js.map