Exemple #1
0
        public Program VisitInputFile(string projectFilePath, DecompilerInput_v5 sInput)
        {
            //$REVIEW: make this null
            //if (sInput.Filename == null)
            //    return null;
            var binAbsPath = ConvertToAbsolutePath(projectFilePath, sInput.Filename) !;
            var sUser      = sInput.User ?? new UserData_v4
            {
                ExtractResources = true,
                OutputFilePolicy = Program.SingleFilePolicy,
            };
            var     address = LoadAddress(sUser, this.arch !);
            Program program = LoadProgram(projectFilePath, sInput);

            LoadUserData(sUser, program, program.User, projectFilePath);
            program.Filename             = binAbsPath;
            program.DisassemblyDirectory = ConvertToAbsolutePath(projectFilePath, sInput.DisassemblyDirectory) !;
            program.SourceDirectory      = ConvertToAbsolutePath(projectFilePath, sInput.SourceDirectory) !;
            program.IncludeDirectory     = ConvertToAbsolutePath(projectFilePath, sInput.IncludeDirectory) !;
            program.ResourcesDirectory   = ConvertToAbsolutePath(projectFilePath, sInput.ResourcesDirectory) !;
            program.EnsureDirectoryNames(program.Filename);
            program.User.LoadAddress = address;
            ProgramLoaded?.Fire(this, new ProgramEventArgs(program));
            return(program);
        }
Exemple #2
0
        public Program VisitInputFile(string projectFilePath, DecompilerInput_v5 sInput)
        {
            //$REVIEW: make this null
            //if (sInput.Filename == null)
            //    return null;
            var binAbsPath = ConvertToAbsolutePath(projectFilePath, sInput.Filename) !;
            var bytes      = loader.LoadImageBytes(binAbsPath, 0);
            var sUser      = sInput.User ?? new UserData_v4
            {
                ExtractResources = true,
                OutputFilePolicy = Program.SingleFilePolicy,
            };
            var     address     = LoadAddress(sUser, this.arch);
            var     archOptions = XmlOptions.LoadIntoDictionary(sUser.Processor?.Options, StringComparer.OrdinalIgnoreCase);
            Program program;

            if (!string.IsNullOrEmpty(sUser.Loader))
            {
                // The presence of an explicit loader name prompts us to
                // use the LoadRawImage path.
                var archName = sUser.Processor?.Name;
                var platform = sUser.PlatformOptions?.Name;
                program = loader.LoadRawImage(binAbsPath, bytes, address, new LoadDetails
                {
                    LoaderName          = sUser.Loader,
                    ArchitectureName    = archName,
                    ArchitectureOptions = archOptions,
                    PlatformName        = platform,
                    LoadAddress         = sUser.LoadAddress,
                });
            }
            else
            {
                program = loader.LoadExecutable(binAbsPath, bytes, sUser.Loader, address)
                          ?? new Program(); // A previous save of the project was able to read the file,
                                            // but now we can't...
            }
            LoadUserData(sUser, program, program.User, projectFilePath);
            program.Filename             = binAbsPath;
            program.DisassemblyDirectory = ConvertToAbsolutePath(projectFilePath, sInput.DisassemblyDirectory);
            program.SourceDirectory      = ConvertToAbsolutePath(projectFilePath, sInput.SourceDirectory);
            program.IncludeDirectory     = ConvertToAbsolutePath(projectFilePath, sInput.IncludeDirectory);
            program.ResourcesDirectory   = ConvertToAbsolutePath(projectFilePath, sInput.ResourcesDirectory);
            program.EnsureDirectoryNames(program.Filename);
            program.User.LoadAddress = address;
            ProgramLoaded?.Fire(this, new ProgramEventArgs(program));
            return(program);
        }
Exemple #3
0
        /// <summary>
        /// Migrate DecompilerInput_v4 to DecompilerInput_v5.
        /// </summary>
        /// <remarks>
        /// Ignored fields (They existed in v4 but are unused in current code):
        ///     IntermediateFilename
        ///     GlobalsFilename
        /// </remarks>
        public static DecompilerInput_v5 MigrateDecompilerInput(DecompilerInput_v4 v4)
        {
            var v5 = new DecompilerInput_v5()
            {
                Filename             = v4.Filename,
                Comment              = v4.Comment,
                DisassemblyDirectory = v4.DisassemblyFilename != null?Path.GetDirectoryName(v4.DisassemblyFilename) : null,
                                           SourceDirectory = v4.OutputFilename != null?Path.GetDirectoryName(v4.OutputFilename) : null,
                                                                 IncludeDirectory = v4.TypesFilename != null?Path.GetDirectoryName(v4.TypesFilename) : null,
                                                                                        ResourcesDirectory = v4.ResourcesDirectory,
                                                                                        User = v4.User ?? new UserData_v4
                {
                    ExtractResources = true,
                }
            };

            if (string.IsNullOrWhiteSpace(v5.User.OutputFilePolicy))
            {
                v5.User.OutputFilePolicy = Program.SingleFilePolicy;
            }

            return(v5);
        }
Exemple #4
0
        private Program LoadProgram(string projectFilePath, DecompilerInput_v5 sInput)
        {
            var binAbsPath = ConvertToAbsolutePath(projectFilePath, sInput.Filename) !;
            var bytes      = loader.LoadImageBytes(binAbsPath, 0);
            var sUser      = sInput.User ?? new UserData_v4
            {
                ExtractResources = true,
                OutputFilePolicy = Program.SingleFilePolicy,
            };
            var     address     = LoadAddress(sUser, this.arch !);
            var     archOptions = XmlOptions.LoadIntoDictionary(sUser.Processor?.Options, StringComparer.OrdinalIgnoreCase);
            Program program;

            if (!string.IsNullOrEmpty(sUser.Loader))
            {
                // The presence of an explicit loader name prompts us to
                // use the LoadRawImage path.
                var archName = sUser.Processor?.Name;
                var platform = sUser.PlatformOptions?.Name;
                program = loader.LoadRawImage(binAbsPath, bytes, address, new LoadDetails
                {
                    LoaderName          = sUser.Loader,
                    ArchitectureName    = archName,
                    ArchitectureOptions = archOptions,
                    PlatformName        = platform,
                    LoadAddress         = sUser.LoadAddress,
                });
            }
            else
            {
                program = loader.LoadExecutable(binAbsPath, bytes, sUser.Loader, address)
                          ?? new Program(); // A previous save of the project was able to read the file,
                                            // but now we can't...
            }
            return(program);
        }