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

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

Open
kamil-kielczewski opened this issue Aug 26, 2020 · 4 comments
Open

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

kamil-kielczewski opened this issue Aug 26, 2020 · 4 comments

Comments

@kamil-kielczewski
Copy link
Contributor

kamil-kielczewski commented Aug 26, 2020

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

hazzik commented Aug 27, 2020

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

kamil-kielczewski commented Aug 27, 2020

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

hazzik commented Aug 27, 2020

Oh, cool. Nice.

@hazzik
Copy link
Contributor

hazzik commented Aug 27, 2020

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

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