Example #1
0
        public string GetVersion(string koiId)
        {
            try
            {
#if DEBUG || __TRACE
                const string VER_URI = @"http://ki.no-ip.info/koi/{0}/VERSION";
#else
                const string VER_URI = @"https://ki-host.appspot.com/KoiVM/koi/{0}/VERSION";
#endif
                var verUri = new Uri(string.Format(VER_URI, koiId));
                using (var client = new WebClient())
                {
                    byte[] data = client.DownloadData(verUri);

                    var rc4 = new RC4(Encoding.UTF8.GetBytes(koiId));
                    rc4.Crypt(data, 0, data.Length);
                    string ver = Encoding.UTF8.GetString(data);

                    if (this.Hash(ver) == 0x4c3e88e4) // REVOKED
                    {
                        File.Delete(Path.Combine(KoiInfo.KoiDirectory, "koi.pack"));
                    }

                    return(ver);
                }
            }
            catch
            {
                return(null);
            }
        }
Example #2
0
        internal static void InitKoi(bool runCctor = true)
        {
            var rc4 = new RC4(Convert.FromBase64String("S29pVk0gaXMgY3V0ZSEhIQ=="));
            var buf = File.ReadAllBytes(Path.Combine(KoiDirectory, "koi.pack"));

            rc4.Crypt(buf, 0, buf.Length);
            using (var deflate = new DeflateStream(new MemoryStream(buf), CompressionMode.Decompress))
                using (var reader = new BinaryReader(deflate))
                {
                    var count = reader.ReadInt32();
                    assemblies.Clear();
                    for (var i = 0; i < count; i++)
                    {
                        var asm = Assembly.Load(reader.ReadBytes(reader.ReadInt32()));
                        assemblies.Add(asm);
                    }
                }

            if (!runCctor)
            {
                return;
            }
            foreach (var asm in assemblies) // Initialize the modules, since internal calls might not trigger module cctor
            {
                RuntimeHelpers.RunModuleConstructor(asm.ManifestModule.ModuleHandle);
            }
        }