|
| 1 | +using Newtonsoft.Json.Linq; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Management; |
| 5 | +using System.Net.Http; |
| 6 | +using System.Threading.Tasks; |
| 7 | + |
| 8 | +namespace XenAuth |
| 9 | +{ |
| 10 | + public static class XenAuth |
| 11 | + { |
| 12 | + private static readonly HttpClient httpclient = new HttpClient(); |
| 13 | + |
| 14 | + public static async Task<bool> Status(string api) |
| 15 | + { |
| 16 | + var apiUri = new Uri(api) + "?status"; |
| 17 | + var response = await httpclient.GetAsync(apiUri); |
| 18 | + |
| 19 | + if (response.IsSuccessStatusCode) |
| 20 | + { |
| 21 | + return true; |
| 22 | + } |
| 23 | + else |
| 24 | + { |
| 25 | + return false; |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + public static async Task<int> Compare(string username, string password, string api) |
| 30 | + { |
| 31 | + var apiUri = new Uri(api) + "?compare"; |
| 32 | + |
| 33 | + var form = new FormUrlEncodedContent(new[] |
| 34 | + { |
| 35 | + new KeyValuePair<string, string>("username", username), |
| 36 | + new KeyValuePair<string, string>("password", password), |
| 37 | + new KeyValuePair<string, string>("hwid", GetHwid()), |
| 38 | + }); |
| 39 | + |
| 40 | + try |
| 41 | + { |
| 42 | + HttpResponseMessage response = await httpclient.PostAsync(apiUri, form); |
| 43 | + |
| 44 | + if (response.IsSuccessStatusCode) |
| 45 | + { |
| 46 | + string json = await response.Content.ReadAsStringAsync(); |
| 47 | + JObject jsonobject = JObject.Parse(json); |
| 48 | + string status = jsonobject["status"].ToString(); |
| 49 | + |
| 50 | + return status == "Ok" ? 200 : (status == "hwid_missmatch" ? 403 : 404); |
| 51 | + } |
| 52 | + else |
| 53 | + { |
| 54 | + return (int)response.StatusCode; |
| 55 | + } |
| 56 | + } |
| 57 | + catch (Exception) |
| 58 | + { |
| 59 | + return -1; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + public static string GetHwid() |
| 67 | + { |
| 68 | + string hdd = string.Empty; |
| 69 | + string motherboardn = string.Empty; |
| 70 | + string cpu = string.Empty; |
| 71 | + |
| 72 | + try |
| 73 | + { |
| 74 | + ManagementObjectSearcher hdds = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive"); |
| 75 | + foreach (ManagementObject diskDrive in hdds.Get()) |
| 76 | + { |
| 77 | + if (diskDrive["MediaType"] != null && diskDrive["MediaType"].ToString().Contains("Fixed")) |
| 78 | + { |
| 79 | + hdd = diskDrive["SerialNumber"].ToString().Trim(); |
| 80 | + break; |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + catch (Exception) {} |
| 85 | + |
| 86 | + try |
| 87 | + { |
| 88 | + ManagementObjectSearcher motherboards = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard"); |
| 89 | + foreach (ManagementObject motherboard in motherboards.Get()) |
| 90 | + { |
| 91 | + motherboardn = motherboard["SerialNumber"].ToString().Trim(); |
| 92 | + break; |
| 93 | + } |
| 94 | + } |
| 95 | + catch (Exception) {} |
| 96 | + |
| 97 | + |
| 98 | + try |
| 99 | + { |
| 100 | + ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT ProcessorId FROM Win32_processor"); |
| 101 | + ManagementObjectCollection mbsList = searcher.Get(); |
| 102 | + |
| 103 | + foreach (ManagementObject mo in mbsList) |
| 104 | + { |
| 105 | + cpu = mo["ProcessorId"].ToString(); |
| 106 | + break; |
| 107 | + } |
| 108 | + } |
| 109 | + catch (Exception) {} |
| 110 | + |
| 111 | + |
| 112 | + return hdd + motherboardn + cpu + "XenAuth"; |
| 113 | + } |
| 114 | + } |
| 115 | +} |
0 commit comments