Coder Social home page Coder Social logo

jscrewit's Introduction

JScrewIt

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

Example

The following source will do an alert(1) in any browser, including Internet Explorer:

[][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+
(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]][(+(+!![]+[+([][(![]+[])[+[]]+([![]]+
[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]
]+(!![]+[])[+!![]]]+[])[+[]]])+[!![]]+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]
]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]
])[+!![]+[+[]]]+(!!(+([][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]
+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]]+[])[+[]]+!![])
+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]
+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]])[+!![]+[+!![]]]+([][[]]+[])[+!![]]+
(![]+[])[!![]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+(+(+!!
[]+[+([][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])
[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]]+[])[+[]]])+[!![]]+[][(![]+[])[
+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!!
[]+!![]+!![]]+(!![]+[])[+!![]]])[+!![]+[+[]]]+(!![]+[])[+[]]+(!!(+([][(![]+[])[+
[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![
]+!![]+!![]]+(!![]+[])[+!![]]]+[])[+[]]+!![])+[][(![]+[])[+[]]+([![]]+[][[]])[+!
![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[]
)[+!![]]])[+!![]+[+!![]]]+(!![]+[])[+!![]]]((![]+[])[+!![]]+(![]+[])[!![]+!![]]+
(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]+(!!(+([][(![]+[])[+[]]
+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!
![]+!![]]+(!![]+[])[+!![]]]+[])[+[]]+!![])+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]
+[+[]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+
!![]]])[!![]+!![]+[+[]]]+[+!![]]+(!!(+([][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[
]]]+(![]+[])[!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]
]]+[])[+[]]+!![])+[][(![]+[])[+[]]+([![]]+[][[]])[+!![]+[+[]]]+(![]+[])[!![]+!![
]]+(!![]+[])[+[]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]])[!![]+!![]+[+!![]]
])()

Usage

Installation

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");

Encoding

Basics

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!".

Features

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+
  • ATOB
  • ENTRIES (implied by NO_SAFARI_ARRAY_ITERATOR)
  • FF_SAFARI_SRC
  • FILL (Firefox 31+)
  • GMT
  • NAME
  • NO_IE_SRC (implied by FF_SAFARI_SRC)
  • NO_SAFARI_ARRAY_ITERATOR
  • NO_SAFARI_LF
  • QUOTE
  • SELF (implied by WINDOW)
  • UNDEFINED
  • WINDOW
Google Chrome 35+, Opera 22+
  • ATOB
  • ENTRIES (implied by NO_SAFARI_ARRAY_ITERATOR; Chrome 38+, Opera 25+)
  • GMT
  • NAME
  • NO_IE_SRC (implied by V8_SRC)
  • NO_SAFARI_ARRAY_ITERATOR (Chrome 38+, Opera 25+)
  • NO_SAFARI_LF
  • SELF (implied by WINDOW)
  • UNDEFINED
  • V8_SRC
  • WINDOW
Internet Explorer 9+
  • ATOB (Internet Explorer 10+)
  • GMT (Internet Explorer 11)
  • IE_SRC
  • NO_SAFARI_LF
  • SELF (implied by WINDOW)
  • UNDEFINED
  • WINDOW
Safari 7.0+
  • ATOB
  • ENTRIES (implied by SAFARI_ARRAY_ITERATOR; Safari 7.1+)
  • FF_SAFARI_SRC
  • FILL (Safari 7.1+)
  • GMT
  • NAME
  • NO_IE_SRC (implied by FF_SAFARI_SRC)
  • SAFARI_ARRAY_ITERATOR (Safari 7.1+)
  • SELF (implied by WINDOW)
  • UNDEFINED
  • WINDOW
Android Browser 4.0+
  • ATOB
  • DOMWINDOW (not in Android Browser 4.4.2+)
  • GMT
  • NAME
  • NO_IE_SRC (implied by V8_SRC)
  • NO_SAFARI_LF
  • SELF (implied by DOMWINDOW and WINDOW)
  • UNDEFINED (Android Browser 4.1.2+)
  • V8_SRC
  • WINDOW (Android Browser 4.4.2+)
Node.js 0.10.28+
  • GMT
  • NAME
  • NO_IE_SRC (implied by V8_SRC)
  • NO_SAFARI_LF
  • UNDEFINED
  • V8_SRC

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"];

Reference

JScrewIt.areFeaturesAvailable(features)

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.
Examples
JScrewIt.areFeaturesAvailable("NO_IE_SRC")
JScrewIt.areFeaturesAvailable(["ATOB", "GMT", "NAME"])
Notes

If features is an empty array or undefined, the return value is true.

This function throws a ReferenceError if some unknown features are specified.

JScrewIt.areFeaturesCompatible(features)

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.
Examples
JScrewIt.areFeaturesCompatible(["V8_SRC", "IE_SRC"]) // returns false
JScrewIt.areFeaturesCompatible(["DEFAULT", "FILL"]) // returns true
Notes

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.

JScrewIt.encode(input, wrapWithEval, features)

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.
Notes

This function throws a ReferenceError if some unknown features are specified.

JScrewIt.FEATURE_INFOS

This is a container mapping feature names to descriptors. A feature descriptor is an object with a set of properties defining the feature.

Feature descriptor properties
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.
Examples

This will return an array with the names of all features supported by JScrewIt:

Object.getOwnPropertyNames(JScrewIt.FEATURE_INFOS)

Links

jscrewit's People

Contributors

aemkei avatar fasttime avatar hawur avatar hazzik avatar mathiasbynens avatar subzey avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.