aemkei / jsfuck

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

It is possible to call function with 2 arguments? #102

Open kamil-kielczewski opened 4 years ago

kamil-kielczewski commented 4 years ago

Suppose I have some string and want to use function "replace"

"truefalse"["replace"]("true") --> "undefinedfalse"

this line can be easily converted to JSF without using any kind of eval (interpreting string as code) as follows (I use comments and new lines to increase readability)

// "truefalse"[
([]+!![]+![])[

// long 'replace' word:
[]+(!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(+(!+[]+!+[]+[+!+[]]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]])[+!+[]+[+[]]]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]][([][[]]+[])[+!+[]]+(![]+[])[+!+[]]+((+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]+[])[+!+[]+[+!+[]]]+(!![]+[])[!+[]+!+[]+!+[]]]](!+[]+!+[]+!+[]+[+!+[]])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[+!+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]

// ]("true") 
]([]+!![])

Questions:

  1. It is possible to call function replace with 2 arguments - Like that: "truefalse"["replace"]("true","1") and write it in similar way in JSF (without any kind of 'eval')? I have/see problem with comma which separate arguments... :(

  2. It is possible to write in similar way regular expression in replace function argument e.g."truefalse"["replace"](/e/g,"E") (without any kind of 'eval') (we want to change e to E in whole string) ? (here I have/see problem with slash I don't know how to "construct" them in JSF to be interpreted as regexp

hazzik commented 4 years ago

No, it is not possible to call function with more than one arguments without eval in JSfuck. So... you need to come up with a way to represent this with functions with single argument.

The solution that can express your immediate problem in JSfuck without eval:

"truefalse".split("true").join("1") => "1false"
"truefalse"["split"]("true")["join"]("1")

And RegExp:

"truefalse"["split"](RegExp("e"))["join"]("E")

However, RegExp involves an eval expression.

kamil-kielczewski commented 4 years ago

@hazzik actually it is possible :) Yesterday I ask question on stackoverflow and one smart guy: trincot discover the way for n-parameters (working example):

["true"]["concat"]("1")["reduce"](""["replace"]["bind"]("truefalse"))

I also ask another question: it is possible to call such n-param methods in chain/flow way (not nested) e.g. "truefalse".replace("true",1).replace("false",0) - and he discover way to do it too - explanation here:

"truefalse"
  ["split"]()["concat"]([["true"]["concat"]("1")])["reduce"](""["replace"]["apply"]["bind"](""["replace"]))
  ["split"]()["concat"]([["false"]["concat"]("0")])["reduce"](""["replace"]["apply"]["bind"](""["replace"]))

In above code I use jsf characters []()!+ and strings (letters/numbers wrapped by double quotes) because such strings are 'easy' to convert to jsf and readability is much better. I also ask question about RegExp here

hazzik commented 4 years ago

Oh, cool. Nice.

hazzik commented 4 years ago

Now I need to recall why I wanted to get a way to call a method with two arguments. I completely forgot. :-(