@@ -309,7 +309,61 @@ describe('BlockStatementControlFlowTransformer', function () {
309
309
} ) ;
310
310
} ) ;
311
311
312
- describe ( 'Variant #8: block statement contain while statement with break statement' , ( ) => {
312
+ describe ( 'Variant #8: block statement contain break statement #3' , ( ) => {
313
+ const statementRegExp : RegExp = / ^ \( f u n c t i o n * \( * \) * \{ * w h i l e * \( ! ! \[ \] \) * \{ * i f * \( ! ! \[ \] \) * b r e a k ; * c o n s o l e \[ ' l o g ' \] \( 0 x 1 \) ; / ;
314
+
315
+ let obfuscatedCode : string ;
316
+
317
+ before ( ( ) => {
318
+ const code : string = readFileAsString ( __dirname + '/fixtures/break-statement-3.js' ) ;
319
+
320
+ obfuscatedCode = JavaScriptObfuscator . obfuscate (
321
+ code ,
322
+ {
323
+ ...NO_ADDITIONAL_NODES_PRESET ,
324
+ controlFlowFlattening : true ,
325
+ controlFlowFlatteningThreshold : 1
326
+ }
327
+ ) . getObfuscatedCode ( ) ;
328
+ } ) ;
329
+
330
+ it ( 'shouldn\'t transform block statement' , ( ) => {
331
+ assert . match ( obfuscatedCode , statementRegExp ) ;
332
+ } ) ;
333
+ } ) ;
334
+
335
+ describe ( 'Variant #9: block statement contain while statement with break statement' , ( ) => {
336
+ const switchCaseRegExp : RegExp = / s w i t c h * \( _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } \[ _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } \+ \+ \] \) * \{ / ;
337
+ const switchCaseLengthRegExp : RegExp = / c a s e * ' [ 0 - 5 ] ' : * c o n s o l e \[ ' l o g ' \] \( 0 x [ 0 - 6 ] \) ; / g;
338
+ const expectedSwitchCaseLength : number = 5 ;
339
+
340
+ let obfuscatedCode : string ,
341
+ switchCaseLength : number ;
342
+
343
+ before ( ( ) => {
344
+ const code : string = readFileAsString ( __dirname + '/fixtures/break-statement-inside-while-statement-1.js' ) ;
345
+
346
+ obfuscatedCode = JavaScriptObfuscator . obfuscate (
347
+ code ,
348
+ {
349
+ ...NO_ADDITIONAL_NODES_PRESET ,
350
+ controlFlowFlattening : true ,
351
+ controlFlowFlatteningThreshold : 1
352
+ }
353
+ ) . getObfuscatedCode ( ) ;
354
+ switchCaseLength = obfuscatedCode . match ( switchCaseLengthRegExp ) ! . length ;
355
+ } ) ;
356
+
357
+ it ( 'should wrap block statement statements in switch-case structure' , ( ) => {
358
+ assert . match ( obfuscatedCode , switchCaseRegExp ) ;
359
+ } ) ;
360
+
361
+ it ( 'each statement should be wrapped by switch-case structure' , ( ) => {
362
+ assert . equal ( switchCaseLength , expectedSwitchCaseLength ) ;
363
+ } ) ;
364
+ } ) ;
365
+
366
+ describe ( 'Variant #10: block statement contain while statement with break statement' , ( ) => {
313
367
const switchCaseRegExp : RegExp = / s w i t c h * \( _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } \[ _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } \+ \+ \] \) * \{ / ;
314
368
const switchCaseLengthRegExp : RegExp = / c a s e * ' [ 0 - 5 ] ' : * c o n s o l e \[ ' l o g ' \] \( 0 x [ 0 - 6 ] \) ; / g;
315
369
const expectedSwitchCaseLength : number = 5 ;
@@ -318,7 +372,7 @@ describe('BlockStatementControlFlowTransformer', function () {
318
372
switchCaseLength : number ;
319
373
320
374
before ( ( ) => {
321
- const code : string = readFileAsString ( __dirname + '/fixtures/break-statement-inside-while-statement.js' ) ;
375
+ const code : string = readFileAsString ( __dirname + '/fixtures/break-statement-inside-while-statement-2 .js' ) ;
322
376
323
377
obfuscatedCode = JavaScriptObfuscator . obfuscate (
324
378
code ,
@@ -340,7 +394,7 @@ describe('BlockStatementControlFlowTransformer', function () {
340
394
} ) ;
341
395
} ) ;
342
396
343
- describe ( 'Variant #9 : block statement contain continue statement #1' , ( ) => {
397
+ describe ( 'Variant #11 : block statement contain continue statement #1' , ( ) => {
344
398
const statementRegExp : RegExp = / ^ \( f u n c t i o n * \( * \) * \{ * w h i l e * \( ! ! \[ \] \) * \{ * c o n t i n u e ; * c o n s o l e \[ ' l o g ' \] \( 0 x 1 \) ; / ;
345
399
346
400
let obfuscatedCode : string ;
@@ -363,7 +417,7 @@ describe('BlockStatementControlFlowTransformer', function () {
363
417
} ) ;
364
418
} ) ;
365
419
366
- describe ( 'Variant #10 : block statement contain continue statement #2' , ( ) => {
420
+ describe ( 'Variant #12 : block statement contain continue statement #2' , ( ) => {
367
421
const statementRegExp : RegExp = / ^ \( f u n c t i o n * \( * \) * \{ * w h i l e * \( ! ! \[ \] \) * \{ * i f * \( ! ! \[ \] \) * \{ * c o n t i n u e ; * \} * c o n s o l e \[ ' l o g ' \] \( 0 x 1 \) ; / ;
368
422
369
423
let obfuscatedCode : string ;
@@ -386,7 +440,61 @@ describe('BlockStatementControlFlowTransformer', function () {
386
440
} ) ;
387
441
} ) ;
388
442
389
- describe ( 'Variant #11: block statement contain while statement with continue statement' , ( ) => {
443
+ describe ( 'Variant #13: block statement contain continue statement #3' , ( ) => {
444
+ const statementRegExp : RegExp = / ^ \( f u n c t i o n * \( * \) * \{ * w h i l e * \( ! ! \[ \] \) * \{ * i f * \( ! ! \[ \] \) * c o n t i n u e ; * c o n s o l e \[ ' l o g ' \] \( 0 x 1 \) ; / ;
445
+
446
+ let obfuscatedCode : string ;
447
+
448
+ before ( ( ) => {
449
+ const code : string = readFileAsString ( __dirname + '/fixtures/continue-statement-3.js' ) ;
450
+
451
+ obfuscatedCode = JavaScriptObfuscator . obfuscate (
452
+ code ,
453
+ {
454
+ ...NO_ADDITIONAL_NODES_PRESET ,
455
+ controlFlowFlattening : true ,
456
+ controlFlowFlatteningThreshold : 1
457
+ }
458
+ ) . getObfuscatedCode ( ) ;
459
+ } ) ;
460
+
461
+ it ( 'shouldn\'t transform block statement' , ( ) => {
462
+ assert . match ( obfuscatedCode , statementRegExp ) ;
463
+ } ) ;
464
+ } ) ;
465
+
466
+ describe ( 'Variant #14: block statement contain while statement with continue statement' , ( ) => {
467
+ const switchCaseRegExp : RegExp = / s w i t c h * \( _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } \[ _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } \+ \+ \] \) * \{ / ;
468
+ const switchCaseLengthRegExp : RegExp = / c a s e * ' [ 0 - 5 ] ' : * c o n s o l e \[ ' l o g ' \] \( 0 x [ 0 - 6 ] \) ; / g;
469
+ const expectedSwitchCaseLength : number = 5 ;
470
+
471
+ let obfuscatedCode : string ,
472
+ switchCaseLength : number ;
473
+
474
+ before ( ( ) => {
475
+ const code : string = readFileAsString ( __dirname + '/fixtures/continue-statement-inside-while-statement-1.js' ) ;
476
+
477
+ obfuscatedCode = JavaScriptObfuscator . obfuscate (
478
+ code ,
479
+ {
480
+ ...NO_ADDITIONAL_NODES_PRESET ,
481
+ controlFlowFlattening : true ,
482
+ controlFlowFlatteningThreshold : 1
483
+ }
484
+ ) . getObfuscatedCode ( ) ;
485
+ switchCaseLength = obfuscatedCode . match ( switchCaseLengthRegExp ) ! . length ;
486
+ } ) ;
487
+
488
+ it ( 'should wrap block statement statements in switch-case structure' , ( ) => {
489
+ assert . match ( obfuscatedCode , switchCaseRegExp ) ;
490
+ } ) ;
491
+
492
+ it ( 'each statement should be wrapped by switch-case structure' , ( ) => {
493
+ assert . equal ( switchCaseLength , expectedSwitchCaseLength ) ;
494
+ } ) ;
495
+ } ) ;
496
+
497
+ describe ( 'Variant #15: block statement contain continue statement #4' , ( ) => {
390
498
const switchCaseRegExp : RegExp = / s w i t c h * \( _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } \[ _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } \+ \+ \] \) * \{ / ;
391
499
const switchCaseLengthRegExp : RegExp = / c a s e * ' [ 0 - 5 ] ' : * c o n s o l e \[ ' l o g ' \] \( 0 x [ 0 - 6 ] \) ; / g;
392
500
const expectedSwitchCaseLength : number = 5 ;
@@ -395,7 +503,7 @@ describe('BlockStatementControlFlowTransformer', function () {
395
503
switchCaseLength : number ;
396
504
397
505
before ( ( ) => {
398
- const code : string = readFileAsString ( __dirname + '/fixtures/continue-statement-inside-while-statement.js' ) ;
506
+ const code : string = readFileAsString ( __dirname + '/fixtures/continue-statement-inside-while-statement-2 .js' ) ;
399
507
400
508
obfuscatedCode = JavaScriptObfuscator . obfuscate (
401
509
code ,
@@ -417,7 +525,7 @@ describe('BlockStatementControlFlowTransformer', function () {
417
525
} ) ;
418
526
} ) ;
419
527
420
- describe ( 'Variant #12 : block statement contain function declaration' , ( ) => {
528
+ describe ( 'Variant #16 : block statement contain function declaration' , ( ) => {
421
529
const statementRegExp : RegExp = / ^ \( f u n c t i o n * \( * \) * \{ * f u n c t i o n * _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } * \( * \) * \{ * \} * c o n s o l e \[ ' l o g ' \] \( 0 x 1 \) ; /
422
530
423
531
let obfuscatedCode : string ;
@@ -440,7 +548,7 @@ describe('BlockStatementControlFlowTransformer', function () {
440
548
} ) ;
441
549
} ) ;
442
550
443
- describe ( 'Variant #13 : block statement contain class declaration' , ( ) => {
551
+ describe ( 'Variant #17 : block statement contain class declaration' , ( ) => {
444
552
const statementRegExp : RegExp = / ^ \( f u n c t i o n * \( * \) * { * * c l a s s * _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } * { .* ?} * } .* c l a s s * _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } * { .* ?} * } .* c l a s s * _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } * { .* ?} * } / ;
445
553
446
554
let obfuscatedCode : string ;
@@ -463,7 +571,7 @@ describe('BlockStatementControlFlowTransformer', function () {
463
571
} ) ;
464
572
} ) ;
465
573
466
- describe ( 'Variant #14 : `controlFlowFlatteningThreshold` chance' , ( ) => {
574
+ describe ( 'Variant #18 : `controlFlowFlatteningThreshold` chance' , ( ) => {
467
575
const samples : number = 1000 ;
468
576
const delta : number = 0.1 ;
469
577
@@ -507,7 +615,7 @@ describe('BlockStatementControlFlowTransformer', function () {
507
615
} ) ;
508
616
} ) ;
509
617
510
- describe ( 'Variant #15 : No `unreachable code after return statement` warning' , ( ) => {
618
+ describe ( 'Variant #19 : No `unreachable code after return statement` warning' , ( ) => {
511
619
const switchCaseRegExp : RegExp = / s w i t c h * \( _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } \[ _ 0 x ( [ a - f 0 - 9 ] ) { 4 , 6 } \+ \+ \] \) * \{ / ;
512
620
const switchCaseLengthRegExp : RegExp = / c a s e * ' [ 0 - 5 ] ' : * c o n s o l e \[ ' l o g ' \] \( 0 x [ 0 - 6 ] \) ; / g;
513
621
const returnStatementRegExp : RegExp = / c a s e * ' [ 0 - 5 ] ' : * r e t u r n ; * ( c a s e | } ) / ;
0 commit comments