ソースを参照

Allow running generated code in parent scope

Andrew Taylor 10 年 前
コミット
b2dae714ba
2 ファイル変更18 行追加5 行削除
  1. 6 1
      index.html
  2. 12 4
      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();
     

+ 12 - 4
jsfuck.js

@@ -238,7 +238,7 @@
     }
   }
 
-  function encode(input, wrapWithEval){
+  function encode(input, wrapWithEval, runInParentScope){
     var output = [];
 
     if (!input){
@@ -288,9 +288,17 @@
     }
 
     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;