-
Notifications
You must be signed in to change notification settings - Fork 39
/
index.js
119 lines (104 loc) · 3.56 KB
/
index.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
'use strict';
var gutil = require('gulp-util');
var replace = require('gulp-regex-replace');
function convertVar(nameHash, prefix, v) {
for (var key in nameHash) {
if (key == v) {
return nameHash[v];
}
}
var name = prefix + (Object.keys(nameHash).length + gulpObfuscate.seed);
nameHash[v] = name;
if (gulpObfuscate.debug) {
gutil.log('gulp-obfuscate (converting): ' + name + ' <-> ' + v );
}
return name;
}
var gulpObfuscate = function(options) {
if (options == void 0) { options = {}; }
if (options.exclude == void 0) {
options.exclude = [];
}
if(!(options.exclude instanceof Array)) {
options.exclude = [options.exclude];
}
gulpObfuscate.defaultExclude.forEach(function(element) {
options.exclude.push(element);
});
if (options.replaceMethod == void 0) {
options.replaceMethod = gulpObfuscate.LOOK_OF_DISAPPROVAL;
}
var replaceStr;
switch(options.replaceMethod) {
case gulpObfuscate.ZALGO:
replaceStr = 'H͇̬͔̳̖̅̒ͥͧẸ̖͇͈͍̱̭̌͂͆͊_C͈OM̱̈́͛̈ͩ͐͊ͦEͨ̓̐S̬̘͍͕͔͊̆̑̈́̅';
break;
default:
case gulpObfuscate.LOOK_OF_DISAPPROVAL:
replaceStr = 'ಠ_ಠ';
break;
}
return replace([
{
'regex': [ 'var (.*?[\.;])',
{ include: '([a-zA-Z\__$][0-9a-zA-Z\__$]*?)[(, =;]',
exclude: '=[ ]*?([a-zA-Z\__$][0-9a-zA-Z\__$]*?)[(, =;]',
} ],
'replace': function(input) {
return convertVar(gulpObfuscate.nameHash, replaceStr, input);
},
'exclude': options.exclude
},
{
'regex': 'function[ ]+([a-zA-Z\__$][0-9a-zA-Z\__$]*?)[ ]*?\\(',
'replace': function(input) {
return convertVar(gulpObfuscate.nameHash, replaceStr, input);
},
'exclude': options.exclude
},
{
'regex': '\\.([a-zA-Z\__$][0-9a-zA-Z\__$]*?)[ ]*?\\=(?!=)',
'replace': function(input) {
return convertVar(gulpObfuscate.nameHash, replaceStr, input);
},
'exclude': options.exclude
},
{
'regex': '([a-zA-Z\__$][0-9a-zA-Z\__$]*?):[ ]*?function',
'replace': function(input) {
return convertVar(gulpObfuscate.nameHash, replaceStr, input);
},
'exclude': options.exclude
},
{
'regex': [ '\\((.*?[\)])[ ]*?{',
'([a-zA-Z\__$][0-9a-zA-Z\__$]*?)[ ]*?[),]'
],
'replace': function(input) {
return convertVar(gulpObfuscate.nameHash, replaceStr, input);
},
'exclude': options.exclude
},
]);
};
gulpObfuscate.init = function() {
gulpObfuscate.debug = false;
gulpObfuscate.ZALGO = 0;
gulpObfuscate.LOOK_OF_DISAPPROVAL = 1;
gulpObfuscate.nameHash = {};
gulpObfuscate.minSeed = 1;
gulpObfuscate.maxSeed = 999;
gulpObfuscate.defaultReplace = gulpObfuscate.LOOK_OF_DISAPPROVAL;
gulpObfuscate.defaultExclude = [
'break', 'case', 'catch', 'continue', 'debugger', 'default', 'delete',
'do', 'else', 'finally', 'for', 'function', 'if', 'in', 'instanceof',
'new', 'return', 'switch', 'this', 'throw', 'try', 'typeof', 'var',
'void', 'while', 'with', 'prototype', 'null', 'true', 'false',
'undefined', 'NaN', 'Infinity', 'ಠ_ಠ', 'H͇̬͔̳̖̅̒ͥͧẸ̖͇͈͍̱̭̌͂͆͊_C͈OM̱̈́͛̈ͩ͐͊ͦEͨ̓̐S̬̘͍͕͔͊̆̑̈́̅', 'each', 'forEach'
];
gulpObfuscate.seed = Math.floor(Math.random() *
(gulpObfuscate.maxSeed - gulpObfuscate.minSeed + 1))
+ gulpObfuscate.minSeed;
};
gulpObfuscate.init();
module.exports = gulpObfuscate;