flutter_js icon indicating copy to clipboard operation
flutter_js copied to clipboard

This JS code returns an error condition in the library but runs fine in a browser & node.js

Open gatecrasher777 opened this issue 3 years ago • 0 comments

The code in question transforms a string in an obfuscated manner. It is designed to be difficult to emulate. It is pure javascript, however, with no external dependencies.

 function transform(nCode) {
  var ala = function (a) {
    var b = a.split(""), c = [function (d, e) { e = (e % d.length + d.length) % d.length; d.splice(-e).reverse().forEach(function (f) { d.unshift(f) }) },
    -1921058111, -550767080, 700635937, -681127572, -2036895570, '"\\[,;{(', 573397093, "case", function (d, e) { e.splice(e.length, 0, d) },
      1531196722, 633332557, 528984348, -1607694989, 1055836676, 1918638563, /\/[[\],],}[);"](\\)/, -961585583, function (d, e, f, h, l) { return e(f, h, l) },
      '"\\]{', -163811383, function (d) { for (var e = d.length; e;)d.push(d.splice(--e, 1)[0]) },
    function (d, e, f, h, l, m) { return e(h, l, m) },
    -412319399, function () { for (var d = 64, e = []; ++d - e.length - 32;)switch (d) { case 58: d = 96; continue; case 91: d = 44; break; case 65: d = 47; continue; case 46: d = 153; case 123: d -= 58; default: e.push(String.fromCharCode(d)) }return e },
    function (d, e) { for (e = (e % d.length + d.length) % d.length; e--;)d.unshift(d.pop()) },
    -32381959, 885725605, function () { for (var d = 64, e = []; ++d - e.length - 32;) { switch (d) { case 91: d = 44; continue; case 123: d = 65; break; case 65: d -= 18; continue; case 58: d = 96; continue; case 46: d = 95 }e.push(String.fromCharCode(d)) } return e },
    -1312226002, 2063686934, 2085930185, 576539933, function (d, e) { d = (d % e.length + e.length) % e.length; e.splice(0, 1, e.splice(d, 1, e[0])[0]) },
    function () { for (var d = 64, e = []; ++d - e.length - 32;) { switch (d) { case 58: d -= 14; case 91: case 92: case 93: continue; case 123: d = 47; case 94: case 95: case 96: continue; case 46: d = 95 }e.push(String.fromCharCode(d)) } return e },
      2056862263, 1375054214, -1350068165, 1766781546, -1543464133, -2047101538, 1096253002, -1609890806, 744789249, -1489867586, 125155855, -887105894, function (d, e) { d = (d % e.length + e.length) % e.length; e.splice(d, 1) },
    -1986842888, function (d, e, f, h, l, m, n, p) { return d(m, n, p) },
      2064682343, -1533195787, 466091162, 810599612, -578194583, null, b, 1277323162, -1815627253, function (d) { d.reverse() },
    -1601555489, function (d, e, f, h, l, m, n, p) { return e(f, h, l, m, n, p) },
    function (d, e, f) { var h = d.length; f.forEach(function (l, m, n) { this.push(n[m] = d[(d.indexOf(l) - d.indexOf(this[m]) + m + h--) % d.length]) }, e.split("")) },
    function (d, e) { e.push(d) },
      504398874, 281244892, -1992584841, -1832354004, b, function (d, e) { e = (e % d.length + d.length) % d.length; var f = d[0]; d[0] = d[e]; d[e] = f },
      null, 1654194707, 60495725, 1987139773, -1553802360, -104589219, 1838355129, function () { for (var d = 64, e = []; ++d - e.length - 32;)switch (d) { case 46: d = 95; default: e.push(String.fromCharCode(d)); case 94: case 95: case 96: break; case 123: d -= 76; case 92: case 93: continue; case 58: d = 44; case 91: }return e },
      1592131649, -71282267, -704854045, 566447420, b, 1507988747, null, -2040686642, -460220910, 633332557, 682194956]; c[55] = c; c[70] = c; c[84] = c; try {
        try {
          -6 !== c[54] && (0 > c[88] && ((0, c[33])(c[27], c[84]), 1) || (0, c[69])(c[56], c[38])), 9 > c[3] && ((((0, c[33])(c[65], c[82]), c[62])((0, c[77])(), c[8], c[82]), c[18])((0, c[18])((0, c[62])((0, c[new Date("December 31 1969 17:15:34 -0645") / 1E3])(), c[8], c[68]) * (0, c[69])(c[68], c[new Date("December 31 1969 17:01:26 PDT") / 1E3]) === (0, c[62])((0, c[77])(), c[8], c[82]), c[69], c[56], c[37]), c[21], c[70]),
            (0, c[0])(c[56], c[76]), 1) || (0, c[22])((0, c[21])(c[Math.pow(6, 3) - 53 + -107]), c[25], (0, c[61])((0, c[62])((0, c[77])(), c[8], c[56]), c[22], (0, c[18])((0, c[21])(c[56]), c[21], c[56]), c[0], ((0, c[25])(c[82], c[20]), c[69])(c[82], c[71]), c[55], c[15]), c[40], c[2])
        } catch (d) { (0, c[403 % Math.pow(7, 1) - -53])((0, c[86])(c[62], c[20]), c[64], c[20], c[75]) } try {
          -10 !== c[21] && (c[53] === new Date("Wednesday 31 December 1969 18:00:08 MDT") / 1E3 ? (0, c[12])((0, c[67])(), c[47], c[6]) : (0, c[72])(c[25], c[34])), 10 <= c[36] && ((((0, c[12])((0, c[63])(), c[47],
            c[18]), c[new Date("Wednesday December 31 1969 16:00:12 PST") / 1E3])((0, c[67])(), c[47], c[32]), c[12])((0, c[73])(), c[47], c[18]), 1) || (0, c[57])((0, c[57])((0, c[39])(c[5], c[3]), c[22], c[77], c[20]), c[15], c[16], c[29])
        } catch (d) { (0, c[60])(c[14], c[77]), (0, c[8])((0, c[63])(), c[43], c[14]) } try {
          8 != c[31] ? (0, c[53])((0, c[53])((0, c[68])(c[61], c[30]), c[new Date("1970-01-01T09:45:15.000+09:45") / 1E3], c[2], c[66]), c[5], c[30]) : (0, c[35])(((0, c[6])(c[61], c[58]), c[6])(c[78], c[60]), c[88], c[39], c[74]), (-1 != c[8] || ((0, c[new Date("December 31 1969 15:15:28 -0845") /
            1E3])(c[58], c[new Date("Wednesday 31 December 1969 19:00:36 EST") / 1E3]), 0)) && (0, c[6])(c[82], c[74]), -3 <= c[3] && ((0, c[88])(c[41], c[86]), c[35])((0, c[88])(c[Math.pow(8, 3) % 261 - 203], c[Math.pow(1, 1) % 414 - -57]), c[28], c[87], c[76]), -5 !== c[74] && (((0, c[29])(c[78], (0, c[24])(c[26], c[58 - Math.pow(4, 5) % 247]), (0, c[9])(c[22], c[45]), (0, c[new Date("12/31/1969 17:00:53 MST") / 1E3])(c[22], c[6]), ((0, c[69])(c[82], c[23]), c[53])(c[83], c[77]), c[89], c[68]), c[49])((0, c[42])(c[89], c[28]), c[13], c[27], c[89]) <= ((0, c[4])(c[37], c[72]),
              c[new Date("1969-12-31T17:00:20.000-07:00") / 1E3])(c[86], c[74]) <= (0, c[49])((((0, c[13])(c[26], c[12]), c[88])(c[72], c[10]), (0, c[88])(c[72], c[90]), c[8])(c[87]), c[77], c[6], c[18]), ",") || ((((0, c[41])((0, c[41])((0, c[85])((0, c[57])(), c[-78 * Math.pow(1, 4) - -109], c[1]), c[70], c[36], c[79]), c[77], c[54], c[1]), c[41])((0, c[41])((0, c[76 - Math.pow(8, 5) + 32762])(c[7], c[79]), c[44], c[1]), c[85], (0, c[47])(), c[31], c[79]) > (0, c[41])((0, c[41])((0, c[48])(c[16], c[74]), c[70], c[52], c[1]), c[70], c[81], c[16]), (0, c[85])((0, c[10])(), c[31],
                c[16]), c[48])(c[16], c[69]), c[new Date("January 01 1970 00:00:41 GMT") / 1E3])((0, c[70])(c[25], c[-5586 + Math.pow(3, 1) - -5661]), c[77], c[27], c[18]) <= (0, c[70])(c[68], c[16]) < (0, c[82])(c[3])
        } catch (d) { ((0, c[48])(c[16], c[14]), c[2])(c[1653 + Math.pow(2, 3) - 1658], c[67]), (0, c[85])((0, c[57])(), c[31], c[1]), (0, c[70])(c[71], c[79]) } try {
          9 < c[30] && (((0, c[70])(c[26], c[1]), c[23])(c[79], c[30]), /({)/) || ((0, c[70])(c[19], c[79]), c[70])(c[64], c[18]), -1 == c[83] ? (0, c[41])((0, c[82])(c[1]), c[82], c[79]) : (0, c[41])((0, c[48])(c[3], c[58]),
            c[36], c[21], c[47])
        } catch (d) { (0, c[36])(c[37], c[45]), (0, c[82])(c[21], c[67]) }
      } catch (d) { return "enhanced_except_hZcB-uj-_w8_" + a } return b.join("")
  }; return ala(nCode);
}
transform('jM4AdVF7yBo4huh5I');

In my browser this code produces the result '1Zx9iSk1emsfzQ'. I get the same result from nodejs when changing the last line to console.log( transform('jM4AdVF7yBo4huh5I') ); I also get the same result in jsfiddle.

But in flutter_js with the above code in a String variable transformFn and running as follows

   JsEvalResult jsEvalResult = runtime.evaluate( transformFn );
   return jsEvalResult.stringResult;

I get the result: enhanced_except_hZcB-uj-_w8_zCNZQZpiBU8WZ-xlR

which is you can see is returned from an error catch block.

If I replace "enhanced_except_hZcB-uj-_w8_"+a with d.message the code via the library returns not a function.

Hopefully this a clue as to what is breaking the JS emulation.

Run with flutter_js 0.6.0 on Windows 10.

gatecrasher777 avatar Dec 09 '22 17:12 gatecrasher777