Exemplo n.º 1
0
        public override Program Load(Address addrLoad, IProcessorArchitecture arch, IPlatform platform)
        {
            BeImageReader rdr = new BeImageReader(this.RawImage, 0);
            DolStructure? str = new StructureReader <DolStructure>(rdr).Read();

            if (!str.HasValue)
            {
                throw new BadImageFormatException("Invalid DOL header.");
            }
            this.hdr = new DolHeader(str.Value);
            var segments = new List <ImageSegment>();

            // Create code segments
            for (uint i = 0, snum = 1; i < 7; i++, snum++)
            {
                if (hdr.addressText[i] == Address32.NULL)
                {
                    continue;
                }
                var bytes = new byte[hdr.sizeText[i]];
                Array.Copy(RawImage, hdr.offsetText[i], bytes, 0, bytes.Length);
                var mem = new MemoryArea(hdr.addressText[i], bytes);
                segments.Add(new ImageSegment(
                                 string.Format("Text{0}", snum),
                                 mem,
                                 AccessMode.ReadExecute));
            }

            // Create all data segments
            for (uint i = 0, snum = 1; i < 11; i++, snum++)
            {
                if (hdr.addressData[i] == Address32.NULL ||
                    hdr.sizeData[i] == 0)
                {
                    continue;
                }
                var bytes = new byte[hdr.sizeData[i]];
                Array.Copy(RawImage, hdr.offsetData[i], bytes, 0, bytes.Length);
                var mem = new MemoryArea(hdr.addressText[i], bytes);

                segments.Add(new ImageSegment(
                                 string.Format("Data{0}", snum),
                                 mem,
                                 AccessMode.ReadWrite));
            }

            if (hdr.addressBSS != Address32.NULL)
            {
                segments.Add(new ImageSegment(
                                 ".bss",
                                 new MemoryArea(hdr.addressBSS, new byte[hdr.sizeBSS]),
                                 AccessMode.ReadWrite));
            }

            var segmentMap = new SegmentMap(addrLoad, segments.ToArray());

            var entryPoint = new ImageSymbol(this.hdr.entrypoint)
            {
                Type = SymbolType.Procedure
            };
            var program = new Program(
                segmentMap,
                arch,
                platform)
            {
                ImageSymbols = { { this.hdr.entrypoint, entryPoint } },
                EntryPoints  = { { this.hdr.entrypoint, entryPoint } }
            };

            return(program);
        }
Exemplo n.º 2
0
 public DolLoader(IServiceProvider services, ImageLocation imageLocation, byte[] imgRaw)
     : base(services, imageLocation, imgRaw)
 {
     this.hdr = null !;
 }
Exemplo n.º 3
0
 public DolLoader(IServiceProvider services, string filename, byte[] imgRaw) : base(services, filename, imgRaw)
 {
     this.hdr = null !;
 }
Exemplo n.º 4
0
        public override Program Load(Address addrLoad, IProcessorArchitecture arch, IPlatform platform)
        {
            BeImageReader rdr = new BeImageReader(this.RawImage, 0);

            try {
                this.hdr = new DolHeader(new StructureReader <DolStructure>(rdr).Read());
            } catch (Exception ex) {
                throw new BadImageFormatException("Invalid DOL header. " + ex.Message);
            }

            var segments = new List <ImageSegment>();

            // Create code segments
            for (uint i = 0, snum = 1; i < 7; i++, snum++)
            {
                if (hdr.addressText[i] == Address32.NULL)
                {
                    continue;
                }

                segments.Add(new ImageSegment(
                                 string.Format("Text{0}", snum),
                                 hdr.addressText[i], hdr.sizeText[i],
                                 AccessMode.ReadExecute
                                 ));
            }

            // Create all data segments
            for (uint i = 0, snum = 1; i < 11; i++, snum++)
            {
                if (hdr.addressData[i] == Address32.NULL)
                {
                    continue;
                }
                segments.Add(new ImageSegment(
                                 string.Format("Data{0}", snum),
                                 hdr.addressData[i], hdr.sizeData[i],
                                 AccessMode.ReadWrite
                                 ));
            }

            if (hdr.addressBSS != Address32.NULL)
            {
                segments.Add(new ImageSegment(
                                 ".bss",
                                 hdr.addressBSS, hdr.sizeBSS,
                                 AccessMode.ReadWrite
                                 ));
            }

            var segmentMap = new SegmentMap(addrLoad, segments.ToArray());

            var entryPoint = new ImageSymbol(this.hdr.entrypoint)
            {
                Type = SymbolType.Procedure
            };
            var program = new Program(
                segmentMap,
                arch,
                platform)
            {
                ImageSymbols = { { this.hdr.entrypoint, entryPoint } },
                EntryPoints  = { { this.hdr.entrypoint, entryPoint } }
            };

            return(program);
        }