public IsLicense postCheckLicense(string uri, string post, int i) { IsLicense result2; if (i < this.servers.Length) { byte[] rv = System.Text.Encoding.UTF8.GetBytes(post); System.Uri target = new System.Uri(this.servers[i] + uri); System.Net.WebRequest req = System.Net.WebRequest.Create(target); req.Timeout = this.timeout; req.Method = "POST"; req.PreAuthenticate = true; req.ContentType = "application/x-www-form-urlencoded"; req.ContentLength = (long)rv.Length; System.IO.Stream os = req.GetRequestStream(); os.Write(rv, 0, rv.Length); os.Close(); try { System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)req.GetResponse(); string a = ""; if (response == null) { i++; result2 = this.postCheckLicense(uri, post, i); return(result2); } System.IO.Stream receiveStream = response.GetResponseStream(); System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8"); System.IO.StreamReader readStream = new System.IO.StreamReader(receiveStream, encode); char[] read = new char[256]; for (int count = readStream.Read(read, 0, 256); count > 0; count = readStream.Read(read, 0, 256)) { string str = new string(read, 0, count); a += str; } if (a != "") { IsLicense result = new IsLicense(); result.getFromJson(a); result2 = result; return(result2); } response.Close(); result2 = new IsLicense(); return(result2); } catch (System.Net.WebException) { i++; result2 = this.postCheckLicense(uri, post, i); return(result2); } } result2 = new IsLicense(); return(result2); }
static void Main(string[] args) { Stopwatch ICwatch = new Stopwatch(); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); if (false && File.Exists(@"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\gmfdiprp.bab\DebuggerShared.dll")) { DebuggerPath = @"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\gmfdiprp.bab\DebuggerShared.dll"; Console.WriteLineFormatted("Found {0}", Color.LightGreen, Color.Gray, DebuggerPath); } else { var result = USNEngine.GetSearchPath("DebuggerShared.dll"); if (result.Count() > 0) { foreach (var item in result) { if (item is FileAndDirectoryEntry) { if (item.Path.Contains(@"\IDE\Extensions")) { //DebuggerPath = item.FullFileName; Console.WriteLineFormatted("Found {0}", Color.LightGreen, Color.Gray, DebuggerPath); } } } Console.WriteLine(); } } string licensPrivatekey = rsa.ToXmlString(true); string licensePublicKey = rsa.ToXmlString(false); if (DebuggerPath == "") { Console.WriteLineFormatted("Example {0} ", Color.LightYellow, Color.Gray, @"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\gmfdiprp.bab\DebuggerShared.dll"); while (!DebuggerPath.Contains("DebuggerShared.dll")) { Console.WriteLineFormatted("Not Found [{0}]", Color.LightGreen, Color.Gray, "DebuggerShared.dll"); Console.WriteLineFormatted("Please Input [{0}] Path", Color.Red, Color.Gray, "DebuggerShared.dll"); DebuggerPath = Console.ReadLine(); } } byte[] array = File.ReadAllBytes(DebuggerPath); byte[] resbyteST = Encoding.UTF8.GetBytes(FileReplace.CharsFill("<RSAKeyValue><Modulus>".ToCharArray())); byte[] resbyteED = Encoding.UTF8.GetBytes(FileReplace.CharsFill("</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>".ToCharArray())); int rsastarting = FileReplace.SundayIndexOf(array, resbyteST); int rsaEnding = FileReplace.SundayIndexOf(array, resbyteED); //byte[] searchRsa = Encoding.UTF8.GetBytes(FileReplace.CharsFill(rsaPublicKey.ToCharArray())); byte[] searchRsa = array.Skip(rsastarting).Take(rsaEnding - rsastarting + resbyteED.Length).ToArray(); string Rsastr = Encoding.UTF8.GetString(searchRsa).Replace($"\0", ""); Console.WriteLineFormatted("XmlRAS {0}", Color.LightGreen, Color.Gray, Rsastr); byte[] replaceRsa = Encoding.UTF8.GetBytes(FileReplace.CharsFill(licensePublicKey.ToCharArray())); try { if (FileReplace.SundayIndexOf(array, searchRsa) > -1) { Console.WriteLine("WriteAllBytes HexReplace"); File.WriteAllBytes(DebuggerPath, FileReplace.HexReplace(array, searchRsa, replaceRsa)); } } catch (Exception ex) { Console.WriteLineFormatted("ERR# \r\n {0}", Color.Red, Color.PowderBlue, ex); Console.WriteLineFormatted("Please Close VStudio ", Color.LightSeaGreen); } LicenseXml = Generating.Getkey(licensPrivatekey, "yang.linhao", Guid.NewGuid(), DateTime.UtcNow.AddYears(5), new Dictionary <string, string> { }, (Generating.EnumSet) 2); string Licensekey = Compression.CompressStringToBase64(LicenseXml); LicenseXml = Compression.DecompressStringFromBase64(Licensekey); //Console.WriteLine(LicenseXml); IsLicense isLicense = new IsLicense(); array = File.ReadAllBytes(DebuggerPath); rsastarting = FileReplace.SundayIndexOf(array, resbyteST); rsaEnding = FileReplace.SundayIndexOf(array, resbyteED); //byte[] searchRsa = Encoding.UTF8.GetBytes(FileReplace.CharsFill(rsaPublicKey.ToCharArray())); searchRsa = array.Skip(rsastarting).Take(rsaEnding - rsastarting + resbyteED.Length).ToArray(); Rsastr = Encoding.UTF8.GetString(searchRsa).Replace($"\0", ""); if (isLicense.HasExistingLicense(Rsastr)) { Console.WriteLineFormatted("It`s [{0}]", Color.LightGreen, Color.Gray, "OK."); Console.WriteLine(Licensekey); } else { Console.WriteLineFormatted("It`s [{0}]", Color.Red, Color.Gray, "ERR."); } Console.ReadKey(); }