abelard2008
abelard2008

Reputation: 2084

What's such magic javascript code used for and how is it created?

I am a new man for javascript and I am working hard to understanding it.

The following snippet javascript code is from a file vishEditor.js of the project Vish, the whole file include more than 30 thousand lines, so I cut the magic part into a small file magic-javascript.js.

eval(function(p, a, c, k, e, r) {
e = function(c) {
    return (c < a ? "" : e(parseInt(c / a))) + ((c = c % a) > 35 ? String.fromCharCode(c + 29) : c.toString(36))
};
 .......
}
return p
}("(D($){8($.1s.1v){H}$.1s.6i=$.1s.1v=D(u,w){8(1l.S==0){18(J,'6j 55 6k 1j \"'+1l.4o+'\".');H 1l}8(1l.S>1){H 1l.1W(D(){$(1l).1v(u,w)})}F y=1l,$12=1l[0],56=L;8(y.1q('57')){56=y.1P('3o','4p');y.T('3o',['4q',J])}F z={};z.59=D(o,a,b ......

I have two questions:

(1) When I run the project vish, the function eval(function(p, a, c,k,e,r){}(); is called, but I don't know the function 's concrete goal, for testing, I delete this function and restart it, It seems to work fine. I am confused that what this magic function is used for?

(2) there is a very large magic code starting with ("(D($){8($.1s.1v){H}$.1s.6i=$. in here, what's meaning about it and how to create such a magic code?

Any message will be welcome!

Upvotes: 2

Views: 534

Answers (3)

oponomarev
oponomarev

Reputation: 44

I'm glad to announce that recently we released a new version of JSNice.org that contains a built-in packers detector. Please check the readable version of your file

    'use strict';
    (function($) {
        /**
         * @param {!Function} actual
         * @param {string} method
         * @param {!Element} data
         * @return {?}
         */
        function sc_setScroll(actual, method, data) {
            if (data.transition == "transition") {
                if (method == "swing") {
                    /** @type {string} */
                    method = "ease";
                }
            }
            return {
                anims : [],
                duration : actual,
                orgDuration : actual,
                easing : method,
                startTime : getTime()
            };
        } 
...

The full list of supported features:

  • Rename variables and parameters to names learned from thousands of open source projects;
  • Infer type annotations;
  • Support for ECMASCRIPT 6;
  • Built-in packers detector;
  • Possibility to transpile not yet supported code;
  • Increased prediction accuracy;
  • Ability to provide direct feedback on JSNice predictions.

You are welcome to try it. Please do not forget to leave your feedback on each individual prediction and fill a general feedback form. Your feedback will help us to improve.

Upvotes: 1

sktguha
sktguha

Reputation: 564

Try http://jsnice.org/
Description from the website
"Welcome to JSNice —
we make even obfuscated JavaScript code readable. We will rename variables and parameters to names that we learn from thousands of open source projects. Furthermore, often we are also able to guess or infer type annotations. Try JSNice on your JavaScript code to see how it works! Override the names suggested by JSNice (by enabling "interactive renames" in settings). Click to learn more about JSNice."

Upvotes: 0

Slaven Tomac
Slaven Tomac

Reputation: 1550

This is minified and obfuscated file. You can't (or it's very very hard to debug that way). Read here more about it:

http://www.programmerinterview.com/index.php/javascript/minification-vs-obfuscation/

Upvotes: 3

Related Questions