forked from fiseleo/BlueArchiveDownloaderJP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetDownloadLink.cs
63 lines (52 loc) · 2.21 KB
/
GetDownloadLink.cs
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
using System.Text.Json;
using Crypto;
class GetDownloadLink
{
public static async Task GetDownloadLinkMain(string[] args)
{
try
{
string url = ServerInfoDataUrl();
Console.WriteLine("Extracted URL: " + url);
await Url.UrlMain(args);
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}
}
public static string ServerInfoDataUrl()
{
// 1. 從 GameMainConfig 獲取資料
byte[] data = GameMainConfig();
// 2. 將資料進行 Base64 編碼
string base64EncodedData = Convert.ToBase64String(data);
// 3. 使用密鑰加密轉換
string encryptedJson = TableEncryptionService.Convert(base64EncodedData, TableEncryptionService.CreateKey("GameMainConfig"));
// 4. 解析 JSON 並提取目標值
Dictionary<string, string> jsonObject = JsonSerializer.Deserialize<Dictionary<string, string>>(encryptedJson);
string encryptedValue = jsonObject["X04YXBFqd3ZpTg9cKmpvdmpOElwnamB2eE4cXDZqc3ZgTg=="];
// 5. 解密 URL
string url = TableEncryptionService.Convert(encryptedValue, TableEncryptionService.CreateKey("ServerInfoDataUrl"));
// 6. 將 URL 寫入檔案
string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
string UrlFolder = Path.Combine(currentDirectory, "Downloads", "XAPK", "Processed");
if (!Directory.Exists(UrlFolder))
{
Directory.CreateDirectory(UrlFolder);
}
string filePath = Path.Combine(UrlFolder, "url.txt");
File.WriteAllText(filePath, url);
Console.WriteLine("URL extracted successfully and saved to url.txt!");
return url;
}
// 模擬 GameMainConfig() 的功能,應替換為實際實現
public static byte[] GameMainConfig()
{
string rootDirectory = Directory.GetCurrentDirectory();
string GameMainConfigPath = Path.Combine(rootDirectory, "Downloads", "XAPK", "Processed");
string GameMainConfigFile = Path.Combine(GameMainConfigPath, "GameMainConfig");
// 模擬返回的 byte array,應替換為實際實現
return File.ReadAllBytes(GameMainConfigFile);
}
}