|
//用 token 登录获取对应服务器连接信息
public async static Task<object> LoginAuthuser(string info, int serverId = 0)
{
Dictionary<string, object> result = new Dictionary<string, object>()
{
["info"] = info,
["platform"] = "hortor",
["platformExt"] = "mix",
["serverId"] = serverId,
};
BonEncoder encoder = new BonEncoder();
encoder.encode(result);
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("User-Agent", "Dalvik/2.1.0 (Linux; U; Android 9; Pixel 3 Build/PQ3A.190801.002)");
headers.Add("Content-Type", "application/octet-stream");
HttpClient client = new HttpClient(/*new HttpClientHandler() { UseCookies = true }*/);
foreach (var item in headers)
{
client.DefaultRequestHeaders.TryAddWithoutValidation(item.Key, item.Value);
}
//StringContent content1 = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded");
StreamContent content1 = new StreamContent(new MemoryStream(lz4XorEncode(encoder.getBytes())));
content1.Headers.Add("content-type", "application/octet-stream");
var bt = await client.PostAsync("https://xxz-xyzw.hortorgames.com/login/authuser?_seq=1", content1);
var ret = await bt.Content.ReadAsStreamAsync() as MemoryStream;
//var r = lz4XorDecode(ret.ToArray());
BonDecoder decoder = new BonDecoder(ret.ToArray());
Dictionary<string, object> dic = decoder.decode() as Dictionary<string, object>;
decoder.reset((byte[])dic["body"]);
return decoder.decode();
}
//用 token 获取服务器列表
public async static Task<object> LoginsSrverList(string info)
{
try
{
Dictionary<string, object> result = new Dictionary<string, object>()
{
["platform"] = "hortor",
["platformExt"] = "mix",
["info"] = info,
};
BonEncoder encoder = new BonEncoder();
encoder.encode(result);
Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("User-Agent", "Dalvik/2.1.0 (Linux; U; Android 9; Pixel 3 Build/PQ3A.190801.002)");
//headers.Add("content-type", "application/octet-stream");
HttpClient client = new HttpClient(/*new HttpClientHandler() { UseCookies = true }*/);
foreach (var item in headers)
{
client.DefaultRequestHeaders.TryAddWithoutValidation(item.Key, item.Value);
}
//StringContent content1 = new StringContent(content, Encoding.UTF8, "application/x-www-form-urlencoded");
StreamContent content1 = new StreamContent(new MemoryStream(lz4XorEncode(encoder.getBytes())));
content1.Headers.Add("content-type", "application/octet-stream");
var bt = await client.PostAsync("https://xxz-xyzw.hortorgames.com/login/serverlist?_seq=2", content1);
var ret = await bt.Content.ReadAsStreamAsync() as MemoryStream;
//var r = lz4XorDecode(ret.ToArray());
BonDecoder decoder = new BonDecoder(ret.ToArray());
Dictionary<string, object> dic = decoder.decode() as Dictionary<string, object>;
decoder.reset((byte[])dic["body"]);
return decoder.decode();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
return null;
}
//游戏发包用到的算法
private static byte[] lz4XorDecode(byte[] e)
{
byte t = (byte)((e[2] >> 6 & 1) << 7 | (e[2] >> 4 & 1) << 6 | (e[2] >> 2 & 1) << 5 | (e[2] >> 0 & 1) << 4 | (e[3] >> 6 & 1) << 3 | (e[3] >> 4 & 1) << 2 | (e[3] >> 2 & 1) << 1 | (e[3] >> 0 & 1) << 0);
for (int n = Math.Min(100, e.Length); --n >= 2;) e[n] ^= t;
e[0] = 4;
e[1] = 34;
e[2] = 77;
e[3] = 24;
//byte[] result = new byte[e.Length * 255];
//int len = LZ4.Decompress(e, result);
return Lz4.decompress(e);
}
private static byte[] lz4XorEncode(byte[] e)
{
e = Lz4.compress(e);
byte t = (byte)(2 + ~~(248 * new Random().Next()));
for (var n = Math.Min(e.Length, 100); --n >= 0;) e[n] ^= t;
e[0] = 112;
e[1] = 108;
e[2] = (byte)(170 & e[2] | (t >> 7 & 1) << 6 | (t >> 6 & 1) << 4 | (t >> 5 & 1) << 2 | (t >> 4 & 1) << 0);
e[3] = (byte)(170 & e[3] | (t >> 3 & 1) << 6 | (t >> 2 & 1) << 4 | (t >> 1 & 1) << 2 | (t >> 0 & 1) << 0);
return e;
}
public static byte[] xorEncode(byte[] data)
{
int n = (int)(4294967295 * new Random().Next());
int r = data.Length + 4;
byte[] i = new byte[r];
i[0] = (byte)(255 & n);
i[1] = (byte)(n >> 8 & 255);
i[2] = (byte)(n >> 16 & 255);
i[3] = (byte)(n >> 24 & 255);
Array.Copy(data, 0, i, 4, data.Length);
var o = (byte)(2 + (248 * new Random().Next()));
for (int a = i.Length; --a >= 0;)
{
i[a] ^= o;
}
i[0] = 112;
i[1] = 120;
i[2] = (byte)(170 & i[2] | (o >> 7 & 1) << 6 | (o >> 6 & 1) << 4 | (o >> 5 & 1) << 2 | (o >> 4 & 1) << 0);
i[3] = (byte)(170 & i[3] | (o >> 3 & 1) << 6 | (o >> 2 & 1) << 4 | (o >> 1 & 1) << 2 | (o >> 0 & 1) << 0);
return i;
}
public static byte[] xorDecode(byte[] e)
{
var t = (e[2] >> 6 & 1) << 7 | (e[2] >> 4 & 1) << 6 | (e[2] >> 2 & 1) << 5 | (e[2] >> 0 & 1) << 4 | (e[3] >> 6 & 1) << 3 | (e[3] >> 4 & 1) << 2 | (e[3] >> 2 & 1) << 1 | (e[3] >> 0 & 1) << 0;
for (int n = e.Length; --n >= 4;)
{
e[n] ^= (byte)t;
}
return e.Skip(4).ToArray();
} |
|