Skip to content

Commit 2b1435f

Browse files
committed
API: 最新バージョンに対応
1 parent 9d4efa0 commit 2b1435f

File tree

4 files changed

+142
-125
lines changed

4 files changed

+142
-125
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Common IDEs
2-
.idea/
2+
deresute.code-workspace
33

44
# Composer
55
vendor/

Cryptographer.php

+24-24
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
<?php
2-
3-
namespace towa0131\deresute;
4-
5-
class Cryptographer{
6-
7-
public static function encode(string $data){
8-
$str = "";
9-
for($i = 0; $i < mb_strlen($data); $i++){
10-
$str .= mt_rand(0, 9) . mt_rand(0, 9) . chr(ord($data[$i]) + 10) . mt_rand(0, 9);
11-
}
12-
return sprintf("%04x", strlen($data)) . $str .
13-
mt_rand(1000000000, 9999999999) . mt_rand(1000000000, 9999999999) . mt_rand(100000000000, 999999999999);
14-
}
15-
16-
public static function decode(string $data){
17-
$num = hexdec(substr($data, 0, 4));
18-
$result = '';
19-
for ($i = 6; $i < strlen($data) && strlen($result) < $num; $i += 4) {
20-
$result .= chr(ord($data[$i]) - 10);
21-
}
22-
return $result;
23-
}
24-
}
1+
<?php
2+
3+
namespace towa0131\deresute;
4+
5+
class Cryptographer{
6+
7+
public static function encode(string $data){
8+
$str = "";
9+
for($i = 0; $i < mb_strlen($data); $i++){
10+
$str .= mt_rand(0, 9) . mt_rand(0, 9) . chr(ord($data[$i]) + 10) . mt_rand(0, 9);
11+
}
12+
return sprintf("%04x", strlen($data)) . $str .
13+
mt_rand(10000000, 99999999) . mt_rand(10000000, 99999999);
14+
}
15+
16+
public static function decode(string $data){
17+
$num = hexdec(substr($data, 0, 4));
18+
$result = '';
19+
for ($i = 6; $i < strlen($data) && strlen($result) < $num; $i += 4) {
20+
$result .= chr(ord($data[$i]) - 10);
21+
}
22+
return $result;
23+
}
24+
}

DeresuteAPI.php

+108-91
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,139 @@
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+
99
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";
1616
public const SID_SALT = "r!I@nt8e5i=";
17-
18-
protected $udid = "";
19-
protected $viewerId = 0;
17+
18+
protected $udid = "";
19+
protected $viewerId = 0;
2020
protected $userId = 0;
21-
22-
protected $sid = "";
23-
21+
22+
protected $sid = "";
23+
2424
public function __construct(string $udid, int $viewerId, int $userId){
2525
ini_set("msgpack.use_str8_serialization", 0); // Enable compatibility mode
2626

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+
}
3232

3333
/**
3434
* Core API
3535
*/
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+
5959
$headers = [
6060
"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",
6363
"Content-Length: " . strlen($body),
6464
"Connection: keep-alive",
6565
"Accept: */*",
6666
"Accept-Encoding: gzip, deflate",
6767
"Accept-Language: en-us",
6868
"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),
7272
"PARAM: " . sha1($this->udid . (string)$this->viewerId . $endpoint . $plain),
7373
"DEVICE: 1",
74-
"APP-VER: " . self::APP_VER,
74+
"APP-VER: " . self::APP_VER,
7575
"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",
7780
"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+
]);
9598
$response = curl_exec($curl);
99+
curl_close($curl);
100+
101+
unset($curl);
96102

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);
103108
$result = msgpack_unpack(base64_decode($plain));
104109

105110
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;
110127
}
111128

112129
public static function generateHeader(string $host) : array{
113-
$header = [
114-
"APP-VER: " . self::APP_VER,
130+
$header = [
131+
"APP-VER: " . self::APP_VER,
115132
"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
120137
];
121138

122139
return $header;
@@ -144,6 +161,6 @@ public function createNewAccount() : bool{
144161
return true;
145162
}
146163

147-
return false;
148-
}
149-
}
164+
return false;
165+
}
166+
}

ManifestDB.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
<?php
2-
3-
namespace towa0131\deresute;
4-
5-
use towa0131\deresute\Cryptographer;
6-
1+
<?php
2+
3+
namespace towa0131\deresute;
4+
5+
use towa0131\deresute\Cryptographer;
6+
77
class ManifestDB{
88

99
public const HTTP_SCHEME = "http://";
10-
public const RESOURCE_SERVER_OLD = "storage.game.starlight-stage.jp/";
10+
public const RESOURCE_SERVER_OLD = "storage.game.starlight-stage.jp/";
1111
public const RESOURCE_SERVER = "asset-starlight-stage.akamaized.net/";
12-
12+
1313
public const DB_NAME = "manifest.db";
1414
public const MANIFEST_TABLE = "manifests";
1515
public const DL_ROOT = "dl/";
@@ -98,4 +98,4 @@ public static function getPlatformDirectory(int $type = 0) : string{
9898
break;
9999
}
100100
}
101-
}
101+
}

0 commit comments

Comments
 (0)