All files / src/custom-nodes/debug-protection-nodes DebugProtectionFunctionNode.js

38.46% Statements 5/13
100% Branches 1/1
0% Functions 0/1
41.67% Lines 5/12
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  1x 1x 1x 1x                                                                         1x  
"use strict";
const esprima = require('esprima');
const Node_1 = require('../Node');
const NodeUtils_1 = require('../../NodeUtils');
const Utils_1 = require("../../Utils");
class DebugProtectionFunctionNode extends Node_1.Node {
    constructor(debugProtectionFunctionName, options) {
        super(options);
        this.debugProtectionFunctionName = debugProtectionFunctionName;
        this.node = this.getNodeStructure();
    }
    appendNode(blockScopeNode) {
        let programBodyLength = blockScopeNode.body.length, randomIndex = Utils_1.Utils.getRandomGenerator().integer({
            min: 0,
            max: programBodyLength
        });
        NodeUtils_1.NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), randomIndex);
    }
    getNodeIdentifier() {
        return this.debugProtectionFunctionName;
    }
    getNodeStructure() {
        return NodeUtils_1.NodeUtils.getBlockStatementNodeByIndex(esprima.parse(`
                var ${this.debugProtectionFunctionName} = function () {
                    function debuggerProtection (counter) {
                        if (('' + counter / counter)['length'] !== 1 || counter % 20 === 0) {
                            (function () {}.constructor('debugger')());
                        } else {
                            [].filter.constructor(${Utils_1.Utils.stringToJSFuck('debugger')})();
                        }
                        
                        debuggerProtection(++counter);
                    }
                    
                    try {
                        debuggerProtection(0);
                    } catch (y) {}
                };
            `));
    }
}
exports.DebugProtectionFunctionNode = DebugProtectionFunctionNode;
//# sourceMappingURL=DebugProtectionFunctionNode.js.map