Skip to content

Commit e8e92c6

Browse files
authored
debugProtectionInteraval option now accepts value in milliseconds instead of boolean value (javascript-obfuscator#1063)
1 parent 30ba697 commit e8e92c6

File tree

21 files changed

+152
-35
lines changed

21 files changed

+152
-35
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Change Log
22

3+
v4.0.0
4+
---
5+
* **Breaking change:** `debugProtectionInteraval` option now accepts value in milliseconds instead of `boolean` value. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1031
6+
37
v3.2.7
48
---
59
* Fixed cases when dead code is added to the inner code of `eval` expressions. Fixed https://github.com/javascript-obfuscator/javascript-obfuscator/issues/1053

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ Following options are available for the JS Obfuscator:
349349
deadCodeInjection: false,
350350
deadCodeInjectionThreshold: 0.4,
351351
debugProtection: false,
352-
debugProtectionInterval: false,
352+
debugProtectionInterval: 0,
353353
disableConsoleOutput: false,
354354
domainLock: [],
355355
domainLockRedirectUrl: 'about:blank',
@@ -413,7 +413,7 @@ Following options are available for the JS Obfuscator:
413413
--dead-code-injection <boolean>
414414
--dead-code-injection-threshold <number>
415415
--debug-protection <boolean>
416-
--debug-protection-interval <boolean>
416+
--debug-protection-interval <number>
417417
--disable-console-output <boolean>
418418
--domain-lock '<list>' (comma separated)
419419
--domain-lock-redirect-url <string>
@@ -678,11 +678,11 @@ Type: `boolean` Default: `false`
678678
This option makes it almost impossible to use the `debugger` function of the Developer Tools (both on WebKit-based and Mozilla Firefox).
679679

680680
### `debugProtectionInterval`
681-
Type: `boolean` Default: `false`
681+
Type: `number` Default: `0`
682682

683683
##### :warning: Can freeze your browser! Use at own risk.
684684

685-
If checked, an interval is used to force the debug mode on the Console tab, making it harder to use other features of the Developer Tools. Works if [`debugProtection`](#debugprotection) is enabled.
685+
If set, an interval in milliseconds is used to force the debug mode on the Console tab, making it harder to use other features of the Developer Tools. Works if [`debugProtection`](#debugprotection) is enabled. Recommended value is between `2000` and `4000` milliseconds.
686686

687687
### `disableConsoleOutput`
688688
Type: `boolean` Default: `false`
@@ -1507,7 +1507,7 @@ The performance will be much slower than without obfuscation
15071507
deadCodeInjection: true,
15081508
deadCodeInjectionThreshold: 1,
15091509
debugProtection: true,
1510-
debugProtectionInterval: true,
1510+
debugProtectionInterval: 4000,
15111511
disableConsoleOutput: true,
15121512
identifierNamesGenerator: 'hexadecimal',
15131513
log: false,
@@ -1545,7 +1545,7 @@ The performance will be slower than without obfuscation
15451545
deadCodeInjection: true,
15461546
deadCodeInjectionThreshold: 0.4,
15471547
debugProtection: false,
1548-
debugProtectionInterval: false,
1548+
debugProtectionInterval: 0,
15491549
disableConsoleOutput: true,
15501550
identifierNamesGenerator: 'hexadecimal',
15511551
log: false,
@@ -1582,7 +1582,7 @@ The performance will be at a relatively normal level
15821582
controlFlowFlattening: false,
15831583
deadCodeInjection: false,
15841584
debugProtection: false,
1585-
debugProtectionInterval: false,
1585+
debugProtectionInterval: 0,
15861586
disableConsoleOutput: true,
15871587
identifierNamesGenerator: 'hexadecimal',
15881588
log: false,
@@ -1614,7 +1614,7 @@ The performance will be at a relatively normal level
16141614
controlFlowFlattening: false,
16151615
deadCodeInjection: false,
16161616
debugProtection: false,
1617-
debugProtectionInterval: false,
1617+
debugProtectionInterval: 0,
16181618
disableConsoleOutput: false,
16191619
identifierNamesGenerator: 'hexadecimal',
16201620
log: false,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "javascript-obfuscator",
3-
"version": "3.2.7",
3+
"version": "4.0.0",
44
"description": "JavaScript obfuscator",
55
"keywords": [
66
"obfuscator",

src/cli/JavaScriptObfuscatorCLI.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ export class JavaScriptObfuscatorCLI implements IInitializable {
223223
BooleanSanitizer
224224
)
225225
.option(
226-
'--debug-protection-interval <boolean>',
227-
'Disable browser Debug panel even after page was loaded (can cause DevTools enabled browser freeze)',
228-
BooleanSanitizer
226+
'--debug-protection-interval <number>',
227+
'Sets interval in milliseconds for debug protection so it is working even after page was loaded (can cause DevTools enabled browser freeze)',
228+
parseInt
229229
)
230230
.option(
231231
'--disable-console-output <boolean>',

src/custom-code-helpers/debug-protection/DebugProtectionFunctionIntervalCodeHelper.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import { ICustomCodeHelperObfuscator } from '../../interfaces/custom-code-helper
99
import { IOptions } from '../../interfaces/options/IOptions';
1010
import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator';
1111

12+
import { ObfuscationTarget } from '../../enums/ObfuscationTarget';
13+
1214
import { initializable } from '../../decorators/Initializable';
1315

1416
import { DebugProtectionFunctionIntervalTemplate } from './templates/debug-protection-function-interval/DebugProtectionFunctionIntervalTemplate';
17+
import { GlobalVariableNoEvalTemplate } from '../common/templates/GlobalVariableNoEvalTemplate';
1518

1619
import { AbstractCustomCodeHelper } from '../AbstractCustomCodeHelper';
1720
import { NodeUtils } from '../../node/NodeUtils';
@@ -24,6 +27,12 @@ export class DebugProtectionFunctionIntervalCodeHelper extends AbstractCustomCod
2427
@initializable()
2528
private debugProtectionFunctionName!: string;
2629

30+
/**
31+
* @type {number}
32+
*/
33+
@initializable()
34+
private debugProtectionInterval!: number;
35+
2736
/**
2837
* @param {TIdentifierNamesGeneratorFactory} identifierNamesGeneratorFactory
2938
* @param {ICustomCodeHelperFormatter} customCodeHelperFormatter
@@ -50,9 +59,11 @@ export class DebugProtectionFunctionIntervalCodeHelper extends AbstractCustomCod
5059

5160
/**
5261
* @param {string} debugProtectionFunctionName
62+
* @param {number} debugProtectionInterval
5363
*/
54-
public initialize (debugProtectionFunctionName: string): void {
64+
public initialize (debugProtectionFunctionName: string, debugProtectionInterval: number): void {
5565
this.debugProtectionFunctionName = debugProtectionFunctionName;
66+
this.debugProtectionInterval = debugProtectionInterval;
5667
}
5768

5869
/**
@@ -67,8 +78,14 @@ export class DebugProtectionFunctionIntervalCodeHelper extends AbstractCustomCod
6778
* @returns {string}
6879
*/
6980
protected override getCodeHelperTemplate (): string {
81+
const globalVariableTemplate: string = this.options.target !== ObfuscationTarget.BrowserNoEval
82+
? this.getGlobalVariableTemplate()
83+
: GlobalVariableNoEvalTemplate();
84+
7085
return this.customCodeHelperFormatter.formatTemplate(DebugProtectionFunctionIntervalTemplate(), {
71-
debugProtectionFunctionName: this.debugProtectionFunctionName
86+
debugProtectionFunctionName: this.debugProtectionFunctionName,
87+
debugProtectionInterval: this.debugProtectionInterval,
88+
globalVariableTemplate
7289
});
7390
}
7491
}

src/custom-code-helpers/debug-protection/group/DebugProtectionCodeHelperGroup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class DebugProtectionCodeHelperGroup extends AbstractCustomCodeHelperGrou
124124
: nodeWithStatements.body.length;
125125
const randomIndex: number = this.randomGenerator.getRandomInteger(0, programBodyLength);
126126

127-
customCodeHelper.initialize(debugProtectionFunctionName);
127+
customCodeHelper.initialize(debugProtectionFunctionName, this.options.debugProtectionInterval);
128128

129129
NodeAppender.insertAtIndex(nodeWithStatements, customCodeHelper.getNode(), randomIndex);
130130
}

src/custom-code-helpers/debug-protection/templates/debug-protection-function-interval/DebugProtectionFunctionIntervalTemplate.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
*/
44
export function DebugProtectionFunctionIntervalTemplate (): string {
55
return `
6-
setInterval(function () {
7-
{debugProtectionFunctionName}();
8-
}, 4000);
6+
(function () {
7+
{globalVariableTemplate}
8+
9+
that.setInterval({debugProtectionFunctionName}, {debugProtectionInterval});
10+
})();
911
`;
1012
}

src/custom-code-helpers/debug-protection/templates/debug-protection-function/DebugProtectionFunctionTemplate.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export function DebugProtectionFunctionTemplate (): string {
55
return `
66
function {debugProtectionFunctionName} (ret) {
77
function debuggerProtection (counter) {
8-
98
{debuggerTemplate}
109
1110
debuggerProtection(++counter);

src/interfaces/options/IOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface IOptions {
1818
readonly deadCodeInjection: boolean;
1919
readonly deadCodeInjectionThreshold: number;
2020
readonly debugProtection: boolean;
21-
readonly debugProtectionInterval: boolean;
21+
readonly debugProtectionInterval: number;
2222
readonly disableConsoleOutput: boolean;
2323
readonly domainLock: string[];
2424
readonly domainLockRedirectUrl: string;

src/options/Options.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ export class Options implements IOptions {
112112
public readonly debugProtection!: boolean;
113113

114114
/**
115-
* @type {boolean}
115+
* @type {number}
116116
*/
117-
@IsBoolean()
118-
public readonly debugProtectionInterval!: boolean;
117+
@IsNumber()
118+
@Min(0)
119+
public readonly debugProtectionInterval!: number;
119120

120121
/**
121122
* @type {boolean}

0 commit comments

Comments
 (0)