Exemple #1
0
        /// <summary>
        /// Returns true if the specified address + length partially overlaps
        /// a relocation.
        /// </summary>
        /// <returns></returns>
        public bool Overlaps(Address addr, uint length)
        {
            ulong linAddr    = addr.ToLinear();
            ulong linAddrEnd = linAddr + length;

            if (map.TryGetLowerBoundKey(linAddr, out ulong linReloc))
            {
                // |-reloc----|
                //      |-addr----|
                var linRelocEnd = linReloc + (uint)map[linReloc].DataType.Size;
                if (linReloc < linAddr && linAddr < linRelocEnd)
                {
                    return(true);
                }
            }
            if (map.TryGetUpperBoundKey(linAddr, out linReloc))
            {
                //     |-reloc----|
                // |-addr----|
                var linRelocEnd = linReloc + (uint)map[linReloc].DataType.Size;
                if (linReloc < linAddrEnd)
                {
                    if (linAddrEnd < linRelocEnd)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #2
0
 public bool IsValidAddress(Address addr)
 {
     if (addr == null)
     {
         return(false);
     }
     return(IsValidLinearAddress(addr.ToLinear()));
 }
        public void Dump(Address addrBase)
        {
            var lin = addrBase.ToLinear();

            foreach (var de in map)
            {
                Debug.Print("{0:X8} - {1}", de.Key - lin, de.Value);
            }
        }
Exemple #4
0
 /// <summary>
 /// Returns the segment that contains the specified address.
 /// </summary>
 /// <param name="addr"></param>
 /// <returns></returns>
 public bool TryFindSegment(Address addr, out ImageSegment segment)
 {
     if (!segments.TryGetLowerBound(addr, out segment))
     {
         return(false);
     }
     if (segment.Address.ToLinear() == addr.ToLinear())
     {
         return(true);
     }
     return(segment.IsInRange(addr));
 }
Exemple #5
0
        public void DumpData(SegmentMap map, Address address, long cbBytes, TextWriter stm)
        {
            ulong        cSkip = address.ToLinear() & 0x0F;
            ImageSegment segment;

            if (!map.TryFindSegment(address, out segment) || segment.MemoryArea == null)
            {
                return;
            }
            ImageReader rdr = arch.CreateImageReader(segment.MemoryArea, address);

            while (cbBytes > 0)
            {
                StringBuilder sb = new StringBuilder(0x12);
                try
                {
                    stm.Write("{0} ", rdr.Address);
                    for (int i = 0; i < 16; ++i)
                    {
                        if (cbBytes > 0 && cSkip == 0)
                        {
                            byte b = rdr.ReadByte();
                            stm.Write("{0:X2} ", b);
                            sb.Append(0x20 <= b && b < 0x7F
                                                                ? (char)b
                                                                : '.');
                            --cbBytes;
                        }
                        else
                        {
                            stm.Write("   ");
                            if (cSkip > 0)
                            {
                                sb.Append(' ');
                            }
                            --cSkip;
                        }
                    }
                }
                catch
                {
                    stm.WriteLine();
                    stm.WriteLine("...end of image");
                    return;
                }
                stm.WriteLine(sb.ToString());
            }
        }
Exemple #6
0
        public void DumpData(LoadedImage image, Address address, long cbBytes, TextWriter stm)
        {
            ulong       cSkip = address.ToLinear() & 0x0F;
            ImageReader rdr   = arch.CreateImageReader(image, address);

            while (cbBytes > 0)
            {
                StringBuilder sb = new StringBuilder(0x12);
                try
                {
                    stm.Write("{0} ", rdr.Address);
                    for (int i = 0; i < 16; ++i)
                    {
                        if (cbBytes > 0 && cSkip == 0)
                        {
                            byte b = rdr.ReadByte();
                            stm.Write("{0:X2} ", b);
                            sb.Append(0x20 <= b && b < 0x7F
                                                                ? (char)b
                                                                : '.');
                            --cbBytes;
                        }
                        else
                        {
                            stm.Write("   ");
                            if (cSkip > 0)
                            {
                                sb.Append(' ');
                            }
                            --cSkip;
                        }
                    }
                }
                catch
                {
                    stm.WriteLine();
                    stm.WriteLine("...end of image");
                    return;
                }
                stm.WriteLine(sb.ToString());
            }
        }
Exemple #7
0
        bool ExpressionVisitor <bool> .VisitAddress(Reko.Core.Address addr)
        {
            var anyC = p as WildConstant;

            if (anyC != null)
            {
                if (!string.IsNullOrEmpty(anyC.Label))
                {
                    capturedExpressions[anyC.Label] = addr;
                }
                return(true);
            }
            var cP = p as Address;

            if (cP == null)
            {
                return(false);
            }
            return(addr.ToLinear() == cP.ToLinear());
        }
Exemple #8
0
        public void DumpData(SegmentMap map, Address address, long cbBytes, Formatter stm)
        {
            const int    BytesPerLine = 16;
            var          linAddr      = address.ToLinear();
            ulong        cSkip        = linAddr - BytesPerLine * (linAddr / BytesPerLine);
            ImageSegment segment;

            if (!map.TryFindSegment(address, out segment) || segment.MemoryArea == null)
            {
                return;
            }
            byte[]            prevLine     = null;
            bool              showEllipsis = true;
            EndianImageReader rdr          = arch.CreateImageReader(segment.MemoryArea, address);

            while (cbBytes > 0)
            {
                StringBuilder sb      = new StringBuilder(0x12);
                var           bytes   = new List <byte>();
                var           sbBytes = new StringBuilder();
                try
                {
                    sbBytes.AppendFormat("{0} ", rdr.Address);
                    for (int i = 0; i < BytesPerLine; ++i)
                    {
                        if (cbBytes > 0 && cSkip == 0)
                        {
                            byte b = rdr.ReadByte();
                            bytes.Add(b);
                            sbBytes.AppendFormat("{0:X2} ", b);
                            sb.Append(0x20 <= b && b < 0x7F
                                                                ? (char)b
                                                                : '.');
                            --cbBytes;
                        }
                        else
                        {
                            sbBytes.Append("   ");
                            if (cSkip > 0)
                            {
                                sb.Append(' ');
                            }
                            --cSkip;
                        }
                    }
                    var ab = bytes.ToArray();
                    if (!HaveSameZeroBytes(prevLine, ab))
                    {
                        stm.Write(sbBytes.ToString());
                        stm.WriteLine(sb.ToString());
                        showEllipsis = true;
                    }
                    else
                    {
                        if (showEllipsis)
                        {
                            stm.WriteLine("; ...");
                            showEllipsis = false;
                        }
                    }
                    prevLine = ab;
                }
                catch
                {
                    stm.WriteLine();
                    stm.WriteLine(";;; ...end of image");
                    return;
                }
            }
        }
Exemple #9
0
 public bool IsInRange(Address addr)
 {
     return(IsInRange(addr.ToLinear()));
 }
Exemple #10
0
 public static string GenerateDefaultName(Address address) => string.Format("g_{0:X}", address.ToLinear());
Exemple #11
0
 private long ToOffset(Address addr)
 {
     return((long)addr.ToLinear() - (long)this.BaseAddress.ToLinear());
 }
Exemple #12
0
 public bool IsValidAddress(Address addr)
 {
     return(IsValidLinearAddress(addr.ToLinear()));
 }
Exemple #13
0
        public void DumpData(
            IProcessorArchitecture arch,
            MemoryArea mem,
            Address address,
            long cbBytes,
            Formatter stm)
        {
            const int BytesPerLine = 16;
            var       linAddr      = address.ToLinear();
            ulong     cSkip        = linAddr - BytesPerLine * (linAddr / BytesPerLine);

            byte[]? prevLine = null;
            bool showEllipsis = true;

            cbBytes = Math.Min(cbBytes, mem.Length - (address - mem.BaseAddress));
            if (cbBytes <= 0)
            {
                return;
            }
            var rdr = arch.CreateImageReader(mem, address);

            while (cbBytes > 0)
            {
                StringBuilder sb      = new StringBuilder(0x12);
                var           bytes   = new List <byte>();
                var           sbBytes = new StringBuilder();
                try
                {
                    sbBytes.AppendFormat("{0} ", rdr.Address);
                    for (int i = 0; i < BytesPerLine; ++i)
                    {
                        if (cbBytes > 0 && cSkip == 0)
                        {
                            byte b = rdr.ReadByte();
                            bytes.Add(b);
                            sbBytes.AppendFormat("{0:X2} ", b);
                            sb.Append(0x20 <= b && b < 0x7F
                                                                ? (char)b
                                                                : '.');
                            --cbBytes;
                        }
                        else
                        {
                            sbBytes.Append("   ");
                            if (cSkip > 0)
                            {
                                sb.Append(' ');
                            }
                            --cSkip;
                        }
                    }
                    var ab = bytes.ToArray();
                    if (!HaveSameZeroBytes(prevLine, ab))
                    {
                        stm.Write(sbBytes.ToString());
                        stm.WriteLine(sb.ToString());
                        showEllipsis = true;
                    }
                    else
                    {
                        if (showEllipsis)
                        {
                            stm.WriteLine("; ...");
                            showEllipsis = false;
                        }
                    }
                    prevLine = ab;
                }
                catch
                {
                    stm.WriteLine();
                    stm.WriteLine(";;; ...end of image");
                    return;
                }
            }
        }
Exemple #14
0
 private ulong ToOffset(Address addr)
 {
     return(addr.ToLinear() - this.BaseAddress.ToLinear());
 }