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