jsfuck
Advanced tools
Comparing version 0.1.0 to 0.4.0
219
jsfuck.js
@@ -1,2 +0,2 @@ | ||
/*! JSFuck 1.0 - http://jsfuck.com */ | ||
/*! JSFuck 0.4.0 - http://jsfuck.com */ | ||
@@ -19,56 +19,57 @@ (function(self){ | ||
'Array': '[]', | ||
'Number': '+[]', | ||
'String': '[]+[]', | ||
'Boolean': '![]', | ||
'Function': '[]["filter"]' | ||
'Number': '(+[])', | ||
'String': '([]+[])', | ||
'Boolean': '(![])', | ||
'Function': '[]["filter"]', | ||
'RegExp': 'Function("return/0/")()' | ||
}; | ||
var MAPPING = { | ||
'a': '("false")[1]', | ||
'b': '(GLOBAL+[])[2]', | ||
'c': '([]["filter"]+[])[3]', | ||
'd': '("undefined")[2]', | ||
'e': '("true")[3]', | ||
'f': '("false")[0]', | ||
'g': '([]+String)[14]', | ||
'h': '(+(17))["toString"](20)', | ||
'i': '("undefined")[5]', | ||
'j': '(GLOBAL+"")[3]', | ||
'a': '(false+"")[1]', | ||
'b': '(+(11))["toString"](20)', | ||
'c': '([]["filter"]+"")[3]', | ||
'd': '(undefined+"")[2]', | ||
'e': '(true+"")[3]', | ||
'f': '(false+"")[0]', | ||
'g': '(+false+[false]+String)[20]', | ||
'h': '(+(101))["toString"](21)[1]', | ||
'i': '([false]+undefined)[10]', | ||
'j': '(+(40))["toString"](21)[1]', | ||
'k': '(+(20))["toString"](21)', | ||
'l': '("false")[2]', | ||
'l': '(false+"")[2]', | ||
'm': '(Number+"")[11]', | ||
'n': '("undefined")[1]', | ||
'o': '([]["filter"]+"")[6]', | ||
'p': '(+(25))["toString"](30)', | ||
'q': '(+(26))["toString"](30)', | ||
'r': '("true")[1]', | ||
's': '("false")[3]', | ||
't': '("true")[0]', | ||
'u': '("undefined")[0]', | ||
'n': '(undefined+"")[1]', | ||
'o': '(true+[]["filter"])[10]', | ||
'p': '(+(211))["toString"](31)[1]', | ||
'q': '(+(212))["toString"](31)[1]', | ||
'r': '(true+"")[1]', | ||
's': '(false+"")[3]', | ||
't': '(true+"")[0]', | ||
'u': '(undefined+"")[0]', | ||
'v': '(+(31))["toString"](32)', | ||
'w': '(+(32))["toString"](33)', | ||
'x': '(+(33))["toString"](34)', | ||
'y': '("Infinity")[7]', | ||
'x': '(+(101))["toString"](34)[1]', | ||
'y': '(NaN+[Infinity])[10]', | ||
'z': '(+(35))["toString"](36)', | ||
'A': '(Array+"")[9]', | ||
'B': '(Boolean+"")[9]', | ||
'C': 'GLOBAL["unescape"]("%"+(43))[0]', | ||
'D': USE_CHAR_CODE, | ||
'E': USE_CHAR_CODE, | ||
'F': '(Function+"")[9]', | ||
'G': USE_CHAR_CODE, | ||
'A': '(+false+Array)[10]', | ||
'B': '(+false+Boolean)[10]', | ||
'C': 'Function("return escape")()("<")[2]', | ||
'D': 'Function("return escape")()("=")[2]', | ||
'E': '(RegExp+"")[12]', | ||
'F': '(+false+Function)[10]', | ||
'G': '(false+Function("return Date")()())[30]', | ||
'H': USE_CHAR_CODE, | ||
'I': '("Infinity")[0]', | ||
'J': USE_CHAR_CODE, | ||
'I': '(Infinity+"")[0]', | ||
//'J': USE_CHAR_CODE, | ||
'K': USE_CHAR_CODE, | ||
'L': USE_CHAR_CODE, | ||
'M': USE_CHAR_CODE, | ||
'N': '("NaN")[0]', | ||
'O': USE_CHAR_CODE, | ||
'M': '(true+Function("return Date")()())[30]', | ||
'N': '(NaN+"")[0]', | ||
//'O': USE_CHAR_CODE, | ||
'P': USE_CHAR_CODE, | ||
'Q': USE_CHAR_CODE, | ||
'R': USE_CHAR_CODE, | ||
'S': '(String+[])[9]', | ||
'T': USE_CHAR_CODE, | ||
'R': '(+false+RegExp)[10]', | ||
'S': '(+false+String)[10]', | ||
'T': '(NaN+Function("return Date")()())[30]', | ||
'U': USE_CHAR_CODE, | ||
@@ -81,27 +82,27 @@ 'V': USE_CHAR_CODE, | ||
' ': '([]["filter"]+[])[8]', | ||
' ': '(NaN+[]["filter"])[11]', | ||
'!': USE_CHAR_CODE, | ||
'"': '("")["link"](0)[10]', | ||
'"': '("")["fontcolor"]()[12]', | ||
'#': USE_CHAR_CODE, | ||
'$': USE_CHAR_CODE, | ||
'%': 'GLOBAL["escape"]("<")[0]', | ||
'%': 'Function("return escape")()("<")[0]', | ||
'&': USE_CHAR_CODE, | ||
'\'': 'GLOBAL["unescape"]("%"+(27))[0]', | ||
'(': '([]["filter"]+"")[15]', | ||
')': '([]["filter"]+"")[16]', | ||
'\'': USE_CHAR_CODE, | ||
'(': '(false+[]["filter"])[20]', | ||
')': '(true+[]["filter"])[20]', | ||
'*': USE_CHAR_CODE, | ||
'+': '(+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]])+[])[2]', | ||
',': '[[]]["concat"]([][[]])+[]', | ||
'-': USE_CHAR_CODE, | ||
'.': USE_CHAR_CODE, | ||
'/': '("")["link"]()[21]', | ||
':': 'GLOBAL["Date"]()[21]', | ||
',': '[[]]["concat"]([[]])+""', | ||
'-': '(+(.+[0000000001])+"")[2]', | ||
'.': '(+(+!+[]+[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+[!+[]+!+[]]+[+[]])+[])[+!+[]]', | ||
'/': '(false+[+false])["italics"]()[10]', | ||
':': '(RegExp()+"")[3]', | ||
';': USE_CHAR_CODE, | ||
'<': '("")["link"]()[0]', | ||
'<': '("")["italics"]()[0]', | ||
'=': '("")["fontcolor"]()[11]', | ||
'>': '("")["link"]([])[10]', | ||
'?': USE_CHAR_CODE, | ||
'>': '("")["italics"]()[2]', | ||
'?': '(RegExp()+"")[2]', | ||
'@': USE_CHAR_CODE, | ||
'[': USE_CHAR_CODE, | ||
'\\': 'GLOBAL["unescape"]("%"+(5)+"c")[0]', | ||
'[': '(GLOBAL+"")[0]', | ||
'\\': USE_CHAR_CODE, | ||
']': USE_CHAR_CODE, | ||
@@ -111,3 +112,3 @@ '^': USE_CHAR_CODE, | ||
'`': USE_CHAR_CODE, | ||
'{': '([]["filter"]+"")[18]', | ||
'{': '(NaN+[]["filter"])[21]', | ||
'|': USE_CHAR_CODE, | ||
@@ -118,3 +119,3 @@ '}': USE_CHAR_CODE, | ||
var GLOBAL = '[]["filter"]["constructor"]("return this")()'; | ||
var GLOBAL = 'Function("return this")()'; | ||
@@ -124,3 +125,3 @@ function fillMissingChars(){ | ||
if (MAPPING[key] === USE_CHAR_CODE){ | ||
MAPPING[key] = 'String["fromCharCode"](' + key.charCodeAt(0) + ')'; | ||
MAPPING[key] = 'Function("return unescape")()("%"'+ key.charCodeAt(0).toString(16).replace(/(\d+)/g, "+($1)+\"") + '")'; | ||
} | ||
@@ -146,3 +147,3 @@ } | ||
function replaceMap(){ | ||
var character = "", value, original; | ||
var character = "", value, original, i, key; | ||
@@ -156,19 +157,33 @@ function replace(pattern, replacement){ | ||
for (var i = MIN; i <= MAX; i++){ | ||
function digitReplacer(_,x) { return MAPPING[x]; } | ||
function numberReplacer(_,y) { | ||
var values = y.split(""); | ||
var head = +(values.shift()); | ||
var output = "+[]"; | ||
if (head > 0){ output = "+!" + output; } | ||
for (i = 1; i < head; i++){ output = "+!+[]" + output; } | ||
if (head > 1){ output = output.substr(1); } | ||
return [output].concat(values).join("+").replace(/(\d)/g, digitReplacer); | ||
} | ||
for (i = MIN; i <= MAX; i++){ | ||
character = String.fromCharCode(i); | ||
value = MAPPING[character]; | ||
if(!value) {continue;} | ||
original = value; | ||
for (key in CONSTRUCTORS){ | ||
replace("\\b" + key, '(' + CONSTRUCTORS[key] + ')["constructor"]'); | ||
replace("\\b" + key, CONSTRUCTORS[key] + '["constructor"]'); | ||
} | ||
for (key in SIMPLE){ | ||
replace('"' + key + '"', SIMPLE[key] + "+[]"); | ||
replace(key, SIMPLE[key]); | ||
} | ||
for (key = 0; key < 10; key++){ | ||
replace(key, "+[" + MAPPING[key] + "]"); | ||
} | ||
replace('(\\d\\d+)', numberReplacer); | ||
replace('\\((\\d)\\)', digitReplacer); | ||
replace('\\[(\\d)\\]', digitReplacer); | ||
@@ -185,7 +200,5 @@ replace("GLOBAL", GLOBAL); | ||
var regEx = /[^\[\]\(\)\!\+]{1}/g, | ||
all, value, missing; | ||
all, value, missing, | ||
count = MAX - MIN; | ||
function findMissing(){ | ||
@@ -209,6 +222,12 @@ var all, value, done = false; | ||
function mappingReplacer(a, b) { | ||
return b.split("").join("+"); | ||
} | ||
function valueReplacer(c) { | ||
return missing[c] ? c : MAPPING[c]; | ||
} | ||
for (all in MAPPING){ | ||
MAPPING[all] = MAPPING[all].replace(/\"([^\"]+)\"/gi, function(a, b){ | ||
return b.split("").join("+"); | ||
}); | ||
MAPPING[all] = MAPPING[all].replace(/\"([^\"]+)\"/gi, mappingReplacer); | ||
} | ||
@@ -219,5 +238,3 @@ | ||
value = MAPPING[all]; | ||
value = value.replace(regEx, function(c){ | ||
return missing[c] ? c : MAPPING[c]; | ||
}); | ||
value = value.replace(regEx, valueReplacer); | ||
@@ -228,3 +245,3 @@ MAPPING[all] = value; | ||
if (count-- == 0){ | ||
if (count-- === 0){ | ||
console.error("Could not compile the following chars:", missing); | ||
@@ -242,4 +259,44 @@ } | ||
input.replace(/./g, function(c){ | ||
output.push(MAPPING[c] || 'String["fromCharCode"](' + c.charCodeAt(0) + ')' ); | ||
var r = ""; | ||
for (var i in SIMPLE) { | ||
r += i + "|"; | ||
} | ||
r+="."; | ||
input.replace(new RegExp(r, 'g'), function(c) { | ||
var replacement = SIMPLE[c]; | ||
if (replacement) { | ||
output.push("[" + replacement + "]+[]"); | ||
} else { | ||
replacement = MAPPING[c]; | ||
if (replacement){ | ||
output.push(replacement); | ||
} else { | ||
if (c === "J") { | ||
replacement = | ||
"([][" + encode("filter") + "]" + | ||
"[" + encode("constructor") + "]" + | ||
"(" + encode("return new Date(200000000)") + ")()+[])[!+[]+!+[]+!+[]+!+[]]"; | ||
output.push(replacement); | ||
MAPPING[c] = replacement; | ||
} else if (c === "O") { | ||
replacement = | ||
"([][" + encode("filter") + "]" + | ||
"[" + encode("constructor") + "]" + | ||
"(" + encode("return new Date(24000000000)") + ")()+[])[!+[]+!+[]+!+[]+!+[]]"; | ||
output.push(replacement); | ||
MAPPING[c] = replacement; | ||
} else { | ||
replacement = | ||
"([]+[])[" + encode("constructor") + "]" + | ||
"[" + encode("fromCharCode") + "]" + | ||
"(" + encode(c.charCodeAt(0) + "") + ")"; | ||
output.push(replacement); | ||
MAPPING[c] = replacement; | ||
} | ||
} | ||
} | ||
}); | ||
@@ -256,3 +313,3 @@ | ||
"[" + encode("constructor") + "]" + | ||
"(" + output + ")()" | ||
"(" + output + ")()"; | ||
} | ||
@@ -271,2 +328,2 @@ | ||
}; | ||
})(typeof(exports) == "undefined" ? window : exports); | ||
})(typeof(exports) === "undefined" ? window : exports); |
{ | ||
"name": "jsfuck", | ||
"version": "0.1.0", | ||
"version": "0.4.0", | ||
"description": "Write any JavaScript with just 6 characters: []()!+", | ||
@@ -27,3 +27,9 @@ "main": "jsfuck.js", | ||
"url": "https://github.com/aemkei/jsfuck/issues" | ||
}, | ||
"devDependencies": { | ||
"grunt": "~0.4.1", | ||
"grunt-contrib-nodeunit": "~0.2.0", | ||
"grunt-contrib-watch": "~0.5.3", | ||
"grunt-contrib-jshint": "~0.6.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
252725
270
4