3

I'm on a website that references a javascript file that looks like this:

eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--){d[e(c)]=k[c]||e(c)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('h=[\'.I-l\',\'#f-m\',\'.e-d-f\',\'.e-d-q\',\'.r-1-s\',c.t,c.k];5 g(0){8(0 6 w||0 6 v){y(b a z 0){b 9=0[a];$(9).7()}}8(0 6 E){$(0).7()}}$.G.7=5(){x j.H(\'F\',\'i\').2(\'3-1\',\'4\').2(\'-D-3-1\',\'4\').2(\'-C-3-1\',\'4\').2(\'-B-3-1\',\'4\').i(\'A\',u)};p(o).n(5($){g(h)});',45,45,'elements|select|css|user|none|function|instanceof|tknDisableSelection|if|current|key|var|tknSelectors|videos|recommended|next|tknSetUnselectable|tknUnselectable|on|this|vocabContent|listings|video|ready|document|jQuery|previous|expanded|wrapper|vocabTabList|false|Object|Array|return|for|in|selectstart|ms|moz|webkit|String|unselectable|fn|attr|dialogue'.split('|'),0,{}))

This is probably a recognizable obfuscation pattern, but I don't know which one.

How can I reverse this and turn it into javascript I can read?

4
  • What is expected result of javascript at Question? Adding a method to jQuery? Commented Jul 29, 2016 at 5:24
  • T'he only way to unobscure these things is to find a safe Javascript environment and actually execute them to see what code they generate. Commented Jul 29, 2016 at 5:25
  • 1
    You see that part where it says eval? Replace it with console.log. Then you will see the lame jQuery plugin. Commented Jul 29, 2016 at 5:25
  • 1
    This isn't obfuscation, it's minification, which is a standard way of reducing network load. Basically, the script has been reduced to the minimal size where it still does what the original does. It can be read like any other JS, you just need to add in the indentation yourself. Also, am I the only one who is amused by the fact that the function args spell "packed"? Commented Jul 29, 2016 at 5:28

1 Answer 1

5

This is pretty easy. It seems it's been packed with a tool similar to "packer". jsbeautifier handles it nicely (notice the option called "detect packers and obfuscators?"):

tknUnselectable = ['.dialogue-listings', 
                  '#next-video', 
                  '.recommended-videos-next', 
                  '.recommended-videos-previous', 
                  '.expanded-select-wrapper',        
                  tknSelectors.vocabTabList,       
                  tknSelectors.vocabContent];

function tknSetUnselectable(elements) {
    if (elements instanceof Array || elements instanceof Object) {
        for (var key in elements) {
            var current = elements[key];
            $(current).tknDisableSelection()
        }
    }
    if (elements instanceof String) {
        $(elements).tknDisableSelection()
    }
}
$.fn.tknDisableSelection = function() {
    return this.attr('unselectable', 'on')
           .css('user-select', 'none')
           .css('-webkit-user-select', 'none')
           .css('-moz-user-select', 'none')
           .css('-ms-user-select', 'none')
           .on('selectstart', false)
};
jQuery(document).ready(function($) {
    tknSetUnselectable(tknUnselectable)
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.