Ejemplo n.º 1
0
 private void parseICQ2003aBody(ICQDataStream strmBody)
 {
     byte[] baText = strmBody.readBinary();
     if (null != baText && baText.Length > 0)
     {
         Text = Encoding.Default.GetString(baText);
         string textUTF8Temp;
         string textRTFTemp;
         strmBody.parsePossiblyRemainingRTFandUTF8(out textRTFTemp, out textUTF8Temp);   // sometimes, textUTF8Temp is plaintext with spaces in between :-(
         TextRTF = textRTFTemp;  // TextRTF will be null before that operation anyway
         if (null != textUTF8Temp)
             Text = textUTF8Temp;
     }
 }
Ejemplo n.º 2
0
        private void parseMessagePacket(ICQDataStream streamContent)
        {
            Text = streamContent.readString();

            byte[] messageFlags = streamContent.readFixedBinary(0x0a);    // Mostly 0x00, but last two bytes are 0xC8 0x01(?), 0x23 0x02, or 0x19 0x02, or 0x03 0x02
            // the first four bytes seem to be ff ff ff ff in case of an SMS
            isOutgoing = ((messageFlags[4] & 0x01) == 0x01);

            TimeOfMessage = streamContent.readUnixTime();

            byte[] zeroes = streamContent.readFixedBinary(0x13);
            if (streamContent.Position > streamContent.Length - 8)
                return; // not enough to read anymore
            if (zeroes.Any(zeroByte => zeroByte != 0x00))
                return;     // The RTF messages are always zero in these bytes
            UInt16 possibleRTFLength = streamContent.readUInt16();
            byte[] baPossibleStrangeHeader = streamContent.readFixedBinary(6);      // in later versions of ICQ, these prepend the RTF
            AfterTextFooterType footerType = parseFooterTypeFromStrangeHeader(possibleRTFLength, baPossibleStrangeHeader);

            if (footerType == AfterTextFooterType.NoFooterBeforeRTF || footerType == AfterTextFooterType.SMSText)
                streamContent.Seek(-8, SeekOrigin.Current); // seek back the 8 bytes for the header
            //else if ()
            //    streamContent.Seek(-6, SeekOrigin.Current); // Only an UTF-8 text will be provided
            else if (footerType == AfterTextFooterType.NoFooterAtAll)
                return;
            //else
            //{
            //    UInt32 nextStrangeNumber = streamContent.readUInt32();
            //    if (0x00c0c0c0 != (0xFFc0c0c0 & nextStrangeNumber))
            //        return;
            //    // if the two strange numbers are there... just go on and parse the RTF :-)
            //}

            try
            {
                string textUTF8Temp;
                string textRTFTemp;
                streamContent.parsePossiblyRemainingRTFandUTF8(out textRTFTemp, out textUTF8Temp);
                TextRTF = textRTFTemp;  // TextRTF will be null before that operation anyway
                if (null != textUTF8Temp)
                    Text = textUTF8Temp;
            }
            catch (Exception ex)
            {
                throw new InvalidDataException("Parsed message text \"" + Text + "\" after which a footer of type "
                    + footerType.ToString() + " was detected, but there was a problem parsing the RTF/UTF-8 footer.", ex);
            }

            //            byte[] tail = streamContent.readFixedBinary(0x08);  // zeroes for incoming messages, E4 04 00 00 00 80 80 00 for outgoing
        }