How to use javascript-obfuscator - 10 common examples

To help you get started, we’ve selected a few javascript-obfuscator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / javascript-obfuscator / javascript-obfuscator-tests.ts View on Github external
/// <reference path="javascript-obfuscator" />

import { JavaScriptObfuscator } from 'javascript-obfuscator';

let sourceCode1: string = JavaScriptObfuscator.obfuscate('var foo = 1;');
let sourceCode2: string = JavaScriptObfuscator.obfuscate('var foo = 1;', {
  compact: true,
    debugProtection: false,
    debugProtectionInterval: false,
    disableConsoleOutput: true,
    encodeUnicodeLiterals: false,
    reservedNames: ['^foo$'],
    rotateUnicodeArray: true,
    selfDefending: true,
    unicodeArray: true,
    unicodeArrayThreshold: 0.8,
    wrapUnicodeArrayCalls: true
});
github nils-kt / asar-package-obfuscator / index.js View on Github external
files.forEach(file => {
        if (path.extname(file) === '.js') {
            let contents = fs.readFileSync(file, 'utf8');
            console.log('Protecting ' + file);

            // Change the settings here  -  https://github.com/javascript-obfuscator/javascript-obfuscator
            let ret = javaScriptObfuscator.obfuscate(contents, {
                compact: true
                , controlFlowFlattening: false
                , controlFlowFlatteningThreshold: 0.75
                , deadCodeInjection: false
                , deadCodeInjectionThreshold: 0.4
                , debugProtection: false
                , debugProtectionInterval: false
                , disableConsoleOutput: false
                , domainLock: []
                , identifierNamesGenerator: 'hexadecimal'
                , identifiersPrefix: ''
                , inputFileName: ''
                , log: false
                , renameGlobals: false
                , reservedNames: []
                , reservedStrings: []
github javascript-obfuscator / javascript-obfuscator-ui / server.js View on Github external
const {code, options} = body;

    if (!options.sourceMap) {
        delete options.sourceMapMode
    }

    // options.stringArrayEncoding come from the client as strings, but the
    // obfuscator expects it to be a boolean or a string if 'base64'/'rc4'
    if (['false', 'true'].indexOf(options.stringArrayEncoding) !== -1) {
        options.stringArrayEncoding = options.stringArrayEncoding === 'true';
    }

    let response = {};

    try {
        const result = JavaScriptObfuscator.obfuscate(code, options);
        response = {
            code: result.getObfuscatedCode(),
            sourceMap: result.getSourceMap(),
        }
    } catch (e) {
        response = {
            code: e.toString(),
            sourceMap: '',
        }
    }

    res.send(JSON.stringify(response));

});
github javascript-obfuscator / obfuscator-loader / lib / index.js View on Github external
}
    });
  }

  // Wraps requires in conditional comments
  let commentedSource = source.slice();
  entries.sort((a, b) => b.end - a.end).forEach((n) => {
    const before = commentedSource.slice(0, n.start);
    const mid = commentedSource.slice(n.start, n.end);
    const after = commentedSource.slice(n.end);
    commentedSource = `${before}/* javascript-obfuscator:disable */${mid}/* javascript-obfuscator:enable */${after}`;
  });

  // Obfuscates commented source code
  const options = loaderUtils.getOptions(this) || {};
  const obfuscationResult = JavaScriptObfuscator.obfuscate(commentedSource, options);
  const code = obfuscationResult.getObfuscatedCode();
  return code;
};
github javascript-obfuscator / webpack-obfuscator / index.ts View on Github external
private obfuscate(javascript: string): { obfuscatedSource: string, obfuscationSourceMap: string } {
        const obfuscationResult = JavaScriptObfuscator.obfuscate(
            javascript,
            this.options
        );

        return {
            obfuscatedSource: obfuscationResult.getObfuscatedCode(),
            obfuscationSourceMap: obfuscationResult.getSourceMap()
        }
    }
}
github javascript-obfuscator / gulp-javascript-obfuscator / index.js View on Github external
return through2.obj(function (file, enc, cb) {
		if (file.isNull()) return cb(null, file);
		if (!file.isBuffer()) throw new PluginError('gulp-javascript-obfuscator', 'Only Buffers are supported!');
		if (file.sourceMap) {
			options.sourceMap = true;
			options.inputFileName = file.relative;
			options.sourceMapMode = 'separate';
		}

		try {
			const obfuscationResult = JavaScriptObfuscator.obfuscate(String(file.contents), options);
			file.contents = new Buffer(obfuscationResult.getObfuscatedCode());
			if (options.sourceMap && options.sourceMapMode !== 'inline') {
				if ( file.sourceMap ) {
					const sourceMap = JSON.parse(obfuscationResult.getSourceMap());
					sourceMap.file = file.sourceMap.file;
					applySourceMap(file, sourceMap);
				}
				else {
					this.push(new Vinyl({
						cwd: file.cwd,
						base: file.base,
						path: file.path + '.map',
						contents: new Buffer(obfuscationResult.getSourceMap())
					}))
				}
			}
github javascript-obfuscator / webpack-obfuscator / index.js View on Github external
var sourceAndMap = asset.sourceAndMap();
                            inputSourceMap = sourceAndMap.map;
                            input = sourceAndMap.source;
                        }
                        else {
                            inputSourceMap = asset.map();
                            input = asset.source();
                        }
                        if (inputSourceMap) {
                            _this.options.sourceMap = true;
                        }
                    }
                    else {
                        input = asset.source();
                    }
                    var obfuscationResult = JavaScriptObfuscator.obfuscate(input, _this.options);
                    if (_this.options.sourceMap) {
                        var obfuscationSourceMap = obfuscationResult.getSourceMap(), transferredSourceMap = transferSourceMap({
                            fromSourceMap: obfuscationSourceMap,
                            toSourceMap: inputSourceMap
                        });
                        compilation.assets[file] = new SourceMapSource(obfuscationResult.toString(), file, JSON.parse(transferredSourceMap), asset.source(), inputSourceMap);
                    }
                    else {
                        compilation.assets[file] = new RawSource(obfuscationResult.toString());
                    }
                });
            });
github weexteam / devtool-for-Apache-Weex / src / router / Websocket.js View on Github external
if (device) {
            message.params.url = new MemoryFile('js-framework.js', message.params.source).getUrl();
            if (device.deviceInfo.logLevel) {
              message.params.env.WXEnvironment.logLevel = device.deviceInfo.logLevel;
            }
            device.debuggerSession.postMessage(this, message);
          }
          else {
            Logger.error('Fatal Error:native device unregistered before initJSRuntime!');
          }
        }
        else if (method === 'callJS' && message.params.method === 'createInstance') {
          if (device) {
            let code = message.params.args[1];
            if (message.params.args[2] && (message.params.args[2]['debuggable'] === 'false' || message.params.args[2]['debuggable'] === false)) {
              const obfuscationResult = JavaScriptObfuscator.obfuscate(message.params.args[1], {
                compact: true,
                controlFlowFlattening: false,
                debugProtection: false,
                debugProtectionInterval: false,
                disableConsoleOutput: true,
                rotateStringArray: true,
                selfDefending: true,
                stringArray: true,
                stringArrayEncoding: false,
                stringArrayThreshold: 0.75,
                unicodeEscapeSequence: true
              });
              code = obfuscationResult.getObfuscatedCode();
            }
            message.params.sourceUrl = new MemoryFile(message.params.args[2].bundleUrl || (Uuid() + '.js'), bundleWrapper(code)).getUrl();
            device.debuggerSession.postMessage(this, message);
github felamos / weirdhta / api / index.js View on Github external
app.post('/api/weirdhta', (req, res) => {
  const base64 = req.body.code;
  let data = base64;
  let buff = new Buffer(data, 'base64');
  let text = buff.toString('ascii');
  var obfuscationResult = JavaScriptObfuscator.obfuscate(
    `
    ${text}
    `,
    {
        compact: true,
        controlFlowFlattening: true,
        debugProtection: true,
        log: false,
        disableConsoleOutput: true,
        rotateStringArray: true,
        stringArray: true,
    }
  );

  res.send(obfuscationResult.getObfuscatedCode());
});
github weexteam / devtool-for-Apache-Weex / src / router / Websocket.js View on Github external
if (device) {
                        message.params.url = new MemoryFile('js-framework.js', message.params.source).getUrl();
                        if (device.deviceInfo.logLevel) {
                            message.params.env.WXEnvironment.logLevel = device.deviceInfo.logLevel;
                        }
                        device.debuggerSession.postMessage(this, message);
                    }
                    else {
                        Logger.error('Fatal Error:native device unregistered before initJSRuntime!');
                    }
                }
                else if (method == 'callJS' && message.params.method == 'createInstance') {
                    if (device) {
                        let code = message.params.args[1];
                        if (message.params.args[2] && (message.params.args[2]['debuggable'] === 'false' || message.params.args[2]['debuggable'] === false)) {
                            var obfuscationResult = JavaScriptObfuscator.obfuscate(message.params.args[1], {
                                compact: true,
                                controlFlowFlattening: false,
                                debugProtection: false,
                                debugProtectionInterval: false,
                                disableConsoleOutput: true,
                                rotateStringArray: true,
                                selfDefending: true,
                                stringArray: true,
                                stringArrayEncoding: false,
                                stringArrayThreshold: 0.75,
                                unicodeEscapeSequence: true
                            });
                            code = obfuscationResult.getObfuscatedCode();
                        }
                        message.params.sourceUrl = new MemoryFile(message.params.args[2].bundleUrl || (Uuid() + '.js'), bundleWrapper(code)).getUrl();
                        device.debuggerSession.postMessage(this, message);

javascript-obfuscator

JavaScript obfuscator

BSD-2-Clause
Latest version published 10 months ago

Package Health Score

71 / 100
Full package analysis

Popular JavaScript code snippets

Find secure code to use in your application or website