├── .gitignore ├── LICENSE.md ├── README.md ├── index.js ├── package.json └── test.js /.gitignore: -------------------------------------------------------------------------------- 1 | gs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # Compiled binary addons (http://nodejs.org/api/addons.html) 20 | build/Release 21 | 22 | # Dependency directory 23 | # Commenting this out is preferred by some people, see 24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 25 | node_modules 26 | 27 | # Users Environment Variables 28 | .lock-wscript 29 | .idea 30 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Tang Khai Phuong - tangkhaiphuong@gmail.com. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gulp-javascriptobfuscator 2 | 3 | Obfuscate JavasScript via javascriptobfuscator.com. Please DO NOT include any sensitive data. 4 | 5 | Installation 6 | ---- 7 | npm install gulp-javascriptobfuscator 8 | Usage 9 | ==== 10 |

11 | var javascriptobfuscator = require('gulp-javascriptobfuscator');
12 | 
13 | gulp.task('scripts', function() {
14 |     gulp.src('./lib/*.js')
15 |     .pipe(javascriptobfuscator({
16 |         encodeString: true, // (Optional - default: true)
17 |         encodeNumber: true, // (Optional - default: true)
18 |         replaceNames: true, // (Optional - default: true)
19 |         moveString: true,   // (Optional - default: true)
20 |         exclusions: ["^_get_", "^_set_", "^_mtd_"] // (Optional)
21 |     }))
22 |     .pipe(gulp.dest('./dist/'));
23 | });
24 | 
25 | 26 | # License 27 | 28 | MIT 29 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var http, obfuscate, unescapeHTML; 3 | 4 | var _host = "www.javascriptobfuscator.com"; 5 | var _path = "/Javascript-Obfuscator.aspx"; 6 | 7 | http = require("http"); 8 | 9 | unescapeHTML = function(str) { 10 | var escapeChars; 11 | if (str == null) { 12 | return ""; 13 | } 14 | escapeChars = { 15 | lt: '<', 16 | gt: '>', 17 | quot: '"', 18 | apos: "'", 19 | amp: '&' 20 | }; 21 | return String(str).replace(/\&([^;]+);/g, function(entity, entityCode) { 22 | var match; 23 | match = void 0; 24 | if (entityCode in escapeChars) { 25 | return escapeChars[entityCode]; 26 | } else if (match = entityCode.match(/^#x([\da-fA-F]+)$/)) { 27 | return String.fromCharCode(parseInt(match[1], 16)); 28 | } else if (match = entityCode.match(/^#(\d+)$/)) { 29 | return String.fromCharCode(~~match[1]); 30 | } else { 31 | return entity; 32 | } 33 | }); 34 | }; 35 | 36 | obfuscate = function(source, options, cb) { 37 | var item, req, _i, _len, _ref; 38 | if (!options) { 39 | options = {}; 40 | } 41 | _ref = ["encodeString", "encodeNumber", "replaceNames", "moveString"]; 42 | for (_i = 0, _len = _ref.length; _i < _len; _i++) { 43 | item = _ref[_i]; 44 | if (options[item] == null) { 45 | options[item] = "on"; 46 | } else { 47 | options[item] = !!options[item] ? "on" : "off"; 48 | } 49 | } 50 | if (options.exclusions == null) { 51 | options.exclusions = ["^_get_", "^_set_", "^_mtd_"]; 52 | } 53 | 54 | req = http.get({ 55 | hostname: _host, 56 | port: 80, 57 | path: _path 58 | }, function(res) { 59 | var data; 60 | res.setEncoding("utf8"); 61 | data = ""; 62 | res.on("data", function(chunk) { 63 | return data += chunk; 64 | }); 65 | return res.on("end", function() { 66 | var eventValidation, qr, req2, viewState, viewstategenerator; 67 | 68 | viewState = /id=\"__VIEWSTATE\".+value=\"(.+)\"/.exec(data)[1]; 69 | eventValidation = /id=\"__EVENTVALIDATION\".+value=\"(.+)\"/.exec(data)[1]; 70 | viewstategenerator = /id=\"__VIEWSTATEGENERATOR\".+value=\"(.+)\"/.exec(data)[1]; 71 | 72 | qr = require("querystring").stringify({ 73 | __EVENTTARGET: 'ctl00$MainContent$Button1', 74 | __VIEWSTATE: viewState, 75 | __VIEWSTATEGENERATOR: viewstategenerator, 76 | __EVENTVALIDATION: eventValidation, 77 | ctl00$MainContent$TextBox1: source, 78 | ctl00$MainContent$TextBox2: "", 79 | ctl00$MainContent$cbEncodeStr: options.encodeString, 80 | ctl00$MainContent$cbEncodeNumber: options.encodeNumber, 81 | ctl00$MainContent$cbMoveStr: options.replaceNames, 82 | ctl00$MainContent$cbReplaceNames: options.moveString, 83 | ctl00$MainContent$TextBox3: options.exclusions.join("\r\n") 84 | }); 85 | req2 = http.request({ 86 | hostname: _host, 87 | port: 80, 88 | path: _path, 89 | method: "POST", 90 | headers: { 91 | 'Content-Type': 'application/x-www-form-urlencoded' 92 | } 93 | }, function(res) { 94 | res.setEncoding("utf8"); 95 | data = ""; 96 | res.on("data", function(chunk) { 97 | return data += chunk; 98 | }); 99 | 100 | return res.on("end", function() { 101 | var code, ex; 102 | try { 103 | code = /]*id="ctl00_MainContent_TextBox2"[^>]*>[\r\n]*(.+)<\/textarea>/.exec(data); 104 | return typeof cb === "function" ? cb(null, unescapeHTML(code[1])) : void 0; 105 | } catch (_error) { 106 | ex = _error; 107 | return typeof cb === "function" ? cb(ex) : void 0; 108 | } 109 | }); 110 | }); 111 | req2.on("error", function(error) { 112 | return typeof cb === "function" ? cb(error) : void 0; 113 | }); 114 | req2.write(qr); 115 | return req2.end(); 116 | }); 117 | }); 118 | req.on("error", function(error) { 119 | return typeof cb === "function" ? cb(error) : void 0; 120 | }); 121 | return req.end(); 122 | }; 123 | 124 | module.exports = function(options) { 125 | return require("through2").obj(function(file, encoding, callback) { 126 | if (file.isNull()) { 127 | this.push(file); 128 | return callback(); 129 | } 130 | if (file.isStream()) { 131 | return callback(new Error("gulp-jsobfuscator: Streaming not supported")); 132 | } 133 | return obfuscate(file.contents.toString(encoding), options, (function(_this) { 134 | return function(error, data) { 135 | if (error != null) { 136 | return callback(error); 137 | } 138 | file.contents = new Buffer(data); 139 | _this.push(file); 140 | return callback(); 141 | }; 142 | })(this)); 143 | }); 144 | }; 145 | 146 | module.exports.obfuscate = obfuscate; 147 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gulp-javascriptobfuscator", 3 | "version": "0.2.0", 4 | "description": "Obfuscate JavasScript via javascriptobfuscator.com. Please DO NOT include any sensitive data.", 5 | "email": "tangkhaiphuong@gmail.com", 6 | "main": "index.js", 7 | "scripts": { 8 | "test": "node ./test.js" 9 | }, 10 | "keywords": [ 11 | "gulp", 12 | "gulpplugin", 13 | "obfuscate", 14 | "obfuscator" 15 | ], 16 | "author": { 17 | "name": "Tang Khai Phuong", 18 | "email": "tangkhaiphuong@gmail.com" 19 | }, 20 | "dependencies": { 21 | "through2": "*" 22 | }, 23 | "license": "MIT" 24 | } 25 | 26 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | var o = require('./index.js'); 2 | var assert = require('assert'); 3 | 4 | var source = 'console.log("123", 456)'; 5 | var obfuscatedTemplate = 'var __VAR__=["\x31\x32\x33","\x6C\x6F\x67"];console[__VAR__[1]](__VAR__[0],456)' 6 | 7 | 8 | o.obfuscate('console.log("123", 456)', {}, function(error, data) { 9 | var obfuscatedString = data.replace(/__VAR__/g, /var\s(.+)=/.exec(data)[1]) 10 | 11 | assert.equal(error, null); 12 | assert.equal(data, obfuscatedString); 13 | }); 14 | --------------------------------------------------------------------------------