public ImageMapSegment AddSegment(Address addr, string segmentName, AccessMode access) { ImageMapSegment seg; if (!TryFindSegment(addr, out seg)) { ImageMapSegment segNew = new ImageMapSegment(segmentName, access); segNew.Address = addr; segNew.Size = ~0U; segments.Add(segNew.Address, segNew); MapChanged.Fire(this); return(segNew); } long delta = addr - seg.Address; Debug.Assert(delta >= 0); if (delta > 0) { // Need to split the segment. //$REVIEW: or do we? x86 segments can overlap. var segNew = new ImageMapSegment(segmentName, access); segNew.Address = addr; segNew.Size = (uint)(seg.Size - delta); seg.Size = (uint)delta; segments.Add(segNew.Address, segNew); // And split any items in the segment. AddItem(addr, new ImageMapItem()); MapChanged.Fire(this); return(segNew); } return(seg); }
public ImageSegment AddSegment(ImageSegment segNew) { ImageSegment seg; if (!TryFindSegment(segNew.Address, out seg)) { EnsureSegmentSize(segNew); segments.Add(segNew.Address, segNew); MapChanged.Fire(this); //DumpSections(); return(segNew); } long delta = segNew.Address - seg.Address; Debug.Assert(delta >= 0); if (delta > 0) { // Need to split the segment if it has a size // x86 real mode segments don't have sizes, and can overlap. var segSplit = new ImageSegment(segNew.Name, segNew.Address, segNew.MemoryArea, segNew.Access); segSplit.Size = (uint)(seg.Size - delta); seg.Size = (uint)delta; segments.Add(segNew.Address, segSplit); // And split any items in the segment MapChanged.Fire(this); //DumpSections(); return(segSplit); } return(seg); }
/// <summary> /// Adds an image map item at the specified address. /// </summary> /// <param name="addr"></param> /// <param name="itemNew"></param> /// <returns></returns> public ImageMapItem AddItem(Address addr, ImageMapItem itemNew) { itemNew.Address = addr; ImageMapItem item; if (!TryFindItem(addr, out item)) { // Outside of range. Items.Add(itemNew.Address, itemNew); MapChanged.Fire(this); return(itemNew); } else { long delta = addr - item.Address; Debug.Assert(delta >= 0, "TryFindItem is supposed to find a block whose address is <= the supplied address"); if (delta > 0) { if (delta < item.Size) { // Need to split the item. itemNew.Size = (uint)(item.Size - delta); item.Size = (uint)delta; Items.Add(itemNew.Address, itemNew); MapChanged.Fire(this); return(itemNew); } else { Items.Add(itemNew.Address, itemNew); MapChanged.Fire(this); return(itemNew); } } else { if (itemNew.Size > 0 && itemNew.Size != item.Size) { Debug.Assert(item.Size >= itemNew.Size); item.Size -= itemNew.Size; item.Address += itemNew.Size; Items[itemNew.Address] = itemNew; Items[item.Address] = item; MapChanged.Fire(this); return(itemNew); } if (item.GetType() != itemNew.GetType()) //$BUGBUG: replaces the type. { Items[itemNew.Address] = itemNew; itemNew.Size = item.Size; } MapChanged.Fire(this); return(item); } } }
public void UnpauseEventHandler() { mapChangedEventHandlerPaused = false; if (mapChangedPendingEvents) { MapChanged.Fire(this); } mapChangedPendingEvents = false; }
private void FireMapChanged() { if (!mapChangedEventHandlerPaused) { MapChanged.Fire(this); } else { mapChangedPendingEvents = true; } }
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)) { 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); } } MapChanged.Fire(this); }
public void RemoveItem(Address addr) { ImageMapItem item; if (!TryFindItemExact(addr, out item)) { return; } item.DataType = new UnknownType(); ImageMapItem mergedItem = item; // Merge with previous item ImageMapItem prevItem; if (Items.TryGetLowerBound((addr - 1), out prevItem) && prevItem.DataType is UnknownType && prevItem.EndAddress.Equals(item.Address)) { mergedItem = prevItem; mergedItem.Size = (uint)(item.EndAddress - mergedItem.Address); Items.Remove(item.Address); } // Merge with next item ImageMapItem nextItem; if (Items.TryGetUpperBound((addr + 1), out nextItem) && nextItem.DataType is UnknownType && mergedItem.EndAddress.Equals(nextItem.Address)) { mergedItem.Size = (uint)(nextItem.EndAddress - mergedItem.Address); Items.Remove(nextItem.Address); } MapChanged.Fire(this); }
public ImageSegment AddSegment(ImageSegment segNew) { ImageSegment seg; if (!TryFindSegment(segNew.Address, out seg)) { EnsureSegmentSize(segNew); segments.Add(segNew.Address, segNew); AddItem(segNew.Address, new ImageMapItem(segNew.Size) { DataType = new UnknownType() }); MapChanged.Fire(this); Debug.Print("== New segment {0}", segNew.Name); DumpSections(); return(segNew); } long delta = segNew.Address - seg.Address; Debug.Assert(delta >= 0); if (delta > 0) { // Need to split the segment. //$REVIEW: or do we? x86 segments can overlap. var segSplit = new ImageSegment(segNew.Name, segNew.Address, segNew.MemoryArea, segNew.Access); segSplit.Size = (uint)(seg.Size - delta); seg.Size = (uint)delta; segments.Add(segNew.Address, segSplit); // And split any items in the segment AddItem(segSplit.Address, new ImageMapItem()); MapChanged.Fire(this); Debug.Print("== Split segment into {0} and {1}", seg.Name, segSplit.Name); DumpSections(); return(segSplit); } return(seg); }