What are JavaScript's builtin strings?

前端 未结 7 575
情歌与酒
情歌与酒 2020-11-28 00:52

this question is difficult to summarize in a question title

UPDATE I created a JSFiddle that builds an obfuscated string out of your input

7条回答
  •  我在风中等你
    2020-11-28 01:06

    Here's the part that generates the n/v:

    ([]+/-/[(!!1+[])[1>>1]+(!!1+[])[1<<1^1]+(!1+[])[1|1<<1]+(!!1+[])[1^1]])[1^11<<1]
    

    In Firefox, ([]+/-/[(!!1+[])[1>>1]+(!!1+[])[1<<1^1]+(!1+[])[1|1<<1]+(!!1+[])[1^1]]) evaluates to

    "function test() {
        [native code]
    }"
    

    while in Chrome it is

    "function test() { [native code] }"
    

    1^11<<1 equals 23. So due to Firefox's extra whitespace, this isn't quite enough to get to the 'v', and is instead 'n'.

    And this is why you shouldn't rely on Function#toString behavior. ;)

    EDIT: Finally I found a reasonably obfuscated cross-browser version:

    [[]+1/!1][1^1][1>>1]+({}+[])[1<<1^11>>1]+([]+!!-[])[1<<1]+[/~/+{}][+!1][-~1<<1]+([]+/-/[(!!1+[])[1>>1]+(!!1+[])[1<<1^1]+(!1+[])[1|1<<1]+(!!1+[])[1^1]])[(1^11<<1)+(parseInt("010")<10?(1+1+1+1):0)]+([,][~1]+[])[1-~1]+[[]+{}][!1.1%1][11111.1%11.1*111e11|!1]+(/1/+1/[1<1][1%1])[1^11]+[[],[]+{}][1][+1]+(/<

    This replaces the n/v section with:

    ([]+/-/[(!!1+[])[1>>1]+(!!1+[])[1<<1^1]+(!1+[])[1|1<<1]+(!!1+[])[1^1]])[(1^11<<1)+(parseInt("010")<10?(1+1+1+1):0)]
    

    which exploits differences in parseInt (apparently Firefox parses numbers starting with 0 as octal, while Chrome doesn't) to add 4 in Firefox's case, thus getting 'v' from 'native' in both cases (I can't find another 'v' :P).
    The parseInt looks a little out of place, but that's the best I can do for now.

提交回复
热议问题