News for hackers. Stuff that matters.
Re:JSFuck (2012) by usui on Saturday September 25, 2021 @09:33PM (#28657626)
I don't understand how this works. I've seen brainfuck before, but not truly understood it. How is it possible to open up a new tab, paste the encoded form, and have working JavaScript?
Re:JSFuck (2012) by mb7733 on Saturday September 25, 2021 @09:40PM (#28657658)
It's because it _is_ working javascript. It's just obfuscated, taking advantage of the quirks of javascript's implicit type casting to represent expressions in odd ways. Look at the "basics" section of the page to get an idea of how it works on a small scale.

Brainfuck is an unrelated, separate programming language.

Re:JSFuck (2012) by city41 on Saturday September 25, 2021 @09:41PM (#28657665)
Here's the decoder ring: https://github.com/aemkei/jsfuck/blob/master/jsfuck.js

With this I was able to get the letter 'a' by starting with their initial definition `(false+"")[1]`, then continually substituting

(false+'')[1]

(![]+'')[1]

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

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

All of the above lines when evaluated result in 'a'.

Re:JSFuck (2012) by hn_throwaway_99 on Saturday September 25, 2021 @10:03PM (#28657777)
Yep, in addition the other part that helped me understand was how it encodes eval for actually executing code. Details are on this line, https://github.com/aemkei/jsfuck/blob/1f02651e98da1c13aef76d... , and details of that are:

1. [] => An array object

2. []["flat"] => The built in flat function on the Array object

3. []["flat"]["constructor"] => The constructor of any JS function is the Function constructor, which can take JavaScript, as a string, as its sole parameter. Thus, to create a function that executes any CODE_AS_STRING:

4. []["flat"]["constructor"](CODE_AS_STRING) => gives you the Function object, and finally:

5. []["flat"]["constructor"](CODE_AS_STRING)() => executes it

Thus, all that's left is to encode the strings "flat", "constructor" and CODE_AS_STRING using the patterns described early in that file.

Re:JSFuck (2012) by colejohnson66 on Saturday September 25, 2021 @09:37PM (#28657641)
This isn't related to BF (despite looking like it). At the bottom of the page, it explains how the conversions work. Basically, it takes advantage of JavaScript's loose typing and implicit conversions.
Re:JSFuck (2012) by tacticalmook on Saturday September 25, 2021 @11:09PM (#28658099)
brainfuck isn't an obfuscator, but a language with a very small and simple instruction set. Technically it falls somewhere between c and assembly, since it doesn't have a 1:1 relationship with machine code, but in practice it is less powerful than assembly because you have to work within the confines of its restrictive conventions to recreate something as simple as y = x

There are some tasks which lend themselves to the way the language is constructed, and can be done with few instructions.

Reversing a string, for example, is just ,[[<]<+>>[>],]<[.<] which is quite short compared to most "practical" programs in this language.

And a destructive y = y + x is just [->+<] (destructive because this also sets x to zero)