Skip to content

Commit 51ffe59

Browse files
committed
Remove nativeFunctions option
1 parent e0c3ae6 commit 51ffe59

File tree

3 files changed

+2
-104
lines changed

3 files changed

+2
-104
lines changed

src/options.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -406,20 +406,6 @@ export interface ObfuscateOptions {
406406
*/
407407
context?: string[];
408408

409-
/**
410-
* ### `lock.nativeFunctions`
411-
*
412-
* Set of global functions that are native. Such as `require`, `fetch`. If these variables are modified the program crashes.
413-
* Set to `true` to use the default set of native functions. (`string[]/true/false`)
414-
*
415-
* - Potency Low
416-
* - Resilience Medium
417-
* - Cost Medium
418-
*
419-
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
420-
*/
421-
nativeFunctions?: string[] | Set<string> | boolean;
422-
423409
/**
424410
* ### `lock.startDate`
425411
*

src/transforms/lock/lock.ts

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ export default class Lock extends Transform {
219219
if (this.options.lock.domainLock && this.options.lock.domainLock.length) {
220220
choices.push("domainLock");
221221
}
222-
if (this.options.lock.nativeFunctions) {
223-
choices.push("nativeFunction");
224-
}
222+
225223
if (this.options.lock.context && this.options.lock.context.length) {
226224
choices.push("context");
227225
}
@@ -312,45 +310,6 @@ export default class Lock extends Transform {
312310

313311
break;
314312

315-
case "nativeFunction":
316-
var set = this.options.lock.nativeFunctions;
317-
if (set === true) {
318-
if (this.options.target == "node") {
319-
set = new Set(["Function", "String"]);
320-
} else {
321-
set = new Set(["Function", "String", "fetch"]);
322-
}
323-
}
324-
if (Array.isArray(set)) {
325-
set = new Set(set);
326-
}
327-
if (!set) {
328-
set = new Set();
329-
}
330-
331-
var fn = choice(Array.from(set));
332-
if (fn) {
333-
test = Template(
334-
`(${fn}+"").indexOf("[native code]") == -1`
335-
).single().expression;
336-
337-
if (Math.random() > 0.5) {
338-
test = Template(
339-
`${fn}.toString().split("{ [native code] }").length <= 1`
340-
).single().expression;
341-
}
342-
343-
nodes.push(
344-
IfStatement(
345-
test,
346-
this.getCounterMeasuresCode(object, parents) || [],
347-
null
348-
)
349-
);
350-
}
351-
352-
break;
353-
354313
case "startDate":
355314
test = BinaryExpression(
356315
"<",

test/transforms/lock/lock.test.ts

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ it("should work with endDate and call countermeasures function", async () => {
6464
expect(value).toStrictEqual(true);
6565
});
6666

67+
// REMOVED FEATURE:
6768
// it("strings should be encoded when startDate and endDate are given", async () => {
6869
// var startDate = await JsConfuser.obfuscate(` input("ENCODED_STRING") `, {
6970
// target: "node",
@@ -82,54 +83,6 @@ it("should work with endDate and call countermeasures function", async () => {
8283
// expect(value).toStrictEqual("ENCODED_STRING");
8384
// });
8485

85-
it("should work with nativeFunctions and call countermeasures function", async () => {
86-
var output = await JsConfuser.obfuscate(
87-
` function countermeasures(){ input(true) } `,
88-
{
89-
target: "node",
90-
lock: {
91-
nativeFunctions: ["fetch"],
92-
countermeasures: "countermeasures",
93-
},
94-
}
95-
);
96-
97-
// custom function, not "native"
98-
var fetch = () => {};
99-
100-
var value = "never_called";
101-
function input(valueIn) {
102-
value = valueIn;
103-
}
104-
105-
eval(output);
106-
expect(value).toStrictEqual(true);
107-
});
108-
109-
it("should work with nativeFunctions and not call countermeasures function when correct", async () => {
110-
var output = await JsConfuser.obfuscate(
111-
` function countermeasures(){ input(true) } `,
112-
{
113-
target: "node",
114-
lock: {
115-
nativeFunctions: ["fetch"],
116-
countermeasures: "countermeasures",
117-
},
118-
}
119-
);
120-
121-
// bound functions return the "[native code]" string
122-
var fetch = (() => {}).bind(this);
123-
124-
var value = "never_called";
125-
function input(valueIn) {
126-
value = valueIn;
127-
}
128-
129-
eval(output);
130-
expect(value).toStrictEqual("never_called");
131-
});
132-
13386
it("countermeasures function should still work even with renameVariables enabled", async () => {
13487
var output = await JsConfuser.obfuscate(
13588
` function countermeasures(){ input(true) } `,

0 commit comments

Comments
 (0)