Пример #1
0
        public void addItemsMethod(string packetInfo, byte[] PayLoadData)
        {
            bool isToClient = false;

            string[]      sData = packetInfo.Split(new char[] { ',' });
            List <byte[]> data  = new List <byte[]>();

            byte[]       useIv = new byte[4];
            ListViewItem lvi   = new ListViewItem((listView1.Items.Count + 1).ToString());

            foreach (string s in sData)
            {
                if (s.Contains("ToClient"))
                {
                    isToClient    = true;
                    lvi.BackColor = Color.FromArgb(229, 235, 224);
                }
                lvi.SubItems.Add(s);
            }
            if (PayLoadData[0] != 0x0F)
            {
                byte[] decryptData = new byte[PayLoadData.Length - 4];

                Buffer.BlockCopy(PayLoadData, 4, decryptData, 0, PayLoadData.Length - 4);

                byte[] tempData;
                if (isToClient)
                {
                    useIv    = clientRecv.getIv();
                    tempData = clientRecv.crypt(decryptData);
                    Console.WriteLine(BitTools.GetHexString(tempData));
                    if (tempData[0] == 0x6D)//如果是验证账号密码的封包 接受的时候需要再换一次iv才能正确解包
                    {
                        clientRecv.updateIv();
                        needUpdateIv = true;
                    }
                }
                else
                {
                    useIv    = clientSend.getIv();
                    tempData = clientSend.crypt(decryptData);
                }

                data.Add(PayLoadData);
                data.Add(tempData);
            }
            else
            {
                data.Add(PayLoadData);
            }

            lvi.SubItems[5].Text = BitTools.GetHexString(useIv);

            lvi.Tag = data;
            listView1.Items.Add(lvi);
        }
Пример #2
0
 private void textBox4_TextChanged(object sender, EventArgs e)
 {
     try
     {
         textBox5.Text = string.Format("Default:\r\n{0}\r\nASCII:\r\n{1}\r\nUTF8:\r\n{2}\r\n",
                                       Encoding.Default.GetString(BitTools.StringToBytes(textBox4.Text)),
                                       Encoding.ASCII.GetString(BitTools.StringToBytes(textBox4.Text)),
                                       Encoding.UTF8.GetString(BitTools.StringToBytes(textBox4.Text)));
     }
     catch
     {
         textBox5.Text = "";
     }
 }
Пример #3
0
        public byte[] getPacketHeader(int length)
        {
            int iiv = (iv[3]) & 0xFF;

            iiv |= (iv[2] << 8) & 0xFF00;
            iiv ^= mapleVersion;
            int mlength = ((length << 8) & 0xFF00) | BitTools.MoveByte(length, 8);
            int xoredIv = iiv ^ mlength;

            byte[] ret = new byte[4];
            ret[0] = (byte)(BitTools.MoveByte(iiv, 8) & 0xFF);
            ret[1] = (byte)(iiv & 0xFF);
            ret[2] = (byte)(BitTools.MoveByte(xoredIv, 8) & 0xFF);
            ret[3] = (byte)(xoredIv & 0xFF);
            return(ret);
        }
Пример #4
0
 private void listView1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listView1.SelectedIndices != null && listView1.SelectedIndices.Count > 0)
     {
         ListView.SelectedIndexCollection c = listView1.SelectedIndices;
         ListViewItem  selectItem           = listView1.Items[c[0]];
         List <byte[]> data = (List <byte[]>)selectItem.Tag;
         if (data.Count == 2)
         {
             richTextBox1.Text = string.Format("[原始数据 长度:{0}]\n{1} \n[解密数据 长度:{2}]\n{3} \n[Ascii]\n{4}",
                                               data[0].Length, BitTools.GetHexString(data[0]),
                                               data[1].Length, BitTools.GetHexString(data[1]),
                                               Encoding.ASCII.GetString(data[1]));
         }
         else
         {
             richTextBox1.Text = string.Format("[原始数据 长度:{0}]\n{1} ", data[0].Length, BitTools.GetHexString(data[0]));
         }
     }
 }
Пример #5
0
        private static byte[] funnyShit(byte inputByte, byte[] newIn)
        {
            byte elina  = newIn[1];
            byte anna   = inputByte;
            byte moritz = funnyBytes[elina & 0xFF];

            moritz   -= inputByte;
            newIn[0] += moritz;
            moritz    = newIn[2];
            moritz   ^= funnyBytes[anna & 0xFF];
            elina    -= (byte)(moritz & 0xFF);
            newIn[1]  = elina;
            elina     = newIn[3];
            moritz    = elina;
            elina    -= (byte)(newIn[0] & 0xFF);
            moritz    = funnyBytes[moritz & 0xFF];
            moritz   += inputByte;
            moritz   ^= newIn[2];
            newIn[2]  = moritz;
            elina    += (byte)(funnyBytes[anna & 0xFF] & 0xFF);
            newIn[3]  = elina;

            long merry = (newIn[0]) & 0xFF;

            merry |= Convert.ToInt64((newIn[1] << 8) & 0xFF00);
            merry |= Convert.ToInt64((newIn[2] << 16) & 0xFF0000);
            merry |= (newIn[3] << 24) & 0xFF000000;
            long ret_value = merry;

            ret_value = BitTools.MoveByte(ret_value, 0x1D);
            merry     = merry << 3;
            ret_value = ret_value | merry;

            newIn[0] = (byte)(ret_value & 0xFF);
            newIn[1] = (byte)((ret_value >> 8) & 0xFF);
            newIn[2] = (byte)((ret_value >> 16) & 0xFF);
            newIn[3] = (byte)((ret_value >> 24) & 0xFF);
            return(newIn);
        }
Пример #6
0
        private void button2_Click(object sender, EventArgs e)
        {
            byte[] b = new byte[]
            {
                0x76, 0x2D, 0xD0, 0xC2, 0xC9, 0xCD, 0x68, 0xD4, 0x49, 0x6A, 0x79, 0x25, 0x08, 0x61, 0x40, 0x14,
                0xB1, 0x3B, 0x6A, 0xA5, 0x11, 0x28, 0xC1, 0x8C, 0xD6, 0xA9, 0x0B, 0x87, 0x97, 0x8C, 0x2F, 0xF1
            };

            byte[] c = new byte[b.Length];
            for (int i = 0; i < b.Length; i++)
            {
                if (i % 4 == 0)
                {
                    c[i] = b[i];
                }
                else
                {
                    c[i] = 0x00;
                }
            }
            textBox6.Text = BitTools.GetHexStringWithTrim(c);
        }
Пример #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            MapleAES m_Cipher = null;

            string strIv = textBox1.Text.Trim();

            byte[] Iv = BitTools.StringToBytes(strIv);

            string strData = textBox2.Text.Trim();

            byte[] Data = BitTools.StringToBytes(strData);

            if (radBtn_SendIV.Checked)
            {
                m_Cipher = new MapleAES(Iv, this.mapleVersion);
            }
            else if (radBtn_RecvIV.Checked)
            {
                m_Cipher = new MapleAES(Iv, (ushort)(0xFFFF - this.mapleVersion));
            }

            if (checkBox1.Checked)
            {
                m_Cipher.updateIv();
            }
            try
            {
                byte[] packetBuffer = new byte[Data.Length - 4];
                Buffer.BlockCopy(Data, 4, packetBuffer, 0, packetBuffer.Length);

                m_Cipher.crypt(packetBuffer);

                textBox3.Text = BitConverter.ToString(packetBuffer).Replace("-", " ");
            }
            catch
            {
            }
        }
Пример #8
0
 public override string ToString()
 {
     return("IV: " + BitTools.GetHexString(this.iv));
 }