什么是JavaScript的内置字符串? [英] What are JavaScript's builtin strings?

查看:129
本文介绍了什么是JavaScript的内置字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题很难在问题标题中总结

更新
我创建了一个JSFiddle根据从这个问题中提取的字母从输入中构建一个混淆的字符串:你可以访问它这里,或要点会更容易吗?

我最近在此个人资料中遇到了一些有趣的混淆JavaScript,如下所示:

I recently came across a fun bit of obfuscated JavaScript in this profile that looks like this:

javascript:[[]+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]+([,][
~1]+[])[1-~1]+[[]+{}][!1.1%1][11111.1%11.1*111e11|!1]+(/1/+
1/[1<1][1%1])[1^11]+[[],[]+{}][1][+1]+(/<</[1]+[])[1/1.1&1]

很抱歉破坏了惊喜但是当评估它时会返回此:

Sorry to ruin the surprise but when this is evaluated it returns this:

"I love you" in Chrome
"I lone you" In Firefox
"I lo[e you" in IE10

这种方法在分解时的工作方式是生成一系列消息并像这样拉出字母(以我为例):

The way this works when broken out, is to generate a series of messages and to pull letters out of them like so (using the "I" as an example):

[]+1/!1
returns
"Infinity"
then
[[]+1/!1]
creates this array:
["Infinity"]
then
[[]+1/!1][1^1]
Takes the first (1^1 == 0) element of that array
"Infinity"
finally
[[]+1/!1][1^1][1>>1]
Takes the first (1>>1 == 0) char of that string
"I"

生成的其他字符串包括:

Other strings that are generated include:

({}+[])       -> "[object Object]" (where the space comes from)
([]+!!-[])    -> "false" (used for it's "l")
[/~/+{}][+!1] -> "/~/[object Object]" (this is used for an "o")
(/<</[1]+[])  -> "undefined"

我有兴趣找到n和[的替代品并且来了以上:

I was interested in finding a replacement for the "n" and "[" and came up with this:

String.fromCharCode(('1'.charCodeAt(0)<<1)+(10<<1))

我本着使用1和0的精神感受到了,但违反了原始代码的一个更优雅的方面是与字符串完全无关的外观。有没有其他人知道如何生成与原始混淆代码保持一致的v?

Which I feel in in the spirit of using 1's and 0's, but violates one of the more elegant aspects of the original code which is the appearance of having nothing to do with strings at all. Does anyone else have an idea of how to generate a "v" that is in keeping with the original obfuscated code?

这是一些额外的信息这是在许多有才华的JavaScript程序员深入研究之后发现的

Here is some extra information that was found after many talented JavaScript programers took a deeper look at this

Firefox返回I lone you由于这一行:

Firefox returns "I lone you" Because of this line:

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

[1 ^ 11<< 1 ] 从中修剪特定字符:

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

评估为:

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

看起来我们可能有V!!!

Which looks like we might have our "V"!!!

Chrome返回我爱你,因为相同的代码会返回:

Chrome returns "I love you", because the same code returns this:

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






在关于真正的编程问题的可疑连接问题关闭之前,我想我会添加一个基于 @ Supr's @ Cory's @ alpha123的,看哪:

alert([[]+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+(1^(11+1+1)<<1)],([]+/-/[(!!1+[
])[1>>1]+(!!1+[])[1<<1^1]+(!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^(11
+1+1)<<1]][((([]+/-/[(!!1+[])[1>>1]+(!!1+[])[1<<
1^1]+(!1+[])[1|1<<1]+(!!1+[])[1^1]])[(1<<1<<1<<1
)+1<<1]==({}+[])[1^1])*1)+((([]+/-/[(!!1+[])[1>>
1]+(!!1+[])[1<<1^1]+(!1+[])[1|1<<1]+(!!1+[])[1^1
]])[(1^11<<1)-1]==({}+[])[1^1])<<1)]+([,][~1]+[]
)[1-~1]+[[]+{}][!1.1%1][11111.1%11.1*111e11|!1]+
(/1/+1/[1<1][1%1])[1^11]+[[],[]+{}][1][+1]+(/<</
[1]+[])[1/1.1&1])

鉴于代码的复杂性及其产生的消息,它几乎就像JavaScript引擎告诉你有多特别感觉:)

Given the complexity of the code and the message it produces it's almost like the JavaScript engine is telling how special you make it feel :)

推荐答案

首先,我要感谢Jason和所有贡献者玩这个有趣的片段。我已经写了那段代码只是为了好玩以便在2月14日将它发送给我的妻子:)在笔记本电脑上只安装了Chrome我无法检查它在Firefox和IE中是如何工作的。此外,我并没有真正期望内置方法的 toString()表示在其他浏览器中看起来可能有所不同。

First of all, I would like to thank Jason and all the contributors for playing with that funny snippet. I have written that piece of code just for fun in order to send it to my wife on February 14 :) Having only Chrome installed on the laptop I had no options to check how it works in Firefox and IE. Moreover, I haven't really expected that toString() representation of build-in methods might look differently in other browsers.

现在,转向真正的问题,让我们来看看代码。是的,v是真正的问题。除了解析 [native code] string之外,我没有找到其他方法来获取这封信,这可以从任何内置方法中获取。由于除了 1 之外我没有字符串和数字限制自己,我需要利用一些名称中只有可用字符的方法。

Now, moving to the real problem, let's precisely have a look at the code. Yes, "v" was the real "problem" here. I found no other ways of getting this letter except parsing [native code] string, which can be taken from any built-in method. Since I limited myself with having no strings and no numbers except 1 used, I needed to exploit some method that has only available characters in its name.

可以从现有关键字和字符串表示中获取可用字符,即从一开始我们就有 NaN null undefined Infinity true false [object Object]。其中一些可以很容易地转换为字符串,例如 1 /!1 + [] 给出Infinity

Available characters can be obtained from existing keywords and string representations, i.e. from the start we had NaN, null, undefined, Infinity, true, false, and "[object Object]". Some of them can be easily converted to strings, e.g. 1/!1+[] gives "Infinity".

我已经分析了数组的不同内置方法 [] ,对象 {} ,正则表达式 /(?:) / ,数字 1.1 ,字符串1,并发现了一个漂亮的 RegExp 对象叫做 试验() 。它的名称可以从所有可用的字符组合,例如te来自 true ,以及s来自 false 。我创建了一个字符串test并使用方括号表示法为正则表达式文字 / - / 正确地解决了这个方法在此行中标识:

I have analyzed different build-in methods for arrays [], objects {}, regular expressions /(?:)/, numbers 1.1, strings "1", and discovered one beautiful method of RegExp object called test(). Its name can be assembled from all available characters, e.g. "t" and "e" from true, and "s" from false. I have created a string "test" and addressed this method using square brackets notation for regex literal /-/, correctly identified in this line:

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

如前所述,这段代码在Chrome中评估为:

As was already discussed, this piece of code is evaluated in Chrome as:

function test() { [native code] }


$ b Firefox中的$ b

in Firefox as:

function test() {
    [native code]
}

和在IE中:

 function test() {     [native code] }  

(在后者支付特殊注意函数关键字之前的空格)

(in the latter pay special attention to the space before function keyword)

所以,正如你清楚地看到的那样,我的代码从呈现的字符串中得到了第24个字符,在Chrome中是v(按计划),但是不幸的是在Firefox和IE中 - n[分别。

So, as you clearly see, my code was getting the 24th character from the presented string, which in Chrome was "v" (as was planned), but unfortunately in Firefox and IE -- "n" and "[" respectively.

为了在所有浏览器中生成相同的输出,我使用了不同的方法,而不是其他答案中所示。现在修改后的版本看起来像这样:

In order to make the same output in all the browsers, I have used different approach than illustrated in the other answers. Now the modified version looks like that:

javascript:[[]+1/!1][1^1][1>>1]+({}+[])[1<<1^11>>1]+([]+!!-
[])[1<<1]+[/~/+{}][+!1][-~1<<1]+/\[[^1]+\]/[([]+![])[1<<1<<
1]+(/|/[(1+{})[1+11>>>1]+[[]+{}][+!1][1]+([]+1/[])[1<<1>>1]
+([1<1]+[])[1+11>>>1+1]+[[!!1]+1][+[]][1-1]+([]+!!/!/)[1|1]
+(/1/[1]+[])[!1%1]+(-{}+{})[-1+1e1-1]+(1+[!!1])[1]+([]+1+{}
)[1<<1]+[!!/!!/+[]][+[]][1&1]]+/=/)[1e1+(1<<1|1)+(([]+/-/[(
!!1+[])[1>>1]+(!!1+[])[1<<1^1]+(!1+[])[1|1<<1]+(!!1+[])[1^1
]])[1^1]==+!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][11>>>1]+([,][~1]+[])[1-~1]+[[]+{}][!
1.1%1][11111.1%11.1*111e11|!1]+(/1/+1/[1<1][1%1])[1^11]+[[]
,[]+{}][1<<1>>>1][1||1]+(/[<+>]/[1&1|1]+[1.1])[1/11.1&1.11]

然而,为了激发读者的兴趣,我不会提供解决方案。老实说,我相信你会很容易理解它是如何工作的......有些人甚至会以跨浏览器的方式惊讶他们心爱的人;)

However, in order to intrigue the readers I won't provide a solution for that. I honestly believe that you will easily understand how it works... and some can even surprise their beloved in cross-browser way ;)

受Jason创建通用混淆工具的想法的启发,我还写了一个。您可以在 JSBin: http://jsbin.com/amecoq/2 找到它。它可以混淆包含数字 [0-9] ,小拉丁字母 [a-z] 和空格的任何文本。字符串长度主要受限于你的RAM(至少我的答案的主体被成功地混淆了)。 Chrome,Firefox和IE支持输出。

Inspired by Jason's idea to create a universal obfuscating tool, I have written one more. You can find it at JSBin: http://jsbin.com/amecoq/2. It can obfuscate any text that contains numbers [0-9], small latin letters [a-z], and spaces. The string length is limited mostly with your RAM (at least the body of my answer was successfully obfuscated). The output is supported by Chrome, Firefox, and IE.

提示:该工具使用与上面介绍的不同的混淆方法。

Hint: the tool uses different obfuscation approach than was presented above.

这篇关于什么是JavaScript的内置字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆