jsfuck.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*! JSFuck 1.0 - http://jsfuck.com */
  2. (function(self){
  3. var USE_CHAR_CODE = "USE_CHAR_CODE";
  4. var MIN = 32, MAX = 126;
  5. var SIMPLE = {
  6. 'false': '![]',
  7. 'true': '!![]',
  8. 'undefined': '[][[]]',
  9. 'NaN': '+[![]]',
  10. 'Infinity': '+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]]+[+[]])' // +"1e1000"
  11. };
  12. var CONSTRUCTORS = {
  13. 'Array': '[]',
  14. 'Number': '+[]',
  15. 'String': '[]+[]',
  16. 'Boolean': '![]',
  17. 'Function': '[]["filter"]'
  18. };
  19. var MAPPING = {
  20. 'a': '("false")[1]',
  21. 'b': '(+(11))["toString"](20)',
  22. 'c': '([]["filter"]+"")[3]',
  23. 'd': '("undefined")[2]',
  24. 'e': '("true")[3]',
  25. 'f': '("false")[0]',
  26. 'g': '(String+"")[14]',
  27. 'h': '(+(17))["toString"](20)',
  28. 'i': '("undefined")[5]',
  29. 'j': '(+(19))["toString"](20)',
  30. 'k': '(+(20))["toString"](21)',
  31. 'l': '("false")[2]',
  32. 'm': '(Number+"")[11]',
  33. 'n': '("undefined")[1]',
  34. 'o': '([]["filter"]+"")[6]',
  35. 'p': '(+(25))["toString"](30)',
  36. 'q': '(+(26))["toString"](30)',
  37. 'r': '("true")[1]',
  38. 's': '("false")[3]',
  39. 't': '("true")[0]',
  40. 'u': '("undefined")[0]',
  41. 'v': '(+(31))["toString"](32)',
  42. 'w': '(+(32))["toString"](33)',
  43. 'x': '(+(33))["toString"](34)',
  44. 'y': '("Infinity")[7]',
  45. 'z': '(+(35))["toString"](36)',
  46. 'A': '(Array+"")[9]',
  47. 'B': '(Boolean+"")[9]',
  48. 'C': USE_CHAR_CODE,
  49. 'D': USE_CHAR_CODE,
  50. 'E': USE_CHAR_CODE,
  51. 'F': '(Function+"")[9]',
  52. 'G': USE_CHAR_CODE,
  53. 'H': USE_CHAR_CODE,
  54. 'I': '("Infinity")[0]',
  55. 'J': USE_CHAR_CODE,
  56. 'K': USE_CHAR_CODE,
  57. 'L': USE_CHAR_CODE,
  58. 'M': USE_CHAR_CODE,
  59. 'N': '("NaN")[0]',
  60. 'O': USE_CHAR_CODE,
  61. 'P': USE_CHAR_CODE,
  62. 'Q': USE_CHAR_CODE,
  63. 'R': USE_CHAR_CODE,
  64. 'S': '(String+"")[9]',
  65. 'T': USE_CHAR_CODE,
  66. 'U': USE_CHAR_CODE,
  67. 'V': USE_CHAR_CODE,
  68. 'W': USE_CHAR_CODE,
  69. 'X': USE_CHAR_CODE,
  70. 'Y': USE_CHAR_CODE,
  71. 'Z': USE_CHAR_CODE,
  72. ' ': '([]["filter"]+"")[8]',
  73. '!': USE_CHAR_CODE,
  74. '"': '("")["fontcolor"]()[12]',
  75. '#': USE_CHAR_CODE,
  76. '$': USE_CHAR_CODE,
  77. '%': 'GLOBAL["escape"]("<")[0]',
  78. '&': USE_CHAR_CODE,
  79. '\'': USE_CHAR_CODE,
  80. '(': '([]["filter"]+"")[15]',
  81. ')': '([]["filter"]+"")[16]',
  82. '*': USE_CHAR_CODE,
  83. '+': '(+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]])+[])[2]',
  84. ',': '[[]]["concat"]([][[]])+""',
  85. '-': '(+(.0000000001)+"")[2]',
  86. '.': '(0)["toFixed"](1)[1]',
  87. '/': '("")["italics"]()[4]',
  88. ':': 'GLOBAL["Date"]()[21]',
  89. ';': USE_CHAR_CODE,
  90. '<': '("")["italics"]()[0]',
  91. '=': '("")["fontcolor"]()[11]',
  92. '>': '("")["italics"]()[2]',
  93. '?': USE_CHAR_CODE,
  94. '@': USE_CHAR_CODE,
  95. '[': '(GLOBAL+"")[0]',
  96. '\\': USE_CHAR_CODE,
  97. ']': USE_CHAR_CODE,
  98. '^': USE_CHAR_CODE,
  99. '_': USE_CHAR_CODE,
  100. '`': USE_CHAR_CODE,
  101. '{': '([]["filter"]+"")[18]',
  102. '|': USE_CHAR_CODE,
  103. '}': USE_CHAR_CODE,
  104. '~': USE_CHAR_CODE
  105. };
  106. var GLOBAL = '[]["filter"]["constructor"]("return this")()';
  107. function fillMissingChars(){
  108. for (var key in MAPPING){
  109. if (MAPPING[key] === USE_CHAR_CODE){
  110. MAPPING[key] = 'GLOBAL["unescape"]("%"'+ key.charCodeAt(0).toString(16).replace(/(\d+)/g, "+($1)+\"") + '")';
  111. }
  112. }
  113. }
  114. function fillMissingDigits(){
  115. var output, number, i;
  116. for (number = 0; number < 10; number++){
  117. output = "+[]";
  118. if (number > 0){ output = "+!" + output; }
  119. for (i = 1; i < number; i++){ output = "+!+[]" + output; }
  120. if (number > 1){ output = output.substr(1); }
  121. MAPPING[number] = "[" + output + "]";
  122. }
  123. }
  124. function replaceMap(){
  125. var character = "", value, original;
  126. function replace(pattern, replacement){
  127. value = value.replace(
  128. new RegExp(pattern, "gi"),
  129. replacement
  130. );
  131. }
  132. for (var i = MIN; i <= MAX; i++){
  133. character = String.fromCharCode(i);
  134. value = MAPPING[character];
  135. original = value;
  136. for (key in CONSTRUCTORS){
  137. replace("\\b" + key, '(' + CONSTRUCTORS[key] + ')["constructor"]');
  138. }
  139. for (key in SIMPLE){
  140. replace('"' + key + '"', SIMPLE[key] + "+[]");
  141. replace(key, SIMPLE[key]);
  142. }
  143. for (key = 0; key < 10; key++){
  144. replace(key, "+[" + MAPPING[key] + "]");
  145. }
  146. replace("GLOBAL", GLOBAL);
  147. replace('\\+""', "+[]");
  148. replace('""', "[]+[]");
  149. MAPPING[character] = value;
  150. }
  151. }
  152. function replaceStrings(){
  153. var regEx = /[^\[\]\(\)\!\+]{1}/g,
  154. all, value, missing;
  155. count = MAX - MIN;
  156. function findMissing(){
  157. var all, value, done = false;
  158. missing = {};
  159. for (all in MAPPING){
  160. value = MAPPING[all];
  161. if (value.match(regEx)){
  162. missing[all] = value;
  163. done = true;
  164. }
  165. }
  166. return done;
  167. }
  168. for (all in MAPPING){
  169. MAPPING[all] = MAPPING[all].replace(/\"([^\"]+)\"/gi, function(a, b){
  170. return b.split("").join("+");
  171. });
  172. }
  173. while (findMissing()){
  174. for (all in missing){
  175. value = MAPPING[all];
  176. value = value.replace(regEx, function(c){
  177. return missing[c] ? c : MAPPING[c];
  178. });
  179. MAPPING[all] = value;
  180. missing[all] = value;
  181. }
  182. if (count-- == 0){
  183. console.error("Could not compile the following chars:", missing);
  184. }
  185. }
  186. }
  187. function encode(input, wrapWithEval){
  188. var output = [];
  189. if (!input){
  190. return "";
  191. }
  192. input.replace(/./g, function(c){
  193. var replacement = MAPPING[c];
  194. if (replacement){
  195. output.push(MAPPING[c]);
  196. } else {
  197. replacement =
  198. "([]+[])[" + encode("constructor") + "]" +
  199. "[" + encode("fromCharCode") + "]" +
  200. "(" + encode(c.charCodeAt(0) + "") + ")";
  201. output.push(replacement);
  202. MAPPING[c] = replacement;
  203. }
  204. });
  205. output = output.join("+");
  206. if (/^\d$/.test(input)){
  207. output += "+[]";
  208. }
  209. if (wrapWithEval){
  210. output = "[][" + encode("filter") + "]" +
  211. "[" + encode("constructor") + "]" +
  212. "(" + output + ")()"
  213. }
  214. return output;
  215. }
  216. fillMissingDigits();
  217. fillMissingChars();
  218. replaceMap();
  219. replaceStrings();
  220. self.JSFuck = {
  221. encode: encode
  222. };
  223. })(typeof(exports) == "undefined" ? window : exports);