Пример #1
0
        /// <summary>
        /// Loads the image into memory at the specified address, using the provided
        /// <seealso cref="IProcessorArchitecture"/> and <seealso cref="IPlatform"/>.
        /// Used when loading raw files; not all image loaders can support this.
        /// </summary>
        /// <param name="addrLoad">Loading address *IGNORED*.</param>
        /// <param name="arch">Processor architecture.</param>
        /// <param name="platform">Platform/operating environment.</param>
        /// <returns>
        /// A <see cref="Program"/> instance.
        /// </returns>
        public override Program Load(Address addrLoad, IProcessorArchitecture arch, IPlatform platform)
        {
            listener = Services.RequireService <DecompilerEventListener>();
            var     memChunks = new MemoryChunksList();
            Address addrEp    = null;

            using (var rdr = new IntelHexReader(new MemoryStream(RawImage)))
            {
                try
                {
                    for (; ;)
                    {
                        if (!rdr.TryReadRecord(out uint address, out byte[] data))
                        {
                            break;
                        }
                        if (data != null)
                        {
                            memChunks.AddData(address, data);
                            continue;
                        }
                    }
                    addrEp = rdr.StartAddress;
                }
                catch (IntelHexException ex)
                {
                    listener.Error(new NullCodeLocation(""), ex.Message);
                    return(null);
                }
            }

            var segs = new SegmentMap(PreferredBaseAddress);

            // Generate the image segments with fake names.
            int i = 0;

            foreach (var mchk in memChunks)
            {
                var mem = new MemoryArea(mchk.BaseAddress, mchk.Datum.ToArray());
                var seg = new ImageSegment($"CODE_{i++:d2}", mem, AccessMode.ReadExecute);
                segs.AddSegment(seg);
            }

            var prog = new Program()
            {
                SegmentMap = segs, Architecture = arch, Platform = platform
            };

            if (addrEp != null)
            {
                prog.EntryPoints.Add(addrEp, new Core.ImageSymbol(addrEp)
                {
                    Type = SymbolType.Procedure
                });
            }
            return(prog);
        }
Пример #2
0
        /// <summary>
        /// Loads the image into memory at the specified address, using the provided
        /// <seealso cref="IProcessorArchitecture"/> and <seealso cref="IPlatform"/>.
        /// Used when loading raw files; not all image loaders can support this.
        /// </summary>
        /// <param name="addrLoad">Loading address *IGNORED*.</param>
        /// <param name="arch">Processor architecture.</param>
        /// <param name="platform">Platform/operating environment.</param>
        /// <returns>
        /// A <see cref="Program"/> instance.
        /// </returns>
        public override Program LoadProgram(Address addrLoad, IProcessorArchitecture arch, IPlatform platform)
        {
            listener = Services.RequireService <DecompilerEventListener>();
            var     memChunks = new MemoryChunksList();
            Address?addrEp    = null;
            Address addrBase  = MakeZeroAddress(arch);

            using (var rdr = new IntelHexReader(new MemoryStream(RawImage), addrBase))
            {
                try
                {
                    for (; ;)
                    {
                        if (!rdr.TryReadRecord(out Address address, out byte[] data))
                        {
                            break;
                        }
                        if (data != null)
                        {
                            memChunks.AddData(address, data);
                            continue;
                        }
                    }
                    addrEp = rdr.StartAddress;
                }
                catch (IntelHexException ex)
                {
                    listener.Error(ex.Message);
                    return(null !);
                }
            }

            var segs = new SegmentMap(PreferredBaseAddress);

            // Generate the image segments with fake names.
            int i = 0;

            foreach (var mchk in memChunks)
            {
                var mem = arch.CreateMemoryArea(mchk.BaseAddress, mchk.Datum.ToArray());
                var seg = new ImageSegment($"CODE_{i:d2}", mem, AccessMode.ReadExecute);
                ++i;
                segs.AddSegment(seg);
            }

            var program = new Program(segs, arch, platform);

            if (addrEp != null)
            {
                program.EntryPoints.Add(addrEp, ImageSymbol.Procedure(arch, addrEp));
            }
            return(program);
        }