Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invalid typings for options #46

Closed
relative opened this issue Dec 14, 2022 · 2 comments
Closed

invalid typings for options #46

relative opened this issue Dec 14, 2022 · 2 comments

Comments

@relative
Copy link

relative commented Dec 14, 2022

Type defs:

js-confuser/src/options.ts

Lines 456 to 605 in 64a5f6a

lock?: {
/**
* ### `lock.selfDefending`
*
* Prevents the use of code beautifiers or formatters against your code.
*
* [Identical to Obfuscator.io's Self Defending](https://github.com/javascript-obfuscator/javascript-obfuscator#selfdefending)
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
selfDefending?: boolean;
/**
* ### `lock.antiDebug`
*
* Adds `debugger` statements throughout the code. Additionally adds a background function for DevTools detection. (`true/false/0-1`)
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
antiDebug?: ProbabilityMap<boolean>;
/**
* ### `lock.context`
*
* Properties that must be present on the `window` object (or `global` for NodeJS). (`string[]`)
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
context?: string[];
/**
* ### `lock.nativeFunctions`
*
* Set of global functions that are native. Such as `require`, `fetch`. If these variables are modified the program crashes.
* Set to `true` to use the default set of native functions. (`string[]/true/false`)
*
* - Potency Low
* - Resilience Medium
* - Cost Medium
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
nativeFunctions?: string[] | Set<string> | boolean;
/**
* ### `lock.startDate`
*
* When the program is first able to be used. (`number` or `Date`)
*
* Number should be in milliseconds.
*
* - Potency Low
* - Resilience Medium
* - Cost Medium
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
startDate?: number | Date | false;
/**
* ### `lock.endDate`
*
* When the program is no longer able to be used. (`number` or `Date`)
*
* Number should be in milliseconds.
*
* - Potency Low
* - Resilience Medium
* - Cost Medium
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
endDate?: number | Date | false;
/**
* ### `lock.domainLock`
* Array of regex strings that the `window.location.href` must follow. (`Regex[]` or `string[]`)
*
* - Potency Low
* - Resilience Medium
* - Cost Medium
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
domainLock?: RegExp[] | string[] | false;
/**
* ### `lock.osLock`
* Array of operating-systems where the script is allowed to run. (`string[]`)
*
* - Potency Low
* - Resilience Medium
* - Cost Medium
*
* Allowed values: `"linux"`, `"windows"`, `"osx"`, `"android"`, `"ios"`
*
* Example: `["linux", "windows"]`
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
osLock?: ("linux" | "windows" | "osx" | "android" | "ios")[] | false;
/**
* ### `lock.browserLock`
* Array of browsers where the script is allowed to run. (`string[]`)
*
* - Potency Low
* - Resilience Medium
* - Cost Medium
*
* Allowed values: `"firefox"`, `"chrome"`, `"iexplorer"`, `"edge"`, `"safari"`, `"opera"`
*
* Example: `["firefox", "chrome"]`
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
browserLock?:
| ("firefox" | "chrome" | "iexplorer" | "edge" | "safari" | "opera")[]
| false;
/**
* ### `lock.integrity`
*
* Integrity ensures the source code is unchanged. (`true/false/0-1`)
*
* [Learn more here](https://github.com/MichaelXF/js-confuser/blob/master/Integrity.md).
*
* - Potency Medium
* - Resilience High
* - Cost High
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
integrity?: ProbabilityMap<boolean>;
/**
* ### `lock.countermeasures`
*
* A custom callback function to invoke when a lock is triggered. (`string/false`)
*
* This could be due to an invalid domain, incorrect time, or code's integrity changed.
*
* [Learn more about the rules of your countermeasures function](https://github.com/MichaelXF/js-confuser/blob/master/Countermeasures.md).
*
* Otherwise, the obfuscator falls back to crashing the process.
*
* [See all settings here](https://github.com/MichaelXF/js-confuser/blob/master/README.md#options)
*/
countermeasures?: string | boolean;
};

Assertion stmts:

js-confuser/src/options.ts

Lines 772 to 823 in 64a5f6a

// Validate browser-lock option
if (typeof options.lock.browserLock !== "undefined") {
ok(
Array.isArray(options.lock.browserLock),
"browserLock must be an array"
);
ok(
!options.lock.browserLock.find(
(browserName) => !validBrowsers.has(browserName)
),
'Invalid browser name. Allowed: "firefox", "chrome", "iexplorer", "edge", "safari", "opera"'
);
}
// Validate os-lock option
if (typeof options.lock.osLock !== "undefined") {
ok(Array.isArray(options.lock.osLock), "osLock must be an array");
ok(
!options.lock.osLock.find((osName) => !validOses.has(osName)),
'Invalid OS name. Allowed: "windows", "linux", "osx", "ios", "android"'
);
}
// Validate domain-lock option
if (typeof options.lock.domainLock !== "undefined") {
ok(Array.isArray(options.lock.domainLock), "domainLock must be an array");
}
// Validate context option
if (typeof options.lock.context !== "undefined") {
ok(Array.isArray(options.lock.context), "context must be an array");
}
// Validate start-date option
if (
typeof options.lock.startDate !== "undefined" &&
options.lock.startDate
) {
ok(
typeof options.lock.startDate === "number" ||
options.lock.startDate instanceof Date,
"startDate must be Date object or number"
);
}
// Validate end-date option
if (typeof options.lock.endDate !== "undefined" && options.lock.endDate) {
ok(
typeof options.lock.endDate === "number" ||
options.lock.endDate instanceof Date,
"endDate must be Date object or number"
);
}
}

booleans (or false) are specified as valid values for some of the keys in the typedefs however there are assertion statements that will error out when it doesn't receive anything other than an array.

@relative
Copy link
Author

is this wontfix ?

@MichaelXF
Copy link
Owner

No it will be fixed next update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants