Exemplo n.º 1
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 = PduPartsEx.Decode7BitText(bytes);
                    return;
                }
            }
        }
Exemplo n.º 2
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 = PduPartsEx.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;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Decodes text from user data in the specified data coding scheme.
        /// </summary>
        /// <param name="userData">The user data to decode. Must contain text according to the specified data coding scheme.</param>
        /// <param name="dataCodingScheme">The data coding scheme specified in the PDU.</param>
        /// <returns>The decoded user data.</returns>
        public static string DecodeText(byte[] userData, byte dataCodingScheme)
        {
            string str;
            byte   alphabet = DataCodingScheme.Decode(dataCodingScheme).Alphabet;
            byte   num      = alphabet;

            switch (num)
            {
            case 0:
            {
                str = PduPartsEx.Decode7BitText(userData);
                break;
            }

            case 1:
            {
                //Label0:
                str = PduPartsEx.Decode7BitText(userData);
                break;
            }

            case 2:
            {
                str = PduPartsEx.DecodeUcs2Text(userData);
                break;
            }

            default:
            {
                //goto Label0;
                str = PduPartsEx.Decode7BitText(userData);
                break;
            }
            }
            return(str);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:GsmComm.PduConverter.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 SmsStatusReportPduEx(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)
                    {
                        PduPartsEx.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);
                    PduPartsEx.DecodeGeneralAddress(pdu, ref num3, out this.recipientAddress, out this.recipientAddressType);
                    if (num3 * 2 < pdu.Length)
                    {
                        try { this.scTimestamp = new SmsTimestampEx(pdu, ref num3); } catch { this.SCTimestamp = SmsTimestampEx.None; }
                        try { this.dischargeTime = new SmsTimestampEx(pdu, ref num3); } catch { this.dischargeTime = SmsTimestampEx.None; }

                        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)
                            {
                                PduPartsEx.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      = SmsTimestampEx.None;
                        this.DischargeTime    = SmsTimestampEx.None;
                        base.ConstructLength  = num3 * 2;
                        return;
                    }
                }
                else
                {
                    return;
                }
            }
            else
            {
                throw new ArgumentException("pdu must not be an empty string.");
            }
        }