public static bool decode(string key, out string reason) { byte[] xin = clib.hex_to_byte(key); int index1 = 0; int mon = 0; reason = ""; if (key.Length < 30) { reason = "tooshort: Keys are 30 char long"; return(false); } MyKey.regid = (int)xin[index1] + (int)xin[index1 + 1] * 256 + (int)xin[index1 + 2] * 65536; int index2 = index1 + 3; MyKey.regdate = (int)xin[index2] + (int)xin[index2 + 1] * 256; int index3 = index2 + 2; MyKey.host = (int)xin[index3] + (int)xin[index3 + 1] * 256; int num1 = index3 + 2; byte[] numArray1 = xin; int index4 = num1; int num2 = index4 + 1; MyKey.prodid = (int)numArray1[index4]; byte[] numArray2 = xin; int index5 = num2; int num3 = index5 + 1; MyKey.flags = (int)numArray2[index5]; byte[] numArray3 = xin; int index6 = num3; int index7 = index6 + 1; MyKey.ulimit = MyKey.keylib_ulimit_decode((int)numArray3[index6]); int num4 = MyKey.keylib_crc(xin, MyKey.PRE_CRC); int num5 = (int)xin[index7] + (int)xin[index7 + 1] * 256; int num6 = index7 + 2; clib.imsg("crc {0} {1}", (object)num4, (object)num5); MyKey.reg_day1 = (int)xin[12]; MyKey.reg_day2 = (int)xin[13]; MyKey.fromdate = MyKey.keylib_fromdate(MyKey.regdate, MyKey.reg_day1, MyKey.reg_day2, out mon); if (MyKey.host != 0) { string host = MyKey.get_host(); if (MyKey.keylib_host(host) != MyKey.host && MyKey.keylib_host(MyKey.keylib_host_trim(host)) != MyKey.host) { reason = string.Format("Key for wrong host=({0}) ({1}) , try activate again", (object)host, (object)MyKey.keylib_host_trim(host)); return(false); } } DateTime date = clib.unix_to_date(MyKey.fromdate); MyKey.expdate = date.AddMonths(mon).to_unix_date(); if (mon == 0) { date = clib.unix_to_date(MyKey.fromdate); MyKey.expdate = date.AddMonths(12).to_unix_date(); } MyKey.istemp = true; if (mon == 0) { MyKey.istemp = false; } clib.imsg("Fromdate is {0} {1} Expires {2}", (object)MyKey.fromdate, (object)clib.nice_unix_date(MyKey.fromdate), (object)clib.nice_unix_date(MyKey.expdate)); if (num4 == num5) { return(true); } reason = "bad crc"; return(false); }
private static int keylib_host(string host) { host = host.ToLower(); return(host == "*" ? 0 : MyKey.keylib_crc(clib.string_to_byte(host), host.Length) & (int)ushort.MaxValue); }