public SMSInitialMessage(IMORZEAccount account, IMORZEContact contact)
        {
            BufferBuilder bb = new BufferBuilder();

            m_account = account;
            bb.AddByte(1);//- init message
            m_newExt = contact.getInitalData();
            bb.AddByte((byte)m_newExt.HashID);
            bb.AddBytes(m_newExt.Ext);

            bb.AddByte((byte)m_newExt.SyncID);
            bb.AddBytes(m_newExt.SyncKey);
            bb.AddBytes(m_newExt.SyncIV);
            bb.AddUshort(0);//или CRC16
            byte [] data = bb.GetAllBytes();
            data = contact.EncryptPK(data);
            byte[] addressdata = m_newExt.SyncEncrypt(account.GetMyAccount());
            bb = new BufferBuilder();

            bb.AddByte(contact.XOR((byte)data.Length, 0x10));
            bb.AddBytes(data);

            bb.AddBytes(addressdata);
            AddMessageBody(bb.GetAllBytes(), m_newExt.HashID, null);
        }
예제 #2
0
        public void AddMessageBody(byte [] msgBody, SMSHash hash, byte [] ext)
        {
            BufferBuilder bb = new BufferBuilder();

            bb.AddByte(0x32); //TTL
            byte idhash = (byte)hash;

            if (idhash != 0)
            {
                if (msgBody.Length < 0xFFFF)
                {
                    byte[] bthash = null;
                    switch (hash)
                    {
                    case SMSHash.MD5:
                        bthash = calcMD5(msgBody);
                        break;

                    default:
                        throw new Exception("Unsupported hash algorithm");
                    }
                    if (ext != null)
                    {
                        byte e = 0x80;
                        idhash |= e;
                        if (ext.Length != bthash.Length)
                        {
                            throw new Exception("Invalid ext");
                        }
                    }
                    bb.AddByte(idhash);

                    bb.AddBytes(bthash);
                    if (ext != null)
                    {
                        bb.AddBytes(ext);
                    }
                    bb.AddUshort((ushort)msgBody.Length);
                    bb.AddBytes(msgBody);
                    if (m_bodies == null)
                    {
                        m_bodies = new List <byte[]>();
                    }
                    m_bodies.Add(bb.GetAllBytes());
                }
                else
                {
                    throw new Exception("Unsupported length message");
                }
            }
            else
            {
                throw new Exception("did't select hash algorithm");
            }
        }