jsfuck.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*! JSFuck 0.3.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': '(+false+[false]+String)[20]',
  27. 'h': '(+(101))["toString"](21)[1]',
  28. 'i': '([false]+undefined)[10]',
  29. 'j': '(+(40))["toString"](21)[1]',
  30. 'k': '(+(20))["toString"](21)',
  31. 'l': '("false")[2]',
  32. 'm': '(Number+"")[11]',
  33. 'n': '("undefined")[1]',
  34. 'o': '(true+[]["filter"])[10]',
  35. 'p': '(+(211))["toString"](31)[1]',
  36. 'q': '(+(212))["toString"](31)[1]',
  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': '(+(101))["toString"](34)[1]',
  44. 'y': '(NaN+[Infinity])[10]',
  45. 'z': '(+(35))["toString"](36)',
  46. 'A': '(+false+Array)[10]',
  47. 'B': '(+false+Boolean)[10]',
  48. 'C': 'GLOBAL["escape"]("<")[2]',
  49. 'D': 'GLOBAL["escape"]("=")[2]',
  50. 'E': 'GLOBAL["escape"](">")[2]',
  51. 'F': '(+false+Function)[10]',
  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': '(+false+String)[10]',
  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. ' ': '(NaN+[]["filter"])[11]',
  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. '(': '(false+[]["filter"])[20]',
  81. ')': '(true+[]["filter"])[20]',
  82. '*': USE_CHAR_CODE,
  83. '+': '(+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]])+[])[2]',
  84. ',': '[[]]["concat"]([][[]])+""',
  85. '-': '(+(.0000000001)+"")[2]',
  86. '.': '(+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]',
  87. '/': '(false+[+false])["italics"]()[10]',
  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. '{': '(NaN+[]["filter"])[21]',
  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, i, key;
  126. function replace(pattern, replacement){
  127. value = value.replace(
  128. new RegExp(pattern, "gi"),
  129. replacement
  130. );
  131. }
  132. for (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. function mappingReplacer(a, b) {
  169. return b.split("").join("+");
  170. }
  171. function valueReplacer(c) {
  172. return missing[c] ? c : MAPPING[c];
  173. }
  174. for (all in MAPPING){
  175. MAPPING[all] = MAPPING[all].replace(/\"([^\"]+)\"/gi, mappingReplacer);
  176. }
  177. while (findMissing()){
  178. for (all in missing){
  179. value = MAPPING[all];
  180. value = value.replace(regEx, valueReplacer);
  181. MAPPING[all] = value;
  182. missing[all] = value;
  183. }
  184. if (count-- === 0){
  185. console.error("Could not compile the following chars:", missing);
  186. }
  187. }
  188. }
  189. function encode(input, wrapWithEval){
  190. var output = [];
  191. if (!input){
  192. return "";
  193. }
  194. input.replace(/./g, function(c){
  195. var replacement = MAPPING[c];
  196. if (replacement) {
  197. output.push(MAPPING[c]);
  198. } else {
  199. replacement =
  200. "([]+[])[" + encode("constructor") + "]" +
  201. "[" + encode("fromCharCode") + "]" +
  202. "(" + encode(c.charCodeAt(0) + "") + ")";
  203. output.push(replacement);
  204. MAPPING[c] = replacement;
  205. }
  206. });
  207. output = output.join("+");
  208. if (/^\d$/.test(input)){
  209. output += "+[]";
  210. }
  211. if (wrapWithEval){
  212. output = "[][" + encode("filter") + "]" +
  213. "[" + encode("constructor") + "]" +
  214. "(" + output + ")()";
  215. }
  216. return output;
  217. }
  218. fillMissingDigits();
  219. fillMissingChars();
  220. replaceMap();
  221. replaceStrings();
  222. self.JSFuck = {
  223. encode: encode
  224. };
  225. })(typeof(exports) === "undefined" ? window : exports);