-
Notifications
You must be signed in to change notification settings - Fork 685
Description
Hi,
You JSFuck compiler is very interesting however it has some drawback - it produce very large code from small code JS :( . So I have following idea:
- Lets Compress our STRING with CODE by switch it to base4 (not 64!) characters, however instead using character 0,1,2,3 we change '3' to letter 'a' becouse in brainfuck letter 'a' is shorter than '3' representation:
var input = "alert('Hello world' + \x22 in 2018! :) \\uC548\\uB155\\uD558\\uC138\\uC694 \x22)"; // our input program as STRING (we can only use code which use ASCII character - for utf8 characters we need to use escape characters as in this example)
// code string
var encode = function(input) {
let output = ""
input.split('').map(function(letter) {
let c =letter.charCodeAt(0).toString(4).split('3').join('a');
if(c.length==3) c="0"+c;
if(c.length==2) c="00"+c;
if(c.length==1) c="000"+c;
if(c.length==0) c="0000";
output = output + '' + c;
})
return output;
};
var code = encode(input);
Ok so in variable 'code' we get following value (remeber number '3' in our base4 we change to letter 'a'):
120112a012111a021a100220021a1020121112a012a012aa02001a1a12aa1a0212a01210021a0200022a020002020200122112a202000a020a000a010a20020102000a220221020011a01a11100a0a110a100a2011a01a1110020a010a110a1111a01a1110100a110a110a2011a01a11100a0a010a0a0a2011a01a11100a0a120a210a10020002020221
- Then we put this string in our decoding/eval procedure:
var b='',c = "120112a012111a021a100220021a1020121112a012a012aa02001a1a12aa1a0212a01210021a0200022a020002020200122112a202000a020a000a010a20020102000a220221020011a01a11100a0a110a100a2011a01a1110020a010a110a1111a01a1110100a110a110a2011a01a11100a0a010a0a0a2011a01a11100a0a120a210a10020002020221";c.split('').map(function(d,i){if(i%4==3) {b=b+String.fromCharCode(parseInt(c.slice(i-3,i+1).split('a').join('3'),4));}});eval(b);
and thats all - we can put this code to our JSFuck compiler and it works (produce 150885 chars) :)
- Tests
a) let say our js ode is alert(1) then clear JSFack produces 1227 chars and after our 'compresion' we get 148563 chars (~150KB - this is approximation of size of our compresion 'library')
b) if we add lets say 50 characters alert('1abcdefgh iklmnoupr stuvwyzx12 abcdefghi klmnouprs') then pure JSFack result increases to 39465 chars - so 39465-1227=38238bytes ~39KB growth compare to case a). If we use compression we get 150635 chars so 150635-148563=2072bytes ~2KB growth compare to case a). So as we see our output code increase more thant 10 times ( !!!!!!!! ) without compression (excluding 'compress library size').
- When I try to compile larger compresed code i get following error (index):162 Uncaught RangeError: Maximum call stack size exceeded at HTMLAnchorElement.$.onclick... - however I think If you build in this technique directly to compiler it will be easy to avoid this error.