JScrewIt converts plain JavaScript into JSFuck code, which uses only six different characters to
write and execute any code: []()!+
.
JScrewIt is a fork of JSFuck with the ability to optimize code for a particular set of JavaScript engines and even just for your browser.
The more specific your engine choice, the shorter the code you'll get.
Demo: jscrew.it
The following source will do an alert(1)
in any browser, including Internet Explorer:
[][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+
(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]][(+(+!![]+[+([][(![]+[])[+[]]+([![]]+
[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]
]+(!![]+[])[+!![]]]+[])[+[]]])+[!![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]
]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]
])[+!![]+[+[]]]+(!!(+([][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]
+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]]+[])[+[]]+!![])
+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]
+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]])[+!![]+[+!![]]]+([][[]]+[])[+!![]]+
(![]+[])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+(+(+!!
[]+[+([][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])
[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]]+[])[+[]]])+[!![]]+[][(![]+[])[
+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!!
[]+!![]+!![]]+(!![]+[])[+!![]]])[+!![]+[+[]]]+(!![]+[])[+[]]+(!!(+([][(![]+[])[+
[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![
]+!![]+!![]]+(!![]+[])[+!![]]]+[])[+[]]+!![])+[][(![]+[])[+[]]+([![]]+[][[]])[+!
![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[]
)[+!![]]])[+!![]+[+!![]]]+(!![]+[])[+!![]]]((![]+[])[+!![]]+(![]+[])[!![]+!![]]+
(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]+(!!(+([][(![]+[])[+[]]
+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!
![]+!![]]+(!![]+[])[+!![]]]+[])[+[]]+!![])+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]
+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+
!![]]])[!![]+!![]+[+[]]]+[+!![]]+(!!(+([][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[
]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]
]]+[])[+[]]+!![])+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![
]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]])[!![]+!![]+[+!![]]
])()
To use JScrewIt in your project, download [jscrewit.js] (https://github.com/fasttime/JScrewIt/blob/master/lib/jscrewit.js) or [jscrewit.min.js] (https://github.com/fasttime/JScrewIt/blob/master/lib/jscrewit.min.js) from GitHub and include it in your HTML file.
<script src="jscrewit.js"></script>
Alternatively, you can hotlink the online file.
<script src="https://rawgithub.com/fasttime/JScrewIt/master/lib/jscrewit.min.js"></script>
If you are using Node.js, you can install JScrewIt with npm.
npm install jscrewit
Then you can include it in your code.
var JScrewIt = require("jscrewit");
This will encode the alert(1)
example shown above and run it using eval
.
var output = JScrewIt.encode("alert(1)", true);
eval(output);
The true
passed as a second parameter indicates that we would like the output to be executable.
This parameter should be false
to encode a plain string rather than JavaScript code.
var output = JScrewIt.encode("Hello, world!", false);
var input = eval(output); // input contains the string "Hello, world!".
JScrewIt has the ability to generate JSFuck code that is targeted for a particular set of JavaScript
engines (web browsers or Node.js).
This optimized code is shorter than generic JSFuck code but does not work everywhere.
To make use of this optimization, you have to specify which features the decoder engine is
expected to support.
In order to understand how this works consider the JavaScript functions atob
and btoa
.
Not all browsers support these functions: without any further information, JScrewIt will assume that
they are unavailable and will not be able to use them in generated code.
Anyway, if you know in advance that the browsers you plan to target do support atob
and btoa
indeed, you can let JScrewIt create code that uses those functions whenever this would make the
output shorter.
The way to tell JScrewIt to use these features is by specifying a string (or array of strings) as
a third parameter to encode
.
For instance, the generic alert(1)
example is 2084 chracters long.
var output = JScrewIt.encode("alert(1)", true); // output is 2084 characters
But if we specify that we are only interested in code that runs in an up to date Firefox browser, the output length shrinks to less than a half:
var output = JScrewIt.encode("alert(1)", true, "FF31"); // 972 characters now
You can specify more than one feature using an array, e.g.
var input = "document.body.style.background='red'";
var features = ["ATOB", "WINDOW"];
var output = JScrewIt.encode(input, true, features);
This table lists individual features of some common browsers.
Target | Features |
---|---|
Firefox 30+ |
|
Google Chrome 35+, Opera 22+ |
|
Internet Explorer 9+ |
|
Safari 7.0+ |
|
Android Browser 4.0+ |
|
Node.js 0.10.28+ |
|
Keep in mind that each of the target engines needs to support every feature you specify. So if you want your JSFuck code to run on both Internet Explorer and Firefox, this won't work.
var features = ["IE9", "FF31"];
Instead, you have to specify features supported by both browsers.
Those turn out out to be "NO_SAFARI_LF"
, "SELF"
, "UNDEFINED"
and "WINDOW"
.
var features = ["NO_SAFARI_LF", "SELF", "UNDEFINED", "WINDOW"];
Returns true
if all of the specified features are available in the current engine; otherwise,
false
.
features
- A string or array of strings specifying the feature(s) to be tested.
JScrewIt.areFeaturesAvailable("NO_IE_SRC")
JScrewIt.areFeaturesAvailable(["ATOB", "GMT", "NAME"])
If features
is an empty array or undefined
, the return value is true
.
This function throws a ReferenceError
if some unknown features are specified.
Returns true
if the specified features are compatible with each other.
features
- A string or array of strings specifying the feature(s) to be tested.
JScrewIt.areFeaturesCompatible(["V8_SRC", "IE_SRC"]) // returns false
JScrewIt.areFeaturesCompatible(["DEFAULT", "FILL"]) // returns true
If features
is an empty array or undefined
, or if it only specifies one feature, the return
value is true
.
This function throws a ReferenceError
if some unknown features are specified.
Encodes a given string into JSFuck. Returns the encoded string.
input
- The string to encode.
wrapWithEval
- If this parameter is truthy, the return value evaluates to a function that runs the specified string as JavaScript code. If this parameter is falsy, the return value evaluates to a string equivalent to the specified input.
features
-
A string or array of strings specifying the feature(s) available on the engine that evaluates the
encoded output.
If this parameter is an empty array or
undefined
,DEFAULT
is assumed: this ensures maximum compatibility but also generates the largest code. To generate shorter code, specify some features.
This function throws a ReferenceError
if some unknown features are specified.
This is a container mapping feature names to descriptors. A feature descriptor is an object with a set of properties defining the feature.
name
- Name of the feature.
description
- A short description of the feature in plain English.
available
-
true
if the specified feature is available on the current engine; otherwise,false
. includes
-
An array of feature names implied by this feature.
If a feature is available, its
includes
are, too. If a feature is not available, other features including it are also not available. excludes
-
An array of feature names not compatible with this feature.
If a feature is available, its
excludes
are not.
This will return an array with the names of all features supported by JScrewIt:
Object.getOwnPropertyNames(JScrewIt.FEATURE_INFOS)
- JSFuck
- Original discussion at Sla.ckers.org