private void UpdateEnumInCollection(C_Enum ceNew, ObservableCollection <C_Variable> collection)
 {
     for (int i = 0; i < collection.Count; i++)
     {
         if (collection[i].Type == C_Type.ENUM)
         {
             if (collection[i].IsArray)
             {
                 C_Array csTmp = collection[i] as C_Array;
                 UpdateEnumInCollection(ceNew, csTmp.Members);
             }
             else
             {
                 C_Enum ceTmp = collection[i] as C_Enum;
                 if (ceTmp.TypeDefName == ceNew.TypeDefName)
                 {
                     C_Variable ceNewTmp = ceNew.Clone();
                     ceNewTmp.Name        = ceTmp.Name;
                     ceNewTmp.IsArray     = ceTmp.IsArray;
                     ceNewTmp.IsPointer   = ceTmp.IsPointer;
                     ceNewTmp.DisplayType = ceTmp.DisplayType;
                     collection[i]        = ceNewTmp;
                 }
             }
         }
         else if (collection[i].Type == C_Type.STRUCT)
         {
             UpdateEnumInCollection(ceNew, (collection[i] as C_Struct).Members);
         }
     }
 }
        public void AddOrUpdate(C_Enum ce, C_VariableListContexts context)
        {
            var enums = (from v in _collection
                         where v is ITypeDef && (v as ITypeDef).TypeDefName == ce.TypeDefName
                         select v).ToList();

            foreach (C_Enum ceItem in enums)
            {
                _collection.Remove(ceItem);
            }
            UpdateEnumInCollection(ce, _collection);
            UpdateEnumInCollection(ce, context.ContextCollection);
            _collection.Add(ce);
            UpdateCollectionChanged(CollectionChangeAction.Add, "Name");
            UpdateCollectionChanged(CollectionChangeAction.Add, "Size");
        }
Exemple #3
0
        public override C_Variable Clone()
        {
            ObservableCollection <C_EnumWrapper> enumValuesClone = new ObservableCollection <C_EnumWrapper>();
            ObservableCollection <C_Variable>    members         = new ObservableCollection <C_Variable>();

            foreach (C_EnumWrapper cewItem in EnumValues)
            {
                enumValuesClone.Add(cewItem.Clone());
            }
            C_Enum ceTmp = new C_Enum()
            {
                enumWrapper = this.EnumWrapper?.Clone(),
                EnumValues  = enumValuesClone,
                Name        = this.Name,
                TypeDefName = this.TypeDefName,
                Members     = members,
                DisplayType = this.DisplayType,
                Parent      = this.Parent,
                //Value = this.Value,
                IsArray    = this.IsArray,
                IsPointer  = this.IsPointer,
                Passed     = this.Passed,
                CheckEqual = this.CheckEqual,
                Type       = this.Type,
                FixedAddr  = this.FixedAddr
            };

            foreach (C_Variable cvItem in Members)
            {
                C_Variable cvItemClone = cvItem.Clone();
                cvItemClone.Parent = ceTmp;
                members.Add(cvItemClone);
            }
            ceTmp.SetAddress(Address);
            return(ceTmp);
        }
Exemple #4
0
        public override bool Equals(object obj)
        {
            C_Enum ca = obj as C_Enum;

            return(ca != null && TypeDefName == ca.TypeDefName && Name == ca.Name && (EnumWrapper == null ? ca.EnumWrapper == null : EnumWrapper.Equals(ca.EnumWrapper)));
        }
Exemple #5
0
        private void Populate(Dictionary <UInt32, SortedDictionary <long, UInt32> > memory,
                              C_Variable variableObj,
                              UInt32 addrBase,
                              UInt32?[] mem,
                              ref UInt32 addrOffset,
                              ref int byteIndex,
                              ref int bitIndex,
                              long timeInNS,
                              bool littleEndian           = true,
                              ICollection <String> output = null)
        {
            UInt32 word       = 0;
            int    shiftCount = 0;

            if (!littleEndian)
            {
                throw new NotImplementedException("Big Endian is not currently supported");
            }

            try
            {
                word = mem[addrOffset] ?? 0;
                variableObj.Passed = null;

                if (variableObj.IsPointer)
                {
                    UInt32 addrBasePtr    = word;
                    int    byteIndexPtr   = 0;
                    int    bitIndexPtr    = 0;
                    UInt32 addrIndexPtr   = 0;
                    UInt32 sizeInBytesPtr = Math.Max(variableObj.SizeInBits / 8, 1);
                    if (sizeInBytesPtr % 4 != 0)
                    {
                        sizeInBytesPtr = sizeInBytesPtr - (sizeInBytesPtr % 4) + 4;
                    }
                    variableObj.Value = addrBasePtr;
                    UInt32?[] data = GetRangeWords(memory, addrBasePtr, sizeInBytesPtr, timeInNS);
                    foreach (C_Variable cvItem in variableObj.Members)
                    {
                        cvItem.Populate(memory, addrBasePtr, data, ref addrIndexPtr, ref byteIndexPtr, ref bitIndexPtr, timeInNS, littleEndian, output);
                    }
                    addrOffset++;
                }
                else
                {
                    if (variableObj.IsArray)
                    {
                        if (byteIndex > 0 && bitIndex == 0)
                        {
                            bitIndex = byteIndex * 8;
                        }
                        C_Array caTmp = variableObj as C_Array;
                        if (caTmp.ArrayLength != caTmp.Members.Count)
                        {
                            throw new Exception("Array length mismatch!!!");
                        }
                        for (int i = 0; i < caTmp.ArrayLength; i++)
                        {
                            caTmp.Members[i].Populate(memory, addrBase, mem, ref addrOffset, ref byteIndex, ref bitIndex, timeInNS, littleEndian, output);
                            caTmp.Members[i].Name = String.Format("({0})", i);
                        }
                        caTmp.ToolTip = caTmp.FormattedValueArray;
                    }
                    else
                    {
                        switch (variableObj.Type)
                        {
                        case C_Type.BIT:
                            (variableObj as C_Primitive).Value = new Bit(word, bitIndex++);
                            if ((byteIndex = ((bitIndex) / 8)) > 3)
                            {
                                bitIndex  = 0;
                                byteIndex = 0;
                                addrOffset++;
                            }
                            break;

                        case C_Type.U8:
                        case C_Type.S8:
                            shiftCount = 8 * byteIndex;
                            (variableObj as C_Primitive).Value = (byte)(word >> shiftCount);
                            if ((byteIndex = (byteIndex + 1) % 4) == 0)
                            {
                                addrOffset++;
                            }
                            break;

                        case C_Type.U16:
                        case C_Type.S16:
                            UInt16 val16;
                            if (byteIndex == 0)
                            {
                                val16      = (UInt16)word;
                                byteIndex += 2;
                            }
                            else
                            {
                                shiftCount = 8 * byteIndex;
                                val16      = (UInt16)(word >> shiftCount);
                                if ((byteIndex = (byteIndex + 1) % 4) == 0)
                                {
                                    word       = mem[++addrOffset] ?? 0;
                                    shiftCount = 0x20 - shiftCount;
                                    val16     |= (UInt16)(word << shiftCount);
                                }
                                byteIndex++;
                                if (byteIndex % 4 == 0)
                                {
                                    byteIndex = 0;
                                    addrOffset++;
                                }
                            }
                            C_Primitive cp16 = (variableObj as C_Primitive);
                            cp16.Value = val16;
                            break;

                        case C_Type.BOOL:
                        case C_Type.U32:
                        case C_Type.S32:
                            UInt32 val32;
                            if (byteIndex == 0)
                            {
                                val32 = word;
                                addrOffset++;
                            }
                            else
                            {
                                shiftCount = 8 * byteIndex;
                                val32      = word >> shiftCount;
                                word       = mem[++addrOffset] ?? 0;
                                val32     |= word << (0x20 - shiftCount);
                            }
                            C_Primitive cp32 = (variableObj as C_Primitive);
                            cp32.Value = val32;
                            break;

                        case C_Type.U64:
                        case C_Type.S64:
                            UInt64 val64;
                            if (byteIndex == 0)
                            {
                                val64  = word;
                                val64 |= (UInt64)(mem[++addrOffset] ?? 0) << 0x20;
                                addrOffset++;
                            }
                            else
                            {
                                shiftCount = 8 * byteIndex;
                                val64      = word >> shiftCount;
                                shiftCount = 0x20 - shiftCount;
                                word       = mem[++addrOffset] ?? 0;
                                val64     |= (UInt64)word << shiftCount;
                                word       = mem[++addrOffset] ?? 0;
                                val64     |= (UInt64)word << (shiftCount + 0x20);
                            }

                            if (!littleEndian)
                            {
                                byte[] bArrTmp = BitConverter.GetBytes(val64);
                                Array.Reverse(bArrTmp);
                                val64 = BitConverter.ToUInt64(bArrTmp, 0);
                            }

                            C_Primitive cp64 = (variableObj as C_Primitive);
                            cp64.Value = val64;
                            break;

                        case C_Type.ENUM:
                            C_Enum ceEnum = (variableObj as C_Enum);
                            shiftCount   = 8 * (littleEndian ? byteIndex : 3 - byteIndex);
                            ceEnum.Value = word >> shiftCount;
                            if (byteIndex != 0)
                            {
                                byteIndex    = 4 - byteIndex;
                                shiftCount   = 8 * (littleEndian ? byteIndex : 3 - byteIndex);
                                word         = mem[++addrOffset] ?? 0;
                                ceEnum.Value = (UInt32)ceEnum.Value | (word >> shiftCount);
                            }
                            else
                            {
                                addrOffset++;
                            }
                            break;

                        case C_Type.STRUCT:
                            C_Struct csTmp = variableObj as C_Struct;
                            csTmp.SetAddress(addrBase + addrOffset * 4);
                            foreach (C_Variable cvItem in csTmp.Members)
                            {
                                cvItem.Populate(memory, addrBase, mem, ref addrOffset, ref byteIndex, ref bitIndex, timeInNS, littleEndian, output);
                            }
                            csTmp.ToolTip = csTmp.FormattedValueStruct;

                            break;

                        default:
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogWriter.Instance.WriteToLog(ex, "Error parsing: {0}", variableObj.Name);
                output?.Add(String.Format("Parsing error: {0}\n{1}", ex.Message, ex.StackTrace));
            }
        }