public void AddItemWithSize(Address addr, ImageMapItem itemNew) { ImageMapItem item; if (!TryFindItem(addr, out item)) { throw new ArgumentException(string.Format("Address {0} is not within the image range.", addr)); } long delta = addr - item.Address; Debug.Assert(delta >= 0, "Should have found an item at the supplied address."); if (delta > 0) { int afterOffset = (int)(delta + itemNew.Size); ImageMapItem itemAfter = null; if (item.Size > afterOffset) { itemAfter = new ImageMapItem { Address = addr + itemNew.Size, Size = (uint)(item.Size - afterOffset), DataType = ChopBefore(item.DataType, afterOffset), }; } item.Size = (uint)delta; item.DataType = ChopAfter(item.DataType, (int)delta); // Shrink the existing mofo. Items.Add(addr, itemNew); if (itemAfter != null) { Items.Add(itemAfter.Address, itemAfter); } } else { if (!(item.DataType is UnknownType) && !(item.DataType is CodeType)) { var u = new Unifier(); if (u.AreCompatible(item.DataType, itemNew.DataType)) { item.DataType = u.Unify(item.DataType, itemNew.DataType); } else { throw new NotSupportedException("Haven't handled this case yet."); } } Items.Remove(item.Address); item.Address += itemNew.Size; item.Size -= itemNew.Size; Items.Add(addr, itemNew); if (item.Size > 0 && !Items.ContainsKey(item.Address)) { Items.Add(item.Address, item); } } FireMapChanged(); }
private bool TypesAreCompatible(DataType dtSrc, DataType dtDst) { if (compTypes.Compare(dtSrc, dtDst) == 0) { return(true); } return(unifier.AreCompatible(dtSrc, dtDst)); }
private StructureField EnsureFieldAtOffset(StructureType str, DataType dt, int offset) { StructureField f = str.Fields.AtOffset(offset); if (f == null) { //$TODO: overlaps and conflicts. //$TODO: strings. f = new StructureField(offset, dt); str.Fields.Add(f); } return(f); #if TODO var f = GlobalVars.Fields.LowerBound(c.ToInt32()); //StructureField f = str.Fields.AtOffset(offset); if (f != null) { Unifier u = new Unifier(); if (u.AreCompatible(f.DataType, dt)) { return(f); } // Check for special case when an array ends at the offset. f = GlobalVars.Fields.LowerBound(c.ToInt32() - 1); var array = f.DataType.ResolveAs <ArrayType>(); if (array != null && u.AreCompatible(array.ElementType, dt)) { return(f); } } //$TODO: overlaps and conflicts. //$TODO: strings. f = new StructureField(offset, dt); str.Fields.Add(f); return(f); #endif }
public bool IsInsideArray(StructureType strGlobals, int offset, DataType dt) { var field = strGlobals.Fields.LowerBound(offset - 1); if (field == null) { return(false); } var array = field.DataType.ResolveAs <ArrayType>(); if (array is null || array is StringType) { return(false); } return(unifier.AreCompatible(array.ElementType, dt)); }
public void CompatibleWord32() { Assert.IsTrue(un.AreCompatible(PrimitiveType.Word32, PrimitiveType.Word32)); }