@@ -33,6 +33,7 @@ var expressionObfuscation_1 = __importDefault(require("./expressionObfuscation")
33
33
var literalObfuscation_1 = __importDefault ( require ( "./literalObfuscation" ) ) ;
34
34
var numberObfuscation_1 = __importDefault ( require ( "./numberObfuscation" ) ) ;
35
35
var unicodeLiteral_1 = __importDefault ( require ( "./unicodeLiteral" ) ) ;
36
+ var estemplate = require ( 'estemplate' ) ;
36
37
var CodeEncryption = /** @class */ ( function ( _super ) {
37
38
__extends ( CodeEncryption , _super ) ;
38
39
function CodeEncryption ( ) {
@@ -165,136 +166,14 @@ var CodeEncryption = /** @class */ (function (_super) {
165
166
* @memberof CodeEncryption
166
167
*/
167
168
CodeEncryption . prototype . generateClientKeyDecl = function ( keyIdent , keyFuncDecl ) {
168
- var resultIdent = identifiers_1 . Identifiers . generate ( ) ;
169
- var numIdent = identifiers_1 . Identifiers . generate ( ) ;
170
- var indexIdent = identifiers_1 . Identifiers . generate ( ) ;
171
- return {
172
- type : 'VariableDeclaration' ,
173
- declarations : [
174
- {
175
- type : 'VariableDeclarator' ,
176
- id : {
177
- type : 'Identifier' ,
178
- name : keyIdent
179
- } ,
180
- init : {
181
- type : 'CallExpression' ,
182
- callee : {
183
- type : 'MemberExpression' ,
184
- object : {
185
- type : 'CallExpression' ,
186
- callee : {
187
- type : 'MemberExpression' ,
188
- object : {
189
- type : 'CallExpression' ,
190
- callee : {
191
- type : 'MemberExpression' ,
192
- object : {
193
- type : 'Identifier' ,
194
- name : keyFuncDecl . id ? keyFuncDecl . id . name : ''
195
- } ,
196
- property : {
197
- type : 'Literal' ,
198
- value : 'toString'
199
- } ,
200
- computed : true
201
- } ,
202
- arguments : [ ]
203
- } ,
204
- property : {
205
- type : 'Literal' ,
206
- value : 'split'
207
- } ,
208
- computed : true
209
- } ,
210
- arguments : [
211
- {
212
- type : 'Literal' ,
213
- value : ''
214
- }
215
- ]
216
- } ,
217
- property : {
218
- type : 'Literal' ,
219
- value : 'reduce'
220
- } ,
221
- computed : true
222
- } ,
223
- arguments : [
224
- {
225
- type : 'FunctionExpression' ,
226
- id : null ,
227
- generator : false ,
228
- params : [
229
- {
230
- type : 'Identifier' ,
231
- name : resultIdent
232
- } ,
233
- {
234
- type : 'Identifier' ,
235
- name : numIdent
236
- } ,
237
- {
238
- type : 'Identifier' ,
239
- name : indexIdent
240
- }
241
- ] ,
242
- body : {
243
- type : 'BlockStatement' ,
244
- body : [
245
- {
246
- type : 'ReturnStatement' ,
247
- argument : {
248
- type : 'BinaryExpression' ,
249
- left : {
250
- type : 'Identifier' ,
251
- name : resultIdent
252
- } ,
253
- operator : '^' ,
254
- right : {
255
- type : 'BinaryExpression' ,
256
- operator : '+' ,
257
- left : {
258
- type : 'CallExpression' ,
259
- callee : {
260
- type : 'MemberExpression' ,
261
- object : {
262
- type : 'Identifier' ,
263
- name : numIdent
264
- } ,
265
- property : {
266
- type : 'Literal' ,
267
- value : 'charCodeAt'
268
- } ,
269
- computed : true
270
- } ,
271
- arguments : [
272
- {
273
- type : 'Literal' ,
274
- value : 0
275
- }
276
- ]
277
- } ,
278
- right : {
279
- type : 'Identifier' ,
280
- name : indexIdent
281
- }
282
- }
283
- }
284
- }
285
- ]
286
- }
287
- } ,
288
- {
289
- type : 'Literal' ,
290
- value : 0
291
- }
292
- ]
293
- }
294
- }
295
- ] ,
296
- kind : 'var'
297
- } ;
169
+ var template = "var <%= varIdent %> = <%= funcDecl %>['toString']()['split']('')['reduce'](function(<%= resultIdent %>, <%= numIdent %>, <%= indexIdent %>) {return <%= resultIdent %> ^ <%= numIdent %>['charCodeAt'](0) + <%= indexIdent %>}, 0);" ;
170
+ return estemplate ( template , {
171
+ varIdent : { type : 'Identifier' , name : keyIdent } ,
172
+ funcDecl : keyFuncDecl . id ,
173
+ resultIdent : { type : 'Identifier' , name : identifiers_1 . Identifiers . generate ( ) } ,
174
+ numIdent : { type : 'Identifier' , name : identifiers_1 . Identifiers . generate ( ) } ,
175
+ indexIdent : { type : 'Identifier' , name : identifiers_1 . Identifiers . generate ( ) }
176
+ } ) . body [ 0 ] ;
298
177
} ;
299
178
/**
300
179
* @protected
@@ -318,90 +197,12 @@ var CodeEncryption = /** @class */ (function (_super) {
318
197
value : value . charCodeAt ( 0 ) ^ key
319
198
} ) ;
320
199
} ) ;
321
- var encryptedArrayExpression = {
322
- type : 'ArrayExpression' ,
323
- elements : encrypted
324
- } ;
325
- var valueIdent = identifiers_1 . Identifiers . generate ( ) ;
326
- return {
327
- type : 'CallExpression' ,
328
- callee : {
329
- type : 'MemberExpression' ,
330
- object : {
331
- type : 'CallExpression' ,
332
- callee : {
333
- type : 'MemberExpression' ,
334
- object : encryptedArrayExpression ,
335
- property : {
336
- type : 'Literal' ,
337
- value : 'map'
338
- } ,
339
- computed : true
340
- } ,
341
- arguments : [
342
- {
343
- type : 'FunctionExpression' ,
344
- id : null ,
345
- generator : false ,
346
- params : [
347
- {
348
- type : 'Identifier' ,
349
- name : valueIdent
350
- }
351
- ] ,
352
- body : {
353
- type : 'BlockStatement' ,
354
- body : [
355
- {
356
- type : 'ReturnStatement' ,
357
- argument : {
358
- type : 'CallExpression' ,
359
- callee : {
360
- type : 'MemberExpression' ,
361
- object : {
362
- type : 'Identifier' ,
363
- name : 'String'
364
- } ,
365
- property : {
366
- type : 'Literal' ,
367
- value : 'fromCharCode'
368
- } ,
369
- computed : true
370
- } ,
371
- arguments : [
372
- {
373
- type : 'BinaryExpression' ,
374
- left : {
375
- type : 'Identifier' ,
376
- name : valueIdent
377
- } ,
378
- operator : '^' ,
379
- right : {
380
- type : 'Identifier' ,
381
- name : keyIdent
382
- }
383
- }
384
- ]
385
- }
386
- }
387
- ]
388
- }
389
- }
390
- ]
391
- } ,
392
- property : {
393
- type : 'Literal' ,
394
- value : 'join'
395
- } ,
396
- computed : true
397
- } ,
398
- arguments : [
399
- {
400
- type : 'Literal' ,
401
- value : ''
402
- }
403
- ]
404
- } ;
200
+ var template = "[%= elements %]['map'](function(<%= valueIdent %>) {return String['fromCharCode'](<%= valueIdent %> ^ <%= key %>)})['join']('')" ;
201
+ return estemplate ( template , {
202
+ elements : encrypted ,
203
+ valueIdent : { type : 'Identifier' , name : identifiers_1 . Identifiers . generate ( ) } ,
204
+ key : { type : 'Identifier' , name : keyIdent }
205
+ } ) . body [ 0 ] . expression ;
405
206
} ;
406
207
/**
407
208
* @protected
@@ -410,36 +211,10 @@ var CodeEncryption = /** @class */ (function (_super) {
410
211
* @memberof CodeEncryption
411
212
*/
412
213
CodeEncryption . prototype . generateTryCatchExpression = function ( blockCodeDecryptExpr ) {
413
- return {
414
- type : 'TryStatement' ,
415
- block : {
416
- type : 'BlockStatement' ,
417
- body : [
418
- {
419
- type : 'ExpressionStatement' ,
420
- expression : {
421
- type : 'CallExpression' ,
422
- callee : {
423
- type : 'Identifier' ,
424
- name : 'eval'
425
- } ,
426
- arguments : [ blockCodeDecryptExpr ]
427
- }
428
- }
429
- ]
430
- } ,
431
- handler : {
432
- type : 'CatchClause' ,
433
- param : {
434
- type : 'Identifier' ,
435
- name : 'e'
436
- } ,
437
- body : {
438
- type : 'BlockStatement' ,
439
- body : [ ]
440
- }
441
- }
442
- } ;
214
+ var template = 'try {eval(<%= block %>)} catch (e){}' ;
215
+ return estemplate ( template , {
216
+ block : blockCodeDecryptExpr
217
+ } ) . body [ 0 ] ;
443
218
} ;
444
219
return CodeEncryption ;
445
220
} ( transformations_1 . BaseTransformation ) ) ;
0 commit comments