//$TODO: change signature to OpenAs(raw) public bool OpenBinaryAs( string file, LoadDetails details) { var ldr = Services.RequireService <ILoader>(); this.Decompiler = CreateDecompiler(ldr); IWorkerDialogService svc = Services.RequireService <IWorkerDialogService>(); svc.StartBackgroundWork("Loading program", delegate() { Program program = Decompiler.LoadRawImage(file, details); }); var browserSvc = Services.RequireService <IProjectBrowserService>(); if (Decompiler.Project != null) { browserSvc.Load(Decompiler.Project); ShowLowLevelWindow(); } else { browserSvc.Clear(); } return(false); // We never open projects this way. }
public bool OpenBinaryAs(string initialFilename) { IOpenAsDialog dlg = null; try { dlg = dlgFactory.CreateOpenAsDialog(initialFilename); if (uiSvc.ShowModalDialog(dlg) != DialogResult.OK) { return(false); } string fileName = dlg.FileName.Text; LoadDetails details = dlg.GetLoadDetails(); CloseProject(); SwitchInteractor(InitialPageInteractor); pageInitial.OpenBinaryAs(fileName, details); if (fileName.EndsWith(Project_v5.FileExtension)) { ProjectFileName = fileName; } } catch (Exception ex) { uiSvc.ShowError( ex, string.Format("An error occurred when opening the file {0}.", dlg.FileName.Text)); } return(true); }
public bool SaveLoadDetails(LoadDetails loadDetails) { var db = new EfDbContext(); db.LoadDetails.Add(loadDetails); db.SaveChanges(); return(true); }
private void DecompileRawImage(Dictionary <string, object> pArgs) { try { var arch = config.GetArchitecture((string)pArgs["--arch"]); if (arch == null) { throw new ApplicationException(string.Format("Unknown architecture {0}", pArgs["--arch"])); } if (pArgs.TryGetValue("--arch-options", out var oArchOptions)) { var archOptions = (Dictionary <string, object>)oArchOptions; arch.LoadUserOptions(archOptions); } pArgs.TryGetValue("--env", out object sEnv); if (!arch.TryParseAddress((string)pArgs["--base"], out Address addrBase)) { throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", pArgs["--base"])); } pArgs.TryGetValue("--entry", out object oAddrEntry); pArgs.TryGetValue("--loader", out object sLoader); var loadDetails = new LoadDetails { LoaderName = (string)sLoader, ArchitectureName = (string)pArgs["--arch"], ArchitectureOptions = null, //$TODO: How do we handle options for command line? PlatformName = (string)sEnv, LoadAddress = (string)pArgs["--base"], EntryPoint = new EntryPointDefinition { Address = (string)oAddrEntry } }; var program = LoadProgram(pArgs, loadDetails); var state = CreateInitialState(arch, program.SegmentMap, pArgs); if (pArgs.TryGetValue("heuristics", out object oHeur)) { decompiler.Project.Programs[0].User.Heuristics = ((string[])oHeur).ToSortedSet(); } if (pArgs.TryGetValue("aggressive-branch-removal", out object oAggressiveBranchRemoval)) { decompiler.Project.Programs[0].User.AggressiveBranchRemoval = oAggressiveBranchRemoval is bool flag && flag; } decompiler.ScanPrograms(); decompiler.AnalyzeDataFlow(); decompiler.ReconstructTypes(); decompiler.StructureProgram(); decompiler.WriteDecompilerProducts(); } catch (Exception ex) { listener.Error(ex, "An error occurred during decompilation."); } }
/// <summary> /// Loads a program into memory using the additional information in /// <paramref name="raw"/>. Use this to decompile raw blobs of data. /// </summary> /// <param name="fileName">Name of the file to be loaded.</param> /// <param name="raw">Extra metadata supllied by the user.</param> public Program LoadRawImage(byte[] image, LoadDetails raw) { eventListener.ShowStatus("Loading raw bytes."); raw.ArchitectureOptions = raw.ArchitectureOptions ?? new Dictionary <string, object>(); var program = loader.LoadRawImage("image", image, null, raw); Project = AddProgramToProject("image", program); eventListener.ShowStatus("Raw bytes loaded."); return(program); }
/// <summary> /// load the list of churches /// </summary> private void SetupChurchList(bool feedOnly = true) { MainActivity main = this; //Initializer the church list cl = new LoadDetails(main, _churches, _title, "//SermonCasting/Church"); //set the playlist to the adapter items churchList.Adapter = cl.ChurchNames; }
/// <summary> /// Loads a program into memory, but performs no relocations. /// </summary> /// <param name="fileName"></param> /// <param name="arch"></param> /// <param name="platform"></param> public Program LoadRawImage(string fileName, LoadDetails raw) { eventListener.ShowStatus("Loading raw bytes."); byte[] image = loader.LoadImageBytes(fileName, 0); var program = loader.LoadRawImage(fileName, image, null, raw); Project = CreateDefaultProject(fileName, program); eventListener.ShowStatus("Raw bytes loaded."); return(program); }
/// <summary> /// Loads a program from a file into memory using the additional information in /// <paramref name="raw"/>. Use this to open files with insufficient or /// no metadata. /// </summary> /// <param name="fileName">Name of the file to be loaded.</param> /// <param name="raw">Extra metadata supllied by the user.</param> public Program LoadRawImage(string fileName, LoadDetails raw) { eventListener.ShowStatus("Loading raw bytes."); raw.ArchitectureOptions = raw.ArchitectureOptions ?? new Dictionary <string, object>(); byte[] image = loader.LoadImageBytes(fileName, 0); var program = loader.LoadRawImage(fileName, image, null, raw); Project = AddProgramToProject(fileName, program); WriteEntryPoints(program); eventListener.ShowStatus("Raw bytes loaded."); return(program); }
private Program LoadProgram(Dictionary <string, object> pArgs, LoadDetails loadDetails) { if (pArgs.ContainsKey("--data")) { var hexBytes = (string)pArgs["--data"]; var image = BytePattern.FromHexBytes(hexBytes).ToArray(); return(decompiler.LoadRawImage(image, loadDetails)); } else { return(decompiler.LoadRawImage((string)pArgs["filename"], loadDetails)); } }
/// <summary> /// Loads a Program from a flat image where all the metadata has been /// supplied by the user in <paramref name="details"/>. /// </summary> /// <param name="filename"></param> /// <param name="image"></param> /// <param name="addrLoad"></param> /// <param name="details"></param> /// <returns></returns> public Program LoadRawImage(string filename, byte[] image, Address addrLoad, LoadDetails details) { var arch = cfgSvc.GetArchitecture(details.ArchitectureName); arch.LoadUserOptions(details.ArchitectureOptions); 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."); } } if (addrLoad.DataType.BitSize == 16 && image.Length > 65535) { //$HACK: this works around issues when a large ROM image is read // for a 8- or 16-bit processor. Once we have a story for overlays // this can go away. var newImage = new byte[65535]; Array.Copy(image, newImage, newImage.Length); image = newImage; } var imgLoader = CreateCustomImageLoader(Services, details.LoaderName, filename, image); var program = imgLoader.Load(addrLoad, arch, platform); if (details.EntryPoint != null && arch.TryParseAddress(details.EntryPoint.Address, out Address 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.User.LoadAddress = addrLoad; program.Architecture.PostprocessProgram(program); program.ImageMap = program.SegmentMap.CreateImageMap(); return(program); }
/// <summary> /// Loads a Program from a flat image where all the metadata has been /// supplied by the user in <paramref name="details"/>. /// </summary> /// <param name="filename"></param> /// <param name="image"></param> /// <param name="addrLoad"></param> /// <param name="details"></param> /// <returns></returns> 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 segmentMap = CreatePlatformSegmentMap(platform, addrLoad, image); program = new Program( segmentMap, 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.User.LoadAddress = addrLoad; program.ImageMap = program.SegmentMap.CreateImageMap(); return(program); }
static void Main(string[] args) { var stopwatch = new Stopwatch(); stopwatch.Start(); var loadDetails = new LoadDetails(); Console.WriteLine("Starting to load files"); //Save structure var repo = new InMemoryDataStore(PathToDblpXml, PathToBhtFolder); var saver = new EntityFrameWorkSaver(100); Console.WriteLine("Starting to save structure"); //saver.SaveConferences(repo.Conferences); saver.SaveConferencesWithAddedAuthors(repo.Conferences, XmlExtractor.Read(PathToDblpXml).Where(k => (k.Value.StartsWith("<inproceeding")) || k.Value.StartsWith("<proceeding"))); repo = null; saver = null; //Add Authors //Console.WriteLine("Updating datasets with authors"); //saver = new EntityFrameWorkSaver(Settings.Default.BatchSize); //saver.UpdateStructureSetAuthor(XmlExtractor.Read(PathToDblpXml).Where(k => (k.Value.StartsWith("<inproceeding")) || k.Value.StartsWith("<proceeding"))); //Add rawdata Console.WriteLine("Starting to load files"); saver = new EntityFrameWorkSaver(Settings.Default.BatchSize); saver.SaveBibTexEntries(XmlExtractor.Read(PathToDblpXml).Where(k => (k.Value.StartsWith("<inproceeding")) || k.Value.StartsWith("<proceeding")).Select(t => new BibTexEntry() { Key = t.Key, Content = t.Value.ToBibTeX() })); stopwatch.Stop(); loadDetails.LoadTime = stopwatch.Elapsed; loadDetails.SizeOfXml = new FileInfo(PathToDblpXml).Length; loadDetails.LastLoaded = DateTime.UtcNow; saver.SaveLoadDetails(loadDetails); }
//$TODO: change signature to OpenAs(raw) public bool OpenBinaryAs( string file, LoadDetails details) { var ldr = Services.RequireService <ILoader>(); this.Decompiler = CreateDecompiler(ldr); IWorkerDialogService svc = Services.RequireService <IWorkerDialogService>(); svc.StartBackgroundWork("Loading program", delegate() { Program program = Decompiler.LoadRawImage(file, details); }); 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, LoadDetails details) { var ldr = Services.RequireService <ILoader>(); IWorkerDialogService svc = Services.RequireService <IWorkerDialogService>(); if (!svc.StartBackgroundWork("Loading program", delegate() { var eventListener = Services.RequireService <DecompilerEventListener>(); eventListener.ShowStatus("Loading source program."); var imageUri = ImageLocation.FromUri(file); Program program = ldr.LoadRawImage(imageUri, details); var project = Project.FromSingleProgram(program); this.Decompiler = CreateDecompiler(project); Decompiler.ExtractResources(); eventListener.ShowStatus("Source program loaded."); })) { return(false); } var browserSvc = Services.RequireService <IProjectBrowserService>(); var procListSvc = Services.RequireService <IProcedureListService>(); if (Decompiler.Project is not null) { browserSvc.Load(Decompiler.Project); browserSvc.Show(); procListSvc.Clear(); ShowLowLevelWindow(); return(true); } else { browserSvc.Clear(); procListSvc.Clear(); return(false); } }
public bool OpenBinaryAs(string initialFilename) { IOpenAsDialog dlg = null; IProcessorArchitecture arch = null; try { dlg = dlgFactory.CreateOpenAsDialog(); dlg.FileName.Text = initialFilename; dlg.Services = sc; dlg.ArchitectureOptions = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); if (uiSvc.ShowModalDialog(dlg) != DialogResult.OK) { return(false); } var rawFileOption = (ListOption)dlg.RawFileTypes.SelectedValue; string archName = null; string envName = null; string sAddr = null; string loader = null; EntryPointDefinition entry = null; if (rawFileOption != null && rawFileOption.Value != null) { var raw = (RawFileDefinition)rawFileOption.Value; loader = raw.Loader; archName = raw.Architecture; envName = raw.Environment; sAddr = raw.BaseAddress; entry = raw.EntryPoint; } ArchitectureDefinition archOption = dlg.GetSelectedArchitecture(); PlatformDefinition envOption = dlg.GetSelectedEnvironment(); archName = archName ?? archOption?.Name; envName = envName ?? envOption?.Name; sAddr = sAddr ?? dlg.AddressTextBox.Text.Trim(); arch = config.GetArchitecture(archName); if (arch == null) { throw new InvalidOperationException(string.Format("Unable to load {0} architecture.", archName)); } arch.LoadUserOptions(dlg.ArchitectureOptions); if (!arch.TryParseAddress(sAddr, out var addrBase)) { throw new ApplicationException(string.Format("'{0}' doesn't appear to be a valid address.", sAddr)); } var details = new LoadDetails { LoaderName = loader, ArchitectureName = archName, ArchitectureOptions = dlg.ArchitectureOptions, PlatformName = envName, LoadAddress = sAddr, EntryPoint = entry, }; OpenBinary(dlg.FileName.Text, (f) => pageInitial.OpenBinaryAs(f, details), f => false); } catch (Exception ex) { uiSvc.ShowError( ex, string.Format("An error occurred when opening the binary file {0}.", dlg.FileName.Text)); } return(true); }
public bool OpenBinaryAs(string file, LoadDetails details) { throw new NotImplementedException(); }
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); }
public StatusViewModel(LoadDetails loadDetails, List <StatusListElement> elements) { LoadDetails = loadDetails; Elements = elements; }