Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

p.acker: support multiple chunks of packed data

  • Loading branch information...
commit 74b47a70338bac1955dbbc91d0255de1a6bb33ab 1 parent 8dafd97
@einars einars authored
Showing with 28 additions and 19 deletions.
  1. +28 −19 unpackers/p_a_c_k_e_r_unpacker.js
View
47 unpackers/p_a_c_k_e_r_unpacker.js
@@ -14,11 +14,23 @@
var P_A_C_K_E_R = {
detect: function (str) {
- return P_A_C_K_E_R._starts_with(str.toLowerCase().replace(/ +/g, ''), 'eval(function(') ||
- P_A_C_K_E_R._starts_with(str.toLowerCase().replace(/ +/g, ''), 'eval((function(') ;
+ return (P_A_C_K_E_R.get_chunks(str).length > 0);
+ },
+
+ get_chunks: function(str) {
+ var chunks = str.match(/eval\(\(?function\(.*?,0,\{\}\)\)/g);
+ return chunks ? chunks : [];
},
unpack: function (str) {
+ var chunks = P_A_C_K_E_R.get_chunks(str);
+ for(var i = 0; i < chunks.length; i++) {
+ str = str.replace(chunks[i], P_A_C_K_E_R.unpack_chunk(chunks[i]))
+ }
+ return str;
+ },
+
+ unpack_chunk: function (str) {
var unpacked_source = '';
if (P_A_C_K_E_R.detect(str)) {
try {
@@ -33,27 +45,24 @@ var P_A_C_K_E_R = {
return str;
},
- _starts_with: function (str, what) {
- return str.substr(0, what.length) === what;
- },
-
run_tests: function (sanity_test) {
- var t = sanity_test || new SanityTest();
+ var t = sanity_test || new SanityTest(),
+ pk1 = "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[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}('0 2=1',3,3,'var||a'.split('|'),0,{}))",
+ unpk1 = 'var a=1',
+ pk2 = "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[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}('0 2=1',3,3,'foo||b'.split('|'),0,{}))",
+ unpk2 = 'foo b=1',
+ pk_broken = "eval(function(p,a,c,k,e,r){BORKBORK;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[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}('0 2=1',3,3,'var||a'.split('|'),0,{}))";
t.test_function(P_A_C_K_E_R.detect, "P_A_C_K_E_R.detect");
t.expect('', false);
t.expect('var a = b', false);
- t.expect('eval(function(p,a,c,k,e,r', true);
- t.expect('eval ( function(p, a, c, k, e, r', true);
- t.test_function(P_A_C_K_E_R.unpack, 'P_A_C_K_E_R.unpack');
- t.expect("eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[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}('0 2=1',3,3,'var||a'.split('|'),0,{}))",
- 'var a=1');
-
- var starts_with_a = function(what) { return P_A_C_K_E_R._starts_with(what, 'a'); }
- t.test_function(starts_with_a, "P_A_C_K_E_R._starts_with(?, a)");
- t.expect('abc', true);
- t.expect('bcd', false);
- t.expect('a', true);
- t.expect('', false);
+ t.test_function(P_A_C_K_E_R.unpack, "P_A_C_K_E_R.unpack");
+ t.expect(pk_broken, pk_broken);
+ t.expect(pk1, unpk1);
+ t.expect(pk2, unpk2);
+
+ var filler = '\nfiller\n';
+ t.expect(filler + pk1 + pk_broken + filler + pk2 + filler, filler + unpk1 + pk_broken + filler + unpk2 + filler);
+
return t;
}
Please sign in to comment.
Something went wrong with that request. Please try again.