Exemple #1
0
        public void TerminateItem(Address addr)
        {
            if (!TryFindItem(addr, out ImageMapItem item))
            {
                return;
            }
            long delta = addr - item.Address;

            if (delta == 0)
            {
                return;
            }

            // Need to split the item.
            var itemNew = new ImageMapItem {
                Address = addr, Size = (uint)(item.Size - delta)
            };

            Items.Add(itemNew.Address, itemNew);

            item.Size = (uint)delta;
        }
Exemple #2
0
        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);
            }

            FireMapChanged();
        }
Exemple #3
0
        /// <summary>
        /// Seed the imagemap with image symbols
        /// </summary>
        public void BuildImageMap()
        {
            this.ImageMap = SegmentMap.CreateImageMap();
            foreach (var sym in this.ImageSymbols.Values.Where(
                         s => s.Type == SymbolType.Data && s.Size != 0))
            {
                this.ImageMap.AddItemWithSize(
                    sym.Address,
                    new ImageMapItem
                {
                    Address  = sym.Address,
                    DataType = sym.DataType,
                    Size     = sym.Size,
                });
            }
            var tlDeser = CreateTypeLibraryDeserializer();

            foreach (var kv in User.Globals)
            {
                var dt   = kv.Value.DataType.Accept(tlDeser);
                var item = new ImageMapItem((uint)dt.Size)
                {
                    Address  = kv.Key,
                    DataType = dt,
                    Name     = kv.Value.Name,
                };
                if (item.Size > 0)
                {
                    this.ImageMap.AddItemWithSize(kv.Key, item);
                }
                else
                {
                    this.ImageMap.AddItem(kv.Key, item);
                }
                //$BUGBUG: what about x86 segmented binaries?
                int offset = (int)kv.Key.ToLinear();
                GlobalFields.Fields.Add(offset, dt, kv.Value.Name);
            }
        }
Exemple #4
0
        public GlobalDataItem_v2 ModifyUserGlobal(IProcessorArchitecture arch, Address address, SerializedType dataType, string name)
        {
            if (!User.Globals.TryGetValue(address, out var gbl))
            {
                gbl = new GlobalDataItem_v2()
                {
                    Address = address.ToString(),
                };
                User.Globals.Add(address, gbl);
            }

            gbl.Name     = name;
            gbl.DataType = dataType;

            this.ImageMap.RemoveItem(address);

            var tlDeser = CreateTypeLibraryDeserializer();
            var dt      = dataType.Accept(tlDeser);
            var size    = GetDataSize(arch, address, dt);
            var item    = new ImageMapItem
            {
                Address  = address,
                Size     = size,
                Name     = name,
                DataType = dt,
            };

            if (size != 0)
            {
                this.ImageMap.AddItemWithSize(address, item);
            }
            else
            {
                this.ImageMap.AddItem(address, item);
            }

            return(gbl);
        }
Exemple #5
0
 public bool TryFindItemExact(Address addr, out ImageMapItem item)
 {
     return(items.TryGetValue(addr, out item));
 }
Exemple #6
0
 public bool TryFindItem(Address addr, out ImageMapItem item)
 {
     return(items.TryGetLowerBound(addr, out item));
 }
Exemple #7
0
        public void AddItemWithSize(Address addr, ImageMapItem itemNew)
        {
            if (!TryFindItem(addr, out var item))
            {
                throw new ArgumentException(string.Format("Address {0} is not within the image range.", addr));
            }
            // Do not split items with known data.
            if (!(item.DataType is UnknownType || item.DataType is CodeType))
            {
                return;
            }
            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();
        }