# All files / src Obfuscator.js

100% Statements 40/40
100% Branches 7/7
100% Functions 5/5
100% Lines 40/40

    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
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x

    8x
    8x

    8x
    8x

    8x
    8x
    8x
    8x
    8x

    8x
    11x
    9x

    8x
    11x
    2x

    885x
    885x
    536x

    349x
    353x

    8x
    8x

    885x

    1x
     "use strict";
    const estraverse = require('estraverse');
    const AppendState_1 = require('./enums/AppendState');
    const NodeType_1 = require('./enums/NodeType');
    const CatchClauseObfuscator_1 = require('./node-obfuscators/CatchClauseObfuscator');
    const ConsoleOutputNodesGroup_1 = require("./node-groups/ConsoleOutputNodesGroup");
    const DebugProtectionNodesGroup_1 = require('./node-groups/DebugProtectionNodesGroup');
    const FunctionDeclarationObfuscator_1 = require('./node-obfuscators/FunctionDeclarationObfuscator');
    const FunctionObfuscator_1 = require('./node-obfuscators/FunctionObfuscator');
    const LiteralObfuscator_1 = require('./node-obfuscators/LiteralObfuscator');
    const MemberExpressionObfuscator_1 = require('./node-obfuscators/MemberExpressionObfuscator');
    const MethodDefinitionObfuscator_1 = require('./node-obfuscators/MethodDefinitionObfuscator');
    const NodeUtils_1 = require("./NodeUtils");
    const ObjectExpressionObfuscator_1 = require('./node-obfuscators/ObjectExpressionObfuscator');
    const SelfDefendingNodesGroup_1 = require("./node-groups/SelfDefendingNodesGroup");
    const UnicodeArrayNodesGroup_1 = require('./node-groups/UnicodeArrayNodesGroup');
    const VariableDeclarationObfuscator_1 = require('./node-obfuscators/VariableDeclarationObfuscator');
    class Obfuscator {
        constructor(options) {
            this.nodeObfuscators = new Map([
                [NodeType_1.NodeType.ArrowFunctionExpression, [FunctionObfuscator_1.FunctionObfuscator]],
                [NodeType_1.NodeType.ClassDeclaration, [FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator]],
                [NodeType_1.NodeType.CatchClause, [CatchClauseObfuscator_1.CatchClauseObfuscator]],
                [NodeType_1.NodeType.FunctionDeclaration, [
                        FunctionDeclarationObfuscator_1.FunctionDeclarationObfuscator,
                        FunctionObfuscator_1.FunctionObfuscator
                    ]],
                [NodeType_1.NodeType.FunctionExpression, [FunctionObfuscator_1.FunctionObfuscator]],
                [NodeType_1.NodeType.MemberExpression, [MemberExpressionObfuscator_1.MemberExpressionObfuscator]],
                [NodeType_1.NodeType.MethodDefinition, [MethodDefinitionObfuscator_1.MethodDefinitionObfuscator]],
                [NodeType_1.NodeType.ObjectExpression, [ObjectExpressionObfuscator_1.ObjectExpressionObfuscator]],
                [NodeType_1.NodeType.VariableDeclaration, [VariableDeclarationObfuscator_1.VariableDeclarationObfuscator]],
                [NodeType_1.NodeType.Literal, [LiteralObfuscator_1.LiteralObfuscator]]
            ]);
            this.options = options;
            this.nodes = new Map([
                ...new SelfDefendingNodesGroup_1.SelfDefendingNodesGroup(this.options).getNodes(),
                ...new ConsoleOutputNodesGroup_1.ConsoleOutputNodesGroup(this.options).getNodes(),
                ...new DebugProtectionNodesGroup_1.DebugProtectionNodesGroup(this.options).getNodes(),
                ...new UnicodeArrayNodesGroup_1.UnicodeArrayNodesGroup(this.options).getNodes()
            ]);
        }
        obfuscateNode(node) {
            NodeUtils_1.NodeUtils.parentize(node);
            this.beforeObfuscation(node);
            this.obfuscate(node);
            this.afterObfuscation(node);
            return node;
        }
        afterObfuscation(astTree) {
            this.nodes.forEach((node) => {
                if (node.getAppendState() === AppendState_1.AppendState.AfterObfuscation) {
                    node.appendNode(astTree);
                }
            });
        }
        beforeObfuscation(astTree) {
            this.nodes.forEach((node) => {
                if (node.getAppendState() === AppendState_1.AppendState.BeforeObfuscation) {
                    node.appendNode(astTree);
                }
            });
        }
        ;
        initializeNodeObfuscators(node, parentNode) {
            if (!this.nodeObfuscators.has(node.type)) {
                return;
            }
            this.nodeObfuscators.get(node.type).forEach((obfuscator) => {
                new obfuscator(this.nodes, this.options).obfuscateNode(node, parentNode);
            });
        }
        obfuscate(node) {
            estraverse.replace(node, {
                leave: (node, parentNode) => {
                    this.initializeNodeObfuscators(node, parentNode);
                }
            });
        }
    }
    exports.Obfuscator = Obfuscator;
    //# sourceMappingURL=Obfuscator.js.map