readNullTerminatedString() публичный статический Метод

public static readNullTerminatedString ( string packet, int &offset ) : string
packet string
offset int
Результат string
Пример #1
0
        protected void RealmList(byte type, List <byte> data)
        {
            UInt32 count  = BitConverter.ToUInt32(data.ToArray(), 8);
            Int32  offset = 12;

            if (ClientlessBot.debugging)
            {
                Console.WriteLine("{0}: [BNCS] List of realms:", m_owner.Account);
            }

            for (ulong i = 1; i <= count; i++)
            {
                offset += 4;
                String realmTitle       = Utils.readNullTerminatedString(System.Text.Encoding.ASCII.GetString(data.ToArray()), ref offset);
                String realmDescription = Utils.readNullTerminatedString(System.Text.Encoding.ASCII.GetString(data.ToArray()), ref offset);
                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("{0}: [BNCS] {1}. {2}, {3}", m_owner.Account, i, realmTitle, realmDescription);
                }

                if (m_owner.Realm == null && i == 1)
                {
                    if (ClientlessBot.debugging)
                    {
                        Console.WriteLine("{0}: [BNCS] No realm was specified in the ini so we're going to connect to {1}", m_owner.Account, realmTitle);
                    }
                    m_owner.Realm = realmTitle;
                }
            }

            if (m_owner.LoggedIn)
            {
                //make_game();
            }
            else
            {
                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("{0}: [BNCS] Logging on to the realm {1}", m_owner.Account, m_owner.Realm);
                }

                UInt32 clientToken = 1;
                byte[] packet      = BuildPacket((byte)0x3e, BitConverter.GetBytes(clientToken), Bsha1.DoubleHash(clientToken, m_owner.ServerToken, "password"), System.Text.Encoding.ASCII.GetBytes(m_owner.Realm), zero);

                byte[] temp = System.Text.Encoding.ASCII.GetBytes(m_owner.Realm);

                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("\tSize of realm string: {0}", temp.Length);

                    Console.WriteLine("\tWriting to Stream: ");
                    for (int i = 0; i < packet.Length; i++)
                    {
                        if (i % 8 == 0 && i != 0)
                        {
                            Console.Write(" ");
                        }
                        if (i % 16 == 0 && i != 0)
                        {
                            Console.WriteLine("");
                        }
                        Console.Write("{0:X2} ", packet[i]);
                    }
                    Console.WriteLine("");
                }
                m_stream.Write(packet, 0, packet.Length);
            }
        }
Пример #2
0
        protected void AuthInfoRequest(byte type, List <byte> data)
        {
            if (ClientlessBot.debugging)
            {
                Console.WriteLine("{0}: [BNCS] Received Auth Info Packet", m_owner.Account);
            }

            m_owner.ServerToken = BitConverter.ToUInt32(data.ToArray(), 8);
            List <byte> temp = data.GetRange(16, 8);

            byte[] tbytes = new byte[temp.Count];
            temp.CopyTo(tbytes);

            String mpq_file_time = System.Text.Encoding.ASCII.GetString(tbytes);

            int offset;

            if (data.ToArray()[24] == 0x76)
            {
                offset = 24;
            }
            else
            {
                offset = 24;
            }
            //Console.WriteLine((char)data.ToArray()[24]);

            String mpq_file_name = Utils.readNullTerminatedString(System.Text.Encoding.ASCII.GetString(data.ToArray()), ref offset);
            //Console.WriteLine(mpq_file_name[0]);
            String formula_string = Utils.readNullTerminatedString(System.Text.Encoding.ASCII.GetString(data.ToArray()), ref offset);

            //Console.WriteLine(formula_string[0]);

            if (ClientlessBot.debugging)
            {
                Console.WriteLine("\tServer Token: {0}", m_owner.ServerToken);
                Console.WriteLine("\tMPQ File Time: {0}", mpq_file_time);
                Console.WriteLine("\tMPQ File Name: {0}", mpq_file_name);
                Console.WriteLine("\tFormula String: {0}", formula_string);
            }


            TcpClient bnftp = new TcpClient();

            bnftp.Connect(m_owner.BattleNetServer, s_bncsPort);
            NetworkStream ftpstream = bnftp.GetStream();

            if (ftpstream.CanWrite)
            {
                //Console.WriteLine(" Connected");
                ftpstream.WriteByte(0x02);
                List <byte> bytes   = new List <byte>();
                byte[]      tempftp = { 0x2f, 0x00, 0x00, 0x01 };

                bytes.AddRange(tempftp);
                bytes.AddRange(System.Text.Encoding.ASCII.GetBytes(platform));
                bytes.AddRange(System.Text.Encoding.ASCII.GetBytes(classic_id));
                bytes.AddRange(nulls);
                bytes.AddRange(nulls);
                bytes.AddRange(nulls);
                bytes.AddRange(System.Text.Encoding.ASCII.GetBytes(mpq_file_time));
                bytes.AddRange(System.Text.Encoding.ASCII.GetBytes(mpq_file_name));
                bytes.AddRange(zero);

                ftpstream.Write(bytes.ToArray(), 0, bytes.Count);

                List <byte> buffer = new List <byte>();

                do
                {
                    buffer.Add((byte)ftpstream.ReadByte());
                } while (buffer.Count < 8);
                byte[] bufferBytes = buffer.ToArray();
                UInt16 headerSize  = BitConverter.ToUInt16(bufferBytes, 0);
                UInt32 fileSize    = BitConverter.ToUInt32(bufferBytes, 4);
                UInt32 totalSize   = fileSize + headerSize;
                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("{0}: [BNCS] Starting BNFTP download", m_owner.Account);
                }

                do
                {
                    if (ftpstream.DataAvailable)
                    {
                        buffer.Add((byte)ftpstream.ReadByte());
                    }
                    else
                    {
                        break;
                    }
                } while (buffer.Count < totalSize);
                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("{0}: [BNCS] Finished BNFTP download", m_owner.Account);
                }

                ftpstream.Close();
                bnftp.Close();
            }
            else
            {
            }

            uint exe_checksum = AdvancedCheckRevision.FastComputeHash(formula_string, mpq_file_name,
                                                                      System.IO.Path.Combine(m_owner.BinaryDirectory, "Game.exe"),
                                                                      System.IO.Path.Combine(m_owner.BinaryDirectory, "Bnclient.dll"),
                                                                      System.IO.Path.Combine(m_owner.BinaryDirectory, "D2Client.dll"));

            /*
             * switch (CheckRevision.DoCheck(formula_string, mpq_file_name,  m_owner.BinaryDirectory, ref exe_checksum))
             * {
             *  case CheckRevision.CheckRevisionResult.CHECK_REVISION_SUCCESS:
             *      if (ClientlessBot.debugging)
             *          Console.WriteLine("\t\tCheck Revision SUCCESS");
             *      break;
             *  default:
             *      if (ClientlessBot.debugging)
             *          Console.WriteLine("\t\tCheck Revision Failed");
             *      break;
             * }
             */
            uint client_token = (uint)System.Environment.TickCount;

            List <byte> classic_hash = new List <byte>(), lod_hash = new List <byte>(), classic_public = new List <byte>(), lod_public = new List <byte>();


            if (CdKey.GetD2KeyHash(m_owner.ClassicKey, ref client_token, m_owner.ServerToken, ref classic_hash, ref classic_public))
            {
                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("{0}: [BNCS] Successfully generated the classic CD key hash", m_owner.Account);
                }
            }
            else
            {
                Console.WriteLine("{0}: [BNCS] CD key is invalid", m_owner.Account);
                m_owner.Status = ClientlessBot.ClientStatus.STATUS_INVALID_CD_KEY;
            }

            if (CdKey.GetD2KeyHash(m_owner.ExpansionKey, ref client_token, m_owner.ServerToken, ref lod_hash, ref lod_public))
            {
                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("{0}: [BNCS] Successfully generated the lod CD key hash", m_owner.Account);
                }
            }
            else
            {
                Console.WriteLine("{0}: [BNCS] Expansion CD key is invalid", m_owner.Account);
                m_owner.Status = ClientlessBot.ClientStatus.STATUS_INVALID_EXP_CD_KEY;
            }


            byte[] packet = BuildPacket((byte)0x51, BitConverter.GetBytes(client_token), BitConverter.GetBytes(0x01000001), BitConverter.GetBytes(exe_checksum),
                                        BitConverter.GetBytes(0x00000002), nulls, ten, six, classic_public, nulls, classic_hash, ten, BitConverter.GetBytes((UInt32)10),
                                        lod_public, nulls, lod_hash, System.Text.Encoding.UTF8.GetBytes(m_owner.GameExeInformation), zero, System.Text.Encoding.ASCII.GetBytes(m_owner.KeyOwner), zero);

            PrintPacket(packet);

            m_stream.Write(packet, 0, packet.Length);
        }
Пример #3
0
        protected void CharacterList(byte type, List <byte> data)
        {
            UInt16 count = BitConverter.ToUInt16(data.ToArray(), 9);

            if (count == 0)
            {
                Console.WriteLine("{0}: [MCP] There are no characters on this account", m_owner.Account);
                m_owner.Status = ClientlessBot.ClientStatus.STATUS_ON_MCP;
            }
            else
            {
                bool foundCharacter       = false;
                bool selectFirstCharacter = false;
                if (ClientlessBot.debugging)
                {
                    Console.WriteLine("{0}: [MCP] List of characters on this account", m_owner.Account);
                }
                int offset = 11;

                for (int i = 1; i <= count; i++)
                {
                    offset += 4;
                    String      dataString    = System.Text.Encoding.ASCII.GetString(data.ToArray());
                    String      characterName = Utils.readNullTerminatedString(dataString, ref offset);
                    int         length        = data.IndexOf(0, offset) - offset;
                    List <byte> stats         = data.GetRange(offset, length);
                    offset           += length;
                    m_owner.ClassByte = (byte)((stats[13] - 0x01) & 0xFF);
                    byte   level         = stats[25];
                    byte   flags         = stats[26];
                    bool   hardcore      = (flags & 0x04) != 0;
                    bool   dead          = (flags & 0x08) != 0;
                    bool   expansion     = (flags & 0x20) != 0;
                    String coreString    = hardcore ? "Hardcore" : "Softcore";
                    String versionString = expansion ? "Expansion" : "Classic";
                    String classType;

                    switch (m_owner.ClassByte)
                    {
                    case 0: classType = "Amazon";
                        break;

                    case 1: classType = "Sorceress";
                        break;

                    case 2: classType = "Necromancer";
                        break;

                    case 3: classType = "Paladin";
                        break;

                    case 4: classType = "Barbarian";
                        break;

                    case 5: classType = "Druid";
                        break;

                    case 6: classType = "Assassin";
                        break;

                    default: classType = "Unknown";
                        break;
                    }

                    if (ClientlessBot.debugging)
                    {
                        Console.WriteLine("{0}: [MCP] {1}. {2}, Level: {3}, {6} ({4}|{5})", m_owner.Account, i, characterName, level, coreString, versionString, classType);
                    }

                    if (m_owner.Character == null && i == 1)
                    {
                        selectFirstCharacter = true;
                        m_owner.Character    = characterName;
                    }

                    if (m_owner.Character.Equals(characterName))
                    {
                        foundCharacter         = true;
                        m_owner.CharacterLevel = level;
                    }
                }
                if (selectFirstCharacter)
                {
                    if (ClientlessBot.debugging)
                    {
                        Console.WriteLine("{0}: [MCP] No character specified, chose first character", m_owner.Account);
                    }
                }
                if (!foundCharacter)
                {
                    Console.WriteLine("{0}: [MCP] Unable to locate character specified", m_owner.Account);
                    return;
                }

                Console.WriteLine("{0}: [MCP] Logging on to character {1}", m_owner.Account, m_owner.Character);

                byte[] packet = BuildPacket(0x07, System.Text.Encoding.ASCII.GetBytes(m_owner.Character), zero);
                m_stream.Write(packet, 0, packet.Length);
            }
        }