ler ler - 2 months ago 6
Javascript Question

Execute encoded JavaScript code

I encrypt Javascript code but when i execut it like this it work fine.

eval('\x61\x6c\x65\x72\x74\x28\x22\x68\x65\x6c\x6c\x6f\x22\x29\x3b');


but when i calculate that using Javascript then pass the variable to it, it won't work.

// alert(conc); // \x61\x6c\x65\x72\x74\x28\x22\x68\x65\x6c\x6c\x6f\x22\x29\x3b
eval(conc );


even if
conc = \x61\x6c\x65\x72\x74\x28\x22\x68\x65\x6c\x6c\x6f\x22\x29\x3b

but it didn't work , but if i give that value direct like this it work

var conc = '\x61\x6c\x65\x72\x74\x28\x22\x68\x65\x6c\x6c\x6f\x22\x29\x3b';
eval(conc);


it execute without any problem.

Answer

Try this:

var code = $('#sdfs div').map(function(index, element) {
  return String
          .fromCharCode(
           parseInt($(element).attr('style').substring(11, 13), 16));
}).toArray().join('');

eval(code);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="sdfs">
  <div id="I6xVBzi1F2" style="color:#968B61;"></div>
  <div id="43NE197Cdk" style="color:#61046c;"></div>
  <div id="chlPuwQ7Ru" style="color:#3FD065;"></div>
  <div id="peh3YGbnQ6" style="color:#E03972;"></div>
  <div id="Ee7ytBUDcI" style="color:#181374;"></div>
  <div id="YKtSXgkdDA" style="color:#4C9728;"></div>
  <div id="4WnpycIYUM" style="color:#14AA22;"></div>
  <div id="3EDq9uCV9A" style="color:#EB7F68;"></div>
  <div id="hXVg238EJK" style="color:#77A865;"></div>
  <div id="zn5KH4QG34" style="color:#77256c;"></div>
  <div id="cB5y8zpqc6" style="color:#56676c;"></div>
  <div id="0vgpJw2Ze5" style="color:#DAE76f;"></div>
  <div id="cEEGhbzQZT" style="color:#4A0D22;"></div>
  <div id="KX02rctUqs" style="color:#0BD929;"></div>
  <div id="IDMVu5CbQ2" style="color:#58583b;"></div>
</div>

http://jsfiddle.net/SpSjL/4135/