Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working self-hosting JSFuck compilers? #91

Open
JobLeonard opened this issue Aug 23, 2019 · 4 comments
Open

Working self-hosting JSFuck compilers? #91

JobLeonard opened this issue Aug 23, 2019 · 4 comments

Comments

@JobLeonard
Copy link

JobLeonard commented Aug 23, 2019

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
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
Copy link
Contributor

hazzik commented Aug 23, 2019

@JobLeonard
Copy link
Author

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

@hazzik
Copy link
Contributor

hazzik commented Aug 23, 2019

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

@JobLeonard
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants