Example #1
0
        private static void Rewrite(Program program, IAssembler asm, Action <Program> postLoad)
        {
            var fakeConfigService = new FakeDecompilerConfiguration();
            var eventListener     = new FakeDecompilerEventListener();
            var sc = new ServiceContainer();

            sc.AddService <IConfigurationService>(fakeConfigService);
            sc.AddService <DecompilerEventListener>(eventListener);
            sc.AddService <IFileSystemService>(new FileSystemServiceImpl());
            var loader  = new Loader(sc);
            var project = new Project
            {
                Programs = { program }
            };

            postLoad(program);
            var scan = new Scanner(
                program,
                new DynamicLinker(project, program, eventListener),
                sc);

            scan.EnqueueImageSymbol(ImageSymbol.Location(program.Architecture, asm.StartAddress), true);
            foreach (var f in project.Programs)
            {
                foreach (var sp in f.User.Procedures.Values)
                {
                    scan.EnqueueUserProcedure(program.Architecture, sp);
                }
            }
            scan.ScanImage();
        }
Example #2
0
 public override RelocationResults Relocate(Program program, Address addrLoad)
 {
     return(new RelocationResults(
                new List <ImageSymbol> {
         ImageSymbol.Location(program.Architecture, addrLoad)
     },
                new SortedList <Address, ImageSymbol>()));
 }
Example #3
0
 private void AddLineNumberSymbols(SortedList <ushort, C64BasicInstruction> lines, Program program)
 {
     foreach (var line in lines.Values)
     {
         var sym = ImageSymbol.Location(program.Architecture, line.Address);
         sym.Name = $"L{line.LineNumber}";
         program.ImageSymbols.Add(line.Address, sym);
     }
 }
Example #4
0
        public override Program LoadProgram(Address?addrLoad)
        {
            var rdr = new BeImageReader(RawImage);

            if (!TryLoadHeader(rdr, out var hdr))
            {
                throw new BadImageFormatException();
            }

            addrLoad ??= PreferredBaseAddress;
            var cfgSvc   = Services.RequireService <IConfigurationService>();
            var arch     = cfgSvc.GetArchitecture("m68k") !;
            var env      = cfgSvc.GetEnvironment("atariTOS");
            var platform = env.Load(Services, arch);

            var bytes = new byte[hdr.TextSize + hdr.DataSize + hdr.BssSize];
            var mem   = arch.CreateMemoryArea(addrLoad, bytes);
            int cRead = rdr.ReadBytes(bytes, 0, hdr.TextSize + hdr.DataSize);

            if (cRead != hdr.TextSize + hdr.DataSize)
            {
                throw new BadImageFormatException();
            }

            var text = new ImageSegment(".text", addrLoad, mem, AccessMode.ReadExecute)
            {
                Size = hdr.TextSize
            };
            var data = new ImageSegment(".data", addrLoad + hdr.TextSize, mem, AccessMode.ReadWrite)
            {
                Size = hdr.DataSize
            };
            var bss = new ImageSegment(".bss", addrLoad + hdr.TextSize + hdr.DataSize, mem, AccessMode.ReadWrite)
            {
                Size = hdr.BssSize
            };

            //$TODO: Implement symbols. For now just skip over them.
            rdr.Offset += hdr.SymbolsSize;

            PerformRelocations(mem, rdr);

            var map = new SegmentMap(
                addrLoad,
                text, data, bss);
            var program = new Program(map, arch, platform);

            program.EntryPoints[addrLoad] = ImageSymbol.Location(program.Architecture, addrLoad);
            return(program);
        }
Example #5
0
        /// <summary>
        /// Build Reko types from CodeView types.
        /// </summary>
        /// <remarks>
        /// We make two passes through the CodeView types. First we locate
        /// and build (empty) <see cref="StructureType"/>s from all
        /// CodeView structures. Then
        /// </remarks>
        public ImageSymbol BuildSymbol(CodeViewLoader.PublicSymbol cvSymbol)
        {
            var imgSym = ImageSymbol.Location(arch, cvSymbol.addr);

            imgSym.Name = cvSymbol.name;
            if (!this.dataTypesByTypeIndex.TryGetValue(cvSymbol.typeidx, out var fnType))
            {
                return(imgSym);
            }
            if (fnType is SerializedSignature ssig)
            {
                imgSym = ImageSymbol.Procedure(arch, cvSymbol.addr, cvSymbol.name, signature: ssig);
            }
            return(imgSym);
        }