Beispiel #1
0
        public override SECSItem XElementToSECSItem(XElement element)
        {
            if (element == null)
            {
                return(null);
            }
            string   str  = element.Name.ToString().Trim().ToUpper();
            SECSItem item = null;

            if (str == "L")
            {
                item = new SECSItem(eSECS_FORMAT.LIST);
                using (IEnumerator <XElement> enumerator = element.Elements().GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        XElement element2 = enumerator.Current;
                        SECSItem child    = this.XElementToSECSItem(element2);
                        if (child != null)
                        {
                            item.Add(child);
                        }
                    }
                    goto IL_3F2;
                }
            }
            string data = element.Value.Trim();
            string key;

            switch (key = str)
            {
            case "A":
                item = new SECSItem(eSECS_FORMAT.ASCII)
                {
                    Value = data
                };
                break;

            case "B":
                item = new SECSItem(eSECS_FORMAT.BINARY)
                {
                    Value = Str2SecsItem.GetBinary(data)
                };
                break;

            case "BOOLEAN":
            {
                item = new SECSItem(eSECS_FORMAT.BOOLEAN);
                bool[] boolean = Str2SecsItem.GetBoolean(data);
                if (boolean.Length == 1)
                {
                    item.Value = boolean[0];
                }
                else
                {
                    item.Value = boolean;
                }
                break;
            }

            case "U1":
            {
                item = new SECSItem(eSECS_FORMAT.U1);
                byte[] buffer = Str2SecsItem.GetU1(data);
                if (buffer.Length == 1)
                {
                    item.Value = buffer[0];
                }
                else
                {
                    item.Value = buffer;
                }
                break;
            }

            case "U2":
            {
                item = new SECSItem(eSECS_FORMAT.U2);
                ushort[] numArray = Str2SecsItem.GetU2(data);
                if (numArray.Length == 1)
                {
                    item.Value = numArray[0];
                }
                else
                {
                    item.Value = numArray;
                }
                break;
            }

            case "U4":
            {
                item = new SECSItem(eSECS_FORMAT.U4);
                uint[] numArray2 = Str2SecsItem.GetU4(data);
                if (numArray2.Length == 1)
                {
                    item.Value = numArray2[0];
                }
                else
                {
                    item.Value = numArray2;
                }
                break;
            }

            case "U8":
            {
                item = new SECSItem(eSECS_FORMAT.U8);
                ulong[] numArray3 = Str2SecsItem.GetU8(data);
                if (numArray3.Length == 1)
                {
                    item.Value = numArray3[0];
                }
                else
                {
                    item.Value = numArray3;
                }
                break;
            }

            case "I1":
            {
                item = new SECSItem(eSECS_FORMAT.I1);
                sbyte[] numArray4 = Str2SecsItem.GetI1(data);
                if (numArray4.Length == 1)
                {
                    item.Value = numArray4[0];
                }
                else
                {
                    item.Value = numArray4;
                }
                break;
            }

            case "I2":
            {
                item = new SECSItem(eSECS_FORMAT.I2);
                short[] numArray5 = Str2SecsItem.GetI2(data);
                if (numArray5.Length == 1)
                {
                    item.Value = numArray5[0];
                }
                else
                {
                    item.Value = numArray5;
                }
                break;
            }

            case "I4":
            {
                item = new SECSItem(eSECS_FORMAT.I4);
                int[] numArray6 = Str2SecsItem.GetI4(data);
                if (numArray6.Length == 1)
                {
                    item.Value = numArray6[0];
                }
                else
                {
                    item.Value = numArray6;
                }
                break;
            }

            case "I8":
            {
                item = new SECSItem(eSECS_FORMAT.I8);
                long[] numArray7 = Str2SecsItem.GetI8(data);
                if (numArray7.Length == 1)
                {
                    item.Value = numArray7[0];
                }
                else
                {
                    item.Value = numArray7;
                }
                break;
            }

            case "CHAR2":
                item = new SECSItem(eSECS_FORMAT.CHAR2)
                {
                    Value = data
                };
                break;

            case "JIS8":
                item = new SECSItem(eSECS_FORMAT.JIS8)
                {
                    Value = data
                };
                break;
            }
IL_3F2:
            if (item != null)
            {
                if (element.Attribute("ItemName") != null)
                {
                    item.Name = element.Attribute("ItemName").Value;
                }
                if (element.Attribute("Count") != null)
                {
                    item.Length = int.Parse(element.Attribute("Count").Value);
                }
                if (element.Attribute("Fixed") != null)
                {
                    item.Fixed = (element.Attribute("Fixed").Value.Trim().ToUpper() == "TRUE");
                }
            }
            return(item);
        }
Beispiel #2
0
        public override SECSItem XElementToSECSItem(XElement element)
        {
            if (element == null)
            {
                return(null);
            }
            string name = ((string)element.Element("Name")).Trim();
            string desc = ((string)element.Element("Description")).Trim();
            string str3 = ((string)element.Element("Format")).Trim().ToUpper(CultureInfo.InvariantCulture);

            if (str3 == "LIST")
            {
                SECSItem item = new SECSItem(eSECS_FORMAT.LIST, name, desc);
                foreach (XElement element2 in element.Elements("Item"))
                {
                    SECSItem child = this.XElementToSECSItem(element2);
                    item.Add(child);
                }
                return(item);
            }
            SECSItem item2 = null;
            string   data  = ((string)element.Element("Value")).Trim();
            string   key;

            switch (key = str3)
            {
            case "ASCII":
                item2 = new SECSItem(eSECS_FORMAT.ASCII, name, desc);
                break;

            case "CHAR2":
                item2 = new SECSItem(eSECS_FORMAT.CHAR2, name, desc);
                break;

            case "BINARY":
                item2 = new SECSItem(eSECS_FORMAT.BINARY, name, desc);
                break;

            case "BOOLEAN":
                item2 = new SECSItem(eSECS_FORMAT.BOOLEAN, name, desc);
                break;

            case "I1":
                item2 = new SECSItem(eSECS_FORMAT.I1, name, desc);
                break;

            case "I2":
                item2 = new SECSItem(eSECS_FORMAT.I2, name, desc);
                break;

            case "I4":
                item2 = new SECSItem(eSECS_FORMAT.I4, name, desc);
                break;

            case "I8":
                item2 = new SECSItem(eSECS_FORMAT.I8, name, desc);
                break;

            case "U1":
                item2 = new SECSItem(eSECS_FORMAT.U1, name, desc);
                break;

            case "U2":
                item2 = new SECSItem(eSECS_FORMAT.U2, name, desc);
                break;

            case "U4":
                item2 = new SECSItem(eSECS_FORMAT.U4, name, desc);
                break;

            case "U8":
                item2 = new SECSItem(eSECS_FORMAT.U8, name, desc);
                break;

            case "F4":
                item2 = new SECSItem(eSECS_FORMAT.F4, name, desc);
                break;

            case "F8":
                item2 = new SECSItem(eSECS_FORMAT.F8, name, desc);
                break;

            case "JIS-8":
            case "JIS8":
                item2 = new SECSItem(eSECS_FORMAT.JIS8, name, desc);
                break;
            }
            if (string.IsNullOrEmpty(data))
            {
                if (item2 != null)
                {
                    item2.Value = null;
                }
                return(item2);
            }
            if (item2 != null && (item2.Format == eSECS_FORMAT.ASCII || item2.Format == eSECS_FORMAT.JIS8 || item2.Format == eSECS_FORMAT.CHAR2))
            {
                item2.Value = data;
                return(item2);
            }
            if (item2 != null)
            {
                switch (item2.Format)
                {
                case eSECS_FORMAT.BINARY:
                {
                    byte[] binary = Str2SecsItem.GetBinary(data);
                    if (binary.Length <= 1)
                    {
                        item2.Value = binary[0];
                        return(item2);
                    }
                    item2.Value = binary;
                    return(item2);
                }

                case eSECS_FORMAT.BOOLEAN:
                {
                    bool[] boolean = Str2SecsItem.GetBoolean(data);
                    if (boolean.Length != 1)
                    {
                        item2.Value = boolean;
                        return(item2);
                    }
                    item2.Value = boolean[0];
                    return(item2);
                }

                case eSECS_FORMAT.I8:
                {
                    long[] numArray7 = Str2SecsItem.GetI8(data);
                    if (numArray7.Length != 1)
                    {
                        item2.Value = numArray7;
                        return(item2);
                    }
                    item2.Value = numArray7[0];
                    return(item2);
                }

                case eSECS_FORMAT.I1:
                {
                    sbyte[] numArray8 = Str2SecsItem.GetI1(data);
                    if (numArray8.Length != 1)
                    {
                        item2.Value = numArray8;
                        return(item2);
                    }
                    item2.Value = numArray8[0];
                    return(item2);
                }

                case eSECS_FORMAT.I2:
                {
                    short[] numArray9 = Str2SecsItem.GetI2(data);
                    if (numArray9.Length != 1)
                    {
                        item2.Value = numArray9;
                        return(item2);
                    }
                    item2.Value = numArray9[0];
                    return(item2);
                }

                case (eSECS_FORMAT)27:
                case (eSECS_FORMAT)29:
                case (eSECS_FORMAT)30:
                case (eSECS_FORMAT)31:
                    return(item2);

                case eSECS_FORMAT.I4:
                {
                    int[] numArray10 = Str2SecsItem.GetI4(data);
                    if (numArray10.Length != 1)
                    {
                        item2.Value = numArray10;
                        return(item2);
                    }
                    item2.Value = numArray10[0];
                    return(item2);
                }

                case eSECS_FORMAT.F8:
                {
                    double[] numArray11 = Str2SecsItem.GetF8(data);
                    if (numArray11.Length != 1)
                    {
                        item2.Value = numArray11;
                        return(item2);
                    }
                    item2.Value = numArray11[0];
                    return(item2);
                }

                case eSECS_FORMAT.F4:
                {
                    float[] numArray12 = Str2SecsItem.GetF4(data);
                    if (numArray12.Length != 1)
                    {
                        item2.Value = numArray12;
                        return(item2);
                    }
                    item2.Value = numArray12[0];
                    return(item2);
                }

                case (eSECS_FORMAT)37:
                case (eSECS_FORMAT)38:
                case (eSECS_FORMAT)39:
                case (eSECS_FORMAT)43:
                    return(item2);

                case eSECS_FORMAT.U8:
                {
                    ulong[] numArray13 = Str2SecsItem.GetU8(data);
                    if (numArray13.Length != 1)
                    {
                        item2.Value = numArray13;
                        return(item2);
                    }
                    item2.Value = numArray13[0];
                    return(item2);
                }

                case eSECS_FORMAT.U1:
                {
                    byte[] buffer2 = Str2SecsItem.GetU1(data);
                    if (buffer2.Length != 1)
                    {
                        item2.Value = buffer2;
                        return(item2);
                    }
                    item2.Value = buffer2[0];
                    return(item2);
                }

                case eSECS_FORMAT.U2:
                {
                    ushort[] numArray14 = Str2SecsItem.GetU2(data);
                    if (numArray14.Length != 1)
                    {
                        item2.Value = numArray14;
                        return(item2);
                    }
                    item2.Value = numArray14[0];
                    return(item2);
                }

                case eSECS_FORMAT.U4:
                {
                    uint[] numArray15 = Str2SecsItem.GetU4(data);
                    if (numArray15.Length != 1)
                    {
                        item2.Value = numArray15;
                        return(item2);
                    }
                    item2.Value = numArray15[0];
                    return(item2);
                }
                }
            }
            return(item2);
        }
Beispiel #3
0
        private SECSItem DecodeDataItem(eSECS_FORMAT format, int lengthBytes)
        {
            int      aLength = this.getBinaryLength(lengthBytes);
            SECSItem item    = new SECSItem(format);

            if (format <= eSECS_FORMAT.BOOLEAN)
            {
                if (format == eSECS_FORMAT.LIST)
                {
                    item.Name = "L";
                    for (int i = 0; i < aLength; i++)
                    {
                        byte num3 = this.mDataItem[this.mReadIndex];
                        this.mReadIndex++;
                        int num4 = num3 >> 2;
                        int num5 = (int)(num3 & 3);
                        item.Add(this.DecodeDataItem((eSECS_FORMAT)num4, num5));
                    }
                    return(item);
                }
                switch (format)
                {
                case eSECS_FORMAT.BINARY:
                {
                    byte[] buffer2 = this.ParseBinary(aLength);
                    item.Value = buffer2;
                    return(item);
                }

                case eSECS_FORMAT.BOOLEAN:
                {
                    bool[] flagArray = this.ParseBoolean(aLength);
                    if (flagArray.Length <= 1)
                    {
                        if (flagArray.Length == 1)
                        {
                            item.Value = flagArray[0];
                        }
                        return(item);
                    }
                    item.Value = flagArray;
                    return(item);
                }
                }
            }
            else
            {
                switch (format)
                {
                case eSECS_FORMAT.ASCII:
                {
                    string str = this.ParseAscii(aLength);
                    item.Length = aLength;
                    item.Value  = str;
                    return(item);
                }

                case eSECS_FORMAT.JIS8:
                    item.Value = this.ParseJIS8(aLength);
                    return(item);

                case eSECS_FORMAT.CHAR2:
                    item.Value = this.ParseChar2(aLength);
                    return(item);

                case (eSECS_FORMAT)19:
                case (eSECS_FORMAT)20:
                case (eSECS_FORMAT)21:
                case (eSECS_FORMAT)22:
                case (eSECS_FORMAT)23:
                case (eSECS_FORMAT)27:
                    break;

                case eSECS_FORMAT.I8:
                {
                    long[] numArray4 = this.ParseInt8(aLength);
                    if (numArray4.Length <= 1)
                    {
                        if (numArray4.Length == 1)
                        {
                            item.Value = numArray4[0];
                        }
                        return(item);
                    }
                    item.Value = numArray4;
                    return(item);
                }

                case eSECS_FORMAT.I1:
                {
                    sbyte[] numArray5 = this.ParseInt1(aLength);
                    if (numArray5.Length <= 1)
                    {
                        if (numArray5.Length == 1)
                        {
                            item.Value = numArray5[0];
                        }
                        return(item);
                    }
                    item.Value = numArray5;
                    return(item);
                }

                case eSECS_FORMAT.I2:
                {
                    short[] numArray6 = this.ParseInt2(aLength);
                    if (numArray6.Length <= 1)
                    {
                        if (numArray6.Length == 1)
                        {
                            item.Value = numArray6[0];
                        }
                        return(item);
                    }
                    item.Value = numArray6;
                    return(item);
                }

                case eSECS_FORMAT.I4:
                {
                    int[] numArray7 = this.ParseInt4(aLength);
                    if (numArray7.Length <= 1)
                    {
                        if (numArray7.Length == 1)
                        {
                            item.Value = numArray7[0];
                        }
                        return(item);
                    }
                    item.Value = numArray7;
                    return(item);
                }

                default:
                    if (format != eSECS_FORMAT.F8)
                    {
                        switch (format)
                        {
                        case eSECS_FORMAT.F4:
                        {
                            float[] numArray8 = this.ParseFloat(aLength);
                            if (numArray8.Length <= 1)
                            {
                                if (numArray8.Length == 1)
                                {
                                    item.Value = numArray8[0];
                                }
                                return(item);
                            }
                            item.Value = numArray8;
                            return(item);
                        }

                        case eSECS_FORMAT.U8:
                        {
                            ulong[] numArray9 = this.ParseUInt8(aLength);
                            if (numArray9.Length <= 1)
                            {
                                if (numArray9.Length == 1)
                                {
                                    item.Value = numArray9[0];
                                }
                                return(item);
                            }
                            item.Value = numArray9;
                            return(item);
                        }

                        case eSECS_FORMAT.U1:
                        {
                            byte[] buffer3 = this.ParseUInt1(aLength);
                            if (buffer3.Length <= 1)
                            {
                                if (buffer3.Length == 1)
                                {
                                    item.Value = buffer3[0];
                                }
                                return(item);
                            }
                            item.Value = buffer3;
                            return(item);
                        }

                        case eSECS_FORMAT.U2:
                        {
                            ushort[] numArray10 = this.ParseUInt2(aLength);
                            if (numArray10.Length <= 1)
                            {
                                if (numArray10.Length == 1)
                                {
                                    item.Value = numArray10[0];
                                }
                                return(item);
                            }
                            item.Value = numArray10;
                            return(item);
                        }

                        case eSECS_FORMAT.U4:
                        {
                            uint[] numArray11 = this.ParseUInt4(aLength);
                            if (numArray11.Length <= 1)
                            {
                                if (numArray11.Length == 1)
                                {
                                    item.Value = numArray11[0];
                                }
                                return(item);
                            }
                            item.Value = numArray11;
                            return(item);
                        }
                        }
                    }
                    else
                    {
                        double[] numArray12 = this.ParseDouble(aLength);
                        if (numArray12.Length > 1)
                        {
                            item.Value = numArray12;
                            return(item);
                        }
                        if (numArray12.Length == 1)
                        {
                            item.Value = numArray12[0];
                        }
                        return(item);
                    }
                    break;
                }
            }
            throw new Exception("Format Not meet the SECS standard");
        }