示例#1
0
文件: Loader.cs 项目: heruix/reko
 public static Address GetRawBinaryEntryAddress(
     RawFileElement rawFile,
     byte[] image,
     IProcessorArchitecture arch,
     Address baseAddr)
 {
     if (!string.IsNullOrEmpty(rawFile.EntryPoint.Address))
     {
         if (arch.TryParseAddress(rawFile.EntryPoint.Address, out Address entryAddr))
         {
             if (rawFile.EntryPoint.Follow)
             {
                 var rdr  = arch.CreateImageReader(new MemoryArea(baseAddr, image), entryAddr);
                 var addr = arch.ReadCodeAddress(0, rdr, arch.CreateProcessorState());
                 return(addr);
             }
             else
             {
                 return(entryAddr);
             }
         }
         else
         {
             return(baseAddr);
         }
     }
     return(baseAddr);
 }
示例#2
0
        public Program LoadRawImage(string fileName, RawFileElement raw)
        {
            eventListener.ShowStatus("Loading raw bytes.");
            byte[] image   = loader.LoadImageBytes(fileName, 0);
            var    program = loader.LoadRawImage(fileName, image, raw);

            Project = CreateDefaultProject(fileName, program);
            eventListener.ShowStatus("Raw bytes loaded.");
            return(program);
        }
示例#3
0
        public Program LoadRawImage(string filename, byte[] image, RawFileElement raw)
        {
            var imgLoader = CreateRawImageLoader(image, new NullImageLoader(Services, filename, image), raw);
            var program   = imgLoader.Load(imgLoader.PreferredBaseAddress);

            program.ImageMap = CreatePlatformMemoryMap(program.Platform, imgLoader.PreferredBaseAddress, image);
            program.Name     = Path.GetFileName(filename);
            var relocations = imgLoader.Relocate(program, imgLoader.PreferredBaseAddress);

            foreach (var ep in relocations.EntryPoints)
            {
                program.EntryPoints.Add(ep.Address, ep);
            }
            program.FunctionHints.AddRange(relocations.Functions);
            return(program);
        }
示例#4
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);
        }
示例#5
0
        public Program LoadRawImage(string filename, byte[] image, RawFileElement raw)
        {
            var imgLoader = CreateRawImageLoader(image, new NullImageLoader(Services, filename, image), raw);
            var program   = imgLoader.Load(imgLoader.PreferredBaseAddress);

            program.SegmentMap = CreatePlatformSegmentMap(program.Platform, imgLoader.PreferredBaseAddress, image);
            program.Name       = Path.GetFileName(filename);
            var relocations = imgLoader.Relocate(program, imgLoader.PreferredBaseAddress);

            foreach (var sym in relocations.Symbols.Values)
            {
                program.ImageSymbols[sym.Address] = sym;
            }
            foreach (var ep in relocations.EntryPoints)
            {
                program.EntryPoints.Add(ep.Address, ep);
            }
            program.ImageMap = program.SegmentMap.CreateImageMap();
            return(program);
        }
示例#6
0
        public bool OpenBinaryAs(
            string file,
            string arch,
            string platform,
            Address addrBase,
            RawFileElement raw)
        {
            var ldr = Services.RequireService <ILoader>();

            this.Decompiler = CreateDecompiler(ldr);
            IWorkerDialogService svc = Services.RequireService <IWorkerDialogService>();

            svc.StartBackgroundWork("Loading program", delegate()
            {
                Program program;
                if (raw != null)
                {
                    program = Decompiler.LoadRawImage(file, raw);
                }
                else
                {
                    program = Decompiler.LoadRawImage(file, arch, platform, addrBase);
                }
                program.User.Processor   = arch;
                program.User.Environment = platform;
                program.User.LoadAddress = program.ImageMap.BaseAddress;;
                svc.SetCaption("Scanning source program.");
                Decompiler.ScanPrograms();
            });
            var browserSvc = Services.RequireService <IProjectBrowserService>();

            browserSvc.Load(Decompiler.Project);
            if (Decompiler.Project.Programs.Count > 0)
            {
                var memSvc = Services.RequireService <ILowLevelViewService>();
                memSvc.ViewImage(Decompiler.Project.Programs.First());
            }
            return(false);   // We never open projects this way.
        }
示例#7
0
        public bool OpenBinaryAs()
        {
            IOpenAsDialog          dlg  = null;
            IProcessorArchitecture arch = null;

            try
            {
                dlg          = dlgFactory.CreateOpenAsDialog();
                dlg.Services = sc;
                if (uiSvc.ShowModalDialog(dlg) != DialogResult.OK)
                {
                    return(true);
                }

                var               rawFileOption = (ListOption)dlg.RawFileTypes.SelectedValue;
                string            archName      = null;
                string            envName       = null;
                string            sAddr         = null;
                string            loader        = null;
                EntryPointElement entry         = null;

                if (rawFileOption != null && rawFileOption.Value != null)
                {
                    RawFileElement raw = null;
                    raw      = (RawFileElement)rawFileOption.Value;
                    loader   = raw.Loader;
                    archName = raw.Architecture;
                    envName  = raw.Environment;
                    sAddr    = raw.BaseAddress;
                    entry    = raw.EntryPoint;
                }
                archName = archName ?? (string)((ListOption)dlg.Architectures.SelectedValue).Value;
                var envOption = (OperatingEnvironment)((ListOption)dlg.Platforms.SelectedValue).Value;
                envName = envName ?? (envOption != null? envOption.Name : null);
                sAddr   = sAddr ?? dlg.AddressTextBox.Text.Trim();

                arch = config.GetArchitecture(archName);
                if (arch == null)
                {
                    throw new InvalidOperationException(string.Format("Unable to load {0} architecture.", archName));
                }
                Address addrBase;
                if (!arch.TryParseAddress(sAddr, out addrBase))
                {
                    throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", sAddr));
                }

                var details = new LoadDetails
                {
                    LoaderName       = loader,
                    ArchitectureName = archName,
                    PlatformName     = envName,
                    LoadAddress      = sAddr,
                    EntryPoint       = entry,
                };

                OpenBinary(dlg.FileName.Text, (f) =>
                           pageInitial.OpenBinaryAs(
                               f,
                               details));
            }
            catch (Exception ex)
            {
                uiSvc.ShowError(
                    ex,
                    string.Format("An error occurred when opening the binary file {0}.", dlg.FileName.Text));
            }
            return(true);
        }
示例#8
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);
        }
示例#9
0
 public bool OpenBinaryAs(
     string file, 
     string arch,
     string platform, 
     Address addrBase, 
     RawFileElement raw)
 {
     var ldr = Services.RequireService<ILoader>();
     this.Decompiler = CreateDecompiler(ldr);
     IWorkerDialogService svc = Services.RequireService<IWorkerDialogService>();
     svc.StartBackgroundWork("Loading program", delegate()
     {
         Program program;
         if (raw != null)
         {
            program = Decompiler.LoadRawImage(file, raw);
         }
         else
         {
            program= Decompiler.LoadRawImage(file, arch, platform, addrBase);
         }
         program.User.Processor = arch;
         program.User.Environment = platform;
         program.User.LoadAddress = program.ImageMap.BaseAddress; ;
         svc.SetCaption("Scanning source program.");
         Decompiler.ScanPrograms();
     });
     var browserSvc = Services.RequireService<IProjectBrowserService>();
     browserSvc.Load(Decompiler.Project);
     if (Decompiler.Project.Programs.Count > 0)
     {
         var memSvc = Services.RequireService<ILowLevelViewService>();
         memSvc.ViewImage(Decompiler.Project.Programs.First());
     }
     return false;   // We never open projects this way.
 }
 public bool OpenBinaryAs(string file, string arch, string platform, Address addrBase, RawFileElement raw)
 {
     throw new NotImplementedException();
 }
示例#11
0
文件: Decompiler.cs 项目: uxmal/reko
 public Program LoadRawImage(string fileName, RawFileElement raw)
 {
     eventListener.ShowStatus("Loading raw bytes.");
     byte[] image = loader.LoadImageBytes(fileName, 0);
     var program = loader.LoadRawImage(fileName, image, raw);
     Project = CreateDefaultProject(fileName, program);
     eventListener.ShowStatus("Raw bytes loaded.");
     return program;
 }
 public bool OpenBinaryAs(string file, string arch, string platform, Address addrBase, RawFileElement raw)
 {
     throw new NotImplementedException();
 }