Ejemplo n.º 1
0
            private string ReadSegmentName()
            {
                var abSegname = rdr.ReadBytes(16);
                var cChars    = Array.IndexOf <byte>(abSegname, 0);

                if (cChars == -1)
                {
                    cChars = 16;
                }
                string segname = Encoding.ASCII.GetString(abSegname, 0, cChars);

                return(segname);
            }
Ejemplo n.º 2
0
        private void AddSection(SegmentMap segmentMap, uint size, uint flags, uint reserved1, uint reserved2, uint protection, Address addr, EndianImageReader bytes, string name)
        {
            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 mem          = new ByteMemoryArea(addr, bytes.ReadBytes((uint)size));
            var machoSection = new MachOSection(name, addr, (SectionFlags)flags, reserved1, reserved2);
            var imageSection = new ImageSegment(name, mem, am);

            ldr.imageSections.Add(machoSection, imageSection);

            this.ldr.sections.Add(machoSection);
            this.ldr.sectionsByName.Add(imageSection.Name, machoSection);
            if (imageSection.Size > 0)
            {
                segmentMap.AddSegment(imageSection);
            }
        }
Ejemplo n.º 3
0
 public CodeFormatter VisitPrimitive(PrimitiveType pt)
 {
     if (pt.Size > 8)
     {
         var bytes = rdr.ReadBytes(pt.Size);
         FormatRawBytes(bytes);
     }
     else
     {
         rdr.Read(pt).Accept(codeFormatter);
     }
     return(codeFormatter);
 }
Ejemplo n.º 4
0
            void parseSegmentCommand64(SegmentMap imageMap)
            {
                var abSegname = rdr.ReadBytes(16);
                var cChars    = Array.IndexOf <byte>(abSegname, 0);

                if (cChars == -1)
                {
                    cChars = 16;
                }
                string segname = Encoding.ASCII.GetString(abSegname, 0, cChars);
                ulong  vmaddr;
                ulong  vmsize;
                ulong  fileoff;
                ulong  filesize;
                uint   maxprot;
                uint   initprot;
                uint   nsects;
                uint   flags;

                if (!rdr.TryReadUInt64(out vmaddr) ||
                    !rdr.TryReadUInt64(out vmsize) ||
                    !rdr.TryReadUInt64(out fileoff) ||
                    !rdr.TryReadUInt64(out filesize) ||
                    !rdr.TryReadUInt32(out maxprot) ||
                    !rdr.TryReadUInt32(out initprot) ||
                    !rdr.TryReadUInt32(out nsects) ||
                    !rdr.TryReadUInt32(out flags))
                {
                    throw new BadImageFormatException("Could not read segment command.");
                }
                Debug.Print("Found segment '{0}' with {1} sections.", segname, nsects);

                for (uint i = 0; i < nsects; ++i)
                {
                    Debug.Print("Parsing section number {0}.", i);
                    parseSection64(initprot, imageMap);
                }
            }
Ejemplo n.º 5
0
        public override WE32100Instruction NotYetImplemented(uint wInstr, string message)
        {
            var rdr2 = rdr.Clone();
            var len  = rdr.Address - this.addr;

            rdr.Offset -= len;
            var hexBytes = string.Join("", rdr.ReadBytes((int)len).Select(b => $"{b:X2}"));

            EmitUnitTest("WE32100", hexBytes, message, "WE32100Dis", this.addr, w =>
            {
                w.WriteLine("AssertCode(\"@@@\", \"{0}\");", hexBytes);
            });
            return(base.NotYetImplemented(wInstr, message));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Render some memory, reading from the provided <see cref="ImageReader"/>, into
        /// a suitable output device <paramref name="output" />. This method
        /// takes into account that the image reader may not be positioned at
        /// the beginning of a logical line; in that case it will render
        /// filler space to ensure the display lines up.
        /// </summary>
        /// <param name="rdr">Imagereader to read the data from.</param>
        /// <param name="enc">Text encoding used to render textual data.</param>
        /// <param name="output">Output device to which the rendered strings
        /// are emitted.</param>
        public bool RenderLine(EndianImageReader rdr, Encoding enc, IMemoryFormatterOutput output)
        {
            output.BeginLine();
            var offStart = rdr.Offset;
            var addr     = rdr.Address;

            output.RenderAddress(addr);

            var addrStart       = Align(addr, unitsPerLine);
            var prePaddingUnits = (int)(addr - addrStart);
            var offsetEndLine   = (rdr.Offset - prePaddingUnits) + unitsPerLine;

            output.RenderFillerSpan(PaddingCells(prePaddingUnits));

            bool moreData         = true;
            int  postPaddingUnits = 0;

            while (moreData && rdr.Offset < offsetEndLine)
            {
                addr     = rdr.Address;
                moreData = rdr.TryRead(dtUnit, out var c);
                if (moreData)
                {
                    output.RenderUnit(addr, string.Format(unitFormat, c.GetValue()));
                }
                else
                {
                    postPaddingUnits = (int)(offsetEndLine - rdr.Offset);
                }
            }

            output.RenderFillerSpan(PaddingCells(postPaddingUnits));

            var cb = rdr.Offset - offStart;

            rdr.Offset = offStart;
            var bytes = rdr.ReadBytes((int)cb);

            string sBytes = RenderAsText(enc, bytes);

            output.RenderUnitsAsText(prePaddingUnits * this.bytesPerUnit, sBytes, postPaddingUnits * this.bytesPerUnit);

            output.EndLine(bytes);

            return(moreData && rdr.IsValid);
        }
Ejemplo n.º 7
0
            private static string ReadSectionName(EndianImageReader rdr, int maxSize)
            {
                byte[]   bytes = rdr.ReadBytes(maxSize);
                Encoding asc   = Encoding.ASCII;

                char[] chars = asc.GetChars(bytes);
                int    i;

                for (i = chars.Length - 1; i >= 0; --i)
                {
                    if (chars[i] != 0)
                    {
                        ++i;
                        break;
                    }
                }
                return(new String(chars, 0, i));
            }
Ejemplo n.º 8
0
 public CodeFormatter VisitPrimitive(PrimitiveType pt)
 {
     if (pt.Size > 8)
     {
         var bytes = rdr.ReadBytes(pt.Size);
         FormatRawBytes(bytes);
     }
     else
     {
         if (rdr.TryRead(pt, out var cValue))
         {
             cValue.Accept(codeFormatter);
         }
         else
         {
             codeFormatter.InnerFormatter.WriteLine("?? /* Can't read address {0} */", rdr.Address);
         }
     }
     return(codeFormatter);
 }