Re:Get any a-Z char using only []()+{}/. in JavaScript (for ...
by eel on Friday February 26, 2010 @01:10PM
(#1153704)
Wow - how does this work? Does anyone know or have a link to a place that might explain this?
[ Parent
| on HN ]
Re:Get any a-Z char using only []()+{}/. in JavaScript (for ...
by there on Friday February 26, 2010 @01:20PM
(#1153727)
it is basically various ways of making javascript return things like "NaN", "undefined", or "false", and then using a numbered index to return a particular character of that word after it is converted to a string.
so "NaN"[1] would be "a". "false"[0] would be "f".
since they are trying to do it without numbers, they can create them using things like "++[[]][+[]]" which returns a 1. by adding up different numbers you can get the digits you need.
Re:Get any a-Z char using only []()+{}/. in JavaScript (for ...
by est on Friday February 26, 2010 @01:29PM
(#1153754)
Making strings out of nothing is hard, but how did they managed to execute that string out of nothing?
Re:Get any a-Z char using only []()+{}/. in JavaScript (for ...
by tptacek on Friday February 26, 2010 @01:36PM
(#1153775)
By deriving an eval-equivalent and indexing [] (read the comments).
Re:Get any a-Z char using only []()+{}/. in JavaScript (for ...
by est on Friday February 26, 2010 @01:49PM
(#1153807)
Yes, I know how to make "eval", but how could it convert "eval" to eval() ?
Edit: by using []["sort"]["call"]()["eval"]
Re:Get any a-Z char using only []()+{}/. in JavaScript (for ...
by lisper on Friday February 26, 2010 @02:59PM
(#1153977)
Yes, but why does that work? I don't get:
+[]
or
[]['sort']
or
[]['eval']
for that matter, why does []['sort']['call'] work but []['call'] doesn't.
All of these look like they should be syntax errors to me. What am I missing?
Re:Get any a-Z char using only []()+{}/. in JavaScript (for ...
by aston on Friday February 26, 2010 @03:24PM
(#1154022)
Here's the breakdown:
[]["sort"]["call"]()["eval"]
is the same in javascript as ([].sort.call()).eval
The part in parentheses calls Array.sort with an undefined this object, defaulting it to window. Array.sort returns this after it's done. Global functions like eval are stored on window, so you end up with window.eval.
Re:Get any a-Z char using only []()+{}/. in JavaScript (for ...
by lisper on Friday February 26, 2010 @04:04PM
(#1154123)
Ah. Thanks!
Re:Get any a-Z char using only []()+{}/. in JavaScript (for ...
by tptacek on Friday February 26, 2010 @03:02PM
(#1153985)
Because [] doesn't have a 'call' attribute, but does have 'sort' attribute (remember that Javascript has a funky object notation, which is why people have to do elaborate dances to iterate over objects), and because the 'sort' attribute of [] itself is an object with a 'call' attribute.