Javascript-obfuscator: Obfuscate class names

Created on 4 Sep 2017  路  3Comments  路  Source: javascript-obfuscator/javascript-obfuscator

I was wondering if it's possible to obfuscate class names. I think I have tried all the options and couldn't obfuscate class names.

Input:

const JavaScriptObfuscator = require('javascript-obfuscator');

const obfuscationResult = JavaScriptObfuscator.obfuscate(
    `
        class SomeClassName {

        }

        const g = new SomeClassName();
        console.log(g);
    `,
    {
        compact: true,
        controlFlowFlattening: false,
        controlFlowFlatteningThreshold: 0.75,
        deadCodeInjection: false,
        deadCodeInjectionThreshold: 0.4,
        debugProtection: false,
        debugProtectionInterval: false,
        disableConsoleOutput: false,
        log: false,
        mangle: false,
        renameGlobals: true,
        reservedNames: [],
        rotateStringArray: true,
        seed: 0,
        selfDefending: true,
        sourceMap: false,
        sourceMapBaseUrl: '',
        sourceMapFileName: '',
        sourceMapMode: 'separate',
        stringArray: true,
        stringArrayEncoding: true,
        stringArrayThreshold: 0.75,
        unicodeEscapeSequence: true
    }
);

console.log(obfuscationResult.getObfuscatedCode());

Output:
var _0xd6ff=['\x62\x47\x39\x6e'];(function(_0x4b055c,_0x4b870b){var _0x4b62bb=function(_0x4884c2){while(--_0x4884c2){_0x4b055c['push'](_0x4b055c['shift']());}};var _0x54f40d=function(){var _0x170f94={'data':{'key':'cookie','value':'timeout'},'setCookie':function(_0x47a3bf,_0x278c5e,_0x464fe7,_0x582ef9){_0x582ef9=_0x582ef9||{};var _0x14b5d0=_0x278c5e+'='+_0x464fe7;var _0x5b3b34=0x0;for(var _0x5b3b34=0x0,_0x574cf8=_0x47a3bf['length'];_0x5b3b34<_0x574cf8;_0x5b3b34++){var _0x532ffb=_0x47a3bf[_0x5b3b34];_0x14b5d0+=';\x20'+_0x532ffb;var _0x36e363=_0x47a3bf[_0x532ffb];_0x47a3bf['push'](_0x36e363);_0x574cf8=_0x47a3bf['length'];if(_0x36e363!==!![]){_0x14b5d0+='='+_0x36e363;}}_0x582ef9['cookie']=_0x14b5d0;},'removeCookie':function(){return'dev';},'getCookie':function(_0xf737d0,_0x41dfc9){_0xf737d0=_0xf737d0||function(_0x37f07d){return _0x37f07d;};var _0xfa4181=_0xf737d0(new RegExp('(?:^|;\x20)'+_0x41dfc9['replace'](/([.$?*|{}()[]\/+^])/g,'$1')+'=([^;]*)'));var _0x3c36c5=function(_0x5b0c03,_0x51d12b){_0x5b0c03(++_0x51d12b);};_0x3c36c5(_0x4b62bb,_0x4b870b);return _0xfa4181?decodeURIComponent(_0xfa4181[0x1]):undefined;}};var _0x5154d9=function(){var _0x1e9b7b=new RegExp('\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*[\x27|\x22].+[\x27|\x22];?\x20*}');return _0x1e9b7b['test'](_0x170f94['removeCookie']['toString']());};_0x170f94['updateCookie']=_0x5154d9;var _0x5851d4='';var _0x46a25c=_0x170f94['updateCookie']();if(!_0x46a25c){_0x170f94['setCookie'](['*'],'counter',0x1);}else if(_0x46a25c){_0x5851d4=_0x170f94['getCookie'](null,'counter');}else{_0x170f94['removeCookie']();}};_0x54f40d();}(_0xd6ff,0xfd));var _0xfd6f=function(_0x57802c,_0x13e92c){_0x57802c=_0x57802c-0x0;var _0x546b69=_0xd6ff[_0x57802c];if(_0xfd6f['initialized']===undefined){(function(){var _0x267010;try{var _0x14bb72=Function('return\x20(function()\x20'+'{}.constructor(\x22return\x20this\x22)(\x20)'+');');_0x267010=_0x14bb72();}catch(_0x41748d){_0x267010=window;}var _0x3dc9b7='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';_0x267010['atob']||(_0x267010['atob']=function(_0x467a99){var _0x3e4116=String(_0x467a99)['replace'](/=+$/,'');for(var _0x20538e=0x0,_0x13d1e4,_0x2cb5ce,_0x1e7df5=0x0,_0x25e3de='';_0x2cb5ce=_0x3e4116['charAt'](_0x1e7df5++);~_0x2cb5ce&&(_0x13d1e4=_0x20538e%0x4?_0x13d1e4*0x40+_0x2cb5ce:_0x2cb5ce,_0x20538e++%0x4)?_0x25e3de+=String['fromCharCode'](0xff&_0x13d1e4>>(-0x2*_0x20538e&0x6)):0x0){_0x2cb5ce=_0x3dc9b7['indexOf'](_0x2cb5ce);}return _0x25e3de;});}());_0xfd6f['base64DecodeUnicode']=function(_0x2b5c85){var _0xadc63b=atob(_0x2b5c85);var _0x32527f=[];for(var _0x5812fb=0x0,_0x27b2fb=_0xadc63b['length'];_0x5812fb<_0x27b2fb;_0x5812fb++){_0x32527f+='%'+('00'+_0xadc63b['charCodeAt'](_0x5812fb)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0x32527f);};_0xfd6f['data']={};_0xfd6f['initialized']=!![];}var _0x37809e=_0xfd6f['data'][_0x57802c];if(_0x37809e===undefined){var _0x181c7a=function(_0x4807eb){this['rc4Bytes']=_0x4807eb;this['states']=[0x1,0x0,0x0];this['newState']=function(){return'newState';};this['firstState']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*';this['secondState']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x181c7a['prototype']['checkState']=function(){var _0x425e47=new RegExp(this['firstState']+this['secondState']);return this['runState'](_0x425e47['test'](this['newState']['toString']())?--this['states'][0x1]:--this['states'][0x0]);};_0x181c7a['prototype']['runState']=function(_0xd75eac){if(!Boolean(~_0xd75eac)){return _0xd75eac;}return this['getState'](this['rc4Bytes']);};_0x181c7a['prototype']['getState']=function(_0x1aa4ce){for(var _0x570051=0x0,_0x228b76=this['states']['length'];_0x570051<_0x228b76;_0x570051++){this['states']['push'](Math['round'](Math['random']()));_0x228b76=this['states']['length'];}return _0x1aa4ce(this['states'][0x0]);};new _0x181c7a(_0xfd6f)['checkState']();_0x546b69=_0xfd6f['base64DecodeUnicode'](_0x546b69);_0xfd6f['data'][_0x57802c]=_0x546b69;}else{_0x546b69=_0x37809e;}return _0x546b69;};var _0x12f5fc=function(){var _0x261762=!![];return function(_0x2d8361,_0x3ceaaa){var _0x49b6d0=_0x261762?function(){if(_0x3ceaaa){var _0xef841a=_0x3ceaaa['apply'](_0x2d8361,arguments);_0x3ceaaa=null;return _0xef841a;}}:function(){};_0x261762=![];return _0x49b6d0;};}();var _0x50ccc4=_0x12f5fc(this,function(){var _0x4b4b20=function(){return'\x64\x65\x76';},_0x38411f=function(){return'\x77\x69\x6e\x64\x6f\x77';};var _0x3a3cb5=function(){var _0x2c778a=new RegExp('\x5c\x77\x2b\x20\x2a\x5c\x28\x5c\x29\x20\x2a\x7b\x5c\x77\x2b\x20\x2a\x5b\x27\x7c\x22\x5d\x2e\x2b\x5b\x27\x7c\x22\x5d\x3b\x3f\x20\x2a\x7d');return!_0x2c778a['\x74\x65\x73\x74'](_0x4b4b20['\x74\x6f\x53\x74\x72\x69\x6e\x67']());};var _0xc73b64=function(){var _0x1b6677=new RegExp('\x28\x5c\x5c\x5b\x78\x7c\x75\x5d\x28\x5c\x77\x29\x7b\x32\x2c\x34\x7d\x29\x2b');return _0x1b6677['\x74\x65\x73\x74'](_0x38411f['\x74\x6f\x53\x74\x72\x69\x6e\x67']());};var _0x5f4460=function(_0x3b3d3a){var _0x2f04c8=~-0x1>>0x1+0xff%0x0;if(_0x3b3d3a['\x69\x6e\x64\x65\x78\x4f\x66']('\x69'===_0x2f04c8)){_0x298efd(_0x3b3d3a);}};var _0x298efd=function(_0x2ca4c2){var _0x234261=~-0x4>>0x1+0xff%0x0;if(_0x2ca4c2['\x69\x6e\x64\x65\x78\x4f\x66']((!![]+'')[0x3])!==_0x234261){_0x5f4460(_0x2ca4c2);}};if(!_0x3a3cb5()){if(!_0xc73b64()){_0x5f4460('\x69\x6e\x64\u0435\x78\x4f\x66');}else{_0x5f4460('\x69\x6e\x64\x65\x78\x4f\x66');}}else{_0x5f4460('\x69\x6e\x64\u0435\x78\x4f\x66');}});_0x50ccc4();class SomeClassName{}const _0x4a6de7=new SomeClassName();console[_0xfd6f('0x0')](_0x4a6de7);

waiting for release

Most helpful comment

Done!
https://github.com/javascript-obfuscator/javascript-obfuscator/commit/bbaa8437396f621b28f6d34c80d33623c582c982

Will be out somewhere in the future with beta release of 0.12.0 version.

All 3 comments

Class names obfuscation not yet implemented, but it should be easy to add it

Done!
https://github.com/javascript-obfuscator/javascript-obfuscator/commit/bbaa8437396f621b28f6d34c80d33623c582c982

Will be out somewhere in the future with beta release of 0.12.0 version.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olOwOlo picture olOwOlo  路  3Comments

slig picture slig  路  8Comments

Andrews54757 picture Andrews54757  路  6Comments

invertedvisuals picture invertedvisuals  路  3Comments

rokoroku picture rokoroku  路  4Comments