aemkei / jsfuck

Write any JavaScript with 6 Characters: []()!+
jsfuck.com
Do What The F*ck You Want To Public License
8.07k stars 671 forks source link

Working self-hosting JSFuck compilers? #91

Open JobLeonard opened 4 years ago

JobLeonard commented 4 years ago

So I just came here from the Low Level JavaScript YouTube video on JSFuck which left me wondering if anyone has managed to write a self-hosting JSFuck compiler that actually runs.

Technically it's simple of course: just pipe a JSFuck compiler through itself. But I wondered if the output would actually run.

Searching for that on-line turned up nothing (honestly, I refuse to believe nobody has tried - surely it must be my own weak Google-Fu). So I gave it a quick shot myself. First I tried running a minified version of this repo's compiler through itself results in 6408898 chars, so roughly 6.1 MiB. Crashed any browser console I tried it on.

Then I figured the issue must be the size, so I took the demo code from the video that brought me here, code golf a bit (leading to the version in the details below below), minify that (resulting in 877 chars), and throw that through various JSFuck compilers. When compiling itself it creates a 5.1 MiB file. When using the online compiler (which clearly is a bit smarter) the result is 1.5 MiB. Still crashes :(

At this point I'm not sure if it's the size or something else, but honestly I should be doing other things right now so I can't investigate further at the moment.

Curious if anyone out there has tried or maybe even succeeded in this?

Pre-minified mangled LLJS channel version ```js const compile = (() => { const N = n => { if (n === 0) return '+[]'; return Array.from({ length: n }, () => '+!![]').join(' + '); } const M = {}; const S = s => s.split('').map(x => { return M[x] || `([]+[])[${S(c)}][${S('fromCharCode')}](${N(x.charCodeAt(0))})`; }).join('+'); // "[object Object]" const O = '({}+[])['; const c = 'constructor'; const t = {}; M.a = `(+{}+[])[${N(1)}]`; M.b = O + N(2) + `]`; M.o = O + N(1) + `]`; M.e = O + N(4) + `]`; M.c = O + N(5) + `]`; M.t = O + N(6) + `]`; M[' '] = O + N(7) + `]`; M.f = `(![]+[])[${N(0)}]`; M.s = `(![]+[])[${N(3)}]`; M.r = `(!![]+[])[${N(1)}]`; M.u = `(!![]+[])[${N(2)}]`; M.i = `((+!![]/+[])+[])[${N(3)}]`; M.n = `((+!![]/+[])+[])[${N(4)}]`; t.c = "([]+([]+[])["+S(c)+"])[" M.S = t.c+N(9)+"]"; M.g = t.c+N(14)+"]"; M.p = `([]+(/-/)[${S(c)}])[${N(14)}]`; M['\\'] = `(/\\\\/+[])[${N(1)}]`; t.S = `)[${S('toString')}](`; M.d = `(${N(13)}`+t.S+`${N(14)})`; M.h = `(${N(17)}`+t.S+`${N(18)})`; M.m = `(${N(22)}`+t.S+`${N(23)})`; M.C = `((()=>{})[${S(c)}](${S('return escape')})()(${M['\\']}))[${N(2)}]`; return p => `(()=>{})[${S(c)}](${S(p)})()`; })(); ```
hazzik commented 4 years ago

@JobLeonard do you mean something like this? https://gist.githubusercontent.com/hazzik/f6e833be141050c597230b0e1337384a/raw/cf434a34ce80c08e84889729213a9ceee510f3f8/jsfuck.js

JobLeonard commented 4 years ago

Maybe? It still crashes my browsers so I have to take your word for it ;)

hazzik commented 4 years ago

What browser do you use? I checked Chrome and FF. Both work for me.

JobLeonard commented 4 years ago

Both work for me.

Cool!

I tried on both Chromium and Firefox, on a fairly powerful Linux laptop with 64 GiB of RAM (so it's probably not that, haha). Maybe it's the add-ons I'm using?