public override void Render(ImageMapSegment segment, Program program, Formatter formatter)
 {
     var entries = shdr.sh_size / shdr.sh_entsize;
     var symtab = (int)shdr.sh_link;
     var rdr = loader.CreateReader(shdr.sh_offset);
     for (int i = 0; i < entries; ++i)
     {
         uint iName;
         if (!rdr.TryReadUInt32(out iName))
             return;
         uint value;
         if (!rdr.TryReadUInt32(out value))
             return;
         uint size;
         if (!rdr.TryReadUInt32(out size))
             return;
         byte info;
         if (!rdr.TryReadByte(out info))
             return;
         byte other;
         if (!rdr.TryReadByte(out other))
             return;
         ushort shIndex;
         if (!rdr.TryReadUInt16(out shIndex))
             return;
         string symStr = loader.GetStrPtr(symtab, iName);
         string segName = loader.GetSectionName(shIndex);
         formatter.Write("{0,-40} {1:X8} {2:X8} {3:X2} {4}", symStr, value, size, info & 0xFF, segName);
         formatter.WriteLine();
     }
 }
 public override void Render(ImageMapSegment segment, Program program, Formatter formatter)
 {
     // Get the entry that has the segment# for the string table.
     var dynStrtab = loader.GetDynEntries(shdr.sh_offset).Where(d => d.d_tag == DT_STRTAB).FirstOrDefault();
     if (dynStrtab == null)
         return;
     var strtabSection = loader.GetSectionInfoByAddr(dynStrtab.d_ptr);
     foreach (var entry in loader.GetDynEntries(shdr.sh_offset))
     {
         switch (entry.d_tag)
         {
         default:
             formatter.Write("{0,-12} {1:X8}", entry.d_tag, entry.d_val);
             break;
         case DT_DEBUG:
             formatter.Write("{0,-12} {1:X8}", "DT_DEBUG", entry.d_val);
             break;
         case DT_FINI:
             formatter.Write("{0,-12} ", "DT_FINI");
             formatter.WriteHyperlink(string.Format("{0:X8}", entry.d_ptr), Address.Ptr32(entry.d_ptr));
             break;
         case DT_HASH:
             formatter.Write("{0,-12} ", "DT_HASH");
             formatter.WriteHyperlink(string.Format("{0:X8}", entry.d_ptr), Address.Ptr32(entry.d_ptr));
             break;
         case DT_INIT:
             formatter.Write("{0,-12} ", "DT_INIT");
             formatter.WriteHyperlink(string.Format("{0:X8}", entry.d_ptr), Address.Ptr32(entry.d_ptr));
             break;
         case DT_JMPREL:
             formatter.Write("{0,-12} ", "DT_JMPREL");
             formatter.WriteHyperlink(string.Format("{0:X8}", entry.d_ptr), Address.Ptr32(entry.d_ptr));
             break;
         case DT_NEEDED:
             formatter.Write("{0,-12} {1}", "DT_NEEDED", loader.ReadAsciiString(loader.RawImage, strtabSection.sh_offset + entry.d_ptr));
             break;
         case DT_STRSZ:
             formatter.Write("{0,-12} {1:X}", "DT_STRSZ", entry.d_val);
             break;
         case DT_STRTAB:
             formatter.Write("{0,-12} ", "DT_STRTAB");
             formatter.WriteHyperlink(string.Format("{0:X8}", entry.d_ptr), Address.Ptr32(entry.d_ptr));
             break;
         case DT_SYMENT:
             formatter.Write("{0,-12} {1}", "DT_SYMENTTRTAB", entry.d_val);
             break;
         case DT_SYMTAB:
             formatter.Write("{0,-12} ", "DT_SYMTAB");
             formatter.WriteHyperlink(string.Format("{0:X8}", entry.d_ptr), Address.Ptr32(entry.d_ptr));
             break;
         }
         formatter.WriteLine();
     }
 }
Exemple #3
0
        public override void Render(ImageMapSegment segment, Program program, Formatter formatter)
        {
            var entries = shdr.sh_size / shdr.sh_entsize;
            var symtab = (int)shdr.sh_link;
            var rdr = loader.CreateReader(shdr.sh_offset);
            for (int i = 0; i < entries; ++i)
            {
                uint offset;
                if (!rdr.TryReadUInt32(out offset))
                    return;
                uint info;
                if (!rdr.TryReadUInt32(out info))
                    return;

                uint sym = info >> 8;
                string symStr = loader.GetSymbol(symtab, (int)sym);
                formatter.Write("{0:X8} {1,3} {2:X8} {3}", offset, info & 0xFF, sym, symStr);
                formatter.WriteLine();
            }
        }
Exemple #4
0
        public override void Render(ImageSegment segment, Program program, Formatter formatter)
        {
            var entries = shdr.Size / shdr.EntrySize;
            var symtab = shdr.LinkedSection;
            var rdr = loader.CreateReader(shdr.FileOffset);
            for (ulong i = 0; i < entries; ++i)
            {
                uint offset;
                if (!rdr.TryReadUInt32(out offset))
                    return;
                uint info;
                if (!rdr.TryReadUInt32(out info))
                    return;

                uint sym = info >> 8;
                string symStr = loader.GetSymbolName(symtab, sym);
                formatter.Write("{0:X8} {1,3} {2:X8} {3}", offset, info & 0xFF, sym, symStr);
                formatter.WriteLine();
            }
        }
        public override void Render(ImageMapSegment segment, Program program, Formatter formatter)
        {
            var entries = shdr.sh_size / shdr.sh_entsize;
            var symtab = (int)shdr.sh_link;
            var rdr = loader.CreateReader(shdr.sh_offset);
            for (ulong i = 0; i < entries; ++i)
            {
                ulong offset;
                if (!rdr.TryReadUInt64(out offset))
                    return;
                ulong info;
                if (!rdr.TryReadUInt64(out info))
                    return;
                ulong addend;
                if (!rdr.TryReadUInt64(out addend))
                    return;

                ulong sym = info >> 32;
                string symStr = loader.GetSymbol64(symtab, (int)sym);
                formatter.Write("{0:X8} {1,3} {2:X8} {3:X16} {4} ({5})", offset, info & 0xFFFFFFFF, sym, addend, symStr, sym);
                formatter.WriteLine();
            }
        }
Exemple #6
0
		public CodeFormatter(Formatter writer)
		{
            this.writer = writer;
		}
Exemple #7
0
 public void DumpData(SegmentMap map, Address address, int cbBytes, Formatter stm)
 {
     if (cbBytes < 0)
         throw new ArgumentException("Must be a nonnegative number.", "cbBytes"); 
     DumpData(map, address, (uint)cbBytes, stm);
 }
Exemple #8
0
 public override void Render(ImageSegment segment, Program program, Formatter formatter)
 {
     // Get the entry that has the segment# for the string table.
     var dynStrtab = loader.GetDynEntries64(shdr.FileOffset).Where(d => d.d_tag == DT_STRTAB).FirstOrDefault();
     if (dynStrtab == null)
         return;
     this.strtabSection = loader.GetSectionInfoByAddr64(dynStrtab.d_ptr);
     foreach (var entry in loader.GetDynEntries64(shdr.FileOffset))
     {
         DtFormat fmt;
         string entryName;
         Entry dser;
         if (!entries.TryGetValue(entry.d_tag, out dser))
         {
             entryName = string.Format("{0:X8}    ", entry.d_tag);
             fmt = DtFormat.Hexadecimal;
         }
         else
         {
             entryName = dser.Name;
             fmt = dser.Format;
         }
         RenderEntry(entryName, fmt, entry, formatter);
         formatter.WriteLine();
     }
 }
Exemple #9
0
 public void DumpData(SegmentMap map, AddressRange range, Formatter stm)
 {
     DumpData(map, range.Begin, (long) (range.End - range.Begin), stm);
 }
Exemple #10
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());
			}
		}
 public TypeReferenceFormatter(Formatter writer)
 {
     this.fmt = writer;
 }
Exemple #12
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();
     }
 }
Exemple #13
0
        public void WriteEntry(TypeVariable tv, Formatter writer)
        {
            writer.Write(tv.Name);
            writer.Write(":");
            WriteExpressionOf(tv, writer);
            writer.WriteLine();

            writer.Write("  Class: ");
            writer.WriteLine(tv.Class.Name);

            writer.Write("  DataType: ");
            writer.WriteLine(tv.DataType);

            writer.Write("  OrigDataType: ");
            writer.WriteLine(tv.OriginalDataType);
        }
 public TypeReferenceFormatter(Formatter writer)
 {
     this.fmt = writer;
 }
 public void Setup()
 {
     this.mr = new MockRepository();
     this.formatter = mr.StrictMock<Formatter>();
 }
Exemple #16
0
        public void Dump(Program program, Formatter formatter)
        {
            var map = program.SegmentMap;
            ImageSegment segment = null;
            foreach (ImageMapItem i in program.ImageMap.Items.Values)
            {
                if (!map.IsValidAddress(i.Address))
                    continue;
                ImageSegment seg;
                if (!map.TryFindSegment(i.Address, out seg))
                    continue;
                if (seg != segment)
                {
                    segment = seg;
                    formatter.WriteLine(";;; Segment {0} ({1})", seg.Name, seg.Address);
                }

                ImageMapBlock block = i as ImageMapBlock;
                if (block != null)
                {
                    formatter.WriteLine();
                    Procedure proc;
                    if (program.Procedures.TryGetValue(block.Address, out proc))
                    {
                        formatter.WriteComment(string.Format(
                            ";; {0}: {1}", proc.Name, block.Address));
                        formatter.WriteLine();

                        formatter.Write(proc.Name);
                        formatter.Write(" ");
                        formatter.Write("proc");
                        formatter.WriteLine();
                    }
                    else
                    {
                        formatter.Write(block.Block.Name);
                        formatter.Write(":");
                        formatter.WriteLine();
                    }
                    DumpAssembler(program.SegmentMap, block.Address, block.Address + block.Size, formatter);
                    continue;
                }

                ImageMapVectorTable table = i as ImageMapVectorTable;
                if (table != null)
                {
                    formatter.WriteLine(";; Code vector at {0} ({1} bytes)",
                        table.Address, table.Size);
                    foreach (Address addr in table.Addresses)
                    {
                        formatter.WriteLine("\t{0}", addr != null ? addr.ToString() : "-- null --");
                    }
                    DumpData(program.SegmentMap, i.Address, i.Size, formatter);
                }
                else
                {
                    var segLast = segment.Address + segment.Size;
                    var size = segLast - i.Address;
                    size = Math.Min(i.Size, size);
                    if (i.DataType == null || i.DataType is UnknownType ||
                        i.DataType is CodeType)
                    {
                        DumpData(program.SegmentMap, i.Address, size, formatter);
                    }
                    else
                    {
                        DumpTypedData(program.SegmentMap, i, formatter);
                    }
                }
            }
        }
Exemple #17
0
 public InstrWriter(Formatter formatter)
 {
     this.formatter = formatter;
 }
Exemple #18
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));
        }
 public CTypeReferenceFormatter(IPlatform platform, Formatter writer)
     : base(writer)
 {
     this.platform = platform;
 }
Exemple #20
0
 public void WriteGlobalVariable(Address address, DataType dataType, string name, Formatter formatter)
 {
     this.formatter     = formatter;
     this.codeFormatter = new CodeFormatter(formatter);
     this.tw            = new TypeReferenceFormatter(formatter);
     this.globals       = new StructureType();
     this.queue         = new Queue <StructureField>(globals.Fields);
     try
     {
         tw.WriteDeclaration(dataType, name);
         if (program.SegmentMap.IsValidAddress(address))
         {
             formatter.Write(" = ");
             this.rdr = program.CreateImageReader(address);
             dataType.Accept(this);
         }
     }
     catch (Exception ex)
     {
         var dc = services.RequireService <DecompilerEventListener>();
         dc.Error(
             dc.CreateAddressNavigator(program, address),
             ex,
             "Failed to write global variable {0}.",
             name);
     }
     formatter.Terminate(";");
 }
Exemple #21
0
 public void WriteExpressionOf(TypeVariable tvMember, Formatter writer)
 {
     Expression e;
     if (tvSources.TryGetValue(tvMember, out e) && e != null)
     {
         writer.Write(" (in {0}", e);
         if (e.DataType != null)
         {
             writer.Write(" : ");
             writer.Write(e.DataType);
         }
         writer.Write(")");
     }
 }
Exemple #22
0
 public AbsynCodeFormatter(Formatter writer) : base(writer)
 {
 }
Exemple #23
0
 private void WriteEntry(TypeVariable tv, DataType dt, Formatter writer)
 {
     writer.Write("{0}: ", tv);
     if (dt != null)
     {
         dt.Accept(new TypeGraphWriter(writer));
         WriteExpressionOf(tv, writer);
     }
     writer.WriteLine();
 }
 public void Emit(string fnName, EmitFlags f, Formatter fmt)
 {
     Emit(fnName, f, fmt, new CodeFormatter(fmt), new TypeFormatter(fmt, true));
 }
 public TypeReferenceFormatter(Formatter writer, bool typeReference)
 {
     this.fmt = writer;
     this.typeReference = typeReference;
 }
        public void Emit(string fnName, EmitFlags f, Formatter fmt, CodeFormatter w, TypeFormatter t)
        {
            bool emitStorage = (f & EmitFlags.ArgumentKind) == EmitFlags.ArgumentKind;
            if (emitStorage)
            {
                if (ReturnValue != null)
                {
                    w.WriteFormalArgumentType(ReturnValue, emitStorage);
                    fmt.Write(" ");
                }
                else
                {
                    fmt.Write("void ");
                }
                fmt.Write("{0}(", fnName);
            }
            else
            {
                if (ReturnValue == null)
                    fmt.Write("void {0}", fnName);
                else
                {
                    t.Write(ReturnValue.DataType, fnName);           //$TODO: won't work with fn's that return pointers to functions or arrays.
                }
                fmt.Write("(");
            }
            var sep = "";
            if (Parameters != null)
            {
                for (int i = 0; i < Parameters.Length; ++i)
                {
                    fmt.Write(sep);
                    sep = ", ";
                    w.WriteFormalArgument(Parameters[i], emitStorage, t);
                }
            }
            fmt.Write(")");

            if ((f & EmitFlags.LowLevelInfo) == EmitFlags.LowLevelInfo)
            {
                fmt.WriteLine();
                fmt.Write("// stackDelta: {0}; fpuStackDelta: {1}; fpuMaxParam: {2}", StackDelta, FpuStackDelta, FpuStackArgumentMax);
                fmt.WriteLine();
            }
        }
Exemple #27
0
 public TypedDataDumper(ImageReader rdr, uint cbSize, Formatter stm) 
 {
     this.rdr = rdr;
     this.cbSize = cbSize;
     this.fmt = stm;
 }
Exemple #28
0
 public override void Render(ImageMapSegment segment, Program program, Formatter formatter)
 {
     throw new NotImplementedException();
 }
Exemple #29
0
        //00 00 00 01 00 00 00 01   needed      ........
        //00 00 00 01 00 00 02 DE   "
        //00 00 00 01 00 00 02 EE   "
        //00 00 00 01 00 00 03 06   "
        //00 00 00 01 00 00 03 10   "
        //00 00 00 01 00 00 03 6B   "
        //00 00 00 01 00 00 03 91   "
        //00 00 00 0C 10 00 29 CC   Init
        //00 00 00 0D 10 03 81 B0   Fini
        //00 00 00 04 10 00 01 A8   Hash
        //6F FF FE F5 10 00 07 E0   ?
        //00 00 00 05 10 00 14 AC   strtab
        //00 00 00 06 10 00 08 3C   symtab
        //00 00 00 0A 00 00 09 90   strsz
        //00 00 00 0B 00 00 00 10   syment
        //00 00 00 15 00 00 00 00   debug
        //00 00 00 03 10 06 60 00   pltgot   -> first byte in linkage table
        //00 00 00 02 00 00 08 D0   pltretsz
        //00 00 00 14 00 00 00 07   pltrel
        //00 00 00 17 10 00 20 FC   jmprel
        //70 00 00 00 10 06 5F F4   loproc
        //00 00 00 07 10 00 20 CC   rela
        //00 00 00 08 00 00 09 00   relasz
        //00 00 00 09 00 00 00 0C   relaent
        //6F FF FF FE 10 00 1F CC  ?
        //6F FF FF FF 00 00 00 04   ?
        //6F FF FF F0 10 00 1E 3C  ?


        protected virtual void RenderEntry(string name, DtFormat format, Elf64_Dyn entry, Formatter formatter)
        {
            formatter.Write("{0,-15} ", name);
            switch (format)
            {
            default:
            case DtFormat.Hexadecimal:
                formatter.Write("{0:X16}", entry.d_val);
                break;
            case DtFormat.Decimal:
                formatter.Write("{0,16}", entry.d_val);
                break;
            case DtFormat.Address:
                formatter.WriteHyperlink(string.Format("{0:X16}", entry.d_ptr), Address.Ptr64(entry.d_ptr));
                break;
            case DtFormat.String:
                formatter.Write(loader.ReadAsciiString(strtabSection.FileOffset + entry.d_ptr));
                break;
            }
        }
Exemple #30
0
 public CodeFormatter(Formatter writer)
 {
     this.writer = writer;
 }
 public abstract void Render(ImageMapSegment segment, Program program, Formatter formatter);
Exemple #32
0
 public void DumpAssembler(Program program, Formatter wr)
 {
     if (wr == null || program.Architecture == null)
         return;
     Dumper dump = new Dumper(program.Architecture);
     dump.Dump(program, wr);
 }
Exemple #33
0
 public CodeFormatter(Formatter writer)
 {
     this.InnerFormatter = writer;
     this.typeWriter     = new TypeGraphWriter(writer);
 }
Exemple #34
0
 public CTypeReferenceFormatter(IPlatform platform, Formatter writer)
     : base(writer)
 {
     this.platform = platform;
 }