Пример #1
0
 private void UpdateStructInCollection(C_Struct csNew, ObservableCollection <C_Variable> collection)
 {
     for (int i = 0; i < collection.Count; i++)
     {
         if (collection[i].Type == C_Type.STRUCT)
         {
             if (collection[i].IsArray)
             {
                 C_Array csTmp = collection[i] as C_Array;
             }
             else
             {
                 C_Struct csTmp = collection[i] as C_Struct;
                 if (csTmp.TypeDefName == csNew.TypeDefName)
                 {
                     C_Variable csNewTmp = csNew.Clone();
                     csNewTmp.Name        = csTmp.Name;
                     csNewTmp.IsArray     = csTmp.IsArray;
                     csNewTmp.IsPointer   = csTmp.IsPointer;
                     csNewTmp.DisplayType = csTmp.DisplayType;
                     csNewTmp.Address     = csTmp.Address;
                     csNewTmp.FixedAddr   = csTmp.FixedAddr;
                     collection[i]        = csNewTmp;
                 }
             }
             UpdateStructInCollection(csNew, collection[i].Members);
         }
     }
 }
Пример #2
0
        public override C_Variable Clone()
        {
            ObservableCollection <C_Variable> members = new ObservableCollection <C_Variable>();
            C_Struct csTmp = new C_Struct()
            {
                Name = this.Name,

                TypeDefName = this.TypeDefName,
                DisplayType = this.DisplayType,
                Parent      = this.Parent,
                Value       = this.Value,
                IsArray     = this.IsArray,
                IsPointer   = this.IsPointer,
                Passed      = this.Passed,
                CheckEqual  = this.CheckEqual,
                Type        = this.Type,
                Members     = members,
                FixedAddr   = this.FixedAddr
            };

            foreach (C_Variable cvItem in Members)
            {
                C_Variable cvItemClone = cvItem.Clone();
                cvItemClone.Parent = csTmp;
                members.Add(cvItemClone);
            }
            csTmp.SetAddress(Address);
            return(csTmp);
        }
Пример #3
0
        public override bool Equals(object obj)
        {
            C_Struct cs = obj as C_Struct;

            //return cs != null && TypeDefName == cs.TypeDefName && Name == cs.Name;
            if (cs != null)
            {
                bool typeDefNameEqual = TypeDefName == cs.TypeDefName;
                bool nameEqual        = Name == cs.Name;
                bool membersEqual     = Members.SequenceEqual(cs.Members);
                return(typeDefNameEqual & nameEqual & membersEqual);
            }
            return(false);
        }
Пример #4
0
        //public C_Variable this[String name]
        //{
        //  get
        //  {
        //    return from v in ContextCollection
        //           where v.Name == name
        //           select v;
        //  }
        //  set
        //  {
        //    collection.Add(name, value);
        //  }
        //}
        #endregion // Indexer

        public void AddOrUpdate(C_Struct cs, C_VariableListContexts context)
        {
            var structs = (from v in _collection
                           where v is ITypeDef && (v as ITypeDef).TypeDefName == cs.TypeDefName
                           select v).ToList();

            foreach (C_Struct csItem in structs)
            {
                _collection.Remove(csItem);
            }
            UpdateStructInCollection(cs, _collection);
            UpdateStructInCollection(cs, context.ContextCollection);
            _collection.Add(cs);
            UpdateCollectionChanged(CollectionChangeAction.Add, "Name");
            UpdateCollectionChanged(CollectionChangeAction.Add, "Size");
        }
Пример #5
0
 public override bool ValidateValue(C_Variable cv)
 {
     if (cv is C_Struct)
     {
         C_Struct cs = cv as C_Struct;
         CheckEqual = cv.CheckEqual;
         if (IsPointer && IsSelected && cv.IsSelected)
         {
             if (Value != null)
             {
                 if (cv.CheckEqual)
                 {
                     Passed = cv.Passed = Value.Equals(cv.Value);
                 }
                 else
                 {
                     Passed = cv.Passed = !Value.Equals(cv.Value);
                 }
             }
             else
             {
                 Passed = false;
             }
         }
         else
         {
             Passed = cv.Passed = true;
         }
         //Passed = IsPointer && IsSelected && cv.IsSelected ? Value != null ? Value.Equals(cv.Value) : false : true;
         for (int i = 0; i < Math.Min(Members.Count, cs.Members.Count); i++)
         {
             Passed &= Members[i].ValidateValue(cs.Members[i]);
             if (Passed == false || Members[i].IsExpanded || cs.Members[i].IsExpanded /* || !(Members[i].IsSelected && cs.Members[i].IsSelected)*/)
             {
                 IsExpanded = true;
             }
         }
         cs.Passed = Passed;
     }
     else
     {
         Passed = IsSelected && cv.IsSelected ? false : true;
     }
     return(Passed == true);
 }
Пример #6
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));
            }
        }