打包javascript代码,如何解压缩?

时间:2013-09-08 13:01:03

标签: c# javascript regex packer

我绝对没有关于javascript的线索,我正在尝试使用C#解压缩javascript打包的源代码。打包的代码会被正则表达式过滤掉,然后应该解压缩。包装工来自Dean Edwards - http://dean.edwards.name/packer/

包裹代码是:

eval(function (p, r, o, x, y, s) {
y = function (c) {
    return (c < r ? '' : y(parseInt(c / r))) + ((c = c % r) > 35 ? String.fromCharCode(c + 29) : c.toString(36))
};
if (!''.replace(/^/, String)) {
    while (o--) {
        s[y(o)] = x[o] || y(o)
    }
    x = [function (y) {
        return s[y]
    }];
    y = function () {
        return '\\w+'
    };
    o = 1
};
while (o--) {
    if (x[o]) {
        p = p.replace(new RegExp('\\b' + y(o) + '\\b', 'g'), x[o])
    }
}
return p
}('g=D^C;f=B^E;h=1;n=8;l=F^A;e=5;o=H^G;t=6;s=J^y;c=4;k=2;d=u^x;i=z^w;j=0;m=v^I;r=7;b=3;q=U^V;a=W^X;p=9;K=j^l;L=h^i;N=k^g;O=b^a;Q=c^d;P=e^m;M=t^s;R=r^q;S=n^o;T=p^f;', 60, 60, '^^^^^^^^^^ZeroSixThree^Two^Six^ZeroOneFive^Zero^EightEightEight^Five5Seven^One^ZeroFiveNine^Five^Eight^OneZeroZero^Eight8Six^Three^Five2One^Seven^OneThreeTwo^Nine^Six2Four^Four^1425^9684^8909^6588^8888^7667^3129^3117^80^4977^1337^9868^8085^11077^81^5847^Eight8ZeroTwo^ThreeZeroSevenThree^SixEightTwoFive^EightNineSixSeven^Four6FourNine^Three1OneFour^NineFourThreeOne^Four7NineZero^NineEightFiveEight^FourThreeEightSix^11146^1080^4347^88'.split('\u005e'), 0, {}))  

(jsfiddle链接为here

所以我发现这个网站允许你在线解压缩打包的代码http://packet.dn.ua/,在这个页面上我找到了解包器的主要功能(至少我认为是这样),它可以查看here

现在我对javascript代码有一些疑问,想知道我是否对这个函数是正确的,以及在if语句中究竟发生了什么。

function _unpack(a) {   // takes an array as parameter?
    var x, p = '';      // defines two empty arrays?
    p = a.match(/%2/);  // Make a regex match of the value '/%2/' ?
    if (p) {            // no clue
        x = _uncase(a);
        return _uncase(x);
    }
    return _uncase(a);
}

2 个答案:

答案 0 :(得分:0)

function _unpack(a) {   // this is a string because down below two line, you are calling a.match() where the method match is defined on the string object
    var x, p = '';      // Defines two empty strings, notice the ''
    p = a.match(/%2/);  // Make a regex match of the value %2 inside a, notice p is now an array, in javascript variables are dynamic and can change their type at runtime
    if (p) {            // if p is not empty or in other words, if there are some matches then
        x = _uncase(a);
        return _uncase(x);
    }
    return _uncase(a);
}

答案 1 :(得分:0)

function _unpack(a) {   // takes a string as argument, we can see that it's a string because strings have the match method, which is used below a.match(...)
    var x, p = '';      // declare x, declare p and initialize it with the empty string value
    p = a.match(/%2/);  // match will return ['%2'] (which is an array that contains the string '%2' at index 0) only if %2 is found in the string 'a', else it returns null
    if (p) {            // if p is thruthy (objects are), but null is falsey. It's like saying, if there was a match
        x = _uncase(a);
        return _uncase(x);
    }
    return _uncase(a);
}