2013-09-08 3 views
0

나는 javascript에 대한 단서가없고 나는 C#으로 자바 스크립트로 압축 된 소스 코드를 풀려고하고있다. 압축 된 코드는 정규식을 사용하여 걸러 낸 다음 압축을 풀어야합니다. 포장업자는 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, {})) 

그래서 난 당신이 온라인 http://packet.dn.ua/을 포장 코드를 압축 해제 할 수 있습니다이 사이트를 발견했습니다

(jsfiddle 링크 here입니다) 나 '이 페이지에 내가 unpacker의 주요 기능을 찾았습니다. (적어도 그것이 내가 생각하는 것입니다.) 볼 수 있습니다. 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); 
} 

답변

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); 
} 
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); 
}