├── .gitignore ├── LICENSE ├── README.md ├── build.js ├── index-obfuscated.js ├── index-obfuscated.jsc ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | yarn.lock 3 | a.out -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2019 Winston Lee. https://github.com/iWinston/javascript-code-protection-example 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all 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, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # javascript-code-protection-example 2 | An example of JavaScript code protection. 3 | 4 | ## Introduction 5 | This repository contains an example of JavaScript code protection using javascript-obfuscator, bytenode and node-packer. 6 | 7 | ## For Local Development 8 | - Clone this repo and change directory to it. 9 | - Install the dependencies using `npm install`. 10 | - Make sure you have installed node-packer: https://github.com/pmq20/node-packer OR https://github.com/slee047/node-packer (For releases after Node.js 8.3.0) 11 | 12 | ## Command Usage 13 | - `npm run obfuscate`: obfuscate the `index.js` to `index-obfuscated.js` 14 | - `npm run bytenode`: compile the `index-obfuscated.js` to `index-obfuscated.jsc` 15 | - `npm run bytenode:run`: run the `index-obfuscated.jsc` 16 | - `npm run nodec`: package your Node.js project 17 | - `npm run build`: package your Node.js project into an executable that is obfuscated and compiled 18 | -------------------------------------------------------------------------------- /build.js: -------------------------------------------------------------------------------- 1 | require('bytenode'); 2 | 3 | require('./index-obfuscated.jsc'); -------------------------------------------------------------------------------- /index-obfuscated.js: -------------------------------------------------------------------------------- 1 | var _0x4c61=['L8OjMg==','5LmQ5Lu35pmL5Li35YKR5Y6h5LuQ55qX5LuX56G8QA==','SH/DsG/DlFJHw6c='];(function(_0x31ae9a,_0x569f4f){var _0x5bbcc9=function(_0x707604){while(--_0x707604){_0x31ae9a['push'](_0x31ae9a['shift']());}};_0x5bbcc9(++_0x569f4f);}(_0x4c61,0x171));var _0x12f9=function(_0x1f1b97,_0x29db6d){_0x1f1b97=_0x1f1b97-0x0;var _0x1f1843=_0x4c61[_0x1f1b97];if(_0x12f9['Ohpbve']===undefined){(function(){var _0x45eb06;try{var _0xfec66b=Function('return\x20(function()\x20'+'{}.constructor(\x22return\x20this\x22)(\x20)'+');');_0x45eb06=_0xfec66b();}catch(_0x14c449){_0x45eb06=window;}var _0x298557='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';_0x45eb06['atob']||(_0x45eb06['atob']=function(_0x554ffa){var _0x5cde4a=String(_0x554ffa)['replace'](/=+$/,'');for(var _0x96552e=0x0,_0x3f173,_0x4e1e83,_0x26c640=0x0,_0x14b906='';_0x4e1e83=_0x5cde4a['charAt'](_0x26c640++);~_0x4e1e83&&(_0x3f173=_0x96552e%0x4?_0x3f173*0x40+_0x4e1e83:_0x4e1e83,_0x96552e++%0x4)?_0x14b906+=String['fromCharCode'](0xff&_0x3f173>>(-0x2*_0x96552e&0x6)):0x0){_0x4e1e83=_0x298557['indexOf'](_0x4e1e83);}return _0x14b906;});}());var _0x3eacd2=function(_0x419241,_0x29db6d){var _0x433c45=[],_0x35da23=0x0,_0x28e708,_0x394856='',_0x333d91='';_0x419241=atob(_0x419241);for(var _0x57ce95=0x0,_0x5456c9=_0x419241['length'];_0x57ce95<_0x5456c9;_0x57ce95++){_0x333d91+='%'+('00'+_0x419241['charCodeAt'](_0x57ce95)['toString'](0x10))['slice'](-0x2);}_0x419241=decodeURIComponent(_0x333d91);for(var _0x31de37=0x0;_0x31de37<0x100;_0x31de37++){_0x433c45[_0x31de37]=_0x31de37;}for(_0x31de37=0x0;_0x31de37<0x100;_0x31de37++){_0x35da23=(_0x35da23+_0x433c45[_0x31de37]+_0x29db6d['charCodeAt'](_0x31de37%_0x29db6d['length']))%0x100;_0x28e708=_0x433c45[_0x31de37];_0x433c45[_0x31de37]=_0x433c45[_0x35da23];_0x433c45[_0x35da23]=_0x28e708;}_0x31de37=0x0;_0x35da23=0x0;for(var _0x2e0691=0x0;_0x2e0691<_0x419241['length'];_0x2e0691++){_0x31de37=(_0x31de37+0x1)%0x100;_0x35da23=(_0x35da23+_0x433c45[_0x31de37])%0x100;_0x28e708=_0x433c45[_0x31de37];_0x433c45[_0x31de37]=_0x433c45[_0x35da23];_0x433c45[_0x35da23]=_0x28e708;_0x394856+=String['fromCharCode'](_0x419241['charCodeAt'](_0x2e0691)^_0x433c45[(_0x433c45[_0x31de37]+_0x433c45[_0x35da23])%0x100]);}return _0x394856;};_0x12f9['ceufnq']=_0x3eacd2;_0x12f9['tUDvEv']={};_0x12f9['Ohpbve']=!![];}var _0x2c09b1=_0x12f9['tUDvEv'][_0x1f1b97];if(_0x2c09b1===undefined){if(_0x12f9['JOexJU']===undefined){_0x12f9['JOexJU']=!![];}_0x1f1843=_0x12f9['ceufnq'](_0x1f1843,_0x29db6d);_0x12f9['tUDvEv'][_0x1f1b97]=_0x1f1843;}else{_0x1f1843=_0x2c09b1;}return _0x1f1843;};console[_0x12f9('0x0','wLHS')](_0x12f9('0x1','ae[I'));var a=0x1;var b=0x1;var c=a+b;console['log'](_0x12f9('0x2','4xJE')+c); -------------------------------------------------------------------------------- /index-obfuscated.jsc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iWinston/javascript-code-protection-example/74b53e8095b628ae6c2db00bbdd248ec5dc4f3e1/index-obfuscated.jsc -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | console.log("以下是价值上千万的代码:"); 2 | var a = 1; 3 | var b = 1; 4 | var c = a + b; 5 | console.log("1 + 1 = " + c) 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "javascript-code-protection-example", 3 | "version": "0.0.1", 4 | "description": "An example of JavaScript code protection", 5 | "main": "index.js", 6 | "scripts": { 7 | "obfuscate": "javascript-obfuscator index.js --string-array-encoding rc4", 8 | "bytenode": "bytenode --compile index-obfuscated.js", 9 | "bytenode:run": "bytenode index-obfuscated.js", 10 | "nodec": "nodec build.js --skip-npm-install", 11 | "build": "npm run obfuscate && npm run bytenode && npm run nodec", 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/iWinston/javascript-code-protection-example.git" 17 | }, 18 | "keywords": [ 19 | "JavaScript", 20 | "code protection" 21 | ], 22 | "author": "Winston Lee", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/iWinston/javascript-code-protection-example/issues" 26 | }, 27 | "homepage": "https://github.com/iWinston/javascript-code-protection-example#readme", 28 | "devDependencies": { 29 | "bytenode": "^1.1.1", 30 | "javascript-obfuscator": "^0.18.1" 31 | } 32 | } 33 | --------------------------------------------------------------------------------