All files / webpack:/src/custom-nodes/self-defending-nodes SelfDefendingUnicodeNode.ts

100% Statements 9/9
50% Branches 1/2
100% Functions 1/1
100% Lines 9/9
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 761x                   1x     1x   1x                     1x                           1x 1x 1x                   1x                                              
import * as esprima from 'esprima';
 
import { INode } from "../../interfaces/nodes/INode";
import { IOptions } from "../../interfaces/IOptions";
 
import { TNodeWithBlockStatement } from "../../types/TNodeWithBlockStatement";
 
import { AppendState } from "../../enums/AppendState";
import { JSFuck } from "../../enums/JSFuck";
 
import { NO_CUSTOM_NODES_PRESET } from "../../preset-options/NoCustomNodesPreset";
 
import { JavaScriptObfuscator } from "../../JavaScriptObfuscator";
import { Node } from '../Node';
import { NodeUtils } from "../../NodeUtils";
import { Utils } from "../../Utils";
 
export class SelfDefendingUnicodeNode extends Node {
    /**
     * @type {AppendState}
     */
    protected IappendState: AppendState = AppendState.AfterObfuscation;
 
    /**
     * @param options
     */
    constructor (options: IOptions) {
        super(options);
 
        this.node = this.getNodeStructure();
    }
 
    /**
     * @param blockScopeNode
     */
    public appendNode (blockScopeNode: TNodeWithBlockStatement): void {
        let programBodyLength: number = blockScopeNode.body.length,
            randomIndex: number = 0;
 
        if (programBodyLength > 2) {
            randomIndex = Utils.getRandomGenerator().integer({
                min: programBodyLength / 2,
                max: programBodyLength - 1
            });
        }
 
        NodeUtils.insertNodeAtIndex(blockScopeNode.body, this.getNode(), randomIndex);
    }
 
    /**
     * @returns {INode}
     */
    protected getNodeStructure (): INode {
        let node: INode = esprima.parse(
            JavaScriptObfuscator.obfuscate(`
                (function () {                                
                    var func = function(){return ${Utils.stringToUnicode('dev')};},
                        func2 = function () {
                            return 'window';
                        };
                
                    !Function(${Utils.stringToUnicode(`return/\\w+ *\\(\\) *{\\w+ *['|"].+['|"];? *}/`)})().test(func.toString()) ? Function(${Utils.stringToUnicode(`return/(\\\\[x|u](\\w){2,4})+/`)})().test(func2.toString()) ? []['filter']['constructor'](${Utils.stringToJSFuck('while')} + '(${JSFuck.False}){}')() : []['filter']['constructor'](${Utils.stringToJSFuck('while')} + '(${JSFuck.True}){}')() : []['filter']['constructor'](${Utils.stringToJSFuck('while')} + '(${JSFuck.False}){}')();
                })();
            `, NO_CUSTOM_NODES_PRESET)
        );
 
        NodeUtils.addXVerbatimPropertyToLiterals(node);
 
        return NodeUtils.getBlockStatementNodeByIndex(node);
    }
}
 
 
 
// WEBPACK FOOTER //
// ./src/custom-nodes/self-defending-nodes/SelfDefendingUnicodeNode.ts