Пример #1
0
        /// <summary>
        /// Decodes an SMSC address out of a PDU string.
        /// </summary>
        /// <param name="pdu">The PDU string to use.</param>
        /// <param name="index">The index where to start in the string.</param>
        /// <param name="address">The address (phone number) read.</param>
        /// <param name="addressType">The address type of the read address.</param>
        public static void DecodeSmscAddress(string pdu, ref int index, out string address, out byte addressType)
        {
            int num  = index;
            int num1 = num;

            index = num + 1;
            byte num2 = BcdWorker.GetByte(pdu, num1);

            if (num2 <= 0)
            {
                addressType = 0;
                address     = string.Empty;
                return;
            }
            else
            {
                int num3 = index;
                int num4 = num3;
                index = num3 + 1;
                byte   num5        = BcdWorker.GetByte(pdu, num4);
                int    num6        = num2 - 1;
                string bytesString = BcdWorker.GetBytesString(pdu, index, num6);
                index = index + num6;
                string str = BcdWorker.DecodeSemiOctets(bytesString);
                if (str.EndsWith("F") || str.EndsWith("f"))
                {
                    str = str.Substring(0, str.Length - 1);
                }
                addressType = num5;
                address     = str;
                return;
            }
        }
Пример #2
0
        protected static void DecodeUserData(string pdu, ref int index, out byte userDataLength, out byte[] userData)
        {
            byte @byte = BcdWorker.GetByte(pdu, index++);

            if (@byte <= 0)
            {
                userDataLength = 0;
                userData       = null;
            }
            else
            {
                int    length = BcdWorker.CountBytes(pdu) - index;
                string s      = BcdWorker.GetBytesString(pdu, index, length);
                index += length;
                string str2 = string.Empty;
                for (int i = 0; i < (s.Length / 2); i++)
                {
                    string byteString = BcdWorker.GetByteString(s, i);
                    if (!Calc.IsHexString(byteString))
                    {
                        break;
                    }
                    str2 = str2 + byteString;
                }
                userDataLength = @byte;
                userData       = Calc.HexToInt(str2);
            }
        }
Пример #3
0
        /// <summary>
        /// Decodes an address out of a PDU string.
        /// </summary>
        /// <param name="pdu">The PDU string to use.</param>
        /// <param name="index">The index where to start in the string.</param>
        /// <param name="address">The address (phone number) read.</param>
        /// <param name="addressType">The address type of the read address.</param>
        public static void DecodeGeneralAddress(string pdu, ref int index, out string address, out byte addressType)
        {
            int num;
            int num1 = index;
            int num2 = num1;

            index = num1 + 1;
            byte num3 = BcdWorker.GetByte(pdu, num2);
            int  num4 = index;
            int  num5 = num4;

            index       = num4 + 1;
            addressType = BcdWorker.GetByte(pdu, num5);
            if (num3 <= 0)
            {
                address = string.Empty;
                return;
            }
            else
            {
                bool flag = false;
                if (num3 % 2 != 0)
                {
                    num = num3 + 1;
                }
                else
                {
                    num = (int)num3;
                }
                int length = num / 2;
                if (index * 2 + length * 2 > pdu.Length - length * 2)
                {
                    length = (pdu.Length - index * 2) / 2;
                    flag   = true;
                }
                AddressType addressType1 = new AddressType(addressType);
                if (addressType1.Ton != 5)
                {
                    string bytesString = BcdWorker.GetBytesString(pdu, index, length);
                    index = index + length;
                    if (flag)
                    {
                        address = BcdWorker.DecodeSemiOctets(bytesString).Substring(0, length * 2);
                        return;
                    }
                    else
                    {
                        address = BcdWorker.DecodeSemiOctets(bytesString).Substring(0, num3);
                        return;
                    }
                }
                else
                {
                    byte[] bytes = BcdWorker.GetBytes(pdu, index, length);
                    index   = index + length;
                    address = PduParts.Decode7BitText(bytes);
                    return;
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Decodes an outgoing SMS PDU stream.
 /// </summary>
 /// <param name="pdu">The PDU string to decode</param>
 /// <param name="includesSmscData">Specify true if the PDU data contains an SMSC header, otherwise false.</param>
 /// <param name="actualLength">The length of the PDU in bytes, not including the SMSC header.</param>
 /// <returns>An <see cref="T:GSMCommunication.PDUDecoder.OutgoingSmsPdu" /> object representing the decoded message.</returns>
 public static OutgoingSmsPdu Decode(string pdu, bool includesSmscData, int actualLength)
 {
     if (pdu != string.Empty)
     {
         int num = 0;
         if (includesSmscData)
         {
             int num1 = num;
             num = num1 + 1;
             byte num2 = BcdWorker.GetByte(pdu, num1);
             if (num2 > 0)
             {
                 num = num + num2;
             }
         }
         int num3 = num;
         OutgoingMessageType messageType         = OutgoingSmsPdu.GetMessageType(BcdWorker.GetByte(pdu, num3));
         OutgoingMessageType outgoingMessageType = messageType;
         if (outgoingMessageType != OutgoingMessageType.SmsSubmit)
         {
             throw new NotSupportedException(string.Concat("Message type ", messageType.ToString(), " recognized, but not supported by the SMS decoder."));
         }
         else
         {
             return(new SmsSubmitPdu(pdu, includesSmscData, actualLength));
         }
     }
     else
     {
         throw new ArgumentException("pdu must not be an empty string.");
     }
 }
Пример #5
0
        protected static void DecodeGeneralAddress(string pdu, ref int index, out string address, out byte addressType)
        {
            byte @byte = BcdWorker.GetByte(pdu, index++);

            addressType = BcdWorker.GetByte(pdu, index++);
            if (@byte > 0)
            {
                bool flag   = false;
                int  length = (((@byte % 2) != 0) ? (@byte + 1) : @byte) / 2;
                if (((index * 2) + (length * 2)) > (pdu.Length - (index * 2)))
                {
                    length = (pdu.Length - (index * 2)) / 2;
                    flag   = true;
                }
                string data = BcdWorker.GetBytesString(pdu, index, length);
                index += length;
                if (!flag)
                {
                    address = BcdWorker.DecodeSemiOctets(data).Substring(0, @byte);
                }
                else
                {
                    address = BcdWorker.DecodeSemiOctets(data).Substring(0, length * 2);
                }
            }
            else
            {
                address = string.Empty;
            }
        }
Пример #6
0
        /// <summary>
        /// Gets the user data out of the string.
        /// </summary>
        /// <param name="pdu">The PDU string to use.</param>
        /// <param name="index">The index where to start in the string.</param>
        /// <param name="dcs">The coding that was used to encode the data. Required to determine the proper data length.</param>
        /// <param name="userDataLength">Receives the user data length in bytes.</param>
        /// <param name="userData">Received the user data.</param>
        /// <remarks>
        /// <para>If there's no data, userDataLength will be set to 0 and userData to null.</para>
        /// <para>The decoded data might require further processing, for example 7-bit data (septets) packed
        /// into octets, that must be converted back to septets before the data can be used.</para>
        /// <para>Processing will stop at the first character that is not hex encountered or if the
        /// string ends too early. It will not change the <b>userDataLength</b> read from the string.</para>
        /// </remarks>
        public static void DecodeUserData(string pdu, ref int index, byte dcs, out byte userDataLength, out byte[] userData)
        {
            int num  = index;
            int num1 = num;

            index = num + 1;
            byte num2 = BcdWorker.GetByte(pdu, num1);

            if (num2 <= 0)
            {
                userDataLength = 0;
                userData       = new byte[0];
                return;
            }
            else
            {
                int remainingUserDataBytes = PduParts.GetRemainingUserDataBytes(num2, dcs);
                int num3 = BcdWorker.CountBytes(pdu) - index;
                if (num3 < remainingUserDataBytes)
                {
                    remainingUserDataBytes = num3;
                }
                string bytesString = BcdWorker.GetBytesString(pdu, index, remainingUserDataBytes);
                index = index + remainingUserDataBytes;
                string empty = string.Empty;
                for (int i = 0; i < bytesString.Length / 2; i++)
                {
                    string byteString = BcdWorker.GetByteString(bytesString, i);
                    if (!Calc.IsHexString(byteString))
                    {
                        break;
                    }
                    empty = string.Concat(empty, byteString);
                }
                userDataLength = num2;
                userData       = Calc.HexToInt(empty);
                return;
            }
        }
Пример #7
0
        /// <summary>
        /// Decodes an incoming SMS PDU stream.
        /// </summary>
        /// <param name="pdu">The PDU string to decode.</param>
        /// <param name="includesSmscData">Specify true if the PDU data contains an SMSC header, otherwise false.</param>
        /// <param name="actualLength">The size of the PDU data in bytes, not counting the SMSC header. Set to -1 if unknown.</param>
        /// <returns>An <see cref="T:GSMCommunication.PDUDecoder.IncomingSmsPdu" /> object representing the decoded message.</returns>
        public static IncomingSmsPdu Decode(string pdu, bool includesSmscData, int actualLength)
        {
            if (pdu != string.Empty)
            {
                int num = 0;
                if (includesSmscData)
                {
                    int num1 = num;
                    num = num1 + 1;
                    byte num2 = BcdWorker.GetByte(pdu, num1);
                    if (num2 > 0)
                    {
                        num = num + num2;
                    }
                }
                int num3 = num;
                IncomingMessageType messageType         = IncomingSmsPdu.GetMessageType(BcdWorker.GetByte(pdu, num3));
                IncomingMessageType incomingMessageType = messageType;
                switch (incomingMessageType)
                {
                case IncomingMessageType.SmsDeliver:
                {
                    return(new SmsDeliverPdu(pdu, includesSmscData, actualLength));
                }

                case IncomingMessageType.SmsStatusReport:
                {
                    return(new SmsStatusReportPdu(pdu, includesSmscData, actualLength));
                }
                }
                throw new NotSupportedException(string.Concat("Message type ", messageType.ToString(), " recognized, but not supported by the SMS decoder."));
            }
            else
            {
                throw new ArgumentException("pdu must not be an empty string.");
            }
        }
Пример #8
0
        protected static void DecodeSmscAddress(string pdu, ref int index, out string address, out byte addressType)
        {
            byte @byte = BcdWorker.GetByte(pdu, index++);

            if (@byte > 0)
            {
                byte   num2   = BcdWorker.GetByte(pdu, index++);
                int    length = @byte - 1;
                string data   = BcdWorker.GetBytesString(pdu, index, length);
                index += length;
                string str2 = BcdWorker.DecodeSemiOctets(data);
                if (str2.EndsWith("F") || str2.EndsWith("f"))
                {
                    str2 = str2.Substring(0, str2.Length - 1);
                }
                addressType = num2;
                address     = str2;
            }
            else
            {
                addressType = 0;
                address     = string.Empty;
            }
        }
Пример #9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:GSMCommunication.PDUDecoder.SmsDeliverPdu" /> class
        /// using the specified PDU string.
        /// </summary>
        /// <param name="pdu">The PDU string to convert.</param>
        /// <param name="includesSmscData">Specifies if the string contains
        /// SMSC data octets at the beginning.</param>
        /// <param name="actualLength">Specifies the actual PDU length, that is the length in bytes without
        /// the SMSC header. Set to -1 if unknown.</param>
        /// <remarks>
        /// <para>This constructor assumes that the string contains an <b>SMS-DELIVER</b>
        /// PDU data stream as specified by GSM 07.05.</para>
        /// </remarks>
        public SmsDeliverPdu(string pdu, bool includesSmscData, int actualLength)
        {
            string str  = null;
            byte   num  = 0;
            byte   num1 = 0;

            byte[] numArray = null;
            if (pdu != string.Empty)
            {
                bool flag = actualLength >= 0;
                int  num2 = actualLength;
                if (!flag || num2 > 0)
                {
                    int num3 = 0;
                    if (includesSmscData)
                    {
                        PduParts.DecodeSmscAddress(pdu, ref num3, out str, out num);
                        base.SetSmscAddress(str, num);
                    }
                    int num4 = num3;
                    num3 = num4 + 1;
                    this.messageFlags = new SmsDeliverMessageFlags(BcdWorker.GetByte(pdu, num4));
                    if (flag)
                    {
                        num2--;
                        if (num2 <= 0)
                        {
                            base.ConstructLength = num3 * 2;
                            return;
                        }
                    }
                    PduParts.DecodeGeneralAddress(pdu, ref num3, out this.originatingAddress, out this.originatingAddressType);
                    if (num3 * 2 < pdu.Length)
                    {
                        int num5 = num3;
                        num3            = num5 + 1;
                        base.ProtocolID = BcdWorker.GetByte(pdu, num5);
                        int num6 = num3;
                        num3 = num6 + 1;
                        base.DataCodingScheme = BcdWorker.GetByte(pdu, num6);
                        this.scTimestamp      = new SmsTimestamp(pdu, ref num3);
                        PduParts.DecodeUserData(pdu, ref num3, base.DataCodingScheme, out num1, out numArray);
                        base.SetUserData(numArray, num1);
                        base.ConstructLength = num3 * 2;
                        return;
                    }
                    else
                    {
                        this.scTimestamp      = SmsTimestamp.None;
                        base.ProtocolID       = 145;
                        base.DataCodingScheme = 137;
                        base.ConstructLength  = num3 * 2;
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                throw new ArgumentException("pdu must not be an empty string.");
            }
        }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:GSMCommunication.PDUDecoder.SmsStatusReportPdu" /> class
        /// using the specified PDU string.
        /// </summary>
        /// <param name="pdu">The PDU string to convert.</param>
        /// <param name="includesSmscData">Specifies if the string contains
        /// SMSC data octets at the beginning.</param>
        /// <param name="actualLength">Specifies the actual PDU length, that is the length in bytes without
        /// the SMSC header. Set to -1 if unknown.</param>
        /// <remarks>
        /// <para>This constructor assumes that the string contains an <b>SMS-STATUS-REPORT</b>
        /// PDU data stream as specified
        /// by GSM 07.05.</para>
        /// </remarks>
        public SmsStatusReportPdu(string pdu, bool includesSmscData, int actualLength)
        {
            string             str = null;
            byte               num = 0;
            ParameterIndicator parameterIndicator;
            byte               num1 = 0;

            byte[] numArray = null;
            if (pdu != string.Empty)
            {
                bool flag = actualLength >= 0;
                int  num2 = actualLength;
                if (!flag || num2 > 0)
                {
                    int num3 = 0;
                    if (includesSmscData)
                    {
                        PduParts.DecodeSmscAddress(pdu, ref num3, out str, out num);
                        base.SetSmscAddress(str, num);
                    }
                    int num4 = num3;
                    num3 = num4 + 1;
                    this.messageFlags = new SmsStatusReportMessageFlags(BcdWorker.GetByte(pdu, num4));
                    if (flag)
                    {
                        num2--;
                        if (num2 <= 0)
                        {
                            base.ConstructLength = num3 * 2;
                            return;
                        }
                    }
                    int num5 = num3;
                    num3 = num5 + 1;
                    this.messageReference = BcdWorker.GetByte(pdu, num5);
                    PduParts.DecodeGeneralAddress(pdu, ref num3, out this.recipientAddress, out this.recipientAddressType);
                    if (num3 * 2 < pdu.Length)
                    {
                        this.scTimestamp   = new SmsTimestamp(pdu, ref num3);
                        this.dischargeTime = new SmsTimestamp(pdu, ref num3);
                        int num6 = num3;
                        num3        = num6 + 1;
                        this.status = BcdWorker.GetByte(pdu, num6);
                        int num7 = BcdWorker.CountBytes(pdu);
                        if (num3 < num7)
                        {
                            int num8 = num3;
                            num3 = num8 + 1;
                            this.parameterIndicator = new ParameterIndicator(BcdWorker.GetByte(pdu, num8));
                            if (this.parameterIndicator.Extension)
                            {
                                do
                                {
                                    int num9 = BcdWorker.CountBytes(pdu);
                                    if (num3 < num9)
                                    {
                                        int num10 = num3;
                                        num3 = num10 + 1;
                                        parameterIndicator = new ParameterIndicator(BcdWorker.GetByte(pdu, num10));
                                    }
                                    else
                                    {
                                        base.ConstructLength = num3 * 2;
                                        return;
                                    }
                                }while (parameterIndicator.Extension);
                            }
                            if (this.parameterIndicator.TP_PID)
                            {
                                int num11 = num3;
                                num3            = num11 + 1;
                                base.ProtocolID = BcdWorker.GetByte(pdu, num11);
                            }
                            if (this.parameterIndicator.TP_DCS)
                            {
                                int num12 = num3;
                                num3 = num12 + 1;
                                base.DataCodingScheme = BcdWorker.GetByte(pdu, num12);
                            }
                            if (this.parameterIndicator.TP_UDL)
                            {
                                PduParts.DecodeUserData(pdu, ref num3, base.DataCodingScheme, out num1, out numArray);
                                base.SetUserData(numArray, num1);
                            }
                            base.ConstructLength = num3 * 2;
                            return;
                        }
                        else
                        {
                            base.ConstructLength = num3 * 2;
                            return;
                        }
                    }
                    else
                    {
                        base.ProtocolID       = 145;
                        base.DataCodingScheme = 137;
                        this.SCTimestamp      = SmsTimestamp.None;
                        this.DischargeTime    = SmsTimestamp.None;
                        base.ConstructLength  = num3 * 2;
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                throw new ArgumentException("pdu must not be an empty string.");
            }
        }
Пример #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:GSMCommunication.PDUDecoder.SmsSubmitPdu" /> class
        /// using the specified PDU string.
        /// </summary>
        /// <param name="pdu">The PDU string to convert.</param>
        /// <param name="includesSmscData">Specifies if the string contains
        /// SMSC data octets at the beginning.</param>
        /// <param name="actualLength">Specifies the actual PDU length, that is the length in bytes without
        /// the SMSC header. Set to -1 if unknown.</param>
        /// <remarks>
        /// <para>This constructor assumes that the string contains an <b>SMS-SUBMIT</b>
        /// PDU data stream as specified
        /// by GSM 07.05.</para>
        /// <para>AbsuluteValidityPeriod and EnhancedValidityPeriod are not
        /// supported and will generate a <see cref="T:System.NotSupportedException" />
        /// when encountered.
        /// </para>
        /// </remarks>
        /// <exception cref="T:System.NotSupportedException">The string contains a
        /// validity and the validity period format is not relative validity.
        /// </exception>
        public SmsSubmitPdu(string pdu, bool includesSmscData, int actualLength)
        {
            byte num = 0;

            byte[] numArray = null;
            int    num1;

            if (pdu != string.Empty)
            {
                bool flag = actualLength >= 0;
                int  num2 = actualLength;
                if (!flag || num2 > 0)
                {
                    int num3 = 0;
                    if (!includesSmscData)
                    {
                        base.SmscAddress = string.Empty;
                    }
                    else
                    {
                        int num4 = num3;
                        num3 = num4 + 1;
                        byte num5 = BcdWorker.GetByte(pdu, num4);
                        if (num5 <= 0)
                        {
                            base.SmscAddress = string.Empty;
                        }
                        else
                        {
                            int num6 = num3;
                            num3 = num6 + 1;
                            byte   num7        = BcdWorker.GetByte(pdu, num6);
                            int    num8        = num5 - 1;
                            string bytesString = BcdWorker.GetBytesString(pdu, num3, num8);
                            num3 = num3 + num8;
                            string str = BcdWorker.DecodeSemiOctets(bytesString);
                            if (str.EndsWith("F") || str.EndsWith("f"))
                            {
                                str = str.Substring(0, str.Length - 1);
                            }
                            base.SetSmscAddress(str, num7);
                        }
                    }
                    int num9 = num3;
                    num3 = num9 + 1;
                    this.messageFlags = new SmsSubmitMessageFlags(BcdWorker.GetByte(pdu, num9));
                    if (flag)
                    {
                        num2--;
                        if (num2 <= 0)
                        {
                            base.ConstructLength = num3 * 2;
                            return;
                        }
                    }
                    int num10 = num3;
                    num3 = num10 + 1;
                    base.MessageReference = BcdWorker.GetByte(pdu, num10);
                    int num11 = num3;
                    num3 = num11 + 1;
                    byte num12 = BcdWorker.GetByte(pdu, num11);
                    int  num13 = num3;
                    num3 = num13 + 1;
                    byte num14 = BcdWorker.GetByte(pdu, num13);
                    if (num12 <= 0)
                    {
                        this.DestinationAddress = string.Empty;
                    }
                    else
                    {
                        if (num12 % 2 != 0)
                        {
                            num1 = num12 + 1;
                        }
                        else
                        {
                            num1 = (int)num12;
                        }
                        int    num15        = num1 / 2;
                        string bytesString1 = BcdWorker.GetBytesString(pdu, num3, num15);
                        num3 = num3 + num15;
                        string str1 = BcdWorker.DecodeSemiOctets(bytesString1).Substring(0, num12);
                        this.SetDestinationAddress(str1, num14);
                    }
                    int num16 = num3;
                    num3            = num16 + 1;
                    base.ProtocolID = BcdWorker.GetByte(pdu, num16);
                    int num17 = num3;
                    num3 = num17 + 1;
                    base.DataCodingScheme = BcdWorker.GetByte(pdu, num17);
                    ValidityPeriodFormat validityPeriodFormat = this.MessageFlags.ValidityPeriodFormat;
                    if (validityPeriodFormat == ValidityPeriodFormat.Unspecified)
                    {
                        this.ValidityPeriod = null;
                    }
                    else if (validityPeriodFormat == ValidityPeriodFormat.Relative)
                    {
                        int num18 = num3;
                        num3 = num18 + 1;
                        this.ValidityPeriod = new RelativeValidityPeriod(BcdWorker.GetByte(pdu, num18));
                    }
                    else if (validityPeriodFormat == ValidityPeriodFormat.Absolute)
                    {
                        throw new NotSupportedException("Absolute validity period format not supported.");
                    }
                    else if (validityPeriodFormat == ValidityPeriodFormat.Enhanced)
                    {
                        throw new NotSupportedException("Enhanced validity period format not supported.");
                    }
                    else
                    {
                        throw new NotSupportedException(string.Concat("Validity period format \"", (object)this.MessageFlags.ValidityPeriodFormat.ToString(), "\" not supported."));
                    }
                    PduParts.DecodeUserData(pdu, ref num3, base.DataCodingScheme, out num, out numArray);
                    base.SetUserData(numArray, num);
                    base.ConstructLength = num3 * 2;
                    return;
                }
                else
                {
                    return;
                }
            }
            else
            {
                throw new ArgumentException("pdu must not be an empty string.");
            }
        }