public override C_Variable Clone() { ObservableCollection <C_Variable> members = new ObservableCollection <C_Variable>(); C_Array caTmp = new C_Array() { ArrayLength = this.ArrayLength, Name = this.Name, Type = this.Type, Members = members, DisplayType = this.DisplayType, Parent = this.Parent, IsArray = this.IsArray, IsPointer = this.IsPointer, Passed = this.Passed, CheckEqual = this.CheckEqual, FixedAddr = this.FixedAddr }; foreach (C_Variable cvItem in Members) { C_Variable cvItemClone = cvItem.Clone(); cvItemClone.Parent = caTmp; members.Add(cvItemClone); } caTmp.SetAddress(Address); return(caTmp); }
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); } } }
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); } } }
public override bool ValidateValue(C_Variable cv) { if (cv is C_Array) { C_Array ca = cv as C_Array; Passed = true; CheckEqual = cv.CheckEqual; for (int i = 0; i < Math.Min(Members.Count, ca.Members.Count); i++) { Passed &= Members[i].ValidateValue(ca.Members[i]); if (Passed == false || Members[i].IsExpanded || ca.Members[i].IsExpanded /* || !(Members[i].IsSelected && ca.Members[i].IsSelected)*/) { IsExpanded = true; } } cv.Passed = Passed; } else { Passed = IsSelected && cv.IsSelected ? false : true; } return(Passed == true); }
public override bool Equals(object obj) { C_Array ca = obj as C_Array; return(ca != null && Name == ca.Name && (Members != null && ca.Members != null ? Members.SequenceEqual(ca.Members) : Members == ca.Members)); }
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)); } }