Exemplo n.º 1
0
        private ImageLoader CreateRawImageLoader(byte[] image, NullImageLoader imgLoader, RawFileElement rawFile)
        {
            var       arch = cfgSvc.GetArchitecture(rawFile.Architecture);
            var       env  = cfgSvc.GetEnvironment(rawFile.Environment);
            IPlatform platform;
            Address   baseAddr;
            Address   entryAddr;

            if (env != null)
            {
                platform = env.Load(Services, arch);
            }
            else
            {
                platform = new DefaultPlatform(Services, arch);
            }
            //ApplyMemoryMap(platform, image
            imgLoader.Architecture = arch;
            imgLoader.Platform     = platform;
            if (arch.TryParseAddress(rawFile.BaseAddress, out baseAddr))
            {
                imgLoader.PreferredBaseAddress = baseAddr;
                entryAddr = GetRawBinaryEntryAddress(rawFile, image, arch, baseAddr);
                var state = arch.CreateProcessorState();
                imgLoader.EntryPoints.Add(new EntryPoint(
                                              entryAddr,
                                              rawFile.EntryPoint.Name,
                                              state));
            }
            return(imgLoader);
        }
Exemplo n.º 2
0
        public ImageLoader CreateDefaultImageLoader(string filename, byte[] image)
        {
            var imgLoader = new NullImageLoader(Services, filename, image);
            var rawFile   = cfgSvc.GetRawFile(DefaultToFormat);

            if (rawFile == null)
            {
                this.Services.RequireService <DecompilerEventListener>().Warn(
                    new NullCodeLocation(""),
                    "The format of the file is unknown.");
                return(imgLoader);
            }

            return(CreateRawImageLoader(image, imgLoader, rawFile));
        }
Exemplo n.º 3
0
        private ImageLoader CreateRawImageLoader(string filename, byte[] image, RawFileElement rawFile)
        {
            var       arch = cfgSvc.GetArchitecture(rawFile.Architecture);
            var       env  = cfgSvc.GetEnvironment(rawFile.Environment);
            IPlatform platform;

            if (env != null)
            {
                platform = env.Load(Services, arch);
            }
            else
            {
                platform = new DefaultPlatform(Services, arch);
            }

            Address entryAddr = null;
            Address baseAddr;

            if (arch.TryParseAddress(rawFile.BaseAddress, out baseAddr))
            {
                entryAddr = GetRawBinaryEntryAddress(rawFile, image, arch, baseAddr);
            }
            var imgLoader = new NullImageLoader(Services, filename, image)
            {
                Architecture         = arch,
                Platform             = platform,
                PreferredBaseAddress = entryAddr,
            };
            Address addrEp;

            if (rawFile.EntryPoint != null)
            {
                if (!string.IsNullOrEmpty(rawFile.EntryPoint.Address))
                {
                    arch.TryParseAddress(rawFile.EntryPoint.Address, out addrEp);
                }
                else
                {
                    addrEp = baseAddr;
                }
                imgLoader.EntryPoints.Add(new ImageSymbol(addrEp)
                {
                    Type = SymbolType.Procedure
                });
            }
            return(imgLoader);
        }
Exemplo n.º 4
0
        public ImageLoader CreateDefaultImageLoader(string filename, byte[] image)
        {
            var imgLoader = new NullImageLoader(Services, filename, image);
            var rawFile   = cfgSvc.GetRawFile(DefaultToFormat);

            if (rawFile == null)
            {
                this.Services.RequireService <DecompilerEventListener>().Warn(
                    new NullCodeLocation(""),
                    "The format of the file is unknown.");
                return(imgLoader);
            }
            var      arch = cfgSvc.GetArchitecture(rawFile.Architecture);
            var      env  = cfgSvc.GetEnvironment(rawFile.Environment);
            Platform platform;
            Address  baseAddr;
            Address  entryAddr;

            if (env != null)
            {
                platform = env.Load(Services, arch);
            }
            else
            {
                platform = new DefaultPlatform(Services, arch);
            }
            imgLoader.Architecture = arch;
            imgLoader.Platform     = platform;
            if (arch.TryParseAddress(rawFile.BaseAddress, out baseAddr))
            {
                imgLoader.PreferredBaseAddress = baseAddr;
                entryAddr = baseAddr;
                if (!string.IsNullOrEmpty(rawFile.EntryPoint.Address))
                {
                    if (!arch.TryParseAddress(rawFile.EntryPoint.Address, out entryAddr))
                    {
                        entryAddr = baseAddr;
                    }
                }
                var state = arch.CreateProcessorState();
                imgLoader.EntryPoints.Add(new EntryPoint(
                                              entryAddr,
                                              rawFile.EntryPoint.Name,
                                              state));
            }
            return(imgLoader);
        }
Exemplo n.º 5
0
        public Program LoadRawImage(string filename, byte[] image, Address addrLoad, LoadDetails details)
        {
            var arch     = cfgSvc.GetArchitecture(details.ArchitectureName);
            var platform = cfgSvc.GetEnvironment(details.PlatformName).Load(Services, arch);

            if (addrLoad == null)
            {
                if (!arch.TryParseAddress(details.LoadAddress, out addrLoad))
                {
                    throw new ApplicationException(
                              "Unable to determine base address for executable. A default address should have been present in the reko.config file.");
                }
            }
            Program program;

            if (!string.IsNullOrEmpty(details.LoaderName))
            {
                var imgLoader = CreateCustomImageLoader(Services, details.LoaderName, filename, image);
                program = imgLoader.Load(addrLoad, arch, platform);
            }
            else
            {
                var imgLoader = new NullImageLoader(Services, filename, image);
                program = new Program(
                    CreatePlatformSegmentMap(platform, addrLoad, image),
                    arch,
                    platform);
                Address addrEp;
                if (details.EntryPoint != null && arch.TryParseAddress(details.EntryPoint.Address, out addrEp))
                {
                    program.EntryPoints.Add(addrEp, new Core.ImageSymbol(addrEp)
                    {
                        Type = SymbolType.Procedure
                    });
                }
            }
            program.Name             = Path.GetFileName(filename);
            program.User.Processor   = arch.Name;
            program.User.Environment = platform.Name;
            program.User.Loader      = details.LoaderName;
            program.ImageMap         = program.SegmentMap.CreateImageMap();
            return(program);
        }