Browse Source

Merge pull request #34 from andrew-t/master

Added an alternate 'eval' implementation that runs on the parent scope.
Martin Kleppe 10 years ago
parent
commit
0431f7bed3
3 changed files with 19 additions and 6 deletions
  1. 2 1
      README.md
  2. 6 1
      index.html
  3. 11 4
      jsfuck.js

+ 2 - 1
README.md

@@ -50,7 +50,8 @@ The following source will do an `alert(1)`:
     String      =>  []+[]
     Boolean     =>  ![]
     Function    =>  []["filter"]
-    eval        =>  []["filter"]["constructor"]( CODE )()
+    run         =>  []["filter"]["constructor"]( CODE )()
+    eval        =>  []["filter"]["constructor"]("return eval")()( CODE )
     window      =>  []["filter"]["constructor"]("return this")()
     
 See the full list [here](https://github.com/aemkei/jsfuck/blob/master/jsfuck.js).

+ 6 - 1
index.html

@@ -90,6 +90,10 @@
     <input id="eval" type="checkbox" checked />
     <label for="eval">Eval Source</label>
   </div>
+    <div class="checkbox">
+    <input id="scope" type="checkbox" checked />
+    <label for="scope">Run In Parent Scope</label>
+  </div>
   
   <textarea id="output"></textarea>
   <div class="actions">
@@ -148,13 +152,14 @@
     }
     
     function encode(){
-      var output = JSFuck.encode($("input").value, $("eval").checked);
+      var output = JSFuck.encode($("input").value, $("eval").checked, $("scope").checked);
       $("output").value = output;
       $("stats").innerHTML = output.length + " chars";
     }
   
     $("encode").onclick = encode;
     $("eval").onchange = encode;
+    $("scope").onchange = encode;
     
     encode();
     

+ 11 - 4
jsfuck.js

@@ -238,7 +238,7 @@
     }
   }
 
-  function encode(input, wrapWithEval){
+  function encode(input, wrapWithEval, runInParentScope){
     var output = [];
 
     if (!input){
@@ -288,9 +288,16 @@
     }
 
     if (wrapWithEval){
-      output = "[][" + encode("filter") + "]" +
-        "[" + encode("constructor") + "]" +
-        "(" + output + ")()";
+      if (runInParentScope){
+        output = "[][" + encode("filter") + "]" +
+          "[" + encode("constructor") + "]" +
+          "(" + encode("return eval") +  ")()" +
+          "(" + output + ")";
+      } else {
+        output = "[][" + encode("filter") + "]" +
+          "[" + encode("constructor") + "]" +
+          "(" + output + ")()";
+      }
     }
 
     return output;