Esempio n. 1
0
        public static void InitWarden()
        {
            MaievData m = new(Realmserver.SS_Hash);

            byte[] seedOut = m.GetBytes(16);
            byte[] seedIn  = m.GetBytes(16);
            Maiev.KeyOut = RC4.Init(seedOut);
            Maiev.KeyIn  = RC4.Init(seedIn);
        }
Esempio n. 2
0
        public static void SendWardenPacket(ref Packets.PacketClass Packet)
        {
            // START Warden Encryption
            byte[] b = new byte[(Packet.Data.Length - 6)];
            Buffer.BlockCopy(Packet.Data, 6, b, 0, b.Length);
            RC4.Crypt(ref b, Maiev.KeyOut);
            Buffer.BlockCopy(b, 0, Packet.Data, 6, b.Length);
            // END

            Worldserver.Send(Packet);
        }
Esempio n. 3
0
            /* TODO ERROR: Skipped RegionDirectiveTrivia */
            public bool LoadModule(string Name, ref byte[] Data, byte[] Key)
            {
                Key = RC4.Init(Key);
                RC4.Crypt(ref Data, Key);
                int UncompressedLen = BitConverter.ToInt32(Data, 0);

                if (UncompressedLen < 0)
                {
                    Console.WriteLine("[WARDEN] Failed to decrypt {0}, incorrect length.", Name);
                    return(false);
                }

                var CompressedData = new byte[(Data.Length - 0x108)];

                Array.Copy(Data, 4, CompressedData, 0, CompressedData.Length);
                int    dataPos = 4 + CompressedData.Length;
                string Sign    = Conversions.ToString((char)Data[dataPos + 3]) + (char)Data[dataPos + 2] + (char)Data[dataPos + 1] + (char)Data[dataPos];

                if (Sign != "SIGN")
                {
                    Console.WriteLine("[WARDEN] Failed to decrypt {0}, sign missing.", Name);
                    return(false);
                }

                dataPos += 4;
                var Signature = new byte[256];

                Array.Copy(Data, dataPos, Signature, 0, Signature.Length);

                // Check signature
                if (CheckSignature(Signature, Data, Data.Length - 0x104) == false)
                {
                    Console.WriteLine("[WARDEN] Signature fail on Warden Module.");
                    return(false);
                }

                var DecompressedData = new ZipService().DeCompress(CompressedData);
                var ms = new MemoryStream(DecompressedData);
                var br = new BinaryReader(ms);

                ModuleData = PrepairModule(ref br);
                ms.Close();
                ms.Dispose();
                br = null;
                Console.WriteLine("[WARDEN] Successfully prepaired Warden Module.");
                if (!InitModule(ref ModuleData))
                {
                    return(false);
                }
                return(true);
            }
Esempio n. 4
0
        public static void On_SMSG_WARDEN_DATA(ref Packets.PacketClass Packet)
        {
            // START Warden Decryption
            byte[] b = new byte[(Packet.Data.Length - 4)];
            Buffer.BlockCopy(Packet.Data, 4, b, 0, b.Length);
            RC4.Crypt(ref b, Maiev.KeyIn);
            Buffer.BlockCopy(b, 0, Packet.Data, 4, b.Length);
            // END

            byte[] WardenData = new byte[(Packet.Data.Length - 4)];
            Buffer.BlockCopy(Packet.Data, 4, WardenData, 0, WardenData.Length);
            MaievOpcode Opcode = (MaievOpcode)Packet.GetInt8();

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("SMSG_WARDEN_DATA [{0}]", Opcode);
            Console.ForegroundColor = ConsoleColor.White;
            switch (Opcode)
            {
            case MaievOpcode.MAIEV_MODULE_INFORMATION:
            {
                byte[] Name = Packet.GetByteArray(16);
                byte[] Key  = Packet.GetByteArray(16);
                uint   Size = Packet.GetUInt32();
                Maiev.ModuleName = BitConverter.ToString(Name).Replace("-", "");
                Maiev.ModuleKey  = Key;
                ModuleLength     = (int)Size;
                Maiev.ModuleData = Array.Empty <byte>();
                if (File.Exists(@"modules\" + Maiev.ModuleName + ".mod") == false)
                {
                    Console.WriteLine("[{0}][WARDEN] Module is missing.", Strings.Format(DateAndTime.TimeOfDay, "HH:mm:ss"));
                    Packets.PacketClass response = new(OPCODES.CMSG_WARDEN_DATA);
                    response.AddInt8((byte)MaievResponse.MAIEV_RESPONSE_FAILED_OR_MISSING);
                    SendWardenPacket(ref response);
                    response.Dispose();
                }
                else
                {
                    Console.WriteLine("[{0}][WARDEN] Module is initiated.", Strings.Format(DateAndTime.TimeOfDay, "HH:mm:ss"));
                    Maiev.ModuleData = File.ReadAllBytes(@"modules\" + Maiev.ModuleName + ".mod");
                    if (Maiev.LoadModule(Maiev.ModuleName, ref Maiev.ModuleData, Maiev.ModuleKey))
                    {
                        Console.WriteLine("[{0}][WARDEN] Successfully loaded the module.", Strings.Format(DateAndTime.TimeOfDay, "HH:mm:ss"));
                        Packets.PacketClass response = new(OPCODES.CMSG_WARDEN_DATA);
                        response.AddInt8((byte)MaievResponse.MAIEV_RESPONSE_SUCCESS);
                        SendWardenPacket(ref response);
                        response.Dispose();
                    }
                    else
                    {
                        Packets.PacketClass response = new(OPCODES.CMSG_WARDEN_DATA);
                        response.AddInt8((byte)MaievResponse.MAIEV_RESPONSE_FAILED_OR_MISSING);
                        SendWardenPacket(ref response);
                        response.Dispose();
                    }
                }

                break;
            }

            case MaievOpcode.MAIEV_MODULE_TRANSFER:
            {
                ushort Size = Packet.GetUInt16();
                byte[] Data = Packet.GetByteArray(Size);
                Maiev.ModuleData = Realmserver.Concat(Maiev.ModuleData, Data);
                ModuleLength    -= Size;
                if (ModuleLength <= 0)
                {
                    Console.WriteLine("[{0}][WARDEN] Module is fully transfered.", Strings.Format(DateAndTime.TimeOfDay, "HH:mm:ss"));
                    if (Directory.Exists("modules") == false)
                    {
                        Directory.CreateDirectory("modules");
                    }

                    File.WriteAllBytes(@"modules\" + Maiev.ModuleName + ".mod", Maiev.ModuleData);
                    if (Maiev.LoadModule(Maiev.ModuleName, ref Maiev.ModuleData, Maiev.ModuleKey))
                    {
                        Console.WriteLine("[{0}][WARDEN] Successfully loaded the module.", Strings.Format(DateAndTime.TimeOfDay, "HH:mm:ss"));
                        Packets.PacketClass response = new(OPCODES.CMSG_WARDEN_DATA);
                        response.AddInt8((byte)MaievResponse.MAIEV_RESPONSE_SUCCESS);
                        SendWardenPacket(ref response);
                        response.Dispose();
                    }
                }
                else
                {
                    Console.WriteLine("[{0}][WARDEN] Module transfer. Bytes left: {1}", Strings.Format(DateAndTime.TimeOfDay, "HH:mm:ss"), ModuleLength);
                }

                break;
            }

            case MaievOpcode.MAIEV_MODULE_RUN:
            {
                Console.WriteLine("[{0}][WARDEN] Requesting a scan.", Strings.Format(DateAndTime.TimeOfDay, "HH:mm:ss"));

                // TODO: Encrypt?
                Maiev.ReadKeys2();
                RC4.Crypt(ref WardenData, Maiev.ModKeyIn);
                int HandledBytes = Maiev.HandlePacket(WardenData);
                if (HandledBytes <= 0)
                {
                    return;
                }

                byte[] thePacket = Maiev.ReadPacket();
                if (thePacket.Length == 0)
                {
                    return;
                }

                RC4.Crypt(ref WardenData, Maiev.ModKeyOut);

                // TODO: Decrypt?

                Packets.DumpPacket(thePacket);
                Packets.PacketClass response = new(OPCODES.CMSG_WARDEN_DATA);
                response.AddByteArray(thePacket);
                SendWardenPacket(ref response);
                response.Dispose();
                break;
            }

            case MaievOpcode.MAIEV_MODULE_UNK:
            {
                // TODO: Encrypt?
                Maiev.ReadKeys2();
                RC4.Crypt(ref WardenData, Maiev.ModKeyIn);
                int HandledBytes = Maiev.HandlePacket(WardenData);
                if (HandledBytes <= 0)
                {
                    return;
                }

                byte[] thePacket = Maiev.ReadPacket();
                if (thePacket.Length == 0)
                {
                    return;
                }

                RC4.Crypt(ref WardenData, Maiev.ModKeyOut);
                // TODO: Decrypt?

                Packets.DumpPacket(thePacket);
                Packets.PacketClass response = new(OPCODES.CMSG_WARDEN_DATA);
                response.AddByteArray(thePacket);
                SendWardenPacket(ref response);
                response.Dispose();
                break;
            }

            case MaievOpcode.MAIEV_MODULE_SEED:
            {
                Maiev.GenerateNewRC4Keys(Realmserver.SS_Hash);
                int HandledBytes = Maiev.HandlePacket(WardenData);
                if (HandledBytes <= 0)
                {
                    return;
                }

                byte[] thePacket = Maiev.ReadPacket();
                Maiev.ModKeyIn  = new byte[258];
                Maiev.ModKeyOut = new byte[258];
                Packets.PacketClass response = new(OPCODES.CMSG_WARDEN_DATA);
                response.AddByteArray(thePacket);
                SendWardenPacket(ref response);
                response.Dispose();
                Maiev.ReadKeys();
                break;
            }

            default:
            {
                Console.WriteLine("[{0}][WARDEN] Unhandled Opcode [{1}] 0x{2:X}", Strings.Format(DateAndTime.TimeOfDay, "HH:mm:ss"), Opcode, Conversions.ToInteger(Opcode));
                break;
            }
            }
        }