|
public string Encrypt(string Text, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray;
inputByteArray = Encoding.UTF8.GetBytes(Text);
des.Key = Encoding.UTF8.GetBytes(sKey.Substring(0, 8));
des.IV = Encoding.UTF8.GetBytes(sKey.Substring(0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return HttpUtility.UrlEncode(Convert.ToBase64String(ms.ToArray()));
}
public string Decrypt(string Text, string sKey)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
int len;
len = Text.Length / 2;
byte[] inputByteArray = new byte[len];
int x, i;
for (x = 0; x < len; x++)
{
i = Convert.ToInt32(Text.Substring(x * 2, 2), 16);
inputByteArray[x] = (byte)i;
}
des.Key = Encoding.ASCII.GetBytes(sKey.Substring(0, 8));
des.IV = Encoding.ASCII.GetBytes(sKey.Substring(0, 8));
System.IO.MemoryStream ms = new System.IO.MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Encoding.UTF8.GetString(ms.ToArray());
}
private string EncodeBytes_bs1(string data)
{
return Encoding.UTF8.GetString(EncodeBytes_bs1(Tool.ToBytesFromHexString(data)));
}
private byte[] EncodeBytes_bs1(byte[] data)
{
int len = data.Length;
for (int i = 0; i < data.Length; i++)
{
data[i] ^= (byte)((len >> 1) + i);
}
return data;
}
private async Task<string> loadArchive(string account, string token)
{
//var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"account={account}&token={token}"));
var content = $"openId={account}&token={token}&deviceId={textBox_deviceId.Text}";
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("User-Agent", "Mozilla/5.0");
headers.Add("Sec-Fetch-Site", "cross-site");
headers.Add("Sec-Fetch-Mode", "cors");
headers.Add("Sec-Fetch-Dest", "empty");
headers.Add("xweb_xhr", "1");
HttpClient client = new HttpClient();
foreach (var item in headers)
{
client.DefaultRequestHeaders.Add(item.Key, item.Value);
}
StringContent content1 = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded");
//StreamContent content1 = new StreamContent(new MemoryStream(content));
HttpResponseMessage resp = await client.PostAsync("https://simh5.soloknight.xyz:9443/FDH5Server/game/wx/loadArchive", content1);
var ret = await resp.Content.ReadAsStringAsync();
return lzw_decompress(JObject.Parse(ret)["data"].ToString());
}
private async Task<string> saveArchive(string data, string account, string token)
{
//var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"account={account}&token={token}"));
var content = $"data={lzw_compress(data).ToUpper()}&openId={account}&token={token}&deviceId={textBox_deviceId.Text}";
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("User-Agent", "Mozilla/5.0");
headers.Add("Sec-Fetch-Site", "cross-site");
headers.Add("Sec-Fetch-Mode", "cors");
headers.Add("Sec-Fetch-Dest", "empty");
headers.Add("xweb_xhr", "1");
HttpClient client = new HttpClient();
foreach (var item in headers)
{
client.DefaultRequestHeaders.Add(item.Key, item.Value);
}
StringContent content1 = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded");
//StreamContent content1 = new StreamContent(new MemoryStream(content));
HttpResponseMessage resp = await client.PostAsync("https://simh5.soloknight.xyz:9443/FDH5Server/game/wx/saveArchive", content1);
var ret = await resp.Content.ReadAsStringAsync();
return JObject.Parse(ret)["code"].ToString();
}
private async Task<string> login(string account)
{
//var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"account={account}&token={token}"));
var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"account={account}&deviceId={Guid.NewGuid().ToString().ToUpper()}&version=3.7.0&sgCode=&crcCode={key}&rtPlatform=IPhonePlayer"));
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("user-agent", "ProductName/61 CFNetwork/1209 Darwin/20.2.0");
headers.Add("x-p-mode", "bs1");
HttpClient client = new HttpClient();
foreach (var item in headers)
{
client.DefaultRequestHeaders.Add(item.Key, item.Value);
}
//StringContent stringContent = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded");
StreamContent content1 = new StreamContent(new MemoryStream(content));
HttpResponseMessage resp = await client.PutAsync($"{addr}/FDServer/game/login/login", content1);
var ret = await resp.Content.ReadAsByteArrayAsync();
var str = Convert.FromBase64String(JObject.Parse(Encoding.UTF8.GetString(EncodeBytes_bs1(ret)))["msg"].ToString());
return JObject.Parse(Encoding.UTF8.GetString(str))["pKey"].ToString();
}
private async Task<string> archiveLoad(string account, string token)
{
//var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"account={account}&token={token}"));
var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"account={account}&token={token}"));
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("user-agent", "ProductName/61 CFNetwork/1209 Darwin/20.2.0");
headers.Add("x-p-mode", "bs1");
HttpClient client = new HttpClient();
foreach (var item in headers)
{
client.DefaultRequestHeaders.Add(item.Key, item.Value);
}
//StringContent stringContent = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded");
StreamContent content1 = new StreamContent(new MemoryStream(content));
HttpResponseMessage resp = await client.PutAsync($"{addr}/FDServer/game/archive/load", content1);
var ret = await resp.Content.ReadAsByteArrayAsync();
ret = EncodeBytes_bs1(ret);
var str = Convert.FromBase64String(JObject.Parse(Encoding.UTF8.GetString(ret))["msg"].ToString());
return Encoding.UTF8.GetString(str);
}
private async Task<string> dataLoad(string dataKey, string account, string token)
{
//var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"account={account}&token={token}"));
var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"dataKey={dataKey}&account={account}&token={token}"));
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("user-agent", "ProductName/61 CFNetwork/1209 Darwin/20.2.0");
headers.Add("x-p-mode", "bs1");
HttpClient client = new HttpClient();
foreach (var item in headers)
{
client.DefaultRequestHeaders.Add(item.Key, item.Value);
}
//StringContent stringContent = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded");
StreamContent content1 = new StreamContent(new MemoryStream(content));
HttpResponseMessage resp = await client.PutAsync($"{addr}/FDServer/game/data/load", content1);
var ret = await resp.Content.ReadAsByteArrayAsync();
ret = EncodeBytes_bs1(ret);
var json = Encoding.UTF8.GetString(ret);
if (!json.Contains("msg"))
{
return "";
}
var str = Convert.FromBase64String(JObject.Parse(json)["msg"].ToString());
return Encoding.UTF8.GetString(str);
}
private async Task<string> archiveSave(string data, string account, string token)
{
//var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"account={account}&token={token}"));
var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"data={HttpUtility.UrlEncode(data)}&account={account}&token={token}"));
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("user-agent", "ProductName/61 CFNetwork/1209 Darwin/20.2.0");
headers.Add("x-p-mode", "bs1");
HttpClient client = new HttpClient();
foreach (var item in headers)
{
client.DefaultRequestHeaders.Add(item.Key, item.Value);
}
//StringContent stringContent = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded");
StreamContent content1 = new StreamContent(new MemoryStream(content));
HttpResponseMessage resp = await client.PutAsync($"{addr}/FDServer/game/archive/save", content1);
var ret = await resp.Content.ReadAsByteArrayAsync();
ret = EncodeBytes_bs1(ret);
return Encoding.UTF8.GetString(ret);
}
private async Task<string> dataSave(string dataKey, string data, string account, string token)
{
//var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"account={account}&token={token}"));
var content = EncodeBytes_bs1(Encoding.UTF8.GetBytes($"dataKey={dataKey}&content={HttpUtility.UrlEncode(data)}&account={account}&token={token}"));
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("user-agent", "ProductName/61 CFNetwork/1209 Darwin/20.2.0");
headers.Add("x-p-mode", "bs1");
HttpClient client = new HttpClient();
foreach (var item in headers)
{
client.DefaultRequestHeaders.Add(item.Key, item.Value);
}
//StringContent stringContent = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded");
StreamContent content1 = new StreamContent(new MemoryStream(content));
HttpResponseMessage resp = await client.PutAsync($"{addr}/FDServer/game/data/save", content1);
var ret = await resp.Content.ReadAsByteArrayAsync();
ret = EncodeBytes_bs1(ret);
return Encoding.UTF8.GetString(ret);
}
private byte[] Decompress(byte[] data)
{
MemoryStream ms = new MemoryStream();
GZip.Decompress(new MemoryStream(data), ms, false);
return ms.ToArray();
}
private byte[] Compress(byte[] data)
{
MemoryStream ms = new MemoryStream();
GZip.Compress(new MemoryStream(data), ms, false);
return ms.ToArray();
}
|
|