Exemplo n.º 1
0
 public void DisplayImageSegment(ImageMapSegment segment, Program program)
 {
     if (segment == null)
         return;
     ShowWindow("imageSegmentViewer", "Segment: " + segment.Name, pane);
     pane.DisplaySegment(segment, program);
 }
Exemplo n.º 2
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 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 void Setup()
 {
     mr = new MockRepository();
     seg1 = new ImageMapSegment("seg1", AccessMode.Execute) { Address = Address.Ptr32(0x01000) };
     seg2 = new ImageMapSegment("seg2", AccessMode.Execute) { Address = Address.Ptr32(0x02000) };
     map = new ImageMap(seg1.Address, 0x4000);
 }
 public override void Initialize(object obj)
 {
     this.segment = (ImageMapSegment) obj;
     base.TreeNode.Text = segment.Name;
     base.TreeNode.ImageName = GetImageName();
     base.TreeNode.ToolTipText = GetTooltip();
     PopulateChildren();
 }
Exemplo n.º 5
0
 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();
     }
 }
Exemplo n.º 6
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();
            }
        }
Exemplo n.º 7
0
        public void DisplaySegment(ImageMapSegment segment, Program program)
        {
            try
            {
                if (segmentView == null ||
                    segment == null ||
                    segment.Designer == null)
                    return;
                this.program = program;
                var tsf = new TextSpanFormatter();
                segment.Designer.Render(
                    segment,
                    program,
                    tsf);
                this.segmentView.TextView.Model = tsf.GetModel();
            }
            catch
            {

            }
        }
Exemplo n.º 8
0
		private uint ImageSize(ImageMapSegment [] segs)
		{
			Address addrStart = segs[0].Address;
			Address addrEnd = segs[segs.Length - 1].Address;
			return segs[segs.Length - 1].Size + (uint) (addrEnd - addrStart);
		}
Exemplo n.º 9
0
		private ImageMapSegment [] ExtractSegments()
		{
			ImageMapSegment [] segs = new ImageMapSegment[map.Segments.Count];
            map.Segments.Values.CopyTo(segs, 0);
            return segs;
		}
Exemplo n.º 10
0
		private void PaintSegment(ImageMapSegment seg, Graphics g, Rectangle rc)
		{
			g.FillRectangle(Brushes.White, rc);
			g.DrawRectangle(seg == segSelected ? Pens.Red : Pens.Black, rc);
		}
Exemplo n.º 11
0
            void parseSection64(uint protection)
            {
                var abSectname = rdr.ReadBytes(16);
                var abSegname = rdr.ReadBytes(16);
                ulong addr;
                ulong size;
                uint offset;
                uint align;
                uint reloff;
                uint nreloc;
                uint flags;
                uint reserved1;
                uint reserved2;
                uint reserved3;

                if (!rdr.TryReadUInt64(out addr) ||
                    !rdr.TryReadUInt64(out size) ||
                    !rdr.TryReadUInt32(out offset) ||
                    !rdr.TryReadUInt32(out align) ||
                    !rdr.TryReadUInt32(out reloff) ||
                    !rdr.TryReadUInt32(out nreloc) ||
                    !rdr.TryReadUInt32(out flags) ||
                    !rdr.TryReadUInt32(out reserved1) ||
                    !rdr.TryReadUInt32(out reserved2) ||
                    !rdr.TryReadUInt32(out reserved3))
                {
                    throw new BadImageFormatException("Could not read Mach-O section.");
                }

                var sectionName = GetAsciizString(abSectname);
                var segmentName = GetAsciizString(abSegname);

                Debug.Print("Found section '{0}' in segment '{1}, addr = 0x{2:X}, size = 0x{3:X}.",
                        sectionName,
                        segmentName,
                        addr,
                        size);

                AccessMode am = 0;
                if ((protection & VM_PROT_READ) != 0)
                    am |= AccessMode.Read;
                if ((protection & VM_PROT_WRITE) != 0)
                    am |= AccessMode.Write;
                if ((protection & VM_PROT_EXECUTE) != 0)
                    am |= AccessMode.Execute;

                var imageSection = new ImageMapSegment(
                    string.Format("{0},{1}", segmentName, sectionName),
                    (uint)size,
                    am);        //imageSection.setData(!imageSection->isCode());
                //imageSection.setBss((section.flags & SECTION_TYPE) == S_ZEROFILL);

                //if (!imageSection.isBss()) {
                //    auto pos = source_->pos();
                //    if (!source_->seek(section.offset)) {
                //        throw ParseError("Could not seek to the beginning of the section's content.");
                //    }
                //    auto bytes = source_->read(section.size);
                //    if (checked_cast<uint>(bytes.size()) != section.size) {
                //        log_.warning("Could not read all the section's content.");
                //    } else {
                //        imageSection->setContent(std::move(bytes));
                //    }
                //    source_->seek(pos);
                //}

                //sections_.push_back(imageSection.get());
                //image_->addSection(std::move(imageSection));
            }
Exemplo n.º 12
0
 public override void Render(ImageMapSegment segment, Program program, Core.Output.Formatter formatter)
 {
     throw new NotImplementedException();
 }