jsfuck.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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': 'Function("return escape")()("<")[2]',
  49. 'D': 'Function("return escape")()("=")[2]',
  50. 'E': 'Function("return escape")()(">")[2]',
  51. 'F': '(+false+Function)[10]',
  52. 'G': '(false+Function("return Date")()())[30]',
  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': '(true+Function("return Date")()())[30]',
  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': '(NaN+Function("return Date")()())[30]',
  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. '%': 'Function("return 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. ':': 'Function("return 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 = 'Function("return this")()';
  107. function fillMissingChars(){
  108. for (var key in MAPPING){
  109. if (MAPPING[key] === USE_CHAR_CODE){
  110. MAPPING[key] = 'Function("return 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. function digitReplacer(_,x) { return MAPPING[x]; }
  133. function numberReplacer(_,y) {
  134. var values = y.split("");
  135. var head = +(values.shift());
  136. var output = "+[]";
  137. if (head > 0){ output = "+!" + output; }
  138. for (i = 1; i < head; i++){ output = "+!+[]" + output; }
  139. if (head > 1){ output = output.substr(1); }
  140. return [output].concat(values).join("+").replace(/(\d)/g, digitReplacer);
  141. }
  142. for (i = MIN; i <= MAX; i++){
  143. character = String.fromCharCode(i);
  144. value = MAPPING[character];
  145. if(!value) {continue;}
  146. original = value;
  147. for (key in CONSTRUCTORS){
  148. replace("\\b" + key, CONSTRUCTORS[key] + '["constructor"]');
  149. }
  150. for (key in SIMPLE){
  151. replace(key, SIMPLE[key]);
  152. }
  153. replace('(\\d\\d+)', numberReplacer);
  154. replace('\\((\\d)\\)', digitReplacer);
  155. replace('\\[(\\d)\\]', digitReplacer);
  156. replace("GLOBAL", GLOBAL);
  157. replace('\\+""', "+[]");
  158. replace('""', "[]+[]");
  159. MAPPING[character] = value;
  160. }
  161. }
  162. function replaceStrings(){
  163. var regEx = /[^\[\]\(\)\!\+]{1}/g,
  164. all, value, missing,
  165. count = MAX - MIN;
  166. function findMissing(){
  167. var all, value, done = false;
  168. missing = {};
  169. for (all in MAPPING){
  170. value = MAPPING[all];
  171. if (value.match(regEx)){
  172. missing[all] = value;
  173. done = true;
  174. }
  175. }
  176. return done;
  177. }
  178. function mappingReplacer(a, b) {
  179. return b.split("").join("+");
  180. }
  181. function valueReplacer(c) {
  182. return missing[c] ? c : MAPPING[c];
  183. }
  184. for (all in MAPPING){
  185. MAPPING[all] = MAPPING[all].replace(/\"([^\"]+)\"/gi, mappingReplacer);
  186. }
  187. while (findMissing()){
  188. for (all in missing){
  189. value = MAPPING[all];
  190. value = value.replace(regEx, valueReplacer);
  191. MAPPING[all] = value;
  192. missing[all] = value;
  193. }
  194. if (count-- === 0){
  195. console.error("Could not compile the following chars:", missing);
  196. }
  197. }
  198. }
  199. function encode(input, wrapWithEval){
  200. var output = [];
  201. if (!input){
  202. return "";
  203. }
  204. var r = "";
  205. for (var i in SIMPLE) {
  206. r += i + "|";
  207. }
  208. r+=".";
  209. input.replace(new RegExp(r, 'g'), function(c) {
  210. var replacement = SIMPLE[c];
  211. if (replacement) {
  212. output.push("[" + replacement + "]+[]");
  213. } else {
  214. replacement = MAPPING[c];
  215. if (replacement){
  216. output.push(replacement);
  217. } else {
  218. if (c === "J") {
  219. replacement =
  220. "([][" + encode("filter") + "]" +
  221. "[" + encode("constructor") + "]" +
  222. "(" + encode("return new Date(200000000)") + ")()+[])[!+[]+!+[]+!+[]+!+[]]";
  223. output.push(replacement);
  224. MAPPING[c] = replacement;
  225. } else if (c === "O") {
  226. replacement =
  227. "([][" + encode("filter") + "]" +
  228. "[" + encode("constructor") + "]" +
  229. "(" + encode("return new Date(24000000000)") + ")()+[])[!+[]+!+[]+!+[]+!+[]]";
  230. output.push(replacement);
  231. MAPPING[c] = replacement;
  232. } else {
  233. replacement =
  234. "([]+[])[" + encode("constructor") + "]" +
  235. "[" + encode("fromCharCode") + "]" +
  236. "(" + encode(c.charCodeAt(0) + "") + ")";
  237. output.push(replacement);
  238. MAPPING[c] = replacement;
  239. }
  240. }
  241. }
  242. });
  243. output = output.join("+");
  244. if (/^\d$/.test(input)){
  245. output += "+[]";
  246. }
  247. if (wrapWithEval){
  248. output = "[][" + encode("filter") + "]" +
  249. "[" + encode("constructor") + "]" +
  250. "(" + output + ")()";
  251. }
  252. return output;
  253. }
  254. fillMissingDigits();
  255. fillMissingChars();
  256. replaceMap();
  257. replaceStrings();
  258. self.JSFuck = {
  259. encode: encode
  260. };
  261. })(typeof(exports) === "undefined" ? window : exports);