@dacely/toildefender 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -661
- package/NOTICE.md +16 -16
- package/README.md +380 -380
- package/cli.js +168 -168
- package/defendjs.js +6 -6
- package/docs/all-modes-output.demo.js +673 -673
- package/estest.js +49 -49
- package/esutils.js +107 -107
- package/logger.js +28 -28
- package/obfuscator.js +534 -534
- package/package.json +108 -108
- package/processors/deadCode.js +62 -62
- package/processors/flattener.js +808 -808
- package/processors/health.js +55 -55
- package/processors/identifiers.js +256 -256
- package/processors/literalObfuscator.js +40 -40
- package/processors/literals.js +233 -233
- package/processors/methods.js +332 -332
- package/processors/modules.js +231 -231
- package/processors/normalizer.js +490 -490
- package/processors/numericVm.js +950 -950
- package/processors/postprocessing.js +69 -69
- package/processors/preprocessing.js +248 -248
- package/processors/scopes.js +177 -177
- package/processors/uglifier.js +25 -25
- package/processors/variables.js +185 -185
- package/toildefender.js +7 -7
- package/traverser.js +115 -115
- package/utils.js +135 -135
package/utils.js
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var assert = require("assert");
|
|
4
|
-
|
|
5
|
-
var _ = require("lodash");
|
|
6
|
-
var escodegen = require("escodegen");
|
|
7
|
-
var esprima = require("esprima");
|
|
8
|
-
|
|
9
|
-
var traverser = require("./traverser");
|
|
10
|
-
|
|
11
|
-
exports.splice = function (arr, pos, del, elems) {
|
|
12
|
-
Array.prototype.splice.apply(arr, [ pos, del ].concat(elems));
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.unshift = function (arr, arr2) {
|
|
16
|
-
if (Array.isArray(arr2)) {
|
|
17
|
-
Array.prototype.unshift(arr, arr2);
|
|
18
|
-
} else {
|
|
19
|
-
arr.push(arr2);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
exports.push = function (arr, arr2) {
|
|
24
|
-
if (Array.isArray(arr2)) {
|
|
25
|
-
Array.prototype.push.apply(arr, arr2);
|
|
26
|
-
} else {
|
|
27
|
-
arr.push(arr2);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
exports.array = function (obj) {
|
|
32
|
-
return Array.isArray(obj) ? obj : [ obj ];
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
exports.cloneISwearIKnowWhatImDoing = function (obj) {
|
|
36
|
-
return JSON.parse(JSON.stringify(obj));
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Generate a random number.
|
|
41
|
-
* @param {number} Inclusive minimum
|
|
42
|
-
* @param {number} Inclusive maximum
|
|
43
|
-
* @returns {number}
|
|
44
|
-
*/
|
|
45
|
-
exports.random = function (minimum, maximum) {
|
|
46
|
-
return Math.floor(Math.random() * (maximum - minimum)) + minimum;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
exports.randomAlpha = function (length) {
|
|
50
|
-
var text = "";
|
|
51
|
-
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
52
|
-
|
|
53
|
-
for (var i=0; i < length; i++) {
|
|
54
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return text;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
exports.isResolvedReference = function (reference) {
|
|
61
|
-
return reference.resolved != null
|
|
62
|
-
&& reference.resolved.defs != null
|
|
63
|
-
&& reference.resolved.defs.length > 0;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
exports.UniqueRandom = function(max) {
|
|
67
|
-
assert(typeof max == "number");
|
|
68
|
-
if (max > 32768) {
|
|
69
|
-
console.warn(`Allocating large (${max}) UniqueRandom instance`);
|
|
70
|
-
}
|
|
71
|
-
var arr = _.shuffle(_.range(max));
|
|
72
|
-
var idx = 0;
|
|
73
|
-
|
|
74
|
-
this.get = function() {
|
|
75
|
-
if (idx < max) {
|
|
76
|
-
return arr[idx++];
|
|
77
|
-
} else {
|
|
78
|
-
throw new Error("No numbers left");
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
exports.UniqueRandomAlpha = function (len) {
|
|
84
|
-
assert(typeof len == "number");
|
|
85
|
-
var offset = Math.pow(32, len - 1);
|
|
86
|
-
var rng = new exports.UniqueRandom(offset * 31);
|
|
87
|
-
|
|
88
|
-
this.get = function() {
|
|
89
|
-
return (offset + rng.get()).toString(32);
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
exports.HashMap = function () {
|
|
94
|
-
var store = {};
|
|
95
|
-
|
|
96
|
-
this.get = function (key) {
|
|
97
|
-
return store["HashMap" + key];
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
this.set = function (key, value) {
|
|
101
|
-
return store["HashMap" + key] = value;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
this.exists = function (key) {
|
|
105
|
-
return store["HashMap" + key] !== undefined;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
this.remove = function (key) {
|
|
109
|
-
delete store["HashMap" + key];
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
exports.hash = function (obj) {
|
|
114
|
-
if (obj == null) {
|
|
115
|
-
return "x";
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (typeof obj == "string") {
|
|
119
|
-
return "s" + obj;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (typeof obj == "number") {
|
|
123
|
-
return "n" + obj.toString();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (!obj.$$hash) {
|
|
127
|
-
Object.defineProperty(obj, "$$hash", {
|
|
128
|
-
configurable: false,
|
|
129
|
-
enumerable: false,
|
|
130
|
-
value: "o" + exports.randomAlpha(8)
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return obj.$$hash;
|
|
135
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var assert = require("assert");
|
|
4
|
+
|
|
5
|
+
var _ = require("lodash");
|
|
6
|
+
var escodegen = require("escodegen");
|
|
7
|
+
var esprima = require("esprima");
|
|
8
|
+
|
|
9
|
+
var traverser = require("./traverser");
|
|
10
|
+
|
|
11
|
+
exports.splice = function (arr, pos, del, elems) {
|
|
12
|
+
Array.prototype.splice.apply(arr, [ pos, del ].concat(elems));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.unshift = function (arr, arr2) {
|
|
16
|
+
if (Array.isArray(arr2)) {
|
|
17
|
+
Array.prototype.unshift(arr, arr2);
|
|
18
|
+
} else {
|
|
19
|
+
arr.push(arr2);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.push = function (arr, arr2) {
|
|
24
|
+
if (Array.isArray(arr2)) {
|
|
25
|
+
Array.prototype.push.apply(arr, arr2);
|
|
26
|
+
} else {
|
|
27
|
+
arr.push(arr2);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.array = function (obj) {
|
|
32
|
+
return Array.isArray(obj) ? obj : [ obj ];
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.cloneISwearIKnowWhatImDoing = function (obj) {
|
|
36
|
+
return JSON.parse(JSON.stringify(obj));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Generate a random number.
|
|
41
|
+
* @param {number} Inclusive minimum
|
|
42
|
+
* @param {number} Inclusive maximum
|
|
43
|
+
* @returns {number}
|
|
44
|
+
*/
|
|
45
|
+
exports.random = function (minimum, maximum) {
|
|
46
|
+
return Math.floor(Math.random() * (maximum - minimum)) + minimum;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
exports.randomAlpha = function (length) {
|
|
50
|
+
var text = "";
|
|
51
|
+
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
52
|
+
|
|
53
|
+
for (var i=0; i < length; i++) {
|
|
54
|
+
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return text;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
exports.isResolvedReference = function (reference) {
|
|
61
|
+
return reference.resolved != null
|
|
62
|
+
&& reference.resolved.defs != null
|
|
63
|
+
&& reference.resolved.defs.length > 0;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
exports.UniqueRandom = function(max) {
|
|
67
|
+
assert(typeof max == "number");
|
|
68
|
+
if (max > 32768) {
|
|
69
|
+
console.warn(`Allocating large (${max}) UniqueRandom instance`);
|
|
70
|
+
}
|
|
71
|
+
var arr = _.shuffle(_.range(max));
|
|
72
|
+
var idx = 0;
|
|
73
|
+
|
|
74
|
+
this.get = function() {
|
|
75
|
+
if (idx < max) {
|
|
76
|
+
return arr[idx++];
|
|
77
|
+
} else {
|
|
78
|
+
throw new Error("No numbers left");
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.UniqueRandomAlpha = function (len) {
|
|
84
|
+
assert(typeof len == "number");
|
|
85
|
+
var offset = Math.pow(32, len - 1);
|
|
86
|
+
var rng = new exports.UniqueRandom(offset * 31);
|
|
87
|
+
|
|
88
|
+
this.get = function() {
|
|
89
|
+
return (offset + rng.get()).toString(32);
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
exports.HashMap = function () {
|
|
94
|
+
var store = {};
|
|
95
|
+
|
|
96
|
+
this.get = function (key) {
|
|
97
|
+
return store["HashMap" + key];
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
this.set = function (key, value) {
|
|
101
|
+
return store["HashMap" + key] = value;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
this.exists = function (key) {
|
|
105
|
+
return store["HashMap" + key] !== undefined;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
this.remove = function (key) {
|
|
109
|
+
delete store["HashMap" + key];
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
exports.hash = function (obj) {
|
|
114
|
+
if (obj == null) {
|
|
115
|
+
return "x";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (typeof obj == "string") {
|
|
119
|
+
return "s" + obj;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (typeof obj == "number") {
|
|
123
|
+
return "n" + obj.toString();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (!obj.$$hash) {
|
|
127
|
+
Object.defineProperty(obj, "$$hash", {
|
|
128
|
+
configurable: false,
|
|
129
|
+
enumerable: false,
|
|
130
|
+
value: "o" + exports.randomAlpha(8)
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return obj.$$hash;
|
|
135
|
+
};
|