jsfuck.js 5.9 KB

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