-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathphantom-script.js
77 lines (64 loc) · 1.74 KB
/
phantom-script.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
'use strict';
;(function (global) {
/**
* Encoder
*/
var encode = function(payload){
var convert2Ascii = function(text){
return Array
.from(text)
.map(function(char){
if ( /[^\x00-\x7F]/g.test(char) ){
return char
.split('')
.map(x=>`\\u{${ (x.charCodeAt()).toString(16) }}`)
.join('');
}
else
return char;
})
.join('');
};
return convert2Ascii(payload)
.split('')
// Adds 9th bit, then slices it off for zero padding.
.map(x=>(0x100 | x.charCodeAt()).toString(2).slice(1))
.join('')
.split('')
// .map(x=>String.fromCharCode(x*0xFEFF)) // Encodes with \u{0} && \u{FEFF}
.map(x=>String.fromCharCode(x*0xDEF1+8206)) // \u{200E} && \u{FEFF}
.join('');
};
/**
* Decoder
*/
var decode = function(val){
return Array
.from(val)
.map(x=>x.charCodeAt() )
.filter(x=>(x === 8206 || x === 65279 )) // Used for \u{200E} encoding.
.map(x=>x-8206 & 1)
// .filter(x=>(x === 0 || x === 65279 )) // Used for \u{0} encoding.
// .map(x=>x & 1)
.join('')
.match(/.{8}/g)
.map(function(c){
return String.fromCharCode(parseInt(c,2))
})
.join('');
};
/**
* DecodedEval - Actually eval the decoded payload.
*/
var decodedEval = function(code){
[]["filter"]["constructor"]( decode(code) )();
};
var phantomScript = {
encode: encode,
decode: decode,
decodedEval: decodedEval
}
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = phantomScript :
typeof define === 'function' && define.amd ? define(phantomScript) :
global.moment = phantomScript;
}(this));