beautifier / js-beautify

Beautifier for javascript
https://beautifier.io
MIT License
8.57k stars 1.37k forks source link

Can't beautify code #1865

Open CreatorEdition opened 3 years ago

CreatorEdition commented 3 years ago

Description

Can't beautify code

Input

The code looked like this before beautification:

var __encode ='jsjiami.com',_a={}, _0xb483=["\x5F\x64\x65\x63\x6F\x64\x65","\x68\x74\x74\x70\x3A\x2F\x2F\x77\x77\x77\x2E\x73\x6F\x6A\x73\x6F\x6E\x2E\x63\x6F\x6D\x2F\x6A\x61\x76\x61\x73\x63\x72\x69\x70\x74\x6F\x62\x66\x75\x73\x63\x61\x74\x6F\x72\x2E\x68\x74\x6D\x6C"];(function(_0xd642x1){_0xd642x1[_0xb483[0]]= _0xb483[1]})(_a);var _0xf56f=["\x69\x6E\x66\x6F","\x54\x68\x69\x73\x20\x69\x73\x20\x61\x20\x73\x65\x72\x69\x65\x73\x20\x6F\x66\x20\x6A\x73\x20\x6F\x70\x65\x72\x61\x74\x69\x6F\x6E\x73\x2E","\x61\x64\x69\x6E\x66\x6F","\x44\x65\x66\x65\x6E\x64\x20\x79\x6F\x75\x72\x20\x6A\x73\x2E","\x77\x61\x72\x6E\x69\x6E\x67","\x54\x68\x69\x73\x20\x74\x6F\x6F\x6C\x20\x63\x61\x6E\x27\x74\x20\x65\x6E\x63\x72\x79\x70\x74\x20\x70\x68\x70\x2C\x20\x6A\x73\x70\x20\x61\x6E\x64\x20\x6F\x74\x68\x65\x72\x20\x74\x65\x6D\x70\x6C\x61\x74\x65\x20\x63\x6F\x6E\x74\x65\x6E\x74\x2E","\x75\x6E\x64\x65\x66\x69\x6E\x65\x64","\x6C\x6F\x67","\u5220\u9664","\u7248\u672C\u53F7\uFF0C\x6A\x73\u4F1A\u5B9A","\u671F\u5F39\u7A97\uFF0C","\u8FD8\u8BF7\u652F\u6301\u6211\u4EEC\u7684\u5DE5\u4F5C","\x6A\x73\x6A\x69\x61","\x6D\x69\x2E\x63\x6F\x6D"];(function(_0xc77dx1,_0xc77dx2){_0xc77dx1[_0xf56f[0x0]]= _0xf56f[0x1];_0xc77dx2[_0xf56f[0x2]]= _0xf56f[0x3];_0xc77dx2[_0xf56f[0x4]]= _0xf56f[0x5]})(window,document);;;(function(_0xc77dx3,_0xc77dx4,_0xc77dx5,_0xc77dx6,_0xc77dx7,_0xc77dx8){_0xc77dx8= _0xf56f[0x6];_0xc77dx6= function(_0xc77dx9){if( typeof alert!== _0xc77dx8){alert(_0xc77dx9)};if( typeof console!== _0xc77dx8){console[_0xf56f[0x7]](_0xc77dx9)}};_0xc77dx5= function(_0xc77dxa,_0xc77dx3){return _0xc77dxa+ _0xc77dx3};_0xc77dx7= _0xc77dx5(_0xf56f[0x8],_0xc77dx5(_0xc77dx5(_0xf56f[0x9],_0xf56f[0xa]),_0xf56f[0xb]));try{_0xc77dx3= __encode;if(!( typeof _0xc77dx3!== _0xc77dx8&& _0xc77dx3=== _0xc77dx5(_0xf56f[0xc],_0xf56f[0xd]))){_0xc77dx6(_0xc77dx7)}}catch(e){_0xc77dx6(_0xc77dx7)}})({})

Expected Output

The code should have looked like this after beautification:

(function(w, d) { 

 w.info = "This is a series of js operations."; 

 d.adinfo = "Defend your js."; 

 d.warning = "This tool can't encrypt php, jsp and other template content."; 

})(window, document);

Actual Output

The code actually looked like this after beautification:

'use strict';
/** @type {string} */
var __encode = "jsjiami.com";
var _a = {};
/** @type {!Array} */
var _0xb483 = ["_decode", "http://www.sojson.com/javascriptobfuscator.html"];
(function(value) {
    value[_0xb483[0]] = _0xb483[1];
})(_a);
/** @type {!Array} */
var _0xf56f = ["info", "This is a series of js operations.", "adinfo", "Defend your js.", "warning", "This tool can't encrypt php, jsp and other template content.", "undefined", "log", "\u5220\u9664", "\u7248\u672c\u53f7\uff0cjs\u4f1a\u5b9a", "\u671f\u5f39\u7a97\uff0c", "\u8fd8\u8bf7\u652f\u6301\u6211\u4eec\u7684\u5de5\u4f5c", "jsjia", "mi.com"];
(function(metaWindow, selector) {
    metaWindow[_0xf56f[0]] = _0xf56f[1];
    selector[_0xf56f[2]] = _0xf56f[3];
    selector[_0xf56f[4]] = _0xf56f[5];
})(window, document);
(function(expected, canCreateDiscussions, require, callback, notifications, object) {
    object = _0xf56f[6];
    /**
     * @param {(Array|HTMLCollection|Node|NodeList|Window|string)} obj
     * @return {undefined}
     */
    callback = function(obj) {
        if (typeof alert !== object) {
            alert(obj);
        }
        if (typeof console !== object) {
            console[_0xf56f[7]](obj);
        }
    };
    /**
     * @param {(Object|number)} options
     * @param {!Object} callback
     * @return {?}
     */
    require = function(options, callback) {
        return options + callback;
    };
    notifications = require(_0xf56f[8], require(require(_0xf56f[9], _0xf56f[10]), _0xf56f[11]));
    try {
        expected = __encode;
        if (!(typeof expected !== object && expected === require(_0xf56f[12], _0xf56f[13]))) {
            callback(notifications);
        }
    } catch (e) {
        callback(notifications);
    }
})({});

Settings

Example:

{
  "indent_size": "4",
  "indent_char": " ",
  "max_preserve_newlines": "5",
  "preserve_newlines": true,
  "keep_array_indentation": false,
  "break_chained_methods": false,
  "indent_scripts": "normal",
  "brace_style": "collapse",
  "space_before_conditional": true,
  "unescape_strings": false,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "0",
  "indent_inner_html": false,
  "comma_first": false,
  "e4x": false,
  "indent_empty_lines": false
}
bitwiseman commented 3 years ago

Deobfuscation issue.

achyut2000 commented 3 years ago

hello @bitwiseman I want to work on this

bitwiseman commented 3 years ago

Go for it.