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); }
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 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); }
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); }
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); }
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() { 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); }
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); }
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(); }
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(); }