1
- <?php
2
-
3
- namespace towa0131 \deresute ;
4
-
5
- use towa0131 \deresute \Cryptographer ;
6
-
7
- class DeresuteAPI{
8
-
1
+ <?php
2
+
3
+ namespace towa0131 \deresute ;
4
+
5
+ use towa0131 \deresute \Cryptographer ;
6
+
7
+ class DeresuteAPI{
8
+
9
9
public const BASE_URL = "https://apis.game.starlight-stage.jp " ;
10
-
11
- public const RES_VER = 10057440 ;
12
- public const APP_VER = "4 .2.1 " ;
13
- public const WC_VER = "2017.4.2f2 " ;
14
-
15
- public const VIEWER_ID_KEY = "s%5VNQ(H$&Bqb6#3+78h29!Ft4wSg)ex " ;
10
+
11
+ public const RES_VER = 10061600 ;
12
+ public const APP_VER = "5 .2.5 " ;
13
+ public const WC_VER = "2018.3.8f1 " ;
14
+
15
+ public const VIEWER_ID_KEY = "s%5VNQ(H$&Bqb6#3+78h29!Ft4wSg)ex " ;
16
16
public const SID_SALT = "r!I@nt8e5i= " ;
17
-
18
- protected $ udid = "" ;
19
- protected $ viewerId = 0 ;
17
+
18
+ protected $ udid = "" ;
19
+ protected $ viewerId = 0 ;
20
20
protected $ userId = 0 ;
21
-
22
- protected $ sid = "" ;
23
-
21
+
22
+ protected $ sid = "" ;
23
+
24
24
public function __construct (string $ udid , int $ viewerId , int $ userId ){
25
25
ini_set ("msgpack.use_str8_serialization " , 0 ); // Enable compatibility mode
26
26
27
- $ this ->udid = $ udid ;
28
- $ this ->viewerId = $ viewerId ;
29
- $ this ->userId = $ userId ;
30
- $ this ->sid = (string )$ this ->viewerId . (string )$ this ->udid ;
31
- }
27
+ $ this ->udid = $ udid ;
28
+ $ this ->viewerId = $ viewerId ;
29
+ $ this ->userId = $ userId ;
30
+ $ this ->sid = (string )$ this ->viewerId . (string )$ this ->udid ;
31
+ }
32
32
33
33
/**
34
34
* Core API
35
35
*/
36
-
37
- private function encrypt256 (string $ data = "" , string $ key , string $ iv ) : string {
38
- $ key = str_pad ( $ key , 32 , "\0" );
39
- $ padding = 32 - ( strlen ( $ data ) % 32 );
40
- $ data .= str_repeat ( chr ( 0 ) , $ padding );
41
- $ encrypted = phpseclib_mcrypt_encrypt ( MCRYPT_RIJNDAEL_256 , $ key , $ data , MCRYPT_MODE_CBC , $ iv );
42
- return rtrim ( $ encrypted );
43
- }
44
-
45
- private function decrypt256 ( string $ data = "" , string $ key , string $ iv ) : string {
46
- return trim ( phpseclib_mcrypt_decrypt ( MCRYPT_RIJNDAEL_256 , $ key , $ data , MCRYPT_MODE_CBC , $ iv ), "\0" );
47
- }
48
-
49
- public function run (array $ args , string $ endpoint ) : array {
50
- $ vid_iv = mt_rand (1000000000 , 9999999999 ) . mt_rand (1000000000 , 9999999999 ) . mt_rand ( 100000000000 , 999999999999 );
51
- $ args ["timezone " ] = "09:00:00 " ;
52
- $ args ["viewer_id " ] = $ vid_iv . base64_encode ($ this ->encrypt256 ((string )$ this ->viewerId , self ::VIEWER_ID_KEY , $ vid_iv ));
53
- $ plain = base64_encode (msgpack_pack ($ args ));
54
-
55
- $ key = mt_rand (1000000000 , 9999999999 ) . mt_rand (1000000000 , 9999999999 ) . mt_rand (100000000000 , 999999999999 );
56
- $ msg_iv = str_replace ("- " , "" , $ this ->udid );
57
- $ body = base64_encode ($ this ->encrypt256 ($ plain , $ key , $ msg_iv ) . $ key );
58
-
36
+
37
+ private function encrypt256 (string $ data = "" , string $ key , string $ iv ) : string {
38
+ $ padding = 16 - ( strlen ( $ data ) % 16 );
39
+ $ data .= str_repeat ( chr ( $ padding ), $ padding );
40
+ return mcrypt_encrypt ( MCRYPT_RIJNDAEL_128 , $ key , $ data, MCRYPT_MODE_CBC , $ iv );
41
+ }
42
+
43
+ private function decrypt256 ( string $ data = "" , string $ key , string $ iv ) : string {
44
+ $ data = mcrypt_decrypt ( MCRYPT_RIJNDAEL_128 , $ key , $ data , MCRYPT_MODE_CBC , $ iv );
45
+ $ padding = ord ( $ data[ strlen ( $ data ) - 1 ]);
46
+ return substr ( $ data , 0 , - $ padding );
47
+ }
48
+
49
+ public function run (array $ args , string $ endpoint ) : array {
50
+ $ vid_iv = mt_rand (10000000 , 99999999 ) . mt_rand (10000000 , 99999999 );
51
+ $ args ["timezone " ] = "09:00:00 " ;
52
+ $ args ["viewer_id " ] = $ vid_iv . base64_encode ($ this ->encrypt256 ((string )$ this ->viewerId , self ::VIEWER_ID_KEY , $ vid_iv ));
53
+ $ plain = base64_encode (msgpack_pack ($ args ));
54
+
55
+ $ key = mt_rand (1000000000 , 9999999999 ) . mt_rand (1000000000 , 9999999999 ) . mt_rand (100000000000 , 999999999999 );
56
+ $ msg_iv = hex2bin ( str_replace ("- " , "" , $ this ->udid ) );
57
+ $ body = base64_encode ($ this ->encrypt256 ($ plain , $ key , $ msg_iv ) . $ key );
58
+
59
59
$ headers = [
60
60
"Host: apis.game.starlight-stage.jp " ,
61
- "User-Agent: Dalvik/1.6. 0 (Linux; U; Android 4.4.2; SM-N9005 Build/NJH47F ) " ,
62
- "Content-Type: application/x-www-form-urlencoded " ,
61
+ "User-Agent: Dalvik/2.1. 0 (Linux; U; Android 8.1.0; Nexus 4 Build/XYZZ1Y ) " ,
62
+ "Content-Type: application/x-www-form-urlencoded " ,
63
63
"Content-Length: " . strlen ($ body ),
64
64
"Connection: keep-alive " ,
65
65
"Accept: */* " ,
66
66
"Accept-Encoding: gzip, deflate " ,
67
67
"Accept-Language: en-us " ,
68
68
"X-Unity-Version: " . self ::WC_VER ,
69
- "UDID: " . Cryptographer::encode ($ this ->udid ),
70
- "USER-ID: " . Cryptographer::encode ((string )$ this ->userId ),
71
- "SID: " . md5 ($ this ->sid . self ::SID_SALT ),
69
+ "UDID: " . Cryptographer::encode ($ this ->udid ),
70
+ "USER-ID: " . Cryptographer::encode ((string )$ this ->userId ),
71
+ "SID: " . md5 ($ this ->sid . self ::SID_SALT ),
72
72
"PARAM: " . sha1 ($ this ->udid . (string )$ this ->viewerId . $ endpoint . $ plain ),
73
73
"DEVICE: 1 " ,
74
- "APP-VER: " . self ::APP_VER ,
74
+ "APP-VER: " . self ::APP_VER ,
75
75
"RES-VER: " . self ::RES_VER ,
76
- "DEVICE-ID: " . md5 ("Totally a real Android " ), "DEVICE-NAME: Nexus 42 " , "GRAPHICS-DEVICE-NAME: 3dfx Voodoo2 (TM) " , "IP-ADDRESS: 127.0.0.1 " ,
76
+ "DEVICE-ID: " . md5 ("Totally a real Android " ),
77
+ "DEVICE-NAME: Nexus 42 " ,
78
+ "GRAPHICS-DEVICE-NAME: 3dfx Voodoo2 (TM) " ,
79
+ "IP-ADDRESS: 127.0.0.1 " ,
77
80
"PLATFORM-OS-VERSION: Android OS 13.3.7 / API-42 (XYZZ1Y/74726f6c6c) " ,
78
- "CARRIER: docomo " ,
79
- "KEYCHAIN: 727238026 " ,
80
- "PROCESSOR-TYPE: ARMv7 VFPv3 NEON " ,
81
- "IDFA: "
82
- ];
83
-
84
- $ curl = curl_init ();
85
- curl_setopt_array ($ curl , [
86
- CURLOPT_URL => self ::BASE_URL . $ endpoint ,
87
- CURLOPT_SSL_VERIFYPEER => true ,
88
- CURLOPT_HTTPHEADER => $ headers ,
89
- CURLOPT_POST => true ,
90
- CURLOPT_POSTFIELDS => $ body ,
91
- CURLOPT_HEADER => false ,
92
- CURLOPT_RETURNTRANSFER => true ,
93
- CURLOPT_ENCODING => "gzip, deflate "
94
- ]);
81
+ "CARRIER: docomo " ,
82
+ "KEYCHAIN: 727238026 " ,
83
+ "PROCESSOR-TYPE: ARMv7 VFPv3 NEON " ,
84
+ "IDFA: "
85
+ ];
86
+
87
+ $ curl = curl_init ();
88
+ curl_setopt_array ($ curl , [
89
+ CURLOPT_URL => self ::BASE_URL . $ endpoint ,
90
+ CURLOPT_SSL_VERIFYPEER => true ,
91
+ CURLOPT_HTTPHEADER => $ headers ,
92
+ CURLOPT_POST => true ,
93
+ CURLOPT_POSTFIELDS => $ body ,
94
+ CURLOPT_HEADER => false ,
95
+ CURLOPT_RETURNTRANSFER => true ,
96
+ CURLOPT_ENCODING => "gzip, deflate "
97
+ ]);
95
98
$ response = curl_exec ($ curl );
99
+ curl_close ($ curl );
100
+
101
+ unset($ curl );
96
102
97
- curl_close ($ curl );
98
-
99
- $ response = base64_decode ($ response );
100
- $ key = substr ($ response , -32 , 32 );
101
-
102
- $ plain = $ this ->decrypt256 (substr ($ response , 0 , -32 ), $ key , $ msg_iv );
103
+ $ response = base64_decode ($ response );
104
+ $ key = substr ($ response , -32 , 32 );
105
+ $ data = substr ($ response , 0 , -32 );
106
+
107
+ $ plain = $ this ->decrypt256 ($ data , $ key , $ msg_iv );
103
108
$ result = msgpack_unpack (base64_decode ($ plain ));
104
109
105
110
if (isset ($ result ["data_headers " ]["sid " ]) && !empty ($ result ["data_headers " ]["sid " ])){
106
- $ this ->sid = $ result ["data_headers " ]["sid " ];
107
- }
108
-
109
- return $ result ;
111
+ $ this ->sid = $ result ["data_headers " ]["sid " ];
112
+ }
113
+
114
+ return $ result ;
115
+ }
116
+
117
+ public function getUdid () : string {
118
+ return $ this ->udid ;
119
+ }
120
+
121
+ public function getViewerId () : int {
122
+ return $ this ->viewerId ;
123
+ }
124
+
125
+ public function getUserId () : int {
126
+ return $ this ->userId ;
110
127
}
111
128
112
129
public static function generateHeader (string $ host ) : array {
113
- $ header = [
114
- "APP-VER: " . self ::APP_VER ,
130
+ $ header = [
131
+ "APP-VER: " . self ::APP_VER ,
115
132
"RES-VER: " . self ::RES_VER ,
116
- "X-Unity-Version: " . self ::WC_VER ,
117
- "User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; SM-N9005 Build/NJH47F) " ,
118
- "Connection: keep-alive " ,
119
- "Host: " . $ host
133
+ "X-Unity-Version: " . self ::WC_VER ,
134
+ "User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.4.2; SM-N9005 Build/NJH47F) " ,
135
+ "Connection: keep-alive " ,
136
+ "Host: " . $ host
120
137
];
121
138
122
139
return $ header ;
@@ -144,6 +161,6 @@ public function createNewAccount() : bool{
144
161
return true ;
145
162
}
146
163
147
- return false ;
148
- }
149
- }
164
+ return false ;
165
+ }
166
+ }
0 commit comments