All files / webpack:/src/node-obfuscators CatchClauseObfuscator.ts

100% Statements 5/5
100% Branches 2/2
100% Functions 2/2
100% Lines 5/5
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          1x                         1x       1x           1x                                             1x          
import * as estraverse from 'estraverse';
 
import { ICatchClauseNode } from "../interfaces/nodes/ICatchClauseNode";
import { INode } from '../interfaces/nodes/INode';
 
import { NodeObfuscator } from './NodeObfuscator';
import { Nodes } from "../Nodes";
import { Utils } from '../Utils';
import {IBlockStatementNode} from "../interfaces/nodes/IBlockStatementNode";
 
/**
 * replaces:
 *     try {} catch (e) { console.log(e); };
 *
 * on:
 *     try {} catch (_0x12d45f) { console.log(_0x12d45f); };
 *
 */
export class CatchClauseObfuscator extends NodeObfuscator {
    /**
     * @type {Map<string, string>}
     */
    private catchClauseParam: Map <string, string> = new Map <string, string> ();
 
    /**
     * @param catchClauseNode
     */
    public obfuscateNode (catchClauseNode: ICatchClauseNode): void {
        this.storeCatchClauseParam(catchClauseNode);
        this.replaceCatchClauseParam(catchClauseNode);
    }
 
    /**
     * @param catchClauseNode
     */
    private storeCatchClauseParam (catchClauseNode: ICatchClauseNode): void {
        estraverse.traverse(catchClauseNode.param, {
            leave: (node: INode): any => this.storeIdentifiersNames(node, this.catchClauseParam)
        });
    }
 
    /**
     * @param catchClauseNode
     */
    private replaceCatchClauseParam (catchClauseNode: ICatchClauseNode): void {
        estraverse.replace(catchClauseNode, {
            leave: (node: INode, parentNode: INode): any => {
                this.replaceIdentifiersWithRandomNames(node, parentNode, this.catchClauseParam);
            }
        });
    }
}
 
 
 
// WEBPACK FOOTER //
// ./src/node-obfuscators/CatchClauseObfuscator.ts