@@ -4,27 +4,28 @@ const shlp = require('sei-helper');
4
4
const xhtml2js = shlp . xhtml2js ;
5
5
6
6
// decrypt
7
- function createString ( args ) {
8
- let a = args [ 2 ] ;
9
- let b = args [ 3 ] ;
10
- let res = '' ;
11
- for ( let i = 0 ; i < args [ 0 ] ; i ++ ) {
12
- b += a ;
13
- a = b - a ;
14
- res += String . fromCharCode ( b % args [ 1 ] + 33 ) ;
7
+ function generateKeyAux ( count , modulo , start ) {
8
+ // Generate String: $&).6CXzPHw=2N_+isZK
9
+ let res = start ;
10
+ for ( let i of Array ( count ) . keys ( ) ) {
11
+ res . push ( res [ res . length - 1 ] + res [ res . length - 2 ] ) ;
15
12
}
13
+ res . splice ( 0 , 2 )
14
+ res = res . map ( x => x % modulo + 33 ) ;
15
+ res = String . fromCharCode ( ...res ) ;
16
16
return res ;
17
17
}
18
- function generateKey ( mediaid ) {
19
- let eq1 = Math . floor ( Math . sqrt ( 6.9 ) * Math . pow ( 2 , 25 ) ) ;
20
- let eq2 = ( mediaid ^ eq1 ) ^ ( mediaid ^ eq1 ) >> 3 ^ ( eq1 ^ mediaid ) * 32 ;
21
- if ( eq2 < 0 ) {
22
- eq2 += 0x100000000 ;
23
- }
24
- let finalHash = crypto . createHash ( 'sha1' ) . update ( createString ( [ 20 , 97 , 1 , 2 ] ) + eq2 . toString ( ) , 'utf8' ) . digest ( ) ;
25
- let res = Buffer . alloc ( 32 ) ;
26
- finalHash . copy ( res ) ;
27
- return res ;
18
+ function generateKey ( id ) {
19
+ const hashMagicConst = Math . floor ( Math . sqrt ( 6.9 ) * Math . pow ( 2 , 25 ) ) ; // 0x0540E9FA
20
+ const hashMagicBaseNum = hashMagicConst ^ id ;
21
+ const hashMagicNumber = hashMagicBaseNum ^ hashMagicBaseNum >> 3 ^ hashMagicBaseNum * 32 ;
22
+ const finalHashMagicNumber = hashMagicNumber < 0 ? hashMagicNumber + 0x100000000 : hashMagicNumber ;
23
+ const keyAux = generateKeyAux ( 20 , 97 , [ 1 , 2 ] ) ;
24
+ const keyText = keyAux + finalHashMagicNumber ;
25
+ const keyHash = crypto . createHash ( 'sha1' ) . update ( keyText , 'utf8' ) . digest ( ) ;
26
+ const finalKey = Buffer . alloc ( 32 ) ;
27
+ keyHash . copy ( finalKey ) ;
28
+ return finalKey ;
28
29
}
29
30
function doDecrypt ( _id , _iv , _data ) {
30
31
let key = generateKey ( _id ) ;
@@ -33,19 +34,27 @@ function doDecrypt(_id, _iv, _data) {
33
34
dec . setAutoPadding ( ) ;
34
35
let decrypted = dec . update ( _data , 'base64' ) ;
35
36
decrypted = Buffer . concat ( [ decrypted , dec . final ( ) ] ) ;
36
- return zlib . unzipSync ( decrypted ) . toString ( 'utf8' ) ;
37
+ try {
38
+ const zlibData = zlib . unzipSync ( decrypted ) . toString ( 'utf8' ) ;
39
+ return { ok : true , data : zlibData } ;
40
+ }
41
+ catch ( err ) {
42
+ return { ok : false , data : err } ;
43
+ }
37
44
}
38
45
function decrypt ( id , data ) {
39
46
let err = data . match ( / < e r r o r > ( .* ) < \/ e r r o r > / ) ;
40
47
if ( err ) {
41
- return { ok : false , data : `[ERROR] Unknown error, data:\n ${ err } ` } ;
48
+ return { ok : false , data : err } ;
42
49
}
43
- let res = data . match ( / < i v > ( .* ) < \/ i v > .* < d a t a > ( .* ) < \/ d a t a > / ) ;
50
+ let res = data . match ( / i d = ' ( . * ) ' . * < i v > ( .* ) < \/ i v > .* < d a t a > ( .* ) < \/ d a t a > / ) ;
44
51
if ( ! res ) {
45
- return { ok : false , data : `[ERROR] Unknown error, data:\n ${ data } ` } ;
52
+ return { ok : false , data : data } ;
46
53
}
47
- return { ok : true , data : doDecrypt ( id , res [ 1 ] , res [ 2 ] ) } ;
54
+ id = id ? id : res [ 1 ] ;
55
+ return doDecrypt ( id , res [ 2 ] , res [ 3 ] ) ;
48
56
}
57
+
49
58
// parse
50
59
function parse ( meta , src ) {
51
60
// pre default
0 commit comments