-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew.js
90 lines (77 loc) · 2.57 KB
/
new.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
constructor:
"[object Object]"[!+[] + !![] + !![] + !![] + !![]] + "[object Object]"[+!![]] + ([][
[]
] + [])[+!![]] + (![] + [])[!+[] + !![] + !![]] + (!![] + [])[+[]] + (!![] + [])[+!![]] + ([][
[]
] + [])[+[]] + "[object Object]"[!+[] + !![] + !![] + !![] + !![]] + (!![] + [])[+[]] + "[object Object]"[+!![]] + (!![] + [])[+!![]]
*/
const window_ = '([]+[])[({}+[])[6]]+[]'
const object_ = '({}+[])' //[object Object]
const undefined_ = '([][[]]+[])' //undefined
const true_ = '(!![]+{})' //true
const false_ = '(![]+{})' //false
const sort = "(![]+[])[!+[]+!![]+!![]]+([]+{})[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]"
const constructor = "({}+[])[!+[]+!![]+!![]+!![]+!![]]+({}+[])[+!![]]+([][[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][[]]+[])[+[]]+({}+[])[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+({}+[])[+!![]]+(!![]+[])[+!![]]"
const convertNumber = number => {
return new Array(number).fill("~~!+[]").join("+")
}
const exec = command => `([]+[])[${charConvert("e")}](${command})`
const ascii = code => {
if (typeof code === 'string')
return `([]+[])[${object_}[5]](${code.charCodeAt(0)})`
return `([]+[])[${object_}[5]](${code})`
}
const asciiStr = (codeArr) => {
if(!(codeArr instanceof Array)){
// string
return asciiStr(codeArr.split('').map((e, i) => codeArr.charCodeAt(i)))
}
return codeArr.map(e => ascii(e)).join("+")
}
// const string = `${asciiStr("String")}`
const chars = {
'a' : `${false_}[1]`,
'b' : `${object_}[2]`,
'c' : `${object_}[5]`,
'd' : `${undefined_}[2]`,
'e' : `${object_}[4]`,
'f' : `${false_}[0]`,
// 'g' : `${string}[14]`,
'i' : `${undefined_}[5]`,
'j' : `${object_}[3]`,
'l' : `${false_}[2]`,
'n' : `${undefined_}[1]`,
'o' : `${object_}[1]`,
'r' : `${true_}[1]`,
's' : `${false_}[3]`,
't' : `${true_}[0]`,
'u' : `${true_}[2]`,
// 'v' : `${string}[25]`,
// 'w' : `(${window_})[13]`,
' ' : `${object_}[7]`,
// 'S' : `${string}[9]`,
}
const charConvert = str => {
let ret = []
for(c of str){
if (!(c in chars) || chars[c] === ''){
ret.push(ascii(c))
continue
}
ret.push(chars[c])
}
return ret.join("+")
}
const windowObj = `([]+[])[${chars['t']}]`
const execEscape = char => `${windowObj}[${charConvert('escape')}](${char})`
const execUnescape = char => `${windowObj}[${charConvert('unescape')}](${char})`
module.exports = {
execEscape,
execUnescape,
charConvert,
convertNumber,
exec
}
// console.log(exec(charConvert(`console.log("hello, world!")`)));
// console.log(exec(charConvert(`console.log("%cI am running behide you", "color: red")`)));