Example #1
0
        public void DumpAssembler(SegmentMap map, Address addrStart, Address addrLast, Formatter formatter)
        {
            ImageSegment segment;

            if (!map.TryFindSegment(addrStart, out segment))
            {
                return;
            }
            var dasm = arch.CreateDisassembler(arch.CreateImageReader(segment.MemoryArea, addrStart));

            try
            {
                var writer = new InstrWriter(formatter);
                foreach (var instr in dasm)
                {
                    if (instr.Address >= addrLast)
                    {
                        break;
                    }
                    if (!DumpAssemblerLine(segment.MemoryArea, instr, writer))
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                formatter.WriteLine(ex.Message);
                formatter.WriteLine();
            }
        }
Example #2
0
        public void DumpAssembler(SegmentMap map, IProcessorArchitecture arch, Address addrStart, Address addrLast, Formatter formatter)
        {
            if (!map.TryFindSegment(addrStart, out var segment))
            {
                return;
            }
            var dasm = arch.CreateDisassembler(arch.CreateImageReader(segment.MemoryArea, addrStart));

            try
            {
                var writer = new InstrWriter(program.Platform, addrStart, formatter);
                foreach (var instr in dasm)
                {
                    writer.Address = instr.Address;
                    if (instr.Address ! >= addrLast)
                    {
                        break;
                    }
                    if (!DumpAssemblerLine(segment.MemoryArea, arch, instr, writer))
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                formatter.WriteLine(ex.Message);
                formatter.WriteLine();
            }
        }
Example #3
0
File: Dumper.cs Project: qcyb/reko
        public void DumpAssembler(SegmentMap map, IProcessorArchitecture arch, Address addrStart, Address addrLast, Formatter formatter)
        {
            if (!map.TryFindSegment(addrStart, out var segment))
            {
                return;
            }
            var dasm = arch.CreateDisassembler(arch.CreateImageReader(segment.MemoryArea, addrStart));

            try
            {
                var writer  = new InstrWriter(formatter);
                var options = new MachineInstructionRendererOptions(
                    flags: MachineInstructionRendererFlags.ResolvePcRelativeAddress,
                    syntax: "");
                foreach (var instr in dasm)
                {
                    if (instr.Address ! >= addrLast)
                    {
                        break;
                    }
                    if (!DumpAssemblerLine(segment.MemoryArea, arch, instr, writer, options))
                    {
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                formatter.WriteLine(ex.Message);
                formatter.WriteLine();
            }
        }
Example #4
0
        private Expression GetMemoryValue(Address addr, DataType dt, SegmentMap segmentMap)
        {
            var pt = dt as PrimitiveType;

            if (pt == null)
            {
                return(Constant.Invalid);
            }
            else if (pt.Domain == Domain.Real && pt.BitSize > 80)
            {
                //$TODO: we can't represent 96- or 128-bit floats quite yet.
                return(Constant.Invalid);
            }
            else if (pt.BitSize > 64)
            {
                //$TODO: we can't represent integer constants larger than 64 bits yet.
                return(Constant.Invalid);
            }
            if (!segmentMap.TryFindSegment(addr, out ImageSegment seg) || seg.IsWriteable)
            {
                return(Constant.Invalid);
            }
            if (!Architecture.TryRead(seg.MemoryArea, addr, pt, out Constant c))
            {
                return(Constant.Invalid);
            }
            return(c);
        }
Example #5
0
 public ImageWriter CreateImageWriter(IProcessorArchitecture arch, Address addr)
 {
     if (!SegmentMap.TryFindSegment(addr, out var segment))
     {
         throw new ArgumentException(string.Format("The address {0} is invalid.", addr));
     }
     return(arch.CreateImageWriter(segment.MemoryArea, addr));
 }
Example #6
0
 // Convenience functions.
 public EndianImageReader CreateImageReader(Address addr)
 {
     if (!SegmentMap.TryFindSegment(addr, out var segment))
     {
         throw new ArgumentException(string.Format("The address {0} is invalid.", addr));
     }
     return(Architecture.CreateImageReader(segment.MemoryArea, addr));
 }
Example #7
0
 public void DumpData(SegmentMap map, IProcessorArchitecture arch, Address address, long cbBytes, Formatter stm)
 {
     if (!map.TryFindSegment(address, out var segment) || segment.MemoryArea == null)
     {
         return;
     }
     DumpData(arch, segment.MemoryArea, address, cbBytes, stm);
 }
Example #8
0
 public IEnumerable <MachineInstruction> CreateDisassembler(IProcessorArchitecture arch, Address addr)
 {
     if (!SegmentMap.TryFindSegment(addr, out var segment))
     {
         throw new ArgumentException(string.Format("The address {0} is invalid.", addr));
     }
     return(arch.CreateDisassembler(
                arch.CreateImageReader(segment.MemoryArea, addr)));
 }
Example #9
0
File: Dumper.cs Project: qcyb/reko
        private void DumpTypedData(SegmentMap map, IProcessorArchitecture arch, ImageMapItem item, Formatter w)
        {
            if (!map.TryFindSegment(item.Address, out var segment) || segment.MemoryArea == null)
            {
                return;
            }
            WriteLabel(item.Address, w);

            var rdr = arch.CreateImageReader(segment.MemoryArea, item.Address);

            item.DataType.Accept(new TypedDataDumper(rdr, item.Size, w));
        }
Example #10
0
        private void DumpTypedData(SegmentMap map, ImageMapItem item, Formatter stm)
        {
            ImageSegment segment;

            if (!map.TryFindSegment(item.Address, out segment) || segment.MemoryArea == null)
            {
                return;
            }
            stm.Write(Block.GenerateName(item.Address));
            stm.Write("\t");

            var rdr = arch.CreateImageReader(segment.MemoryArea, item.Address);

            item.DataType.Accept(new TypedDataDumper(rdr, item.Size, stm));
        }
Example #11
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());
            }
        }
Example #12
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;
                }
            }
        }
Example #13
0
        private void DumpTypedData(SegmentMap map, ImageMapItem item, Formatter stm)
        {
            ImageSegment segment;
            if (!map.TryFindSegment(item.Address, out segment) || segment.MemoryArea == null)
                return;
            stm.Write(Block.GenerateName(item.Address));
            stm.Write("\t");

            ImageReader rdr = arch.CreateImageReader(segment.MemoryArea, item.Address);
            item.DataType.Accept(new TypedDataDumper(rdr, item.Size, stm));
        }
Example #14
0
 public void DumpAssembler(SegmentMap map, Address addrStart, Address addrLast, Formatter formatter)
 {
     ImageSegment segment;
     if (!map.TryFindSegment(addrStart, out segment))
         return;
     var dasm = arch.CreateDisassembler(arch.CreateImageReader(segment.MemoryArea, addrStart));
     try
     {
         var writer = new InstrWriter(formatter);
         foreach (var instr in dasm)
         {
             if (instr.Address >= addrLast)
                 break;
             if (!DumpAssemblerLine(segment.MemoryArea, instr, writer))
                 break;
         }
     }
     catch (Exception ex)
     {
         formatter.WriteLine(ex.Message);
         formatter.WriteLine();
     }
 }
Example #15
0
		public void DumpData(SegmentMap map, Address address, long cbBytes, Formatter 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());
			}
		}