@@ -3,7 +3,7 @@ import * as estree from 'estree';
3
3
import { assert } from 'console' ;
4
4
import { VisitorOption , traverse , replace } from 'estraverse' ;
5
5
import { ProtectionBase } from "./protection" ;
6
- import { cutCode , decodeBase64 , decodeRC4 , isVariableDeclaration , isIdentifier , isFunctionExpression , isLiteral , isCallExpression , isExpressionStatement , isArrayExpression } from './utils' ;
6
+ import * as Utils from './utils' ;
7
7
8
8
type EncodingType = 'none' | 'base64' | 'rc4' ;
9
9
@@ -29,15 +29,15 @@ export class StringArrayProtection extends ProtectionBase {
29
29
30
30
detect ( ) : boolean {
31
31
this . active = false ;
32
- if ( this . ast . body && this . ast . body . length > 0 && isVariableDeclaration ( this . ast . body [ 0 ] ) ) {
32
+ if ( this . ast . body && this . ast . body . length > 0 && Utils . isVariableDeclaration ( this . ast . body [ 0 ] ) ) {
33
33
const strArrayDef = < estree . VariableDeclaration > this . ast . body [ 0 ] ;
34
34
if ( strArrayDef . declarations && strArrayDef . declarations . length > 0 ) {
35
35
const strArrayDecl = strArrayDef . declarations [ 0 ] ;
36
- if ( strArrayDecl . init && isArrayExpression ( strArrayDecl . init ) && isIdentifier ( strArrayDecl . id ) ) {
36
+ if ( strArrayDecl . init && Utils . isArrayExpression ( strArrayDecl . init ) && Utils . isIdentifier ( strArrayDecl . id ) ) {
37
37
this . arrayVar = strArrayDecl . id . name ;
38
38
this . astArray = this . ast . body [ 0 ] as estree . Statement ;
39
39
this . array = strArrayDecl . init . elements . map ( e => {
40
- assert ( isLiteral ( e ) ) ;
40
+ assert ( Utils . isLiteral ( e ) ) ;
41
41
assert ( typeof ( < estree . Literal > e ) . value === 'string' ) ;
42
42
return ( < estree . Literal > e ) . value as string ;
43
43
} ) ;
@@ -52,15 +52,15 @@ export class StringArrayProtection extends ProtectionBase {
52
52
53
53
private detectRotation ( ) : boolean {
54
54
this . hasRotation = false ;
55
- if ( this . ast . body . length > 1 && isExpressionStatement ( this . ast . body [ 1 ] ) ) {
55
+ if ( this . ast . body . length > 1 && Utils . isExpressionStatement ( this . ast . body [ 1 ] ) ) {
56
56
const expr = < estree . ExpressionStatement > this . ast . body [ 1 ] ;
57
- if ( isCallExpression ( expr . expression ) ) {
57
+ if ( Utils . isCallExpression ( expr . expression ) ) {
58
58
if ( expr . expression . arguments . length === 2 ) {
59
- const id = < estree . Identifier > expr . expression . arguments . find ( isIdentifier ) ;
60
- const cnt = < estree . Literal > expr . expression . arguments . find ( isLiteral ) ;
59
+ const id = < estree . Identifier > expr . expression . arguments . find ( Utils . isIdentifier ) ;
60
+ const cnt = < estree . Literal > expr . expression . arguments . find ( Utils . isLiteral ) ;
61
61
if ( id && id . name === this . arrayVar && cnt && typeof cnt . value === 'number' ) {
62
62
this . hasRotation = true ;
63
- this . rotFunc = cutCode ( this . code , expr ) ;
63
+ this . rotFunc = Utils . cutCode ( this . code , expr ) ;
64
64
this . astRot = this . ast . body [ 1 ] as estree . Statement ;
65
65
}
66
66
}
@@ -72,13 +72,13 @@ export class StringArrayProtection extends ProtectionBase {
72
72
private detectEncoding ( ) : boolean {
73
73
this . hasEncoding = false ;
74
74
let index = this . hasRotation ? 2 : 1 ;
75
- if ( this . ast . body . length > index && isVariableDeclaration ( this . ast . body [ index ] ) ) {
75
+ if ( this . ast . body . length > index && Utils . isVariableDeclaration ( this . ast . body [ index ] ) ) {
76
76
const decVar = < estree . VariableDeclaration > this . ast . body [ index ] ;
77
77
if ( decVar . declarations && decVar . declarations . length > 0 ) {
78
78
const decDecl = < estree . VariableDeclarator > decVar . declarations [ 0 ] ;
79
- if ( isIdentifier ( decDecl . id ) && decDecl . init && isFunctionExpression ( decDecl . init ) ) {
79
+ if ( Utils . isIdentifier ( decDecl . id ) && decDecl . init && Utils . isFunctionExpression ( decDecl . init ) ) {
80
80
if ( decDecl . init . params . length === 2 ) {
81
- const decFuncCode = cutCode ( this . code , decDecl . init ) ;
81
+ const decFuncCode = Utils . cutCode ( this . code , decDecl . init ) ;
82
82
this . encoding = / \b a t o b \b / . test ( decFuncCode )
83
83
? ( / % (?: 0 x 1 0 0 | 2 5 6 ) \D / . test ( decFuncCode ) ? 'rc4' : 'base64' )
84
84
: 'none' ;
@@ -105,11 +105,11 @@ export class StringArrayProtection extends ProtectionBase {
105
105
if ( this . hasEncoding && this . astDecoder ) {
106
106
if ( this . encoding === 'base64' ) {
107
107
for ( let i = 0 ; i < this . array . length ; ++ i )
108
- this . array [ i ] = decodeBase64 ( this . array [ i ] ) ;
108
+ this . array [ i ] = Utils . decodeBase64 ( this . array [ i ] ) ;
109
109
} else if ( this . encoding === 'rc4' ) {
110
110
this . fillKeys ( ) ;
111
111
for ( let i = 0 ; i < this . array . length ; ++ i )
112
- this . array [ i ] = decodeRC4 ( this . array [ i ] , this . rc4Keys [ i ] ) ;
112
+ this . array [ i ] = Utils . decodeRC4 ( this . array [ i ] , this . rc4Keys [ i ] ) ;
113
113
}
114
114
this . removeDecoderCalls ( ) ;
115
115
}
@@ -161,10 +161,10 @@ export class StringArrayProtection extends ProtectionBase {
161
161
}
162
162
163
163
private checkDecoderCall ( node : estree . Node ) : estree . CallExpression | null {
164
- if ( isCallExpression ( node ) && isIdentifier ( node . callee ) ) {
164
+ if ( Utils . isCallExpression ( node ) && Utils . isIdentifier ( node . callee ) ) {
165
165
if ( node . callee . name === this . decFuncName ) {
166
166
assert ( node . arguments . length === 2 ) ;
167
- assert ( node . arguments . every ( isLiteral ) ) ;
167
+ assert ( node . arguments . every ( Utils . isLiteral ) ) ;
168
168
return node ;
169
169
}
170
170
}
0 commit comments