Ejemplo n.º 1
0
        public static Message ReadBinMessage(Stream s)
        {
            Message m = new Message();

            s.Seek(4, SeekOrigin.Current);
            int  MsgHeaderFlags = s.ReadByte();
            bool udhi           = ((MsgHeaderFlags & 0x40) > 0);
            int  MsgType        = MsgHeaderFlags & 0x0F;

            s.ReadByte();
            bool ucs2 = (s.ReadByte() == 8);

            s.ReadByte();

            int test, len, len2;

            byte[] buff;

            switch (MsgType)
            {
            case 0x00:
            case 0x04:                     // incoming message
                m.Direction = MessageDirection.Incoming;

                s.ReadByte();
                m.MessageTime = StreamUtilsPdu.ReadDateTime(s);
                s.Seek(8, SeekOrigin.Current);
                m.PhoneNumber = StreamUtilsPdu.ReadPhoneNumber(s);
                s.Seek(5, SeekOrigin.Current);
                m.SmscNumber = StreamUtilsPdu.ReadPhoneNumber(s, true);

                s.Seek(4, SeekOrigin.Current);
                len  = StreamUtils.ReadUInt16(s);
                len2 = StreamUtils.ReadUInt16(s);
                s.Seek(2, SeekOrigin.Current);
                buff = StreamUtils.ReadBuff(s, len2);
                m.DecodeMessageText(udhi, ucs2, len, buff);
                StreamUtils.Counter += len2;

                break;

            case 0x01:                     // outgoing message
                m.Direction = MessageDirection.Outgoing;

                s.Seek(2, SeekOrigin.Current);

                test = s.ReadByte();
                if (test == 1)
                {
                    m.MessageTime = StreamUtils.ReadNokiaDateTime2(s).ToLocalTime();
                    s.Seek(7, SeekOrigin.Current);
                }

                test = s.ReadByte();
                if (test == 1)
                {
                    s.Seek(4, SeekOrigin.Current);
                    m.PhoneNumber = StreamUtilsPdu.ReadPhoneNumber(s);
                    s.Seek(5, SeekOrigin.Current);
                    m.SmscNumber = StreamUtilsPdu.ReadPhoneNumber(s, true);
                }
                else
                {
                    s.Seek(9, SeekOrigin.Current);
                }

                s.Seek(4, SeekOrigin.Current);
                len  = StreamUtils.ReadUInt16(s);
                len2 = StreamUtils.ReadUInt16(s);
                s.Seek(2, SeekOrigin.Current);
                buff = StreamUtils.ReadBuff(s, len2);
                m.DecodeMessageText(udhi, ucs2, len, buff);
                StreamUtils.Counter += len2;

                break;

            case 0x06:                     // delivery report message
                m.Direction = MessageDirection.Incoming;

                s.ReadByte();
                m.MessageTime = StreamUtilsPdu.ReadDateTime(s);
                s.Seek(15, SeekOrigin.Current);
                m.PhoneNumber = StreamUtilsPdu.ReadPhoneNumber(s);
                s.Seek(5, SeekOrigin.Current);
                m.SmscNumber = StreamUtilsPdu.ReadPhoneNumber(s, true);
                s.Seek(10, SeekOrigin.Current);

                m.MessageText = "Delivery report message";
                m.IsDelivery  = true;
                break;

            default:
                throw new ApplicationException("Unknown message type");
            }
            return(m);
        }
Ejemplo n.º 2
0
        public static Message ReadPredefBinMessage(string currentFileName, Stream s, string filename)
        {
            Message m = new Message();

            s.Seek(0xB0, SeekOrigin.Begin);
            int  MsgHeaderFlags = s.ReadByte();
            bool udhi           = (MsgHeaderFlags & 0x40) > 0;
            int  MsgType        = MsgHeaderFlags & 0x0F;
            bool ucs2;

            switch (MsgType)
            {
            case 0:
            case 4:
                m.Direction   = MessageDirection.Incoming;
                m.PhoneNumber = StreamUtilsPdu.ReadPhoneNumber(s);

                s.ReadByte();                         // 00 expected
                ucs2 = (s.ReadByte() == 8);

                try
                {
                    m.MessageTime = StreamUtilsPdu.ReadDateTime(s);
                }
                catch { }

                s.ReadByte();

                m.DecodeMessageBody(udhi, ucs2, s);
                break;

            case 1:
                m.Direction = MessageDirection.Outgoing;

                s.ReadByte();

                m.PhoneNumber = StreamUtilsPdu.ReadPhoneNumber(s);
                if (m.PhoneNumber == "+35856789123456789123")
                {
                    m.PhoneNumber = "";
                }

                s.ReadByte();

                ucs2 = (s.ReadByte() == 8);

                s.ReadByte();

                m.DecodeMessageBody(udhi, ucs2, s);

                if (string.IsNullOrEmpty(m.PhoneNumber))
                {
                    s.Seek(0x5F, SeekOrigin.Begin);
                    StreamUtils.SeekTo(UnicodeZero, s);
                    if (s.Position > 0x61)
                    {
                        int len = (int)(s.Position - 0x5F) / 2;
                        s.Seek(0x5F, SeekOrigin.Begin);
                        m.PhoneNumber = StreamUtils.ReadString(s, len);
                    }
                }

                break;

            case 0x0C:
                s.Seek(-1, SeekOrigin.Current);
                try
                {
                    m.Mms         = new Mms(currentFileName, s, s.Length);
                    m.MessageTime = m.Mms.Time;
                    m.MessageText = m.Mms.ParseLog;
                }
                catch { }
                break;

            default:
                throw new ApplicationException("Unknown message type");
            }

            if (m.messageTime == DateTime.MinValue && filename.Length > 16)
            {
                try
                {
                    string tmp = filename.Substring(8, 8);
                    Int64  sec = Int64.Parse(tmp, System.Globalization.NumberStyles.HexNumber);
                    m.MessageTime = new DateTime(1980, 1, 1).AddSeconds(sec);

                    if (RecalculateUtcToLocal)
                    {
                        m.MessageTime = m.MessageTime.ToLocalTime();
                    }
                }
                catch { }
            }

            return(m);
        }