ソースを参照

Merge pull request #84 from hazzik/unicode-escape

Use unicode escape sequence instead of unescape
Martin Kleppe 5 年 前
コミット
d5aa8d3d84
2 ファイル変更31 行追加26 行削除
  1. 9 4
      jsfuck.js
  2. 22 22
      output.txt

+ 9 - 4
jsfuck.js

@@ -117,9 +117,13 @@
   const GLOBAL = 'Function("return this")()';
 
   function fillMissingChars(){
+    var base16code, escape;
     for (var key in MAPPING){
       if (MAPPING[key] === USE_CHAR_CODE){
-        MAPPING[key] = 'Function("return unescape")()("%"'+ key.charCodeAt(0).toString(16).replace(/(\d+)/g, "+($1)+\"") + '")';
+        //Function('return"\\uXXXX"')()
+        base16code = key.charCodeAt(0).toString(16);
+        escape = ('0000'+base16code).substring(base16code.length).split('').join('+');
+        MAPPING[key] = 'Function("return"+' + MAPPING['"'] + '+"\\u"+' + escape + '+' + MAPPING['"'] + ')()';
       }
     }
   }
@@ -261,10 +265,11 @@
         if (replacement){
           output.push(replacement);
         } else {
+          var cc16 = c.charCodeAt(0).toString(16);
           replacement =
-            "([]+[])[" + encode("constructor") + "]" +
-            "[" + encode("fromCharCode") + "]" +
-            "(" + encode(c.charCodeAt(0) + "") + ")";
+            "[][" + encode("fill") + "]"+
+            "[" + encode("constructor") + "]" +
+            "(" + encode("return\"\\u"+("0000"+cc16).substring(cc16.length)+"\"") + ")()";
 
           output.push(replacement);
           MAPPING[c] = replacement;

+ 22 - 22
output.txt

@@ -1,14 +1,14 @@
 ` ` 109
-`!` 5057
+`!` 4002
 `"` 539
-`#` 5066
-`$` 5071
+`#` 4011
+`$` 4016
 `%` 2551
 `&` 1083
-`'` 5086
+`'` 4031
 `(` 114
 `)` 114
-`*` 5062
+`*` 4010
 `+` 70
 `,` 393
 `-` 153
@@ -30,7 +30,7 @@
 `=` 535
 `>` 260
 `?` 1859
-`@` 5065
+`@` 4010
 `A` 573
 `B` 576
 `C` 2707
@@ -38,31 +38,31 @@
 `E` 1865
 `F` 656
 `G` 3851
-`H` 5101
+`H` 4046
 `I` 70
-`J` 5072
-`K` 5234
-`L` 5163
+`J` 4020
+`K` 4182
+`L` 4111
 `M` 3852
 `N` 16
 `O` 732
-`P` 5070
-`Q` 5072
+`P` 4015
+`Q` 4017
 `R` 1860
 `S` 578
 `T` 3854
 `U` 2227
-`V` 5096
-`W` 5101
-`X` 5106
-`Y` 5111
-`Z` 5077
+`V` 4041
+`W` 4046
+`X` 4051
+`Y` 4056
+`Z` 4025
 `[` 171
 `\` 2121
 `]` 189
-`^` 5087
-`_` 5075
-``` 5075
+`^` 4035
+`_` 4023
+``` 4020
 `a` 15
 `b` 177
 `c` 106
@@ -90,6 +90,6 @@
 `y` 84
 `z` 1416
 `{` 109
-`|` 5178
+`|` 4126
 `}` 460
-`~` 5097
+`~` 4045