taintable/dynamic_taint/jalangi/src/js/instrument/esnstrument.js
/**
     * Instruments the provided code.
     *
     * @param {string} code The code to instrument
     * @param {{wrapProgram: boolean, isEval: boolean }} options
     *    Options for code generation:
     *      'wrapProgram': Should the instrumented code be wrapped with prefix code to load libraries,
     * code to indicate script entry and exit, etc.? should be false for code being eval'd
     *      'isEval': is the code being instrumented for an eval?
     * @return {{code:string, instAST: object}} an object whose 'code' property is the instrumented code string,
     * and whose 'instAST' property is the AST for the instrumented code
     *
     */
Instruments the provided code.
@param {string} code The code to instrument
@param {{wrapProgram: boolean, isEval: boolean }} options
Options for code generation:
'wrapProgram': Should the instrumented code be wrapped with prefix code to load libraries,
code to indicate script entry and exit, etc.. should be false for code being eval'd
'isEval': is the code being instrumented for an eval.
@return {{code:string, instAST: object}} an object whose 'code' property is the instrumented code string,
and whose 'instAST' property is the AST for the instrumented code
Instruments the provided code . @param { string } code The code to instrument @param {{ wrapProgram : boolean isEval : boolean }} options Options for code generation : ' wrapProgram ' : Should the instrumented code be wrapped with prefix code to load libraries code to indicate script entry and exit etc .. should be false for code being eval ' d ' isEval ' : is the code being instrumented for an eval . @return {{ code : string instAST : object }} an object whose ' code ' property is the instrumented code string and whose ' instAST ' property is the AST for the instrumented code
function instrumentCode(code, options, iid) {
        var tryCatchAtTop = options.wrapProgram,
            isEval = options.isEval,
            instCodeCallback = isEval && sandbox.analysis && sandbox.analysis.instrumentCode;
        if (typeof  code === "string") {
            if (iid && sandbox.analysis && sandbox.analysis.instrumentCodePre) {
                var instCodePreResult = sandbox.analysis.instrumentCodePre(iid, code);
                if (instCodePreResult) {
                    code = instCodePreResult;
                }
            }
            if (code.indexOf(noInstr) < 0 && !(isEval && sandbox.noInstrEval)) {
                initializeIIDCounters(isEval);
                wrapProgramNode = tryCatchAtTop;
                var newAst = transformString(code, [visitorRRPost, visitorOps], [visitorRRPre, undefined]);
                var hoistedFcts = [];
                newAst = hoistFunctionDeclaration(newAst, hoistedFcts);
                var newCode = escodegen.generate(newAst);
                var ret = newCode + "\n" + noInstr + "\n";
                if (instCodeCallback) {
                    sandbox.analysis.instrumentCode(iid || -1, newAst);
                }
                return { code: ret, instAST: newAst, iidSourceInfo: iidSourceInfo };
            } else {
                return {code:code };
            }
        } else {
            return {code:code};
        }
    }
function instrumentCode ( code , options , iid ) { var tryCatchAtTop = options . wrapProgram , isEval = options . isEval , instCodeCallback = isEval && sandbox . analysis && sandbox . analysis . instrumentCode ; if ( typeof code === "string" ) { if ( iid && sandbox . analysis && sandbox . analysis . instrumentCodePre ) { var instCodePreResult = sandbox . analysis . instrumentCodePre ( iid , code ) ; if ( instCodePreResult ) { code = instCodePreResult ; } } if ( code . indexOf ( noInstr ) < 0 && ! ( isEval && sandbox . noInstrEval ) ) { initializeIIDCounters ( isEval ) ; wrapProgramNode = tryCatchAtTop ; var newAst = transformString ( code , [ visitorRRPost , visitorOps ] , [ visitorRRPre , undefined ] ) ; var hoistedFcts = [ ] ; newAst = hoistFunctionDeclaration ( newAst , hoistedFcts ) ; var newCode = escodegen . generate ( newAst ) ; var ret = newCode + "\n" + noInstr + "\n" ; if ( instCodeCallback ) { sandbox . analysis . instrumentCode ( iid || - 1 , newAst ) ; } return { code : ret , instAST : newAst , iidSourceInfo : iidSourceInfo } ; } else { return { code : code } ; } } else { return { code : code } ; } }
Instruments the provided code.
Instruments the provided code .
// this is a call in eval // post-process AST to hoist function declarations (required for Firefox) //                StatCollector.resumeTimer("generate"); //                console.time("generate") //                console.timeEnd("generate") //                StatCollector.suspendTimer("generate");